diff --git a/ios/RetroArch/RAModuleInfo.h b/ios/RetroArch/RAModuleInfo.h index 5643037329..e357becb8b 100644 --- a/ios/RetroArch/RAModuleInfo.h +++ b/ios/RetroArch/RAModuleInfo.h @@ -18,18 +18,18 @@ @interface RAModuleInfo : NSObject @property (strong) NSString* path; @property config_file_t* data; -@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; +- (bool)hasCustomConfig; + (NSString*)globalConfigPath; -- (NSString*)customConfigPath; +@property (strong) NSString* customConfigPath; +- (NSString*)configPath; @end diff --git a/ios/RetroArch/RAModuleInfo.m b/ios/RetroArch/RAModuleInfo.m index 9bd47260ce..d0bb6ee2e7 100644 --- a/ios/RetroArch/RAModuleInfo.m +++ b/ios/RetroArch/RAModuleInfo.m @@ -41,6 +41,8 @@ static NSMutableArray* moduleList; RAModuleInfo* newInfo = [RAModuleInfo new]; newInfo.path = [NSString stringWithUTF8String:files.gl_pathv[i]]; + NSString* baseName = newInfo.path.lastPathComponent.stringByDeletingPathExtension; + NSString* infoPath = [newInfo.path stringByReplacingOccurrencesOfString:@"_ios.dylib" withString:@".dylib"]; infoPath = [infoPath stringByReplacingOccurrencesOfString:@".dylib" withString:@".info"]; @@ -49,19 +51,7 @@ static NSMutableArray* moduleList; 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)) - { - newInfo.hasCustomConfig = true; - newInfo.configPath = customConfigPath; - } - else - { - newInfo.hasCustomConfig = false; - newInfo.configPath = self.globalConfigPath; - } - + newInfo.customConfigPath = [NSString stringWithFormat:@"%@/%@.cfg", RetroArch_iOS.get.systemDirectory, baseName]; [moduleList addObject:newInfo]; } @@ -90,31 +80,32 @@ static NSMutableArray* moduleList; - (void)createCustomConfig { if (!self.hasCustomConfig) - { - NSString* target = self.customConfigPath; - - [NSFileManager.defaultManager copyItemAtPath:self.configPath toPath:target error:nil]; - self.hasCustomConfig = true; - } + [NSFileManager.defaultManager copyItemAtPath:RAModuleInfo.globalConfigPath toPath:self.customConfigPath error:nil]; } - (void)deleteCustomConfig { if (self.hasCustomConfig) - { [NSFileManager.defaultManager removeItemAtPath:self.customConfigPath error:nil]; - self.hasCustomConfig = false; - } } + (NSString*)globalConfigPath { - return [NSString stringWithFormat:@"%@/retroarch.cfg", RetroArch_iOS.get.systemDirectory]; + static NSString* path; + if (!path) + path = [NSString stringWithFormat:@"%@/retroarch.cfg", RetroArch_iOS.get.systemDirectory]; + + return path; } -- (NSString*)customConfigPath +- (bool)hasCustomConfig { - return [NSString stringWithFormat:@"%@/%@.cfg", RetroArch_iOS.get.systemDirectory, self.path.lastPathComponent.stringByDeletingPathExtension]; + return path_file_exists(self.customConfigPath.UTF8String); +} + +- (NSString*)configPath +{ + return self.hasCustomConfig ? self.customConfigPath : RAModuleInfo.globalConfigPath; } @end