From 760f9e6693f6a649278ca2a15cf1f6504bb58068 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 23 Feb 2021 22:40:03 -0500 Subject: [PATCH] Add a cache for the machine description. --- Ample/Ample.h | 3 +++ Ample/Ample.m | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Ample/Ample.h b/Ample/Ample.h index 5551e3c..a3132ae 100644 --- a/Ample/Ample.h +++ b/Ample/Ample.h @@ -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; diff --git a/Ample/Ample.m b/Ample/Ample.m index f4a0ca8..0d76a86 100644 --- a/Ample/Ample.m +++ b/Ample/Ample.m @@ -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";