66import com .intellij .openapi .components .*;
77import com .intellij .util .xmlb .XmlSerializerUtil ;
88import com .shuzijun .leetcode .plugin .model .Config ;
9+ import com .shuzijun .leetcode .plugin .model .Constant ;
910import com .shuzijun .leetcode .plugin .model .PluginConstant ;
1011import com .shuzijun .leetcode .plugin .utils .MessageUtils ;
1112import com .shuzijun .leetcode .plugin .utils .PropertiesUtils ;
13+ import com .shuzijun .leetcode .plugin .utils .URLUtils ;
14+ import org .apache .commons .lang3 .StringUtils ;
1215import org .jetbrains .annotations .NotNull ;
1316import org .jetbrains .annotations .Nullable ;
1417
1518import java .io .File ;
1619import java .util .HashMap ;
20+ import java .util .Iterator ;
1721import java .util .Map ;
1822
1923/**
@@ -46,11 +50,27 @@ public void loadState(@NotNull PersistentConfig persistentConfig) {
4650 }
4751
4852 public Config getInitConfig () {
49- return initConfig .get (INITNAME );
53+ Config config = initConfig .get (INITNAME );
54+ if (config != null && config .getVersion () != null && config .getVersion () < Constant .PLUGIN_CONFIG_VERSION_3 ) {
55+ if (URLUtils .leetcodecnOld .equals (config .getUrl ())) {
56+ config .setUrl (URLUtils .leetcodecn );
57+ }
58+ Iterator <String > iterator = config .getUserCookie ().keySet ().iterator ();
59+ while (iterator .hasNext ()) {
60+ String key = iterator .next ();
61+ String value = config .getCookie (key );
62+ if (StringUtils .isBlank (value ) || key .startsWith (URLUtils .leetcodecnOld )) {
63+ iterator .remove ();
64+ }
65+ }
66+ config .setVersion (Constant .PLUGIN_CONFIG_VERSION_3 );
67+ setInitConfig (config );
68+ }
69+ return config ;
5070 }
5171
5272 public Config getConfig () {
53- Config config = initConfig . get ( INITNAME );
73+ Config config = getInitConfig ( );
5474 if (config == null ) {
5575 MessageUtils .showAllWarnMsg ("warning" , PropertiesUtils .getInfo ("config.first" ));
5676 throw new UnsupportedOperationException ("not configured:File -> settings->tools->leetcode plugin" );
@@ -69,10 +89,10 @@ public String getTempFilePath() {
6989 }
7090
7191 public void savePassword (String password , String username ) {
72- if (username == null || password == null ){
92+ if (username == null || password == null ) {
7393 return ;
7494 }
75- PasswordSafe .getInstance ().set (new CredentialAttributes (PluginConstant .PLUGIN_ID , username , this .getClass ()), new Credentials (username , password == null ? "" : password ));
95+ PasswordSafe .getInstance ().set (new CredentialAttributes (PluginConstant .PLUGIN_ID , username , this .getClass ()), new Credentials (username , password == null ? "" : password ));
7696 }
7797
7898 public String getPassword (String username ) {
0 commit comments