diff --git a/backends/platform/ios7/ios7_app_delegate.mm b/backends/platform/ios7/ios7_app_delegate.mm index 55b6c8b7b24..517e509e96c 100644 --- a/backends/platform/ios7/ios7_app_delegate.mm +++ b/backends/platform/ios7/ios7_app_delegate.mm @@ -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]; -} diff --git a/backends/platform/ios7/ios7_common.h b/backends/platform/ios7/ios7_common.h index 6374e0114b6..50b46117af5 100644 --- a/backends/platform/ios7/ios7_common.h +++ b/backends/platform/ios7/ios7_common.h @@ -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); diff --git a/backends/platform/ios7/ios7_misc.mm b/backends/platform/ios7/ios7_misc.mm new file mode 100644 index 00000000000..db9380ac208 --- /dev/null +++ b/backends/platform/ios7/ios7_misc.mm @@ -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 . + * + */ + +#include +#include +#include +#include +#include +#include "backends/platform/ios7/ios7_common.h" +#include + +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]); +} diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp index 7d43e8d468d..e27a095ef9e 100644 --- a/backends/platform/ios7/ios7_osys_main.cpp +++ b/backends/platform/ios7/ios7_osys_main.cpp @@ -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); diff --git a/backends/platform/ios7/module.mk b/backends/platform/ios7/module.mk index 2075dfe6e25..ddda4a6f5ed 100644 --- a/backends/platform/ios7/module.mk +++ b/backends/platform/ios7/module.mk @@ -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 \