From 52dd8ecce8339768bedfb424f9cb233b57cd55f4 Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Sun, 18 Dec 2011 23:51:13 +0000 Subject: Changed utisCanHandle to supportedUTIs. reworked application:openFile: to check if a PcsxrFileHandle supports a file then, if it does, uses the specified PcsxrFileHandle. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@73485 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/ConfigurationController.m | 4 ++-- macosx/PcsxrController.m | 32 ++++++++++++++++---------------- macosx/PcsxrDiscHandler.m | 2 +- macosx/PcsxrFileHandle.h | 2 +- macosx/PcsxrFreezeStateHandler.m | 2 +- macosx/PcsxrMemCardHandler.m | 4 ++-- macosx/PcsxrPluginHandler.m | 4 ++-- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/macosx/ConfigurationController.m b/macosx/ConfigurationController.m index 71601855..875ced70 100644 --- a/macosx/ConfigurationController.m +++ b/macosx/ConfigurationController.m @@ -64,7 +64,7 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier"; [openDlg setCanChooseFiles:YES]; [openDlg setCanChooseDirectories:NO]; - [openDlg setAllowedFileTypes:[PcsxrMemCardHandler utisCanHandle]]; + [openDlg setAllowedFileTypes:[PcsxrMemCardHandler supportedUTIs]]; path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:mcd length:strlen(mcd)]; @@ -96,7 +96,7 @@ NSString *memChangeNotifier = @"PcsxrMemoryCardDidChangeNotifier"; [openDlg setDirectoryURL:[NSURL fileURLWithPath:[path stringByDeletingLastPathComponent]]]; [openDlg setNameFieldStringValue:@"New Memory Card File.mcr"]; - [openDlg setAllowedFileTypes:[PcsxrMemCardHandler utisCanHandle]]; + [openDlg setAllowedFileTypes:[PcsxrMemCardHandler supportedUTIs]]; if ([openDlg runModal] == NSFileHandlingPanelOKButton) { NSString *mcdPath = [[openDlg URL] path]; diff --git a/macosx/PcsxrController.m b/macosx/PcsxrController.m index dea933b3..41830c26 100644 --- a/macosx/PcsxrController.m +++ b/macosx/PcsxrController.m @@ -55,7 +55,7 @@ static NSString *HandleBinCue(NSString *toHandle) [openDlg setCanChooseFiles:YES]; [openDlg setCanChooseDirectories:NO]; - [openDlg setAllowedFileTypes:[PcsxrDiscHandler utisCanHandle]]; + [openDlg setAllowedFileTypes:[PcsxrDiscHandler supportedUTIs]]; if ([openDlg runModal] == NSFileHandlingPanelOKButton) { NSArray* files = [openDlg URLs]; @@ -135,7 +135,7 @@ static NSString *HandleBinCue(NSString *toHandle) [openDlg setCanChooseFiles:YES]; [openDlg setCanChooseDirectories:NO]; - [openDlg setAllowedFileTypes:[PcsxrDiscHandler utisCanHandle]]; + [openDlg setAllowedFileTypes:[PcsxrDiscHandler supportedUTIs]]; if ([openDlg runModal] == NSFileHandlingPanelOKButton) { NSArray* urls = [openDlg URLs]; @@ -476,22 +476,22 @@ static NSString *HandleBinCue(NSString *toHandle) NSRunAlertPanel(NSLocalizedString(@"Error opening file",nil), [NSString stringWithFormat:NSLocalizedString(@"Unable to open %@: %@", nil), [filename lastPathComponent], [err localizedFailureReason]], nil, nil, nil); return NO; } - NSObject *hand = nil; + NSArray *handlers = [NSArray arrayWithObjects:[PcsxrPluginHandler class], [PcsxrMemCardHandler class], [PcsxrFreezeStateHandler class], [PcsxrDiscHandler class], nil]; BOOL isHandled = NO; - if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.plugin"), (CFStringRef)utiFile)) { - hand = [[PcsxrPluginHandler alloc] init]; - isHandled = [hand handleFile:filename]; - } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.memcard"), (CFStringRef)utiFile)) { - hand = [[PcsxrMemCardHandler alloc] init]; - isHandled = [hand handleFile:filename]; - } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.freeze"), (CFStringRef)utiFile)) { - hand = [[PcsxrFreezeStateHandler alloc] init]; - isHandled = [hand handleFile:filename]; - } else if(UTTypeEqual(CFSTR("com.alcohol-soft.mdfdisc"), (CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.apple.disk-image-ndif"), (CFStringRef)utiFile) || UTTypeEqual(CFSTR("public.iso-image"), (CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.codeplex.pcsxr.cuefile"), (CFStringRef)utiFile)) { - hand = [[PcsxrDiscHandler alloc] init]; - isHandled = [hand handleFile:HandleBinCue(filename)]; + for (Class fileHandler in handlers) { + NSObject *hand = [[fileHandler alloc] init]; + BOOL canHandle = NO; + for (NSString *uti in [fileHandler supportedUTIs]) { + if ([[NSWorkspace sharedWorkspace] type:utiFile conformsToType:uti]) { + canHandle = YES; + } + } + if (canHandle) { + isHandled = [hand handleFile:HandleBinCue(filename)]; + } + [hand release]; + } - if (hand) [hand release]; return isHandled; } diff --git a/macosx/PcsxrDiscHandler.m b/macosx/PcsxrDiscHandler.m index 9ba27a79..891acc6c 100644 --- a/macosx/PcsxrDiscHandler.m +++ b/macosx/PcsxrDiscHandler.m @@ -13,7 +13,7 @@ @implementation PcsxrDiscHandler -+ (NSArray *)utisCanHandle ++ (NSArray *)supportedUTIs { return [NSArray arrayWithObjects:@"com.alcohol-soft.mdfdisc", @"com.codeplex.pcsxr.cuefile", @"com.apple.disk-image-ndif", @"public.iso-image", nil]; } diff --git a/macosx/PcsxrFileHandle.h b/macosx/PcsxrFileHandle.h index 199e8bef..f3467a67 100644 --- a/macosx/PcsxrFileHandle.h +++ b/macosx/PcsxrFileHandle.h @@ -10,7 +10,7 @@ @protocol PcsxrFileHandle -+ (NSArray *)utisCanHandle; ++ (NSArray *)supportedUTIs; - (BOOL)handleFile:(NSString *)theFile; @end diff --git a/macosx/PcsxrFreezeStateHandler.m b/macosx/PcsxrFreezeStateHandler.m index 5e1e493c..934aff19 100644 --- a/macosx/PcsxrFreezeStateHandler.m +++ b/macosx/PcsxrFreezeStateHandler.m @@ -12,7 +12,7 @@ @implementation PcsxrFreezeStateHandler -+ (NSArray *)utisCanHandle ++ (NSArray *)supportedUTIs { return [NSArray arrayWithObject:@"com.codeplex.pcsxr.freeze"]; } diff --git a/macosx/PcsxrMemCardHandler.m b/macosx/PcsxrMemCardHandler.m index 7998cdda..b8d3cdd9 100644 --- a/macosx/PcsxrMemCardHandler.m +++ b/macosx/PcsxrMemCardHandler.m @@ -11,7 +11,7 @@ @implementation PcsxrMemCardHandler -+ (NSArray *)utisCanHandle ++ (NSArray *)supportedUTIs { return [NSArray arrayWithObject:@"com.codeplex.pcsxr.memcard"]; } @@ -28,7 +28,7 @@ - (id)init { - self = [super initWithWindowNibName:@"PcsxrMemCardDocument"]; + self = [self initWithWindowNibName:@"PcsxrMemCardDocument"]; return self; } diff --git a/macosx/PcsxrPluginHandler.m b/macosx/PcsxrPluginHandler.m index 48f758af..395c2461 100644 --- a/macosx/PcsxrPluginHandler.m +++ b/macosx/PcsxrPluginHandler.m @@ -10,7 +10,7 @@ @implementation PcsxrPluginHandler -+ (NSArray *)utisCanHandle ++ (NSArray *)supportedUTIs { return [NSArray arrayWithObject:@"com.codeplex.pcsxr.plugin"]; } @@ -27,7 +27,7 @@ - (id)init { - self = [super initWithWindowNibName:@"AddPluginSheet"]; + self = [self initWithWindowNibName:@"AddPluginSheet"]; return self; } -- cgit v1.2.3