From 4243110f560d9a3c73b190b004c0dff7526a9baa Mon Sep 17 00:00:00 2001 From: meancoot Date: Tue, 11 Jun 2013 06:07:09 -0400 Subject: [PATCH] (iOS) Fix major regression that can break file loading (since 99990173ccafe76af54b334bea854da17eda765a); Simplify the variables used to hold system paths --- ios/RetroArch/RAModuleInfo.m | 4 +-- ios/RetroArch/RetroArch_iOS.h | 7 ++-- ios/RetroArch/browser/browser.m | 4 +-- ios/RetroArch/main.m | 60 ++++++++++++++++--------------- ios/RetroArch/settings/settings.m | 2 +- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/ios/RetroArch/RAModuleInfo.m b/ios/RetroArch/RAModuleInfo.m index 0a7834c74e..cba6a0583a 100644 --- a/ios/RetroArch/RAModuleInfo.m +++ b/ios/RetroArch/RAModuleInfo.m @@ -51,7 +51,7 @@ static NSMutableArray* moduleList; config_get_string(newInfo.data, "supported_extensions", &extensions); } - newInfo.configPath = [NSString stringWithFormat:@"%@/%@.cfg", [RetroArch_iOS get].system_directory, [[newInfo.path lastPathComponent] stringByDeletingPathExtension]]; + newInfo.configPath = [NSString stringWithFormat:@"%@/%@.cfg", [RetroArch_iOS get].systemDirectory, [[newInfo.path lastPathComponent] stringByDeletingPathExtension]]; newInfo.displayName = dispname ? [NSString stringWithUTF8String:dispname] : [[newInfo.path lastPathComponent] stringByDeletingPathExtension]; newInfo.supportedExtensions = extensions ? [[NSString stringWithUTF8String:extensions] componentsSeparatedByString:@"|"] : [NSArray array]; @@ -138,7 +138,7 @@ static NSString* get_data_string(config_file_t* config, const char* name, NSStri snprintf(namebuf, 512, "firmware%d_path", i + 1); NSString* path = get_data_string(_data.data, namebuf, @"Unspecified"); - path = [path stringByReplacingOccurrencesOfString:@"%sysdir%" withString:RetroArch_iOS.get.system_directory]; + path = [path stringByReplacingOccurrencesOfString:@"%sysdir%" withString:RetroArch_iOS.get.systemDirectory]; [firmwareSection addObject:path]; } diff --git a/ios/RetroArch/RetroArch_iOS.h b/ios/RetroArch/RetroArch_iOS.h index 57c2bfeb56..e9bc55a0fc 100644 --- a/ios/RetroArch/RetroArch_iOS.h +++ b/ios/RetroArch/RetroArch_iOS.h @@ -29,9 +29,8 @@ - (IBAction)startBluetooth; - (IBAction)stopBluetooth; - -@property (strong, nonatomic) NSString* systemConfigPath; - -@property (strong, nonatomic) NSString* system_directory; +@property (strong, nonatomic) NSString* documentsDirectory; // e.g. /var/mobile/Documents +@property (strong, nonatomic) NSString* systemDirectory; // e.g. /var/mobile/Documents/.RetroArch +@property (strong, nonatomic) NSString* systemConfigPath; // e.g. /var/mobile/Documents/.RetroArch/frontend.cfg @end diff --git a/ios/RetroArch/browser/browser.m b/ios/RetroArch/browser/browser.m index 0697d28f54..d8885968a3 100644 --- a/ios/RetroArch/browser/browser.m +++ b/ios/RetroArch/browser/browser.m @@ -33,8 +33,8 @@ + (id)directoryListAtBrowseRoot { - NSString* rootPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; - NSString* ragPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/RetroArchGames"]; + NSString* rootPath = RetroArch_iOS.get.documentsDirectory; + NSString* ragPath = [rootPath stringByAppendingPathComponent:@"RetroArchGames"]; return [RADirectoryList directoryListForPath:path_is_directory(ragPath.UTF8String) ? ragPath : rootPath]; } diff --git a/ios/RetroArch/main.m b/ios/RetroArch/main.m index 562c57bfbc..20e18a5e70 100644 --- a/ios/RetroArch/main.m +++ b/ios/RetroArch/main.m @@ -21,6 +21,7 @@ #include #include +#include #include "rarch_wrapper.h" #include "general.h" @@ -44,6 +45,14 @@ static bool enable_btstack; static bool use_icade; static uint32_t icade_buttons; +bool path_make_and_check_directory(const char* path, mode_t mode, int amode) +{ + if (!path_is_directory(path) && mkdir(path, mode) != 0) + return false; + + return access(path, amode) == 0; +} + // Input helpers void ios_copy_input(ios_input_data_t* data) { @@ -249,28 +258,27 @@ static void event_reload_config(void* userdata) ios_log_init(); #endif - NSString* documentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; - - self.system_directory = [NSString stringWithFormat:@"%@/.RetroArch", documentsPath]; - self.systemConfigPath = [NSString stringWithFormat:@"%@/.RetroArch/frontend.cfg", documentsPath]; - - // Build system paths and test permissions - if (!path_is_directory(documentsPath.UTF8String) && mkdir(documentsPath.UTF8String, 0755)) - [RetroArch_iOS displayErrorMessage:[NSString stringWithFormat:@"Failed to create base directory: %@", documentsPath]]; - else if (!path_is_directory(self.system_directory.UTF8String) && mkdir(self.system_directory.UTF8String, 0755)) - [RetroArch_iOS displayErrorMessage:[NSString stringWithFormat:@"Failed to create system directory: %@", self.system_directory]]; - else if (access(self.system_directory.UTF8String, R_OK | W_OK | X_OK)) - [RetroArch_iOS displayErrorMessage:[NSString stringWithFormat:@"System directory has incorrect permissions: %@", self.system_directory]]; + self.delegate = self; // Setup window - self.delegate = self; - [self pushViewController:[RADirectoryList directoryListAtBrowseRoot] animated:YES]; - _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; _window.rootViewController = self; [_window makeKeyAndVisible]; - [self refreshSystemConfig]; + // Build system paths and test permissions + self.documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; + self.systemDirectory = [self.documentsDirectory stringByAppendingPathComponent:@".RetroArch"]; + self.systemConfigPath = [self.systemDirectory stringByAppendingPathComponent:@"frontend.cfg"]; + + if (!path_make_and_check_directory(self.documentsDirectory.UTF8String, 0755, R_OK | W_OK | X_OK)) + [RetroArch_iOS displayErrorMessage:[NSString stringWithFormat:@"Failed to create or access base directory: %@", self.documentsDirectory]]; + else if (!path_make_and_check_directory(self.systemDirectory.UTF8String, 0755, R_OK | W_OK | X_OK)) + [RetroArch_iOS displayErrorMessage:[NSString stringWithFormat:@"Failed to create or access system directory: %@", self.systemDirectory]]; + else + { + [self pushViewController:[RADirectoryList directoryListAtBrowseRoot] animated:YES]; + [self refreshSystemConfig]; + } } - (void)applicationWillEnterForeground:(UIApplication *)application @@ -352,17 +360,15 @@ static void event_reload_config(void* userdata) [self pushViewController:RAGameView.get animated:NO]; _isRunning = true; - const char* const sd = RetroArch_iOS.get.system_directory.UTF8String; - const char* const cf = (path_file_exists(_module.configPath.UTF8String)) ? [_module.configPath UTF8String] : 0; - const char* const libretro = [_module.path UTF8String]; - struct rarch_main_wrap* load_data = malloc(sizeof(struct rarch_main_wrap)); - load_data->libretro_path = strdup(libretro); - load_data->rom_path = strdup([path UTF8String]); - load_data->sram_path = strdup(sd); - load_data->state_path = strdup(sd); + memset(load_data, 0, sizeof(load_data)); + load_data->libretro_path = strdup(_module.path.UTF8String); + load_data->rom_path = strdup(path.UTF8String); + load_data->sram_path = strdup(self.systemDirectory.UTF8String); + load_data->state_path = strdup(self.systemDirectory.UTF8String); + load_data->config_path = strdup(_module.configPath.UTF8String); load_data->verbose = false; - load_data->config_path = strdup(cf); + if (pthread_create(&_retroThread, 0, rarch_main_ios, load_data)) { [self rarchExited:NO]; @@ -376,9 +382,7 @@ static void event_reload_config(void* userdata) - (void)rarchExited:(BOOL)successful { if (!successful) - { [RetroArch_iOS displayErrorMessage:@"Failed to load game."]; - } if (_isRunning) { @@ -550,5 +554,5 @@ void ios_rarch_exited(void* result) char* ios_get_rarch_system_directory() { - return strdup([RetroArch_iOS.get.system_directory UTF8String]); + return strdup([RetroArch_iOS.get.systemDirectory UTF8String]); } diff --git a/ios/RetroArch/settings/settings.m b/ios/RetroArch/settings/settings.m index 064d5bd467..4e83b241e9 100644 --- a/ios/RetroArch/settings/settings.m +++ b/ios/RetroArch/settings/settings.m @@ -255,7 +255,7 @@ static RASettingData* custom_action(NSString* action, id data) if (!config) config = config_file_new(0); - config_set_string(config, "system_directory", [[RetroArch_iOS get].system_directory UTF8String]); + config_set_string(config, "system_directory", [[RetroArch_iOS get].systemDirectory UTF8String]); [self writeSettings:nil toConfig:config]; if (config) config_file_write(config, [_module.configPath UTF8String]);