diff --git a/ios/RetroArch/RAModuleInfo.h b/ios/RetroArch/RAModuleInfo.h index 466e2a52e0..d407d7580d 100644 --- a/ios/RetroArch/RAModuleInfo.h +++ b/ios/RetroArch/RAModuleInfo.h @@ -21,8 +21,14 @@ @property (strong) NSString* configPath; @property (strong) NSString* displayName; @property (strong) NSArray* supportedExtensions; +@property bool hasCustomConfig; + (NSArray*)getModules; - (bool)supportsFileAtPath:(NSString*)path; + +- (void)createCustomConfig; +- (void)deleteCustomConfig; + +- (NSString*)customConfigPath; @end diff --git a/ios/RetroArch/RAModuleInfo.m b/ios/RetroArch/RAModuleInfo.m index 197fe80cec..48e41af208 100644 --- a/ios/RetroArch/RAModuleInfo.m +++ b/ios/RetroArch/RAModuleInfo.m @@ -46,21 +46,22 @@ static NSMutableArray* moduleList; newInfo.data = config_file_new([infoPath UTF8String]); - char* dispname = 0; - char* extensions = 0; - - if (newInfo.data) + newInfo.displayName = ios_get_value_from_config(newInfo.data, @"display_name", newInfo.path.lastPathComponent.stringByDeletingPathExtension); + newInfo.supportedExtensions = [ios_get_value_from_config(newInfo.data, @"supported_extensions", @"") componentsSeparatedByString:@"|"]; + + // Get config file + NSString* customConfigPath = [newInfo customConfigPath]; + if (path_file_exists(customConfigPath.UTF8String)) { - config_get_string(newInfo.data, "display_name", &dispname); - config_get_string(newInfo.data, "supported_extensions", &extensions); + newInfo.hasCustomConfig = true; + newInfo.configPath = customConfigPath; + } + else + { + newInfo.hasCustomConfig = false; + newInfo.configPath = [NSString stringWithFormat:@"%@/retroarch.cfg", RetroArch_iOS.get.systemDirectory]; } - 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]; - - free(dispname); - free(extensions); [moduleList addObject:newInfo]; } @@ -86,6 +87,31 @@ static NSMutableArray* moduleList; return [self.supportedExtensions containsObject:[[path pathExtension] lowercaseString]]; } +- (void)createCustomConfig +{ + if (!self.hasCustomConfig) + { + NSString* target = self.customConfigPath; + + [NSFileManager.defaultManager copyItemAtPath:self.configPath toPath:target error:nil]; + self.hasCustomConfig = true; + } +} + +- (void)deleteCustomConfig +{ + if (self.hasCustomConfig) + { + [NSFileManager.defaultManager removeItemAtPath:self.customConfigPath error:nil]; + self.hasCustomConfig = false; + } +} + +- (NSString*)customConfigPath +{ + return [NSString stringWithFormat:@"%@/%@.cfg", RetroArch_iOS.get.systemDirectory, self.path.lastPathComponent.stringByDeletingPathExtension]; +} + @end // Build a string with a second associated string