project_files/HedgewarsMobile/Classes/MainMenuViewController.m
changeset 4463 1fe77f2bc1d1
parent 4358 0445d807193e
child 4547 b70004a576a3
equal deleted inserted replaced
4462:018b5642b873 4463:1fe77f2bc1d1
    35     return rotationManager(interfaceOrientation);
    35     return rotationManager(interfaceOrientation);
    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;
       
    41     NSString *resourcesDir = [[NSBundle mainBundle] resourcePath];
    40     NSString *resourcesDir = [[NSBundle mainBundle] resourcePath];
    42     DLog(@"Creating necessary files");
    41     DLog(@"Creating necessary files");
    43     
    42     
    44     // SAVES - just delete and overwrite
    43     // SAVES - just delete and overwrite
    45     if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()])
    44     if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()])
    67                                                    attributes:nil
    66                                                    attributes:nil
    68                                                         error:NULL];
    67                                                         error:NULL];
    69         // we copy teams only the first time because it's unlikely that newer ones are going to be added
    68         // we copy teams only the first time because it's unlikely that newer ones are going to be added
    70         NSString *baseTeamsDir = [[NSString alloc] initWithFormat:@"%@/Settings/Teams/",resourcesDir];
    69         NSString *baseTeamsDir = [[NSString alloc] initWithFormat:@"%@/Settings/Teams/",resourcesDir];
    71         for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseTeamsDir error:NULL]) {
    70         for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseTeamsDir error:NULL]) {
    72             sourceFile = [baseTeamsDir stringByAppendingString:str];
    71             NSString *sourceFile = [baseTeamsDir stringByAppendingString:str];
    73             destinationFile = [TEAMS_DIRECTORY() stringByAppendingString:str];
    72             NSString *destinationFile = [TEAMS_DIRECTORY() stringByAppendingString:str];
    74             [[NSFileManager defaultManager] removeItemAtPath:destinationFile error:NULL];
    73             [[NSFileManager defaultManager] removeItemAtPath:destinationFile error:NULL];
    75             [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL];
    74             [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL];
    76         }
    75         }
    77         [baseTeamsDir release];
    76         [baseTeamsDir release];
    78     }
    77     }
    79     // TODO: is merge needed?
    78     // merge not needed as format rarely changes
    80 
    79 
    81     // SCHEMES - update old stuff and add new stuff
    80     // SCHEMES - always overwrite and delete custom ones
    82     if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()] == NO)
    81     if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()] == YES)
    83         [[NSFileManager defaultManager] createDirectoryAtPath:SCHEMES_DIRECTORY()
    82         [[NSFileManager defaultManager] removeItemAtPath:SCHEMES_DIRECTORY() error:NULL];
    84                                   withIntermediateDirectories:YES
       
    85                                                    attributes:nil
       
    86                                                         error:NULL];
       
    87     // TODO: do the merge if necessary
       
    88     // we overwrite the default ones because it is likely that new modes are added every release
       
    89     NSString *baseSchemesDir = [[NSString alloc] initWithFormat:@"%@/Settings/Schemes/",resourcesDir];
    83     NSString *baseSchemesDir = [[NSString alloc] initWithFormat:@"%@/Settings/Schemes/",resourcesDir];
    90     for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseSchemesDir error:NULL]) {
    84     [[NSFileManager defaultManager] copyItemAtPath:baseSchemesDir toPath:SCHEMES_DIRECTORY() error:NULL];
    91         sourceFile = [baseSchemesDir stringByAppendingString:str];
    85     
    92         destinationFile = [SCHEMES_DIRECTORY() stringByAppendingString:str];
       
    93         [[NSFileManager defaultManager] removeItemAtPath:destinationFile error:NULL];
       
    94         [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL];
       
    95     }
       
    96     [baseSchemesDir release];
       
    97 
    86 
    98     // WEAPONS - always overwrite
    87     // WEAPONS - always overwrite
    99     if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO)
    88     if ([[NSFileManager defaultManager] fileExistsAtPath:WEAPONS_DIRECTORY()] == NO)
   100         [[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY()
    89         [[NSFileManager defaultManager] createDirectoryAtPath:WEAPONS_DIRECTORY()
   101                                   withIntermediateDirectories:YES
    90                                   withIntermediateDirectories:YES
   106     createWeaponNamed(@"Pro Mode", 2);
    95     createWeaponNamed(@"Pro Mode", 2);
   107     createWeaponNamed(@"Shoppa", 3);
    96     createWeaponNamed(@"Shoppa", 3);
   108     createWeaponNamed(@"Clean Slate", 4);
    97     createWeaponNamed(@"Clean Slate", 4);
   109     createWeaponNamed(@"Minefield", 5);
    98     createWeaponNamed(@"Minefield", 5);
   110     createWeaponNamed(@"Thinking with Portals", 6);
    99     createWeaponNamed(@"Thinking with Portals", 6);
       
   100     // merge not needed because weapons not present in the set are 0ed by GameSetup
   111 
   101 
   112     DLog(@"Success");
   102     DLog(@"Success");
   113 }
   103 }
   114 
   104 
   115 #pragma mark -
   105 #pragma mark -