55 selector:@selector(dismissModalViewController) |
55 selector:@selector(dismissModalViewController) |
56 name: @"dismissModalView" |
56 name: @"dismissModalView" |
57 object:nil]; |
57 object:nil]; |
58 |
58 |
59 // now check if some configuration files are already set; if they are present it means that the current copy must be updated |
59 // now check if some configuration files are already set; if they are present it means that the current copy must be updated |
60 NSError *err = nil; |
60 BOOL doCreateFiles = NO; |
61 NSString *fileToCheck, *teamToCheck, *teamToUpdate, *schemeToCheck, *schemeToUpdate; |
|
62 NSString *resDir = [[NSBundle mainBundle] resourcePath]; |
61 NSString *resDir = [[NSBundle mainBundle] resourcePath]; |
63 |
62 |
64 NSString *dirToCheck = [NSString stringWithFormat:@"%@/done.txt",DOCUMENTS_FOLDER()]; |
63 NSString *versionFileToCheck = [NSString stringWithFormat:@"%@/version.txt",DOCUMENTS_FOLDER()]; |
65 if ([[NSFileManager defaultManager] fileExistsAtPath:dirToCheck] == NO) { |
64 if ([[NSFileManager defaultManager] fileExistsAtPath:versionFileToCheck]) { |
|
65 NSString *currentVersion = [NSString stringWithContentsOfFile:versionFileToCheck encoding:NSUTF8StringEncoding error:nil]; |
|
66 NSString *newVersion = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/Settings/version.txt",resDir] encoding:NSUTF8StringEncoding error:nil]; |
|
67 if ([currentVersion intValue] < [newVersion intValue]) { |
|
68 doCreateFiles = YES; |
|
69 [newVersion writeToFile:versionFileToCheck atomically:YES encoding:NSUTF8StringEncoding error:nil]; |
|
70 } |
|
71 } else { |
|
72 doCreateFiles = YES; |
|
73 [[NSFileManager defaultManager] copyItemAtPath:[NSString stringWithFormat:@"%@/Settings/version.txt",resDir] toPath:versionFileToCheck error:nil]; |
|
74 } |
|
75 |
|
76 |
|
77 if (doCreateFiles == YES) { |
|
78 NSError *err = nil; |
|
79 NSString *directoryToCheck, *fileToCheck, *fileToUpdate; |
66 DLog(@"Creating necessary files"); |
80 DLog(@"Creating necessary files"); |
67 |
81 |
68 // if the settings file is already present, we merge current preferences with the update |
82 // if the settings file is already present, we merge current preferences with the update |
69 fileToCheck = [NSString stringWithFormat:@"%@/Settings/settings.plist",resDir]; |
83 directoryToCheck = [NSString stringWithFormat:@"%@/Settings/settings.plist",resDir]; |
70 if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) { |
84 if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) { |
71 NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; |
85 NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; |
72 NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:fileToCheck]; |
86 NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:directoryToCheck]; |
73 [update addEntriesFromDictionary:settings]; |
87 [update addEntriesFromDictionary:settings]; |
74 [settings release]; |
88 [settings release]; |
75 [update writeToFile:SETTINGS_FILE() atomically:YES]; |
89 [update writeToFile:SETTINGS_FILE() atomically:YES]; |
76 [update release]; |
90 [update release]; |
77 } else |
91 } else |
78 [[NSFileManager defaultManager] copyItemAtPath:fileToCheck toPath:SETTINGS_FILE() error:&err]; |
92 [[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:SETTINGS_FILE() error:&err]; |
79 |
93 |
80 // if the teams are already present we merge the old teams if they still exist |
94 // if the teams are already present we merge the old teams if they still exist |
81 fileToCheck = [NSString stringWithFormat:@"%@/Settings/Teams",resDir]; |
95 directoryToCheck = [NSString stringWithFormat:@"%@/Settings/Teams",resDir]; |
82 if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()]) { |
96 if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()]) { |
83 for (NSString *str in [[NSFileManager defaultManager] contentsAtPath:fileToCheck]) { |
97 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryToCheck error:nil]) { |
84 teamToCheck = [NSString stringWithFormat:@"%@/%@",TEAMS_DIRECTORY(),str]; |
98 fileToCheck = [NSString stringWithFormat:@"%@/%@",TEAMS_DIRECTORY(),str]; |
85 teamToUpdate = [NSString stringWithFormat:@"%@/Settings/Teams/%@",resDir,str]; |
99 fileToUpdate = [NSString stringWithFormat:@"%@/Settings/Teams/%@",resDir,str]; |
86 if ([[NSFileManager defaultManager] fileExistsAtPath:teamToCheck]) { |
100 if ([[NSFileManager defaultManager] fileExistsAtPath:fileToCheck]) { |
87 NSDictionary *team = [[NSDictionary alloc] initWithContentsOfFile:teamToCheck]; |
101 NSDictionary *team = [[NSDictionary alloc] initWithContentsOfFile:fileToCheck]; |
88 NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:teamToUpdate]; |
102 NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:fileToUpdate]; |
89 [update addEntriesFromDictionary:team]; |
103 [update addEntriesFromDictionary:team]; |
90 [team release]; |
104 [team release]; |
91 [update writeToFile:teamToCheck atomically:YES]; |
105 [update writeToFile:fileToCheck atomically:YES]; |
92 [update release]; |
106 [update release]; |
93 } |
107 } |
94 } |
108 } |
95 } else |
109 } else |
96 [[NSFileManager defaultManager] copyItemAtPath:fileToCheck toPath:TEAMS_DIRECTORY() error:&err]; |
110 [[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:TEAMS_DIRECTORY() error:&err]; |
97 |
111 |
98 // the same holds for schemes (but they're arrays) |
112 // the same holds for schemes (but they're arrays) |
99 fileToCheck = [NSString stringWithFormat:@"%@/Settings/Schemes",resDir]; |
113 directoryToCheck = [NSString stringWithFormat:@"%@/Settings/Schemes",resDir]; |
100 if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()]) { |
114 if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()]) { |
101 for (NSString *str in [[NSFileManager defaultManager] contentsAtPath:fileToCheck]) { |
115 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryToCheck error:nil]) { |
102 schemeToCheck = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),str]; |
116 fileToCheck = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),str]; |
103 schemeToUpdate = [NSString stringWithFormat:@"%@/Settings/Schemes/%@",resDir,str]; |
117 fileToUpdate = [NSString stringWithFormat:@"%@/Settings/Schemes/%@",resDir,str]; |
104 if ([[NSFileManager defaultManager] fileExistsAtPath:schemeToCheck]) { |
118 if ([[NSFileManager defaultManager] fileExistsAtPath:fileToCheck]) { |
105 NSArray *scheme = [[NSArray alloc] initWithContentsOfFile:schemeToCheck]; |
119 NSArray *scheme = [[NSArray alloc] initWithContentsOfFile:fileToCheck]; |
106 NSArray *update = [[NSArray alloc] initWithContentsOfFile:schemeToUpdate]; |
120 NSArray *update = [[NSArray alloc] initWithContentsOfFile:fileToUpdate]; |
107 if ([update count] > [scheme count]) |
121 if ([update count] > [scheme count]) |
108 [update writeToFile:schemeToCheck atomically:YES]; |
122 [update writeToFile:fileToCheck atomically:YES]; |
109 [update release]; |
123 [update release]; |
110 [scheme release]; |
124 [scheme release]; |
111 } |
125 } |
112 } |
126 } |
113 } else |
127 } else |
114 [[NSFileManager defaultManager] copyItemAtPath:fileToCheck toPath:SCHEMES_DIRECTORY() error:&err]; |
128 [[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:SCHEMES_DIRECTORY() error:&err]; |
115 |
129 |
116 // we create weapons the first time only, they are autoupdated each time |
130 // we create weapons the first time only, they are autoupdated each time |
117 if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO) { |
131 if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO) { |
118 [[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY() |
132 [[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY() |
119 withIntermediateDirectories:YES |
133 withIntermediateDirectories:YES |