diff options
| author | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2012-09-23 19:24:03 +0000 |
|---|---|---|
| committer | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2012-09-23 19:24:03 +0000 |
| commit | bda521f3a4c42277160381ddfbfb8e42b7e87274 (patch) | |
| tree | 2f09725f74d05c9f1cc9d15cf603d5573414d534 | |
| parent | 148ac41c4d75acd6df08ef8ce204235b1e09e921 (diff) | |
| download | pcsxr-bda521f3a4c42277160381ddfbfb8e42b7e87274.tar.gz | |
Changing encoding of c strings returned for the linker on OS X to ASCII: I doubt the Mach-O file format is in UTF-8
Fixing releasing when the parent's class init fails: The proper way is to pass null when that happens, not release then pass null.
Using fast enumeration where possible.
Modified the bin/cue handling to also find the bin for .toc files. Note that there isn't a UTI for .toc files yet.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@79980 e17a0e51-4ae3-4d35-97c3-1a29b211df97
| -rw-r--r-- | macosx/ConfigurationController.m | 7 | ||||
| -rw-r--r-- | macosx/PcsxrController.m | 54 | ||||
| -rw-r--r-- | macosx/PcsxrPlugin.m | 85 | ||||
| -rw-r--r-- | macosx/PluginController.m | 2 | ||||
| -rw-r--r-- | macosx/PluginList.m | 16 |
5 files changed, 96 insertions, 68 deletions
diff --git a/macosx/ConfigurationController.m b/macosx/ConfigurationController.m index 1820b8e9..42eeee89 100644 --- a/macosx/ConfigurationController.m +++ b/macosx/ConfigurationController.m @@ -127,10 +127,9 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier"; if ([sender pullsDown]) { NSArray *items = [sender itemArray]; - NSUInteger i; - - for (i = 0; i < [items count]; i++) - [[items objectAtIndex:i] setState:NSOffState]; + for (id object in items) { + [object setState:NSOffState]; + } [[sender selectedItem] setState:NSOnState]; } diff --git a/macosx/PcsxrController.m b/macosx/PcsxrController.m index 9b56be64..72409f7e 100644 --- a/macosx/PcsxrController.m +++ b/macosx/PcsxrController.m @@ -16,14 +16,41 @@ NSDictionary *prefByteKeys; NSMutableArray *biosList; NSString *saveStatePath; +static NSString *GetBin(NSString *toHandle) +{ + NSString *extension = [toHandle pathExtension]; + BOOL getBin = NO; + if ([extension caseInsensitiveCompare:@"cue"] == NSOrderedSame) + getBin = YES; + if ([extension caseInsensitiveCompare:@"toc"] == NSOrderedSame) + getBin = YES; + + if (getBin == YES) + { + NSString *returnPath = nil; + NSString *rawPath = [toHandle stringByDeletingPathExtension]; + returnPath = [rawPath stringByAppendingPathExtension:@"bin"]; + if(![[NSFileManager defaultManager] fileExistsAtPath:returnPath]) + { + //TODO: handle case-sensitive filesystems better + returnPath = [rawPath stringByAppendingPathExtension:@"BIN"]; + } + return returnPath; + } else { + return toHandle; + } + +} + static NSString *HandleBinCue(NSString *toHandle) { NSURL *tempURL = [[NSURL alloc] initFileURLWithPath:toHandle]; + BOOL gotBin = NO; NSString *extension = [tempURL pathExtension]; NSString *newName = toHandle; + NSURL *temp1 = [tempURL URLByDeletingLastPathComponent]; + NSURL *temp2 = nil; if ([extension caseInsensitiveCompare:@"cue"] == NSOrderedSame) { - NSURL *temp1 = [tempURL URLByDeletingLastPathComponent]; - NSURL *temp2 = nil; //Get the bin file name from the cue. NSString *cueFile = [NSString stringWithContentsOfURL:tempURL encoding:NSUTF8StringEncoding error:nil]; if (!cueFile) { @@ -49,19 +76,16 @@ static NSString *HandleBinCue(NSString *toHandle) if (![[NSFileManager defaultManager] fileExistsAtPath:[temp2 path]]) goto badCue; - goto goodCue; + gotBin = YES; badCue: - //Fallback if the cue couldn't be loaded - temp1 = [tempURL URLByDeletingPathExtension]; - //TODO: handle case-sensitive filesystems better - temp2 = [temp1 URLByAppendingPathExtension:@"bin"]; - if (![[NSFileManager defaultManager] fileExistsAtPath:[temp2 path]]) { - temp2 = [temp1 URLByAppendingPathExtension:@"BIN"]; - } - - goodCue: + ; + } + if (gotBin == YES) + { newName = [temp2 path]; + } else { + newName = GetBin(toHandle); } [tempURL release]; return newName; @@ -186,8 +210,8 @@ static NSString *HandleBinCue(NSString *toHandle) - (IBAction)freeze:(id)sender { - int num = [sender tag]; - NSString *path = [saveStatePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%s-%3.3d.pcsxrstate", CdromId, num]]; + NSInteger num = [sender tag]; + NSString *path = [saveStatePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%s-%3.3ld.pcsxrstate", CdromId, (long)num]]; [EmuThread freezeAt:path which:num-1]; } @@ -508,7 +532,7 @@ static NSString *HandleBinCue(NSString *toHandle) NSError *err = nil; NSString *utiFile = [[NSWorkspace sharedWorkspace] typeOfFile:filename error:&err]; if (err) { - NSRunAlertPanel(NSLocalizedString(@"Error opening file",nil), [NSString stringWithFormat:NSLocalizedString(@"Unable to open %@: %@", nil), [filename lastPathComponent], [err localizedFailureReason]], nil, nil, nil); + NSRunAlertPanel(NSLocalizedString(@"Error opening file", nil), [NSString stringWithFormat:NSLocalizedString(@"Unable to open %@: %@", nil), [filename lastPathComponent], [err localizedFailureReason]], nil, nil, nil); return NO; } static NSArray *handlers = nil; diff --git a/macosx/PcsxrPlugin.m b/macosx/PcsxrPlugin.m index 2d5e99ce..f286d99b 100644 --- a/macosx/PcsxrPlugin.m +++ b/macosx/PcsxrPlugin.m @@ -30,14 +30,17 @@ { //return @"Plugin" [PcsxrPlugin prefixForType:aType]; switch (aType) { - case PSE_LT_GPU: return @"PluginGPU"; - case PSE_LT_CDR: return @"PluginCDR"; - case PSE_LT_SPU: return @"PluginSPU"; - case PSE_LT_PAD: return @"PluginPAD"; - case PSE_LT_NET: return @"PluginNET"; + case PSE_LT_GPU: + case PSE_LT_CDR: + case PSE_LT_SPU: + case PSE_LT_PAD: + case PSE_LT_NET: + [NSString stringWithFormat:@"Plugin%@", [PcsxrPlugin prefixForType:aType]]; + break; + default: + return @""; + break; } - - return @""; } + (char **)configEntriesForType:(int)aType @@ -61,33 +64,37 @@ + (NSArray *)pluginsPaths { - NSURL *supportURL = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:NULL]; - NSURL *libraryURL = [[NSFileManager defaultManager] URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:NULL]; - NSURL *localSupportURL = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSLocalDomainMask appropriateForURL:nil create:YES error:NULL]; - NSURL *localLibraryURL = [[NSFileManager defaultManager] URLForDirectory:NSLibraryDirectory inDomain:NSLocalDomainMask appropriateForURL:nil create:YES error:NULL]; + static NSArray *returnArray = nil; + if (returnArray == nil) + { + NSURL *supportURL = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:NULL]; + NSURL *libraryURL = [[NSFileManager defaultManager] URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:NULL]; + NSURL *localSupportURL = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSLocalDomainMask appropriateForURL:nil create:YES error:NULL]; + NSURL *localLibraryURL = [[NSFileManager defaultManager] URLForDirectory:NSLibraryDirectory inDomain:NSLocalDomainMask appropriateForURL:nil create:YES error:NULL]; - NSMutableArray *mutArray = [NSMutableArray arrayWithCapacity:5]; + NSMutableArray *mutArray = [NSMutableArray arrayWithCapacity:5]; - [mutArray addObject:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:Config.PluginsDir length:strlen(Config.PluginsDir)]]; - NSURL *url = [localLibraryURL URLByAppendingPathComponent:@"Playstation Emulator Plugins"]; - if ([url checkResourceIsReachableAndReturnError:NULL]) - [mutArray addObject:[url path]]; - url = [localSupportURL URLByAppendingPathComponent:@"Pcsxr/PlugIns"]; - if ([url checkResourceIsReachableAndReturnError:NULL]) - [mutArray addObject:[url path]]; - url = [libraryURL URLByAppendingPathComponent:@"Playstation Emulator Plugins"]; - if ([url checkResourceIsReachableAndReturnError:NULL]) - [mutArray addObject:[url path]]; - url = [supportURL URLByAppendingPathComponent:@"Pcsxr/PlugIns"]; - if ([url checkResourceIsReachableAndReturnError:NULL]) - [mutArray addObject:[url path]]; - return [NSArray arrayWithArray:mutArray]; + [mutArray addObject:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:Config.PluginsDir length:strlen(Config.PluginsDir)]]; + NSURL *url = [localLibraryURL URLByAppendingPathComponent:@"Playstation Emulator Plugins"]; + if ([url checkResourceIsReachableAndReturnError:NULL]) + [mutArray addObject:[url path]]; + url = [[localSupportURL URLByAppendingPathComponent:@"Pcsxr"] URLByAppendingPathComponent:@"PlugIns"]; + if ([url checkResourceIsReachableAndReturnError:NULL]) + [mutArray addObject:[url path]]; + url = [libraryURL URLByAppendingPathComponent:@"Playstation Emulator Plugins"]; + if ([url checkResourceIsReachableAndReturnError:NULL]) + [mutArray addObject:[url path]]; + url = [[supportURL URLByAppendingPathComponent:@"Pcsxr"] URLByAppendingPathComponent:@"PlugIns"]; + if ([url checkResourceIsReachableAndReturnError:NULL]) + [mutArray addObject:[url path]]; + returnArray = [[NSArray alloc] initWithArray:mutArray]; + } + return returnArray; } - (id)initWithPath:(NSString *)aPath { if (!(self = [super init])) { - [self autorelease]; return nil; } @@ -122,7 +129,7 @@ } if (goodPath == nil) { - [self autorelease]; + [self release]; return nil; } @@ -203,11 +210,11 @@ - (void)runCommand:(id)arg { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *pool = [NSAutoreleasePool new]; NSString *funcName = [arg objectAtIndex:0]; long (*func)(void); - func = SysLoadSym(pluginRef, [funcName cStringUsingEncoding:NSUTF8StringEncoding]); + func = SysLoadSym(pluginRef, [funcName cStringUsingEncoding:NSASCIIStringEncoding]); if (SysLibError() == nil) { func(); } else { @@ -230,7 +237,7 @@ return 0; } - sprintf(symbol, "%sinit", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSUTF8StringEncoding]); + sprintf(symbol, "%sinit", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSASCIIStringEncoding]); init = initArg = SysLoadSym(pluginRef, symbol); if (SysLibError() == nil) { if (aType != PSE_LT_PAD) @@ -255,7 +262,7 @@ char symbol[255]; long (*shutdown)(void); - sprintf(symbol, "%sshutdown", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSUTF8StringEncoding]); + sprintf(symbol, "%sshutdown", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSASCIIStringEncoding]); shutdown = SysLoadSym(pluginRef, symbol); if (SysLibError() == nil) { active &= ~aType; @@ -269,7 +276,7 @@ { char symbol[255]; - sprintf(symbol, "%sabout", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSUTF8StringEncoding]); + sprintf(symbol, "%sabout", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSASCIIStringEncoding]); SysLoadSym(pluginRef, symbol); return (SysLibError() == nil); @@ -279,7 +286,7 @@ { char symbol[255]; - sprintf(symbol, "%sconfigure", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSUTF8StringEncoding]); + sprintf(symbol, "%sconfigure", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSASCIIStringEncoding]); SysLoadSym(pluginRef, symbol); return (SysLibError() == nil); @@ -290,13 +297,14 @@ NSArray *arg; char symbol[255]; - sprintf(symbol, "%sabout", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSUTF8StringEncoding]); - arg = [[NSArray alloc] initWithObjects:[NSString stringWithCString:symbol encoding:NSUTF8StringEncoding], + sprintf(symbol, "%sabout", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSASCIIStringEncoding]); + arg = [[NSArray alloc] initWithObjects:[NSString stringWithCString:symbol encoding:NSASCIIStringEncoding], [NSNumber numberWithInt:0], nil]; // detach a new thread [NSThread detachNewThreadSelector:@selector(runCommand:) toTarget:self withObject:arg]; + //NOTE: the runCommand releases the arg command. Probably not the best way to do it... } - (void)configureAs:(int)aType @@ -304,13 +312,14 @@ NSArray *arg; char symbol[255]; - sprintf(symbol, "%sconfigure", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSUTF8StringEncoding]); - arg = [[NSArray alloc] initWithObjects:[NSString stringWithCString:symbol encoding:NSUTF8StringEncoding], + sprintf(symbol, "%sconfigure", [[PcsxrPlugin prefixForType:aType] cStringUsingEncoding:NSASCIIStringEncoding]); + arg = [[NSArray alloc] initWithObjects:[NSString stringWithCString:symbol encoding:NSASCIIStringEncoding], [NSNumber numberWithInt:1], nil]; // detach a new thread [NSThread detachNewThreadSelector:@selector(runCommand:) toTarget:self withObject:arg]; + //NOTE: the runCommand releases the arg command. Probably not the best way to do it... } - (NSString *)displayVersion diff --git a/macosx/PluginController.m b/macosx/PluginController.m index d75e8892..d89b38fc 100644 --- a/macosx/PluginController.m +++ b/macosx/PluginController.m @@ -20,7 +20,7 @@ - (IBAction)selectPlugin:(id)sender { if (sender==pluginMenu) { - int index = [pluginMenu indexOfSelectedItem]; + NSInteger index = [pluginMenu indexOfSelectedItem]; if (index != -1) { PcsxrPlugin *plugin = [plugins objectAtIndex:index]; diff --git a/macosx/PluginList.m b/macosx/PluginList.m index 866e2469..7f340f65 100644 --- a/macosx/PluginList.m +++ b/macosx/PluginList.m @@ -91,7 +91,6 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD, if (!(self = [super init])) { - [self autorelease]; return nil; } @@ -175,6 +174,7 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD, PcsxrPlugin *plugin = [[PcsxrPlugin alloc] initWithPath:pname]; if (plugin != nil) { [pluginList addObject:plugin]; + [plugin release]; } } } @@ -202,16 +202,13 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD, - (NSArray *)pluginsForType:(int)typeMask { NSMutableArray *types = [NSMutableArray array]; - NSUInteger i; - for (i=0; i<[pluginList count]; i++) { - PcsxrPlugin *plugin = [pluginList objectAtIndex:i]; - + for (PcsxrPlugin *plugin in pluginList) { if ([plugin type] & typeMask) { [types addObject:plugin]; } } - + return types; } @@ -220,12 +217,11 @@ const static int typeList[5] = {PSE_LT_GPU, PSE_LT_SPU, PSE_LT_CDR, PSE_LT_PAD, if (nil == path) return NO; - NSUInteger i; - for (i=0; i<[pluginList count]; i++) { - if ([[[pluginList objectAtIndex:i] path] isEqualToString:path]) + for (PcsxrPlugin *plugin in pluginList) { + if ([[plugin path] isEqualToString:path]) return YES; } - + return NO; } |
