From f09ce07b062cdcf86962d53128399630a3dd5533 Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Thu, 5 Jan 2012 01:11:49 +0000 Subject: [PATCH] modified to create a Manifest file before game loads. This is for iOS only as the file handling will be difficult, I am doing this as a way to identify what is already loaded onto the device. --- JGE/src/iOS/wagicAppDelegate.m | 32 +++++++++++++++++++ .../UI/WagicDownloadProgressViewController.m | 12 +++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/JGE/src/iOS/wagicAppDelegate.m b/JGE/src/iOS/wagicAppDelegate.m index 8a389c7a6..39a9a024b 100755 --- a/JGE/src/iOS/wagicAppDelegate.m +++ b/JGE/src/iOS/wagicAppDelegate.m @@ -21,10 +21,40 @@ } +- (NSString *) getDirContents: (NSString *) path +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSArray *dirContents = [fileManager contentsOfDirectoryAtPath: path error:nil]; + NSMutableString *data = [[NSMutableString alloc] init ]; + for (NSString *filename in dirContents) + { + NSString *pathname = [NSString stringWithFormat: @"%@/%@", path, filename]; + [data appendFormat: @"%@\n", pathname]; + + BOOL isDirectory = [[fileManager attributesOfItemAtPath: pathname error: nil] objectForKey: NSFileType] == NSFileTypeDirectory; + if (isDirectory) + [data appendString: [self getDirContents: pathname]]; + } + + NSString *manifestList = [data stringByAppendingFormat: @"\n"]; + [data release]; + + return manifestList; +} + +- (void) createManifest: (NSString *)docsPath +{ + NSString *manifestFile = [docsPath stringByAppendingPathComponent:@"Manifest"]; + [[self getDirContents: docsPath] writeToFile:manifestFile atomically:YES encoding:NSUTF8StringEncoding error: nil]; + +} + /** 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 { NSFileManager *fileManager = [NSFileManager defaultManager]; @@ -57,6 +87,8 @@ NSArray *resDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: resPath error:nil]; NSArray *coreFiles = [resDirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self BEGINSWITH 'core_'"]]; + + [self createManifest: docsPath]; if ([coreFiles count] > 0) { return YES; diff --git a/projects/mtg/iOS/UI/WagicDownloadProgressViewController.m b/projects/mtg/iOS/UI/WagicDownloadProgressViewController.m index dafb623a8..111ac501e 100644 --- a/projects/mtg/iOS/UI/WagicDownloadProgressViewController.m +++ b/projects/mtg/iOS/UI/WagicDownloadProgressViewController.m @@ -40,21 +40,20 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip"; } // No longer needed. -- (void) unpackageResources +- (void) unpackageResources: (NSString *) folderName { - [self.downloadMessageStatus setText: @"Installing Game Resource Files"]; + [self.downloadMessageStatus setText: [NSString stringWithFormat: @"Updating User Game Resource Files: %@", folderName]]; NSError *error = nil; NSFileManager *fm = [NSFileManager defaultManager]; - NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, - NSUserDomainMask, YES); + NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *userDocumentsDirectory = [paths objectAtIndex:0]; - NSString *downloadFilePath = [[paths objectAtIndex: 0] stringByAppendingString: [NSString stringWithFormat: @"/%@", kDownloadFileName]]; + NSString *downloadFilePath = [userDocumentsDirectory stringByAppendingString: [NSString stringWithFormat: @"/%@.zip", folderName]]; ZipArchive *za = [[ZipArchive alloc] init]; if ([za UnzipOpenFile: downloadFilePath]) { - BOOL ret = [za UnzipFileTo: [NSString stringWithFormat: @"%@/Res/",userDocumentsDirectory] overWrite: YES]; + BOOL ret = [za UnzipFileTo: [NSString stringWithFormat: @"%@/User/",userDocumentsDirectory] overWrite: YES]; if (ret == NO) { // some error occurred @@ -127,7 +126,6 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip"; [request setAllowCompressedResponse: YES]; [request setCompletionBlock:^{ -// [self unpackageResources]; wagicAppDelegate *appDelegate = (wagicAppDelegate *)[[UIApplication sharedApplication] delegate]; NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter]; [dnc postNotificationName:@"readyToStartGame" object: appDelegate];