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.

This commit is contained in:
techdragon.nguyen@gmail.com
2012-01-05 01:11:49 +00:00
parent b03449cbf6
commit f09ce07b06
2 changed files with 37 additions and 7 deletions

View File

@@ -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;

View File

@@ -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];