mirror of
https://github.com/ksherlock/ample.git
synced 2024-06-08 02:29:37 +00:00
328ab815fb
commit a91a858d68c845f74db106dd21a800c4d09e6e38 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun Mar 7 22:49:42 2021 -0500 listxml utility. commit e52576797da2609e700a12d1ffd7c78e8f1c2b23 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun Mar 7 22:34:00 2021 -0500 update media to use a structure instead of passing around dictionaries. commit 9277a0f720091c386812ac5f84d96080fe6e14f3 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun Mar 7 20:13:27 2021 -0500 media is working again. commit 7c0ac9a973df85fdcdaa978f80905cb9e8532ea5 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun Mar 7 18:46:38 2021 -0500 use new slot objects [WIP] commit 005e2f14d37e7b83ac4ab3e60e7fb794ac8ed651 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun Mar 7 17:33:59 2021 -0500 new slot code to make sub options easier. commit d7f3d9ef75367fad15081789a33212b7cf928fb3 Author: Kelvin Sherlock <ksherlock@gmail.com> Date: Sun Mar 7 17:33:13 2021 -0500 String Interning...
138 lines
3.8 KiB
Objective-C
138 lines
3.8 KiB
Objective-C
//
|
|
// Ample.m
|
|
// Ample
|
|
//
|
|
// Created by Kelvin Sherlock on 9/1/2020.
|
|
// Copyright © 2020 Kelvin Sherlock. All rights reserved.
|
|
//
|
|
|
|
#include "Ample.h"
|
|
|
|
NSURL *SupportDirectory(void) {
|
|
static NSURL *cached = nil;
|
|
|
|
if (!cached) {
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
NSError *error = nil;
|
|
|
|
NSURL *url = [fm URLForDirectory: NSApplicationSupportDirectory inDomain: NSUserDomainMask appropriateForURL: nil create: YES error: &error];
|
|
cached = [url URLByAppendingPathComponent: @"Ample"];
|
|
|
|
[fm createDirectoryAtURL: cached withIntermediateDirectories: YES attributes: nil error: &error];
|
|
}
|
|
return cached;
|
|
|
|
}
|
|
|
|
NSString *SupportDirectoryPath(void) {
|
|
static NSString *cached = nil;
|
|
|
|
if (!cached) {
|
|
NSURL *url = SupportDirectory();
|
|
cached = [NSString stringWithCString: [url fileSystemRepresentation] encoding: NSUTF8StringEncoding];
|
|
}
|
|
return cached;
|
|
}
|
|
|
|
|
|
NSURL *MameURL(void) {
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
NSBundle *bundle = [NSBundle mainBundle];
|
|
|
|
if ([defaults boolForKey: kUseCustomMame]) {
|
|
NSString *path = [defaults stringForKey: kMamePath];
|
|
if (![path length]) return [NSURL fileURLWithPath: path];
|
|
}
|
|
|
|
return [bundle URLForAuxiliaryExecutable: @"mame64"];
|
|
}
|
|
|
|
NSString *MamePath(void) {
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
NSBundle *bundle = [NSBundle mainBundle];
|
|
|
|
NSString *path;
|
|
|
|
if ([defaults boolForKey: kUseCustomMame]) {
|
|
path = [defaults stringForKey: kMamePath];
|
|
if ([path length]) return path;
|
|
}
|
|
path = [bundle pathForAuxiliaryExecutable: @"mame64"];
|
|
if ([path length]) return path;
|
|
return nil;
|
|
}
|
|
|
|
|
|
NSURL *MameWorkingDirectory(void) {
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
if ([defaults boolForKey: kUseCustomMame]) {
|
|
NSString *path = [defaults stringForKey: kMameWorkingDirectory];
|
|
if (![path length]) return [NSURL fileURLWithPath: path];
|
|
}
|
|
|
|
return SupportDirectory();
|
|
}
|
|
|
|
NSString *MameWorkingDirectoryPath(void) {
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
if ([defaults boolForKey: kUseCustomMame]) {
|
|
NSString *path = [defaults stringForKey: kMameWorkingDirectory];
|
|
if (![path length]) return path;
|
|
}
|
|
|
|
return SupportDirectoryPath();
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
/* NSCache doesn't retain it's key. This essentially interns it. */
|
|
/* could just abuse NSSelectorFromString() */
|
|
NSString *InternString(NSString *key) {
|
|
static NSMutableDictionary *storage = nil;
|
|
|
|
if (!storage) {
|
|
storage = [NSMutableDictionary new];
|
|
}
|
|
NSString *copy = [storage objectForKey: key];
|
|
if (!copy) {
|
|
copy = [key copy];
|
|
[storage setObject: copy forKey: copy];
|
|
}
|
|
return copy;
|
|
}
|
|
|
|
|
|
NSString *kUseCustomMame = @"UseCustomMame";
|
|
NSString *kMamePath = @"MamePath";
|
|
NSString *kMameWorkingDirectory = @"MameWorkingDirectory";
|
|
NSString *kAutoCloseLogWindow = @"AutoCloseLogWindow";
|
|
NSString *kMameComponentsDate = @"MameComponentsDate";
|
|
NSString *kDefaultDownloadURL = @"DefaultDownloadURL";
|
|
NSString *kDefaultDownloadExtension = @"DefaultDownloadExtension";
|
|
|
|
NSString *kDownloadURL = @"DownloadURL";
|
|
NSString *kDownloadExtension = @"DownloadExtension";
|