On iOS the user only has access to the Documents directory via iTunes. Our folder structure is setup as such to read from the Res directory. This change allows users to drop in zip files into the Documents folder and the game will automatically move the zip file into the Res folder on app startup. Note, this is only done on app startup. If the game is running in the background, the user will need to quit the app ( kill it via the multithreaded task bar) and restart it.
Jailbroken devices have full access to the filesystem and don't have this restriction. although I do recommend that they do drop zip files into the Documents directory to reduce the risk of causing any undefined behavior with updating the config files while the game runs.
This commit is contained in:
@@ -106,8 +106,7 @@ JFileSystem::JFileSystem(const string & _userPath, const string & _systemPath)
|
|||||||
string userPath = _userPath;
|
string userPath = _userPath;
|
||||||
|
|
||||||
#ifdef IOS
|
#ifdef IOS
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
|
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
NSUserDomainMask, YES);
|
|
||||||
NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"];
|
NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"];
|
||||||
|
|
||||||
userPath = [documentsDirectory cStringUsingEncoding:1];
|
userPath = [documentsDirectory cStringUsingEncoding:1];
|
||||||
|
|||||||
@@ -21,21 +21,40 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
check for any zip files dropped into the documents directory. If so move them into the "Res" directory.
|
||||||
|
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];
|
||||||
|
|
||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
|
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
NSUserDomainMask, YES);
|
NSString *docsPath = [paths objectAtIndex: 0];
|
||||||
NSString *userResourceDirectory = [[paths objectAtIndex:0] stringByAppendingString: @"/Res"];
|
NSArray *docsPathContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: docsPath error:nil];
|
||||||
|
NSArray *resourceZipFiles = [docsPathContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.zip'"]];
|
||||||
if (![fileManager fileExistsAtPath: userResourceDirectory] )
|
NSString *resPath = [NSString stringWithFormat: @"%@/Res", docsPath];
|
||||||
|
NSError *error = nil;
|
||||||
|
for (NSString *zipFile in resourceZipFiles)
|
||||||
{
|
{
|
||||||
return NO;
|
NSString *oldPath = [NSString stringWithFormat: @"%@/%@", docsPath, zipFile];
|
||||||
|
NSString *newPath = [NSString stringWithFormat: @"%@/%@", resPath, zipFile];
|
||||||
|
|
||||||
|
[fileManager moveItemAtPath: oldPath toPath:newPath error: &error];
|
||||||
|
if ( error != nil )
|
||||||
|
{
|
||||||
|
NSLog(@"Error happened while trying to move %@ to %@: \n%@", oldPath, newPath, [error localizedDescription]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return YES;
|
NSArray *resDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: resPath error:nil];
|
||||||
|
NSArray *coreFiles = [resDirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self BEGINSWITH 'core_'"]];
|
||||||
|
if ([coreFiles count] > 0)
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user