summary refs log tree commit diff stats
path: root/Classes/Cart_CollectAppDelegate.m
diff options
context:
space:
mode:
Diffstat (limited to 'Classes/Cart_CollectAppDelegate.m')
-rwxr-xr-xClasses/Cart_CollectAppDelegate.m44
1 files changed, 39 insertions, 5 deletions
diff --git a/Classes/Cart_CollectAppDelegate.m b/Classes/Cart_CollectAppDelegate.m index 158f660..ba9d60b 100755 --- a/Classes/Cart_CollectAppDelegate.m +++ b/Classes/Cart_CollectAppDelegate.m
@@ -13,6 +13,7 @@
13#import "GameMode.h" 13#import "GameMode.h"
14#import "RootViewController.h" 14#import "RootViewController.h"
15#import "MainMenuLayer.h" 15#import "MainMenuLayer.h"
16#import "TestFlight.h"
16 17
17@implementation Cart_CollectAppDelegate 18@implementation Cart_CollectAppDelegate
18 19
@@ -42,6 +43,9 @@
42 43
43- (void) applicationDidFinishLaunching:(UIApplication*)application 44- (void) applicationDidFinishLaunching:(UIApplication*)application
44{ 45{
46 // REMOVE THIS LINE FOR RELEASE BUILDS
47 [TestFlight takeOff:@"66a3925c85c93e7628c14d167ff6c1b7_MjM4MTEyMDExLTA4LTE3IDEzOjEyOjQ4Ljg2NDE2OQ"];
48
45 [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; 49 [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
46 50
47 NSMutableDictionary* registerDefaults = [NSMutableDictionary dictionaryWithObjectsAndKeys: 51 NSMutableDictionary* registerDefaults = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@@ -138,6 +142,8 @@
138 142
139-(void) applicationDidEnterBackground:(UIApplication*)application { 143-(void) applicationDidEnterBackground:(UIApplication*)application {
140 [[CCDirector sharedDirector] stopAnimation]; 144 [[CCDirector sharedDirector] stopAnimation];
145
146 [[NSUserDefaults standardUserDefaults] synchronize];
141 147
142 if ([[CCDirector sharedDirector] runningScene].tag == GAME_SCENE) 148 if ([[CCDirector sharedDirector] runningScene].tag == GAME_SCENE)
143 { 149 {
@@ -190,20 +196,48 @@
190 { 196 {
191 NSString* databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; 197 NSString* databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
192 [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; 198 [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
193 //[fileManager release];
194 199
195 [userDefaults setInteger:1 forKey:@"databaseVersion"]; 200 [userDefaults setInteger:2 forKey:@"databaseVersion"];
201 }
202
203 if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK)
204 {
205 NSLog(@"Failed to open database");
196 } 206 }
197 207
208 // Database migrations!
198 if ([userDefaults integerForKey:@"databaseVersion"] < 1) 209 if ([userDefaults integerForKey:@"databaseVersion"] < 1)
199 { 210 {
200 // Upgrade the database to version 1, which is completely unnecessary as no prior version exists 211 // Upgrade the database to version 1, which is completely unnecessary as no prior version exists
201 } 212 }
202 213
203 if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) 214 if ([userDefaults integerForKey:@"databaseVersion"] < 2)
204 { 215 {
205 NSLog(@"Failed to open database"); 216 // Database version 2 adds a "gameMode" column to highscores to allow for multiple highscore lists
217 const char* sqlQuery = "ALTER TABLE highscores ADD gameMode varchar(255)";
218 sqlite3_stmt* compiled_statement;
219
220 if (sqlite3_prepare_v2(database, sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK)
221 {
222 sqlite3_step(compiled_statement);
223
224 sqlQuery = "UPDATE highscores SET gameMode = \"Collect\"";
225 if (sqlite3_prepare_v2(database, sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK)
226 {
227 sqlite3_step(compiled_statement);
228
229 NSLog(@"Updated database to version 2.");
230 [userDefaults setInteger:2 forKey:@"databaseVersion"];
231 } else {
232 NSLog(@"Error while updating database to version 2. '%s'", sqlite3_errmsg(database));
233 }
234 } else {
235 NSLog(@"Error while updating database to version 2. '%s'", sqlite3_errmsg(database));
236 }
206 } 237 }
238
239 // It's rather important that the database version gets saved
240 [userDefaults synchronize];
207 } 241 }
208 242
209 return database; 243 return database;