(iOS) Fix major regression that can break file loading (since 99990173cc); Simplify the variables used to hold system paths

This commit is contained in:
meancoot 2013-06-11 06:07:09 -04:00
parent 14b32c3c0b
commit 4243110f56
5 changed files with 40 additions and 37 deletions

View File

@ -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];
}

View File

@ -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

View File

@ -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];
}

View File

@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <pthread.h>
#include <string.h>
#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]);
}

View File

@ -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]);