Skip to content

Commit 4afc19b

Browse files
author
clowwindy
committed
can upgrade configuration from old version
1 parent 37335ff commit 4afc19b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ShadowsocksX/ProfileManager.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,24 @@ @implementation ProfileManager {
1414

1515
+ (Configuration *)configuration {
1616
NSData *data = [[NSUserDefaults standardUserDefaults] dataForKey:CONFIG_DATA_KEY];
17+
Configuration *configuration;
1718
if (data == nil) {
18-
// TODO load data from old version
19+
// upgrade data from old version
20+
configuration = [[Configuration alloc] init];
21+
configuration.profiles = [[NSMutableArray alloc] initWithCapacity:16];
22+
if ([ShadowsocksRunner isUsingPublicServer]) {
23+
configuration.current = -1;
24+
} else {
25+
configuration.current = 0;
26+
Profile *profile = [[Profile alloc] init];
27+
profile.server = [ShadowsocksRunner configForKey:kShadowsocksIPKey];
28+
profile.serverPort = [[ShadowsocksRunner configForKey:kShadowsocksPortKey] integerValue];
29+
profile.password = [ShadowsocksRunner configForKey:kShadowsocksPasswordKey];
30+
profile.method = [ShadowsocksRunner configForKey:kShadowsocksEncryptionKey];
31+
[((NSMutableArray *)configuration.profiles) addObject:profile];
32+
}
33+
return configuration;
1934
}
20-
Configuration *configuration;
2135
if (data == nil) {
2236
// load default configuration
2337
configuration = [[Configuration alloc] init];

0 commit comments

Comments
 (0)