Add a cache for the machine description.

This commit is contained in:
Kelvin Sherlock 2021-02-23 22:40:03 -05:00
parent 5f8b00f021
commit 760f9e6693
2 changed files with 20 additions and 0 deletions

View File

@ -23,6 +23,9 @@ NSString *MamePath(void);
NSURL *MameWorkingDirectory(void);
NSString *MameWorkingDirectoryPath(void);
NSDictionary *MameMachine(NSString *machine);
/* NSUserDefaults keys */
extern NSString *kUseCustomMame;
extern NSString *kMamePath;

View File

@ -90,6 +90,23 @@ NSString *MameWorkingDirectoryPath(void) {
}
NSDictionary *MameMachine(NSString *machine) {
static NSMutableDictionary *cache;
if (!cache) cache = [NSMutableDictionary new];
NSDictionary *d;
if (!machine) return nil;
d = [cache objectForKey: machine];
if (d) return d;
NSBundle *bundle = [NSBundle mainBundle];
NSURL *url= [bundle URLForResource: machine withExtension: @"plist"];
d = [NSDictionary dictionaryWithContentsOfURL: url];
if (d) [cache setObject: d forKey: machine];
return d;
}
NSString *kUseCustomMame = @"UseCustomMame";
NSString *kMamePath = @"MamePath";