IOS7: Cleanup code to access Document and app bundle paths

This commit is contained in:
Thierry Crozat 2023-04-27 00:11:17 +01:00
parent f1f808f7a4
commit aaf6ed536f
5 changed files with 52 additions and 21 deletions

View file

@ -45,7 +45,7 @@
// Create the directory for savegames
NSFileManager *fm = [NSFileManager defaultManager];
NSString *documentPath = [NSString stringWithUTF8String:iOS7_getDocumentsDir()];
NSString *documentPath = [NSString stringWithUTF8String:iOS7_getDocumentsDir().c_str()];
NSString *savePath = [documentPath stringByAppendingPathComponent:@"Savegames"];
if (![fm fileExistsAtPath:savePath]) {
[fm createDirectoryAtPath:savePath withIntermediateDirectories:YES attributes:nil error:nil];
@ -142,14 +142,3 @@
}
@end
const char *iOS7_getDocumentsDir() {
NSArray *paths;
#if TARGET_OS_IOS
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
#else
paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
#endif
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory UTF8String];
}

View file

@ -117,7 +117,8 @@ bool iOS7_isBigDevice();
void iOS7_buildSharedOSystemInstance();
void iOS7_main(int argc, char **argv);
const char *iOS7_getDocumentsDir();
Common::String iOS7_getDocumentsDir();
Common::String iOS7_getAppBundleDir();
bool iOS7_touchpadModeEnabled();
uint getSizeNextPOT(uint size);

View file

@ -0,0 +1,44 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <Foundation/NSArray.h>
#include <Foundation/NSURL.h>
#include <Foundation/NSFileManager.h>
#include <Foundation/NSBundle.h>
#include <Foundation/NSPathUtilities.h>
#include "backends/platform/ios7/ios7_common.h"
#include <common/str.h>
Common::String iOS7_getDocumentsDir() {
#if TARGET_OS_IOS
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
#else
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] firstObject];
#endif
return Common::String([url fileSystemRepresentation]);
}
Common::String iOS7_getAppBundleDir() {
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
if (bundlePath == nil)
return Common::String();
return Common::String([bundlePath fileSystemRepresentation]);
}

View file

@ -98,13 +98,9 @@ OSystem_iOS7::OSystem_iOS7() :
ChRootFilesystemFactory *chFsFactory = new ChRootFilesystemFactory(_chrootBasePath);
_fsFactory = chFsFactory;
// Add virtual drive for bundle path
CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
if (fileUrl) {
UInt8 buf[MAXPATHLEN];
if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf)))
chFsFactory->addVirtualDrive("appbundle:", Common::String((const char *)buf));
CFRelease(fileUrl);
}
Common::String appBubdlePath = iOS7_getAppBundleDir();
if (!appBubdlePath.empty())
chFsFactory->addVirtualDrive("appbundle:", appBubdlePath);
initVideoContext();
@ -392,7 +388,7 @@ void iOS7_main(int argc, char **argv) {
//gDebugLevel = 10;
}
chdir(iOS7_getDocumentsDir());
chdir(iOS7_getDocumentsDir().c_str());
g_system = OSystem_iOS7::sharedInstance();
assert(g_system);

View file

@ -6,6 +6,7 @@ MODULE_OBJS := \
ios7_osys_sound.o \
ios7_osys_video.o \
ios7_osys_misc.o \
ios7_misc.o \
ios7_main.o \
ios7_video.o \
ios7_keyboard.o \