36 } |
36 } |
37 |
37 |
38 // check if some configuration files are already set; if they are present it means that the current copy must be updated |
38 // check if some configuration files are already set; if they are present it means that the current copy must be updated |
39 -(void) createNecessaryFiles { |
39 -(void) createNecessaryFiles { |
40 NSString *sourceFile, *destinationFile; |
40 NSString *sourceFile, *destinationFile; |
41 NSString *resDir = [[NSBundle mainBundle] resourcePath]; |
41 NSString *resourcesDir = [[NSBundle mainBundle] resourcePath]; |
42 DLog(@"Creating necessary files"); |
42 DLog(@"Creating necessary files"); |
43 |
43 |
44 // SAVES - just delete and overwrite |
44 // SAVES - just delete and overwrite |
45 if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()]) |
45 if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()]) |
46 [[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL]; |
46 [[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL]; |
47 [[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL]; |
47 [[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL]; |
48 |
48 |
49 // SETTINGS FILE - merge when present |
49 // SETTINGS FILE - merge when present |
50 NSString *baseSettingsFile = [NSString stringWithFormat:@"%@/Settings/settings.plist",resDir]; |
50 NSString *baseSettingsFile = [[NSString alloc] initWithFormat:@"%@/Settings/settings.plist",resourcesDir]; |
51 if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) { |
51 if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) { |
52 NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; |
52 NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; |
53 NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:baseSettingsFile]; |
53 NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:baseSettingsFile]; |
54 // the order of what adds what is important |
54 // the order of what adds what is important |
55 [update addEntriesFromDictionary:settings]; |
55 [update addEntriesFromDictionary:settings]; |
56 [settings release]; |
56 [settings release]; |
57 [update writeToFile:SETTINGS_FILE() atomically:YES]; |
57 [update writeToFile:SETTINGS_FILE() atomically:YES]; |
58 [update release]; |
58 [update release]; |
59 } else |
59 } else |
60 [[NSFileManager defaultManager] copyItemAtPath:baseSettingsFile toPath:SETTINGS_FILE() error:NULL]; |
60 [[NSFileManager defaultManager] copyItemAtPath:baseSettingsFile toPath:SETTINGS_FILE() error:NULL]; |
|
61 [baseSettingsFile release]; |
61 |
62 |
62 // TEAMS - update exisiting teams with new format |
63 // TEAMS - update exisiting teams with new format |
63 if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()] == NO) { |
64 if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()] == NO) { |
64 [[NSFileManager defaultManager] createDirectoryAtPath:TEAMS_DIRECTORY() |
65 [[NSFileManager defaultManager] createDirectoryAtPath:TEAMS_DIRECTORY() |
65 withIntermediateDirectories:YES |
66 withIntermediateDirectories:YES |
66 attributes:nil |
67 attributes:nil |
67 error:NULL]; |
68 error:NULL]; |
68 // we copy teams only the first time because it's unlikely that newer ones are going to be added |
69 // we copy teams only the first time because it's unlikely that newer ones are going to be added |
69 NSString *baseTeamsDir = [NSString stringWithFormat:@"%@/Settings/Teams",resDir]; |
70 NSString *baseTeamsDir = [[NSString alloc] initWithFormat:@"%@/Settings/Teams/",resourcesDir]; |
70 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseTeamsDir error:NULL]) { |
71 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseTeamsDir error:NULL]) { |
71 sourceFile = [baseTeamsDir stringByAppendingString:str]; |
72 sourceFile = [baseTeamsDir stringByAppendingString:str]; |
72 destinationFile = [TEAMS_DIRECTORY() stringByAppendingString:str]; |
73 destinationFile = [TEAMS_DIRECTORY() stringByAppendingString:str]; |
|
74 [[NSFileManager defaultManager] removeItemAtPath:destinationFile error:NULL]; |
73 [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL]; |
75 [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL]; |
74 } |
76 } |
|
77 [baseTeamsDir release]; |
75 } |
78 } |
76 // TODO: is merge needed? |
79 // TODO: is merge needed? |
77 |
80 |
78 // SCHEMES - update old stuff and add new stuff |
81 // SCHEMES - update old stuff and add new stuff |
79 if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()] == NO) |
82 if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()] == NO) |
81 withIntermediateDirectories:YES |
84 withIntermediateDirectories:YES |
82 attributes:nil |
85 attributes:nil |
83 error:NULL]; |
86 error:NULL]; |
84 // TODO: do the merge if necessary |
87 // TODO: do the merge if necessary |
85 // we overwrite the default ones because it is likely that new modes are added every release |
88 // we overwrite the default ones because it is likely that new modes are added every release |
86 NSString *baseSchemesDir = [NSString stringWithFormat:@"%@/Settings/Schemes",resDir]; |
89 NSString *baseSchemesDir = [[NSString alloc] initWithFormat:@"%@/Settings/Schemes/",resourcesDir]; |
87 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseSchemesDir error:NULL]) { |
90 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseSchemesDir error:NULL]) { |
88 sourceFile = [baseSchemesDir stringByAppendingString:str]; |
91 sourceFile = [baseSchemesDir stringByAppendingString:str]; |
89 destinationFile = [SCHEMES_DIRECTORY() stringByAppendingString:str]; |
92 destinationFile = [SCHEMES_DIRECTORY() stringByAppendingString:str]; |
|
93 [[NSFileManager defaultManager] removeItemAtPath:destinationFile error:NULL]; |
90 [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL]; |
94 [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL]; |
91 } |
95 } |
|
96 [baseSchemesDir release]; |
92 |
97 |
93 // WEAPONS - always overwrite |
98 // WEAPONS - always overwrite |
94 if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO) |
99 if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO) |
95 [[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY() |
100 [[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY() |
96 withIntermediateDirectories:YES |
101 withIntermediateDirectories:YES |