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:
@@ -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 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.
|
check for a "core" zip file in the Res directory. If it exists, then return YES. Otherwise, return NO.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
- (BOOL) hasResourceFiles
|
- (BOOL) hasResourceFiles
|
||||||
{
|
{
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
@@ -57,6 +87,8 @@
|
|||||||
|
|
||||||
NSArray *resDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: resPath error:nil];
|
NSArray *resDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: resPath error:nil];
|
||||||
NSArray *coreFiles = [resDirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self BEGINSWITH 'core_'"]];
|
NSArray *coreFiles = [resDirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self BEGINSWITH 'core_'"]];
|
||||||
|
|
||||||
|
[self createManifest: docsPath];
|
||||||
if ([coreFiles count] > 0)
|
if ([coreFiles count] > 0)
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
|
|||||||
@@ -40,21 +40,20 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip";
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No longer needed.
|
// 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;
|
NSError *error = nil;
|
||||||
|
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
|
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
NSUserDomainMask, YES);
|
|
||||||
NSString *userDocumentsDirectory = [paths objectAtIndex:0];
|
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];
|
ZipArchive *za = [[ZipArchive alloc] init];
|
||||||
if ([za UnzipOpenFile: downloadFilePath])
|
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)
|
if (ret == NO)
|
||||||
{
|
{
|
||||||
// some error occurred
|
// some error occurred
|
||||||
@@ -127,7 +126,6 @@ static NSString *kDownloadFileName = @"core_017_iOS.zip";
|
|||||||
[request setAllowCompressedResponse: YES];
|
[request setAllowCompressedResponse: YES];
|
||||||
|
|
||||||
[request setCompletionBlock:^{
|
[request setCompletionBlock:^{
|
||||||
// [self unpackageResources];
|
|
||||||
wagicAppDelegate *appDelegate = (wagicAppDelegate *)[[UIApplication sharedApplication] delegate];
|
wagicAppDelegate *appDelegate = (wagicAppDelegate *)[[UIApplication sharedApplication] delegate];
|
||||||
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
|
||||||
[dnc postNotificationName:@"readyToStartGame" object: appDelegate];
|
[dnc postNotificationName:@"readyToStartGame" object: appDelegate];
|
||||||
|
|||||||
Reference in New Issue
Block a user