summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-06-22 19:55:35 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-06-22 19:55:35 +0000
commitb6b2beab4846d5579514aed399d7eab56d6d02f0 (patch)
tree86be926c6a96344e7911486ed02ba1749bcaae10
parent33fb691cf7b6440102337966e34558f0a1851028 (diff)
downloadpcsxr-b6b2beab4846d5579514aed399d7eab56d6d02f0.tar.gz
Ignore files passed via the command line if we're parsing.
Calls to GUI functions should happen on the main thread. Put the [NSApp presentError:] in a block to the main thread. Put some bools in PcsxrController inside a struct with a size of 1. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@85488 e17a0e51-4ae3-4d35-97c3-1a29b211df97
-rw-r--r--macosx/ARCBridge.h2
-rw-r--r--macosx/Pcsxr.xcodeproj/project.pbxproj1
-rwxr-xr-xmacosx/PcsxrController.h27
-rwxr-xr-xmacosx/PcsxrController.m160
-rwxr-xr-xmacosx/main.m17
5 files changed, 132 insertions, 75 deletions
diff --git a/macosx/ARCBridge.h b/macosx/ARCBridge.h
index 5a747bdd..ea274b84 100644
--- a/macosx/ARCBridge.h
+++ b/macosx/ARCBridge.h
@@ -14,6 +14,7 @@
#define SUPERDEALLOC
#define RELEASEOBJ(obj)
#define RETAINOBJ(obj) obj
+#define RETAINOBJNORETURN(obj)
#define AUTORELEASEOBJ(obj) obj
#define AUTORELEASEOBJNORETURN(obj)
#define BRIDGE(toType, obj) (__bridge toType)(obj)
@@ -24,6 +25,7 @@
#define SUPERDEALLOC [super dealloc]
#define RELEASEOBJ(obj) [obj release]
#define RETAINOBJ(obj) [obj retain]
+#define RETAINOBJNORETURN(obj) [obj retain]
#define AUTORELEASEOBJ(obj) [obj autorelease]
#define AUTORELEASEOBJNORETURN(obj) [obj autorelease]
#define BRIDGE(toType, obj) (toType)obj
diff --git a/macosx/Pcsxr.xcodeproj/project.pbxproj b/macosx/Pcsxr.xcodeproj/project.pbxproj
index 08bef439..e47f93e5 100644
--- a/macosx/Pcsxr.xcodeproj/project.pbxproj
+++ b/macosx/Pcsxr.xcodeproj/project.pbxproj
@@ -1005,6 +1005,7 @@
"$(GCC_PREPROCESSOR_DEFINITIONS_QUOTED_1)",
"_MACOSX=1",
__MACOSX__,
+ DEBUG,
);
GCC_PREPROCESSOR_DEFINITIONS_QUOTED_1 = "PCSXR_VERSION=\\\"1.5\\\" XA_HACK=1";
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
diff --git a/macosx/PcsxrController.h b/macosx/PcsxrController.h
index 836599b5..8688cde6 100755
--- a/macosx/PcsxrController.h
+++ b/macosx/PcsxrController.h
@@ -12,17 +12,22 @@ void ShowHelpAndExit(FILE* output, int exitCode) __dead2;
@interface PcsxrController : NSObject <NSApplicationDelegate>
{
- ConfigurationController *preferencesController;
- CheatController *cheatController;
- PluginList *pluginList;
-
- IBOutlet NSWindow *preferenceWindow;
- IBOutlet NSWindow *cheatWindow;
- IBOutlet RecentItemsMenu *recentItems;
-
- BOOL sleepInBackground;
- BOOL wasPausedBeforeBGSwitch;
- BOOL endAtEmuClose;
+ ConfigurationController *preferencesController;
+ CheatController *cheatController;
+ PluginList *pluginList;
+
+ IBOutlet NSWindow *preferenceWindow;
+ IBOutlet NSWindow *cheatWindow;
+ IBOutlet RecentItemsMenu *recentItems;
+
+ struct _PSXflags {
+ unsigned int sleepInBackground:1;
+ unsigned int wasPausedBeforeBGSwitch:1;
+ unsigned int endAtEmuClose:1;
+ unsigned int reserved:25;
+ } PSXflags;
+
+ NSMutableArray *skipFiles;
}
@property (readonly) RecentItemsMenu *recentItems;
@property (readonly) BOOL endAtEmuClose;
diff --git a/macosx/PcsxrController.m b/macosx/PcsxrController.m
index 33034761..9bf3900f 100755
--- a/macosx/PcsxrController.m
+++ b/macosx/PcsxrController.m
@@ -18,20 +18,19 @@ NSDictionary *prefStringKeys;
NSDictionary *prefByteKeys;
NSMutableArray *biosList;
NSString *saveStatePath;
-static NSArray *PCSXRParsingArray = nil;
#define HELPSTR "\n" \
"At least one of these must be passed:\n"\
-"\t--iso path launch with selected ISO\n" \
-"\t--cdrom launch with a CD-ROM\n" \
-"\t--bios launch into the BIOS\n\n" \
+"\t--iso path \tlaunch with selected ISO\n" \
+"\t--cdrom \tlaunch with a CD-ROM\n" \
+"\t--bios \tlaunch into the BIOS\n\n" \
"Additional options:\n" \
-"\t--exitAtClose closes PCSX-R at when the emulation has ended\n" \
-"\t--mcd1 path sets the fist memory card to path\n" \
-"\t--mcd2 path sets the second memory card to path\n" \
-"\t--freeze path loads freeze state from path\n\n" \
+"\t--exitAtClose \tcloses PCSX-R at when the emulation has ended\n" \
+"\t--mcd1 path \tsets the fist memory card to path\n" \
+"\t--mcd2 path \tsets the second memory card to path\n" \
+"\t--freeze path \tloads freeze state from path\n\n" \
"Help:\n" \
-"\t--help shows this message\n\n" \
+"\t--help \tshows this message\n\n" \
void ShowHelpAndExit(FILE* output, int exitCode)
@@ -42,12 +41,42 @@ void ShowHelpAndExit(FILE* output, int exitCode)
@interface PcsxrController ()
@property (readwrite) BOOL endAtEmuClose;
+@property (readwrite) BOOL sleepInBackground;
+@property (readwrite) BOOL wasPausedBeforeBGSwitch;
@end
@implementation PcsxrController
@synthesize recentItems;
-@synthesize endAtEmuClose;
+- (BOOL)endAtEmuClose
+{
+ return PSXflags.endAtEmuClose;
+}
+
+- (void)setEndAtEmuClose:(BOOL)endAtEmuClose
+{
+ PSXflags.endAtEmuClose = endAtEmuClose;
+}
+
+- (BOOL)sleepInBackground
+{
+ return PSXflags.sleepInBackground;
+}
+
+- (void)setSleepInBackground:(BOOL)sleepInBackground
+{
+ PSXflags.sleepInBackground = sleepInBackground;
+}
+
+- (BOOL)wasPausedBeforeBGSwitch
+{
+ return PSXflags.wasPausedBeforeBGSwitch;
+}
+
+- (void)setWasPausedBeforeBGSwitch:(BOOL)wasPausedBeforeBGSwitch
+{
+ PSXflags.wasPausedBeforeBGSwitch = wasPausedBeforeBGSwitch;
+}
- (IBAction)ejectCD:(id)sender
{
@@ -200,7 +229,7 @@ void ShowHelpAndExit(FILE* output, int exitCode)
} else {
[pluginList disableNetPlug];
}
- SetIsoFile((const char *)[[url path] fileSystemRepresentation]);
+ SetIsoFile([[url path] fileSystemRepresentation]);
[EmuThread run];
}
}
@@ -234,8 +263,8 @@ void ShowHelpAndExit(FILE* output, int exitCode)
- (IBAction)pauseInBackground:(id)sender
{
- sleepInBackground = !sleepInBackground;
- [[NSUserDefaults standardUserDefaults] setBool:sleepInBackground forKey:@"PauseInBackground"];
+ self.sleepInBackground = !self.sleepInBackground;
+ [[NSUserDefaults standardUserDefaults] setBool:self.sleepInBackground forKey:@"PauseInBackground"];
}
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
@@ -284,7 +313,7 @@ void ShowHelpAndExit(FILE* output, int exitCode)
return ![EmuThread active];
if ([menuItem action] == @selector(pauseInBackground:)) {
- [menuItem setState:(sleepInBackground ? NSOnState : NSOffState)];
+ [menuItem setState:(self.sleepInBackground ? NSOnState : NSOffState)];
return YES;
}
@@ -293,20 +322,26 @@ void ShowHelpAndExit(FILE* output, int exitCode)
- (void)applicationWillResignActive:(NSNotification *)aNotification
{
- wasPausedBeforeBGSwitch = [EmuThread isPaused];
+ self.wasPausedBeforeBGSwitch = [EmuThread isPaused];
- if (sleepInBackground) {
+ if (self.sleepInBackground) {
[EmuThread pause];
}
}
- (void)applicationDidBecomeActive:(NSNotification *)aNotification
{
- if (sleepInBackground && !wasPausedBeforeBGSwitch) {
+ if (self.sleepInBackground && !self.wasPausedBeforeBGSwitch) {
[EmuThread resume];
}
}
+- (void)applicationDidFinishLaunching:(NSNotification *)notification
+{
+ RELEASEOBJ(skipFiles);
+ skipFiles = nil;
+}
+
static void ParseErrorStr(NSString *errStr) __dead2;
static void ParseErrorStr(NSString *errStr)
{
@@ -336,7 +371,6 @@ runtimeStr = arg; \
otherblock();\
}
-
- (void)awakeFromNib
{
pluginList = [[PluginList alloc] init];
@@ -355,10 +389,11 @@ otherblock();\
nil, nil, nil);
}
- sleepInBackground = [[NSUserDefaults standardUserDefaults] boolForKey:@"PauseInBackground"];
+ self.sleepInBackground = [[NSUserDefaults standardUserDefaults] boolForKey:@"PauseInBackground"];
NSProcessInfo *procInfo = [NSProcessInfo processInfo];
NSArray *progArgs = [procInfo arguments];
if ([progArgs count] > 1 && ![[progArgs objectAtIndex:1] hasPrefix:@"-psn"]) {
+ skipFiles = [[NSMutableArray alloc] init];
BOOL isLaunchable = NO;
NSString *runtimeStr = nil;
__block dispatch_block_t runtimeBlock = NULL;
@@ -366,6 +401,8 @@ otherblock();\
__block NSString *(^FileTestBlock)() = NULL;
+ NSMutableArray *unknownOptions = [NSMutableArray array];
+
dispatch_block_t cdromBlock = ^{
hasParsedAnArgument = YES;
runtimeBlock = [^{
@@ -405,23 +442,27 @@ otherblock();\
[EmuThread defrostAt:path];
};
+ BOOL hasFileTestBlock = NO;
for (__block int i = 1; i < [progArgs count]; i++) {
-
- FileTestBlock = ^NSString *(){
- if ([progArgs count] <= ++i) {
- ParseErrorStr(@"Not enough arguments.");
- }
- NSString *path = [progArgs objectAtIndex:i];
- if (![[NSFileManager defaultManager] fileExistsAtPath:path])
- {
- NSString *errStr = [NSString stringWithFormat:@"The file \"%@\" does not exist.", path];
- ParseErrorStr(errStr);
- return nil;
- }
- return path;
-
- };
+ if (!hasFileTestBlock)
+ {
+ FileTestBlock = ^NSString *(){
+ if ([progArgs count] <= ++i) {
+ ParseErrorStr(@"Not enough arguments.");
+ }
+ NSString *path = [progArgs objectAtIndex:i];
+ if (![[NSFileManager defaultManager] fileExistsAtPath:path])
+ {
+ NSString *errStr = [NSString stringWithFormat:@"The file \"%@\" does not exist.", path];
+ ParseErrorStr(errStr);
+ return nil;
+ }
+ [skipFiles addObject:path];
+ return path;
+ };
+ hasFileTestBlock = YES;
+ }
//DO NOT END these MACROS WITH A SIMICOLON! it will break the if-else if process
HandleArg(@"--iso", YES, isoBlock)
@@ -432,14 +473,23 @@ otherblock();\
HandleArgElse(@"--mcd2", NO, ^{mcdBlock(2);})
HandleArgElse(@"--freeze", NO, freezeBlock)
else {
- static BOOL hasBeenWarned = NO;
- NSLog(@"PCSXR does not recognize the command line argument \"%@\".", [progArgs objectAtIndex:i]);
- if (hasBeenWarned == NO) {
- NSLog(@"The OS or something else might have passed it, but check the spelling of the arguments just in case.");
- hasBeenWarned = YES;
+ [unknownOptions addObject:[progArgs objectAtIndex:i]];
+ }
+ }
+#ifdef DEBUG
+ if ([unknownOptions count]) {
+ NSString *unknownString = @"The following options weren't recognized by PCSX-R:";
+ @autoreleasepool {
+ for (NSString *arg in unknownOptions) {
+ unknownString = [NSString stringWithFormat:@"%@ %@", unknownString, arg];
}
+ RETAINOBJNORETURN(unknownString);
}
+ NSLog(@"%@", unknownString);
+ RELEASEOBJ(unknownString);
+ NSLog(@"This may be due to extra arguments passed by the OS or debugger.");
}
+#endif
if (!isLaunchable && hasParsedAnArgument) {
NSString *tmpStr = @"A launch command wasn't found in the command line and an argument that PCSX-R recognizes was.\n";
@autoreleasepool {
@@ -447,11 +497,9 @@ otherblock();\
tmpStr = [NSString stringWithFormat:@"%@ %@", tmpStr, arg];
}
tmpStr = [NSString stringWithFormat:@"%@\n\nThe valid launch commands are --iso, --cdrom, and --bios", tmpStr];
-#if !__has_feature(objc_arc)
- [tmpStr retain];
-#endif
+ RETAINOBJNORETURN(tmpStr);
}
- ParseErrorStr([tmpStr autorelease]);
+ ParseErrorStr(AUTORELEASEOBJ(tmpStr));
} else if (hasParsedAnArgument){
runtimeBlock();
RELEASEOBJ(runtimeBlock);
@@ -483,11 +531,11 @@ otherblock();\
for (NSString *key in prefByteKeys) {
u8 *dst = (u8 *)[[prefByteKeys objectForKey:key] pointerValue];
- if (dst != nil) *dst = [defaults integerForKey:key];
+ if (dst != NULL) *dst = [defaults boolForKey:key];
#ifdef __i386__
//i386 on OS X doesn't like the dynarec core
if ([key isEqualToString:@"NoDynarec"]) {
- *dst = 1;
+ if (dst != NULL) *dst = 1;
[defaults setBool:YES forKey:key];
}
#endif
@@ -559,12 +607,12 @@ otherblock();\
const char *str;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithBool:YES], @"NoDynarec",
- [NSNumber numberWithBool:YES], @"AutoDetectVideoType",
- [NSNumber numberWithBool:NO], @"UseHLE",
- [NSNumber numberWithBool:YES], @"PauseInBackground",
- [NSNumber numberWithBool:NO], @"Widescreen",
- [NSNumber numberWithBool:NO], @"NetPlay",
+ @YES, @"NoDynarec",
+ @YES, @"AutoDetectVideoType",
+ @NO, @"UseHLE",
+ @YES, @"PauseInBackground",
+ @NO, @"Widescreen",
+ @NO, @"NetPlay",
nil];
[defaults registerDefaults:appDefaults];
@@ -690,6 +738,14 @@ otherblock();\
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
+ if (skipFiles && [skipFiles count]) {
+ for (NSString *parsedFile in skipFiles) {
+ if ([filename isEqualToString:parsedFile]) {
+ return YES;
+ }
+ }
+ }
+
NSError *err = nil;
NSString *utiFile = [[NSWorkspace sharedWorkspace] typeOfFile:filename error:&err];
if (err) {
@@ -716,8 +772,8 @@ otherblock();\
break;
}
RELEASEOBJ(hand);
-
}
+
return isHandled;
}
diff --git a/macosx/main.m b/macosx/main.m
index 204d2c29..5dd3410c 100755
--- a/macosx/main.m
+++ b/macosx/main.m
@@ -21,15 +21,6 @@ static BOOL sysInited = NO;
//#define EMU_LOG
static IOPMAssertionID powerAssertion = kIOPMNullAssertionID;
-#define HELPSTR \
-"%s\n\n" \
-"\t--help shows this message\n" \
-"\t--iso path launch with selected ISO\n" \
-"\t--cdrom launch with a CD-ROM\n" \
-"\t--exitAtClose closes PCSX-R at when the emulation has ended\n" \
-"\t--mcd1 path sets the fist memory card to path\n" \
-"\t--mcd2 path sets the second memory card to path\n"
-
int main(int argc, const char *argv[]) {
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
char parentdir[MAXPATHLEN];
@@ -125,14 +116,16 @@ void SysPrintf(const char *fmt, ...) {
void SysMessage(const char *fmt, ...) {
va_list list;
- NSString *locFmtString = NSLocalizedString([NSString stringWithCString:fmt encoding:NSUTF8StringEncoding], nil);
+ NSString *locFmtString = NSLocalizedString(@(fmt), nil);
va_start(list, fmt);
NSString *msg = [[NSString alloc] initWithFormat:locFmtString arguments:list];
va_end(list);
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:msg forKey:NSLocalizedFailureReasonErrorKey];
- [NSApp presentError:[NSError errorWithDomain:@"Unknown Domain" code:-1 userInfo:userInfo]];
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ [NSApp presentError:[NSError errorWithDomain:@"Unknown Domain" code:-1 userInfo:userInfo]];
+ });
RELEASEOBJ(msg);
}
@@ -199,7 +192,7 @@ void OnFile_Exit() {
char* Pcsxr_locale_text(char* toloc){
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *origString = nil, *transString = nil;
- origString = [NSString stringWithCString:toloc encoding:NSUTF8StringEncoding];
+ origString = @(toloc);
transString = [mainBundle localizedStringForKey:origString value:nil table:nil];
return (char*)[transString UTF8String];
}