6
6
import com .intellij .openapi .components .*;
7
7
import com .intellij .util .xmlb .XmlSerializerUtil ;
8
8
import com .shuzijun .leetcode .plugin .model .Config ;
9
+ import com .shuzijun .leetcode .plugin .model .Constant ;
9
10
import com .shuzijun .leetcode .plugin .model .PluginConstant ;
10
11
import com .shuzijun .leetcode .plugin .utils .MessageUtils ;
11
12
import com .shuzijun .leetcode .plugin .utils .PropertiesUtils ;
13
+ import com .shuzijun .leetcode .plugin .utils .URLUtils ;
14
+ import org .apache .commons .lang3 .StringUtils ;
12
15
import org .jetbrains .annotations .NotNull ;
13
16
import org .jetbrains .annotations .Nullable ;
14
17
15
18
import java .io .File ;
16
19
import java .util .HashMap ;
20
+ import java .util .Iterator ;
17
21
import java .util .Map ;
18
22
19
23
/**
@@ -46,11 +50,27 @@ public void loadState(@NotNull PersistentConfig persistentConfig) {
46
50
}
47
51
48
52
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 ;
50
70
}
51
71
52
72
public Config getConfig () {
53
- Config config = initConfig . get ( INITNAME );
73
+ Config config = getInitConfig ( );
54
74
if (config == null ) {
55
75
MessageUtils .showAllWarnMsg ("warning" , PropertiesUtils .getInfo ("config.first" ));
56
76
throw new UnsupportedOperationException ("not configured:File -> settings->tools->leetcode plugin" );
@@ -69,10 +89,10 @@ public String getTempFilePath() {
69
89
}
70
90
71
91
public void savePassword (String password , String username ) {
72
- if (username == null || password == null ){
92
+ if (username == null || password == null ) {
73
93
return ;
74
94
}
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 ));
76
96
}
77
97
78
98
public String getPassword (String username ) {
0 commit comments