From 8f5ebc8109e2695d35c376c73225fb03703150a5 Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Mon, 2 Jan 2012 05:32:22 +0000 Subject: [PATCH] Modified system path defaults to utilize the User vs Res architecture. After reading some comments of the forum I realized I had implemented this all according to 0.16's design and not the new split architecture. All 'core_' zip files are now placed under 'Res' as before, but any other zip file will be put under the 'User' directory --- JGE/src/JFileSystem.cpp | 8 ++++---- JGE/src/iOS/wagicAppDelegate.m | 14 +++++++++++--- .../iOS/UI/WagicDownloadProgressViewController.m | 16 ++++++++++------ projects/mtg/wagic.xcodeproj/project.pbxproj | 2 ++ 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index 764f0b18c..c37840645 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -107,11 +107,11 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath) #ifdef IOS NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); - NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"]; + NSString *documentsDirectory = [paths objectAtIndex:0]; - userPath = [documentsDirectory cStringUsingEncoding:1]; - userPath += "/"; - systemPath = ""; + userPath = [[documentsDirectory stringByAppendingString: @"/User/"] cStringUsingEncoding:1]; + systemPath = [[documentsDirectory stringByAppendingString: @"/Res/"] cStringUsingEncoding:1]; + #elif defined (ANDROID) userPath = "/sdcard/Wagic/Res/"; systemPath = ""; diff --git a/JGE/src/iOS/wagicAppDelegate.m b/JGE/src/iOS/wagicAppDelegate.m index 512411c30..8a389c7a6 100755 --- a/JGE/src/iOS/wagicAppDelegate.m +++ b/JGE/src/iOS/wagicAppDelegate.m @@ -22,7 +22,7 @@ } /** - check for any zip files dropped into the documents directory. If so move them into the "Res" directory. + check for any zip files dropped into the documents directory. If so move them into the "User" directory. check for a "core" zip file in the Res directory. If it exists, then return YES. Otherwise, return NO. */ - (BOOL) hasResourceFiles @@ -32,18 +32,26 @@ NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsPath = [paths objectAtIndex: 0]; NSArray *docsPathContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: docsPath error:nil]; - NSArray *resourceZipFiles = [docsPathContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.zip'"]]; + NSCompoundPredicate *compoundPredicate = [[NSCompoundPredicate alloc] initWithType:NSAndPredicateType subpredicates: [NSArray arrayWithObjects: [NSPredicate predicateWithFormat:@"self ENDSWITH '.zip'"], [NSPredicate predicateWithFormat:@"NOT (self BEGINSWITH 'core_')"], nil]]; + + NSArray *resourceZipFiles = [docsPathContents filteredArrayUsingPredicate: compoundPredicate]; + NSString *userPath = [NSString stringWithFormat: @"%@/User", docsPath]; NSString *resPath = [NSString stringWithFormat: @"%@/Res", docsPath]; NSError *error = nil; + + if ( ([resourceZipFiles count] > 0 ) && ![fileManager fileExistsAtPath: userPath] ) + [fileManager createDirectoryAtPath: userPath withIntermediateDirectories: YES attributes:nil error:nil ]; + for (NSString *zipFile in resourceZipFiles) { NSString *oldPath = [NSString stringWithFormat: @"%@/%@", docsPath, zipFile]; - NSString *newPath = [NSString stringWithFormat: @"%@/%@", resPath, zipFile]; + NSString *newPath = [NSString stringWithFormat: @"%@/%@", userPath, zipFile]; [fileManager moveItemAtPath: oldPath toPath:newPath error: &error]; if ( error != nil ) { NSLog(@"Error happened while trying to move %@ to %@: \n%@", oldPath, newPath, [error localizedDescription]); + error = nil; } } diff --git a/projects/mtg/iOS/UI/WagicDownloadProgressViewController.m b/projects/mtg/iOS/UI/WagicDownloadProgressViewController.m index a9a8ea654..dafb623a8 100644 --- a/projects/mtg/iOS/UI/WagicDownloadProgressViewController.m +++ b/projects/mtg/iOS/UI/WagicDownloadProgressViewController.m @@ -39,7 +39,7 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip"; } - +// No longer needed. - (void) unpackageResources { [self.downloadMessageStatus setText: @"Installing Game Resource Files"]; @@ -93,12 +93,16 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip"; { NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); - NSString *userResourceDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"]; - NSString *downloadFilePath = [userResourceDirectory stringByAppendingString: [NSString stringWithFormat: @"/%@", kDownloadFileName]]; + NSString *systemResourceDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"]; + NSString *userResourceDirectory = [[paths objectAtIndex: 0] stringByAppendingString: @"/User"]; + NSString *downloadFilePath = [systemResourceDirectory stringByAppendingString: [NSString stringWithFormat: @"/%@", kDownloadFileName]]; NSError *error = nil; // make sure Res directory exists - if ( ![[NSFileManager defaultManager] fileExistsAtPath: userResourceDirectory] ) - [[NSFileManager defaultManager] createDirectoryAtPath:userResourceDirectory withIntermediateDirectories: YES attributes:nil error: &error]; + if ( ![[NSFileManager defaultManager] fileExistsAtPath: systemResourceDirectory] ) + [[NSFileManager defaultManager] createDirectoryAtPath:systemResourceDirectory withIntermediateDirectories: YES attributes:nil error: &error]; + // make sure the User directory exists as well + if ( ![[NSFileManager defaultManager] fileExistsAtPath: userResourceDirectory] ) + [[NSFileManager defaultManager] createDirectoryAtPath: userResourceDirectory withIntermediateDirectories: YES attributes:nil error: &error]; // if an error occurred while creating the directory, game can't really run so do something // TODO: throw out a notification and deal with error @@ -123,7 +127,7 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip"; [request setAllowCompressedResponse: YES]; [request setCompletionBlock:^{ - [self unpackageResources]; +// [self unpackageResources]; wagicAppDelegate *appDelegate = (wagicAppDelegate *)[[UIApplication sharedApplication] delegate]; NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter]; [dnc postNotificationName:@"readyToStartGame" object: appDelegate]; diff --git a/projects/mtg/wagic.xcodeproj/project.pbxproj b/projects/mtg/wagic.xcodeproj/project.pbxproj index c5a2dc160..0b363b0ff 100755 --- a/projects/mtg/wagic.xcodeproj/project.pbxproj +++ b/projects/mtg/wagic.xcodeproj/project.pbxproj @@ -2464,6 +2464,7 @@ "$(ARCHS_STANDARD_32_BIT)", ); CODE_SIGN_IDENTITY = "iPhone Distribution"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; COPY_PHASE_STRIP = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = wagic_Prefix.pch; @@ -2494,6 +2495,7 @@ ); PRODUCT_NAME = "wagic copy"; PROVISIONING_PROFILE = ""; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; };