33 |
33 |
34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
35 return rotationManager(interfaceOrientation); |
35 return rotationManager(interfaceOrientation); |
36 } |
36 } |
37 |
37 |
38 // using a different thread for audio 'cos it's slow |
|
39 -(void) initAudioThread { |
|
40 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
41 // do somthing in the future |
|
42 [pool release]; |
|
43 } |
|
44 |
|
45 // 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 |
46 -(void) createNecessaryFiles { |
39 -(void) createNecessaryFiles { |
47 NSError *err = nil; |
40 NSString *sourceFile, *destinationFile; |
48 NSString *directoryToCheck, *fileToCheck, *fileToUpdate; |
|
49 NSString *resDir = [[NSBundle mainBundle] resourcePath]; |
41 NSString *resDir = [[NSBundle mainBundle] resourcePath]; |
50 DLog(@"Creating necessary files"); |
42 DLog(@"Creating necessary files"); |
51 |
43 |
52 // create an empty saves directory by deleting the previous one (saves are incompatible between releases) |
44 // SAVES - just delete and overwrite |
53 if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()]) |
45 if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()]) |
54 [[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL]; |
46 [[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL]; |
55 [[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL]; |
47 [[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL]; |
56 |
48 |
57 // if the settings file is already present, we merge current preferences with the update |
49 // SETTINGS FILE - merge when present |
58 fileToCheck = [NSString stringWithFormat:@"%@/Settings/settings.plist",resDir]; |
50 NSString *baseSettingsFile = [NSString stringWithFormat:@"%@/Settings/settings.plist",resDir]; |
59 if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) { |
51 if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) { |
60 NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; |
52 NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; |
61 NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:fileToCheck]; |
53 NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:baseSettingsFile]; |
|
54 // the order of what adds what is important |
62 [update addEntriesFromDictionary:settings]; |
55 [update addEntriesFromDictionary:settings]; |
63 [settings release]; |
56 [settings release]; |
64 [update writeToFile:SETTINGS_FILE() atomically:YES]; |
57 [update writeToFile:SETTINGS_FILE() atomically:YES]; |
65 [update release]; |
58 [update release]; |
66 } else |
59 } else |
67 [[NSFileManager defaultManager] copyItemAtPath:fileToCheck toPath:SETTINGS_FILE() error:&err]; |
60 [[NSFileManager defaultManager] copyItemAtPath:baseSettingsFile toPath:SETTINGS_FILE() error:NULL]; |
68 |
61 |
69 // TODO: scrap this and always copy the bundled files; update exisising ones in some way |
62 // TEAMS - update exisiting teams with new format |
70 // if the teams are already present we merge the old teams, else we copy new teams |
63 if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()] == NO) { |
71 directoryToCheck = [NSString stringWithFormat:@"%@/Settings/Teams",resDir]; |
64 [[NSFileManager defaultManager] createDirectoryAtPath:TEAMS_DIRECTORY() |
72 if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()]) { |
65 withIntermediateDirectories:YES |
73 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryToCheck error:&err]) { |
66 attributes:nil |
74 fileToCheck = [NSString stringWithFormat:@"%@/%@",TEAMS_DIRECTORY(),str]; |
67 error:NULL]; |
75 fileToUpdate = [NSString stringWithFormat:@"%@/Settings/Teams/%@",resDir,str]; |
68 // we copy teams only the first time because it's unlikely that newer ones are going to be added |
76 if ([[NSFileManager defaultManager] fileExistsAtPath:fileToCheck]) { |
69 NSString *baseTeamsDir = [NSString stringWithFormat:@"%@/Settings/Teams",resDir]; |
77 NSDictionary *team = [[NSDictionary alloc] initWithContentsOfFile:fileToCheck]; |
70 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseTeamsDir error:NULL]) { |
78 NSMutableDictionary *update = [[NSMutableDictionary alloc] initWithContentsOfFile:fileToUpdate]; |
71 sourceFile = [baseTeamsDir stringByAppendingString:str]; |
79 [update addEntriesFromDictionary:team]; |
72 destinationFile = [TEAMS_DIRECTORY() stringByAppendingString:str]; |
80 [team release]; |
73 [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL]; |
81 [update writeToFile:fileToCheck atomically:YES]; |
74 } |
82 [update release]; |
75 } |
83 } else |
76 // TODO: is merge needed? |
84 [[NSFileManager defaultManager] copyItemAtPath:fileToUpdate toPath:fileToCheck error:&err]; |
77 |
85 } |
78 // SCHEMES - update old stuff and add new stuff |
86 } else |
79 if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()] == NO) |
87 [[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:TEAMS_DIRECTORY() error:&err]; |
80 [[NSFileManager defaultManager] createDirectoryAtPath:SCHEMES_DIRECTORY() |
88 |
81 withIntermediateDirectories:YES |
89 // TODO: scrap this and always copy the bundled files; update exisising ones in some way |
82 attributes:nil |
90 // the same holds for schemes (but they're dictionaries containing arrays) |
83 error:NULL]; |
91 directoryToCheck = [NSString stringWithFormat:@"%@/Settings/Schemes",resDir]; |
84 // TODO: do the merge if necessary |
92 if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()]) { |
85 // we overwrite the default ones because it is likely that new modes are added every release |
93 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryToCheck error:nil]) { |
86 NSString *baseSchemesDir = [NSString stringWithFormat:@"%@/Settings/Schemes",resDir]; |
94 fileToCheck = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),str]; |
87 for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseSchemesDir error:NULL]) { |
95 fileToUpdate = [NSString stringWithFormat:@"%@/Settings/Schemes/%@",resDir,str]; |
88 sourceFile = [baseSchemesDir stringByAppendingString:str]; |
96 if ([[NSFileManager defaultManager] fileExistsAtPath:fileToCheck]) { |
89 destinationFile = [SCHEMES_DIRECTORY() stringByAppendingString:str]; |
97 NSDictionary *scheme = [[NSDictionary alloc] initWithContentsOfFile:fileToCheck]; |
90 [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL]; |
98 NSDictionary *update = [[NSDictionary alloc] initWithContentsOfFile:fileToUpdate]; |
91 } |
99 if ([[update objectForKey:@"basic"] count] > [[scheme objectForKey:@"basic"] count] || |
92 |
100 [[update objectForKey:@"gamemod"] count] > [[scheme objectForKey:@"gamemod"] count]) |
93 // WEAPONS - always overwrite |
101 [update writeToFile:fileToCheck atomically:YES]; |
|
102 [update release]; |
|
103 [scheme release]; |
|
104 } else |
|
105 [[NSFileManager defaultManager] copyItemAtPath:fileToUpdate toPath:fileToCheck error:&err]; |
|
106 } |
|
107 } else |
|
108 [[NSFileManager defaultManager] copyItemAtPath:directoryToCheck toPath:SCHEMES_DIRECTORY() error:&err]; |
|
109 |
|
110 // weapons are autoupdated at runtime but it's better to update then every new version |
|
111 if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO) |
94 if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO) |
112 [[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY() |
95 [[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY() |
113 withIntermediateDirectories:YES |
96 withIntermediateDirectories:YES |
114 attributes:nil |
97 attributes:nil |
115 error:&err]; |
98 error:NULL]; |
116 createWeaponNamed(@"Default", 0); |
99 createWeaponNamed(@"Default", 0); |
117 createWeaponNamed(@"Crazy", 1); |
100 createWeaponNamed(@"Crazy", 1); |
118 createWeaponNamed(@"Pro mode", 2); |
101 createWeaponNamed(@"Pro mode", 2); |
119 createWeaponNamed(@"Shoppa", 3); |
102 createWeaponNamed(@"Shoppa", 3); |
120 createWeaponNamed(@"Clean slate", 4); |
103 createWeaponNamed(@"Clean slate", 4); |
121 createWeaponNamed(@"Minefield", 5); |
104 createWeaponNamed(@"Minefield", 5); |
122 |
105 |
123 if (err != nil) |
106 DLog(@"Success"); |
124 DLog(@"%@", err); |
|
125 else |
|
126 DLog(@"Success"); |
|
127 } |
107 } |
128 |
108 |
129 #pragma mark - |
109 #pragma mark - |
130 -(void) viewDidLoad { |
110 -(void) viewDidLoad { |
131 [super viewDidLoad]; |
111 [super viewDidLoad]; |