mirror of
https://github.com/ksherlock/ample.git
synced 2024-11-15 22:07:28 +00:00
added working directory option for custom mame config.
also log path/working directory to the log window.
This commit is contained in:
parent
f3137585c1
commit
57a7e24d21
@ -17,6 +17,7 @@ NSString *SupportDirectoryPath(void);
|
||||
/* NSUserDefaults keys */
|
||||
extern NSString *kUseCustomMame;
|
||||
extern NSString *kMamePath;
|
||||
extern NSString *kMameWorkingDirectory;
|
||||
extern NSString *kAutoCloseLogWindow;
|
||||
extern NSString *kMameComponentsDate;
|
||||
|
||||
|
@ -37,5 +37,6 @@ NSString *SupportDirectoryPath(void) {
|
||||
|
||||
NSString *kUseCustomMame = @"UseCustomMame";
|
||||
NSString *kMamePath = @"MamePath";
|
||||
NSString *kMameWorkingDirectory = @"MameWorkingDirectory";
|
||||
NSString *kAutoCloseLogWindow = @"AutoCloseLogWindow";
|
||||
NSString *kMameComponentsDate = @"MameComponentsDate";
|
||||
|
@ -10,6 +10,7 @@
|
||||
<connections>
|
||||
<outlet property="fixButton" destination="kt8-xs-My0" id="GeF-Kj-q2l"/>
|
||||
<outlet property="pathField" destination="Oz5-Xb-btk" id="EnV-kr-0XI"/>
|
||||
<outlet property="wdField" destination="l8V-pC-gml" id="exX-bU-pbh"/>
|
||||
<outlet property="window" destination="QvC-M9-y7g" id="xJa-tx-X62"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
@ -25,7 +26,7 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Oz5-Xb-btk">
|
||||
<rect key="frame" x="98" y="181" width="362" height="21"/>
|
||||
<rect key="frame" x="138" y="181" width="322" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="vDR-2V-qxd">
|
||||
<font key="font" usesAppearanceFont="YES"/>
|
||||
@ -38,17 +39,31 @@
|
||||
<binding destination="yvB-HG-64y" name="enabled" keyPath="values.UseCustomMame" id="iex-A9-Db6"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Qmb-Ag-Xyr">
|
||||
<rect key="frame" x="18" y="184" width="74" height="16"/>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="l8V-pC-gml">
|
||||
<rect key="frame" x="138" y="150" width="322" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="wfj-GY-Qu2">
|
||||
<font key="font" usesAppearanceFont="YES"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<action selector="wdChanged:" target="-2" id="g1P-8l-ZXi"/>
|
||||
<binding destination="yvB-HG-64y" name="enabled" keyPath="values.UseCustomMame" id="DeG-OW-Gd2"/>
|
||||
<binding destination="yvB-HG-64y" name="value" keyPath="values.MameWorkingDirectory" id="Kc9-Pc-XGU"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vTJ-Ez-c1R">
|
||||
<rect key="frame" x="18" y="153" width="114" height="16"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="MAME Path" id="Xcq-4g-Wlw">
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Working Directory" id="UHt-0s-zxA">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="KAN-P2-ydI">
|
||||
<rect key="frame" x="96" y="234" width="217" height="18"/>
|
||||
<rect key="frame" x="136" y="234" width="217" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Close log window on normal exit" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="QMz-O0-06U">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
@ -59,7 +74,7 @@
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="j7D-jC-17Q">
|
||||
<rect key="frame" x="96" y="208" width="139" height="18"/>
|
||||
<rect key="frame" x="136" y="208" width="139" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Use Custom MAME" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="V61-mz-QFo">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
@ -80,6 +95,15 @@
|
||||
<action selector="fixPerms:" target="-2" id="0e2-yf-UgY"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Qmb-Ag-Xyr">
|
||||
<rect key="frame" x="58" y="184" width="74" height="16"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="MAME Path" id="Xcq-4g-Wlw">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
</view>
|
||||
<point key="canvasLocation" x="140" y="147"/>
|
||||
|
@ -374,6 +374,9 @@ static NSString * JoinArguments(NSArray *argv) {
|
||||
|
||||
if (![_args count]) return;
|
||||
|
||||
[LogWindowController controllerForArgs: _args];
|
||||
|
||||
#if 0
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSURL *url = MameURL();
|
||||
|
||||
@ -395,6 +398,7 @@ static NSString * JoinArguments(NSArray *argv) {
|
||||
}
|
||||
|
||||
[LogWindowController controllerForTask: task];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,13 +47,25 @@ static NSURL *MameURL(void) {
|
||||
}
|
||||
|
||||
return [bundle URLForAuxiliaryExecutable: @"mame64"];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
static 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+(id)controllerForArgs: (NSArray *)args {
|
||||
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
NSURL *url = MameURL();
|
||||
|
||||
@ -65,19 +77,12 @@ static NSURL *MameURL(void) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
NSTask *task = [NSTask new];
|
||||
[task setExecutableURL: url];
|
||||
[task setArguments: args];
|
||||
|
||||
if (![defaults boolForKey: kUseCustomMame]) {
|
||||
// run in Application Support/Ample.
|
||||
[task setCurrentDirectoryURL: SupportDirectory()];
|
||||
}
|
||||
[task setCurrentDirectoryURL: MameWorkingDirectory()];
|
||||
|
||||
return [LogWindowController controllerForTask: task];
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)windowDidLoad {
|
||||
@ -103,25 +108,33 @@ static NSURL *MameURL(void) {
|
||||
|
||||
NSError *error = nil;
|
||||
NSPipe *pipe = [NSPipe pipe];
|
||||
|
||||
|
||||
// window not yet loaded until [self window] called.
|
||||
const char *path = [[task executableURL] fileSystemRepresentation];
|
||||
// if (cp) [self appendString: [NSString stringWithFormat: @"MAME path: %s", cp]];
|
||||
const char *wd = [[task currentDirectoryURL] fileSystemRepresentation];
|
||||
// if (cp) [self appendString: [NSString stringWithFormat: @"Working Directory: %s", cp]];
|
||||
|
||||
[task setStandardError: pipe];
|
||||
[task setStandardOutput: pipe];
|
||||
[task launchAndReturnError: &error];
|
||||
|
||||
|
||||
if (error) {
|
||||
NSURL *url = [task executableURL];
|
||||
NSString *path = [NSString stringWithCString: [url fileSystemRepresentation] encoding: NSUTF8StringEncoding];
|
||||
NSLog(@"NSTask error. Path = %@ error = %@", path, error);
|
||||
[self appendString: path];
|
||||
[self appendString: [error description]];
|
||||
// NSURL *url = [task executableURL];
|
||||
// NSString *path = [NSString stringWithCString: [url fileSystemRepresentation] encoding: NSUTF8StringEncoding];
|
||||
NSLog(@"NSTask error. Path = %s error = %@", path, error);
|
||||
// [self appendString: path];
|
||||
// [self appendString: [error description]];
|
||||
return error;
|
||||
}
|
||||
_task = task;
|
||||
NSString *title = [NSString stringWithFormat: @"Ample Log - %u", [task processIdentifier]];
|
||||
[[self window] setTitle: title];
|
||||
_handle = [pipe fileHandleForReading];
|
||||
|
||||
|
||||
if (path) [self appendString: [NSString stringWithFormat: @"MAME path: %s\n", path]];
|
||||
if (wd) [self appendString: [NSString stringWithFormat: @"Working Directory: %s\n", wd]];
|
||||
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
@interface PreferencesWindowController ()
|
||||
@property (weak) IBOutlet NSTextField *pathField;
|
||||
@property (weak) IBOutlet NSTextField *wdField;
|
||||
@property (weak) IBOutlet NSButton *fixButton;
|
||||
|
||||
@end
|
||||
@ -31,7 +32,8 @@
|
||||
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
||||
|
||||
[self validateMamePath: [defaults stringForKey: kMamePath]];
|
||||
|
||||
[self validateMameWD: [defaults stringForKey: kMameWorkingDirectory]];
|
||||
|
||||
/* check vmnet_helper permissions */
|
||||
|
||||
int needs_fixin = [self checkHelperPermissions: nil];
|
||||
@ -48,6 +50,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
-(void)validateMameWD: (NSString *)path {
|
||||
NSFileManager * fm = [NSFileManager defaultManager];
|
||||
BOOL directory = YES;
|
||||
|
||||
if ([path length] == 0) {
|
||||
[_wdField setTextColor: [NSColor blackColor]];
|
||||
return;
|
||||
}
|
||||
|
||||
if ([fm fileExistsAtPath: path isDirectory: &directory] && directory) {
|
||||
[_wdField setTextColor: [NSColor blackColor]];
|
||||
return;
|
||||
|
||||
}
|
||||
[_wdField setTextColor: [NSColor redColor]];
|
||||
}
|
||||
|
||||
- (IBAction)pathChanged:(id)sender {
|
||||
|
||||
NSString *path = [sender stringValue];
|
||||
@ -55,6 +74,12 @@
|
||||
[self validateMamePath: path];
|
||||
|
||||
}
|
||||
- (IBAction)wdChanged:(id)sender {
|
||||
|
||||
NSString *path = [sender stringValue];
|
||||
|
||||
[self validateMameWD: path];
|
||||
}
|
||||
|
||||
// -1 - error
|
||||
// 1 - needs help
|
||||
@ -150,7 +175,7 @@
|
||||
const char* args_chown[] = {"root", cp , NULL};
|
||||
const char* args_chmod[] = {"+s", cp, NULL};
|
||||
|
||||
// well ... the second command executes a lot more consistently when the (optional) fp is provided and the we fgets the buffer.
|
||||
// well ... the second command executes a lot more consistently when the (optional) fp is provided and the we fgets the buffer.
|
||||
myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, "/usr/sbin/chown", kAuthorizationFlagDefaults, (char**)args_chown, &fp);
|
||||
fgets(buffer, sizeof(buffer), fp);
|
||||
fclose(fp);
|
||||
|
Loading…
Reference in New Issue
Block a user