project_files/HedgewarsMobile/Classes/MainMenuViewController.m
changeset 6104 117bdf4e7af9
parent 6103 55ecfbf834e3
child 6105 29bf0ca70af9
equal deleted inserted replaced
6103:55ecfbf834e3 6104:117bdf4e7af9
    40     return rotationManager(interfaceOrientation);
    40     return rotationManager(interfaceOrientation);
    41 }
    41 }
    42 
    42 
    43 // check if some configuration files are already set; if they are present it means that the current copy must be updated
    43 // check if some configuration files are already set; if they are present it means that the current copy must be updated
    44 -(void) createNecessaryFiles {
    44 -(void) createNecessaryFiles {
    45     NSString *resourcesDir = [[NSBundle mainBundle] resourcePath];
       
    46     DLog(@"Creating necessary files");
    45     DLog(@"Creating necessary files");
       
    46     NSInteger index;
    47     
    47     
    48     // SAVES - just delete and overwrite
    48     // SAVES - just delete and overwrite
    49     if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()])
    49     if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()])
    50         [[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL];
    50         [[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL];
    51     [[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL];
    51     [[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY()
       
    52                               withIntermediateDirectories:NO
       
    53                                                attributes:nil
       
    54                                                     error:NULL];
    52     
    55     
    53     // SETTINGS - nsuserdefaults ftw
    56     // SETTINGS - nsuserdefaults ftw
    54     [CreationChamber createSettings];
    57     [CreationChamber createSettings];
    55 
    58 
    56     // TEAMS - update exisiting teams with new format
    59     // TEAMS - update exisiting teams with new format
    57     if ([[NSFileManager defaultManager] fileExistsAtPath:TEAMS_DIRECTORY()] == NO) {
    60     NSArray *teamNames = [[NSArray alloc] initWithObjects:@"Edit Me!",@"Ninjas",@"Pirates",@"Robots",nil];
    58         [[NSFileManager defaultManager] createDirectoryAtPath:TEAMS_DIRECTORY()
    61     index = 0;
    59                                   withIntermediateDirectories:YES
    62     for (NSString *name in teamNames)
    60                                                    attributes:nil
    63         [CreationChamber createTeamNamed:name ofType:index++ controlledByAI:[name isEqualToString:@"Robots"]];
    61                                                         error:NULL];
    64     [teamNames release];
    62         // we copy teams only the first time because it's unlikely that newer ones are going to be added
       
    63         NSString *baseTeamsDir = [[NSString alloc] initWithFormat:@"%@/Settings/Teams/",resourcesDir];
       
    64         for (NSString *str in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:baseTeamsDir error:NULL]) {
       
    65             NSString *sourceFile = [baseTeamsDir stringByAppendingString:str];
       
    66             NSString *destinationFile = [TEAMS_DIRECTORY() stringByAppendingString:str];
       
    67             [[NSFileManager defaultManager] removeItemAtPath:destinationFile error:NULL];
       
    68             [[NSFileManager defaultManager] copyItemAtPath:sourceFile toPath:destinationFile error:NULL];
       
    69         }
       
    70         [baseTeamsDir release];
       
    71     }
       
    72     // merge not needed as format rarely changes
       
    73 
    65 
    74     // SCHEMES - always overwrite and delete custom ones
    66     // SCHEMES - always overwrite and delete custom ones
    75     if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()] == YES)
    67     if ([[NSFileManager defaultManager] fileExistsAtPath:SCHEMES_DIRECTORY()] == YES)
    76         [[NSFileManager defaultManager] removeItemAtPath:SCHEMES_DIRECTORY() error:NULL];
    68         [[NSFileManager defaultManager] removeItemAtPath:SCHEMES_DIRECTORY() error:NULL];
    77     NSArray *schemeNames = [[NSArray alloc] initWithObjects:@"Default",@"Pro Mode",@"Shoppa",@"Clean Slate",@"Minefield",
    69     NSArray *schemeNames = [[NSArray alloc] initWithObjects:@"Default",@"Pro Mode",@"Shoppa",@"Clean Slate",
    78                             @"Barrel Mayhem",@"Tunnel Hogs",@"Fort Mode",@"Timeless",@"Thinking with Portals",@"King Mode",nil];
    70                             @"Minefield",@"Barrel Mayhem",@"Tunnel Hogs",@"Fort Mode",@"Timeless",
    79     NSInteger index = 0;
    71                             @"Thinking with Portals",@"King Mode",nil];
       
    72     index = 0;
    80     for (NSString *name in schemeNames)
    73     for (NSString *name in schemeNames)
    81         [CreationChamber createSchemeNamed:name ofType:index++];
    74         [CreationChamber createSchemeNamed:name ofType:index++];
    82     [schemeNames release];
    75     [schemeNames release];
    83 
    76 
    84     // WEAPONS - always overwrite as merge is not needed (missing weaps the set are 0ed automatically)
    77     // WEAPONS - always overwrite as merge is not needed (missing weaps are 0ed automatically)
    85     NSArray *weaponNames = [[NSArray alloc] initWithObjects:@"Default",@"Crazy",@"Pro Mode",@"Shoppa",@"Clean Slate",
    78     NSArray *weaponNames = [[NSArray alloc] initWithObjects:@"Default",@"Crazy",@"Pro Mode",@"Shoppa",@"Clean Slate",
    86                             @"Minefield",@"Thinking with Portals",nil];
    79                             @"Minefield",@"Thinking with Portals",nil];
    87     index = 0;
    80     index = 0;
    88     for (NSString *name in weaponNames)
    81     for (NSString *name in weaponNames)
    89         [CreationChamber createWeaponNamed:name ofType:index++];
    82         [CreationChamber createWeaponNamed:name ofType:index++];