From 0a2af525457d7b6b7e5fe7403b1092f020c8d5d6 Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Thu, 12 May 2011 00:45:17 +0000 Subject: [PATCH] Issue 656: game will now work out of the Documents directory. All settings and changes are saved and read from that directory now. TODO: Need to find a mechanism to allow updates to code without having to delete the app entirely. (hence the player data as well) Perhaps implement an option ingame to allow player to download images to the repository. Perhaps a front-end that allows users to first update the app with card images before starting the game. --- JGE/src/JFileSystem.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index 09b37b282..718f4ce2a 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -265,9 +265,20 @@ int JFileSystem::GetFileSize() void JFileSystem::SetResourceRoot(const string& resourceRoot) { #ifdef IOS - NSString *pathUTF8 = [NSString stringWithUTF8String: resourceRoot.c_str()]; - NSString *fullpath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:pathUTF8]; - mResourceRoot = [fullpath cStringUsingEncoding:1]; + //copy the RES folder over to the Documents folder + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSError *error; + NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, + NSUserDomainMask, YES); + NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"]; + + NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] + stringByAppendingPathComponent:@"Res"]; + // copy the Res folder over to the Documents directory if it doesn't exist. + if ( ![fileManager fileExistsAtPath: documentsDirectory]) + [fileManager copyItemAtPath:resourceDBFolderPath toPath:documentsDirectory error:&error]; + + mResourceRoot = [documentsDirectory cStringUsingEncoding:1]; mResourceRoot += "/"; #elif defined (ANDROID) mResourceRoot = "/sdcard/Wagic/Res/";