diff options
| author | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2011-12-17 19:08:51 +0000 |
|---|---|---|
| committer | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2011-12-17 19:08:51 +0000 |
| commit | b6f15852f36e8d017a275bc3727c5dcab1846d29 (patch) | |
| tree | d4913175221b0ea3baca8f0b9bc62e86f481f1aa /macosx/PcsxrController.m | |
| parent | b205e6323f8b10c9dcbfb9fd21e7cb896b3805ef (diff) | |
| download | pcsxr-b6f15852f36e8d017a275bc3727c5dcab1846d29.tar.gz | |
Reduce code duplication in -[PcsxrController application:openFile:].
Added a new function to the PcsxrFileHandle protocol that says what types of UTIs it supports. Currently only used when selecting discs or memory cards from an open dialog, and not used in checking if an app can open a file.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@73437 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/PcsxrController.m')
| -rw-r--r-- | macosx/PcsxrController.m | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/macosx/PcsxrController.m b/macosx/PcsxrController.m index ebc4b2d1..72feab3a 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:[NSArray arrayWithObjects:@"com.alcohol-soft.mdfdisc", @"com.codeplex.pcsxr.cuefile", @"com.apple.disk-image-ndif", @"public.iso-image", nil]]; + [openDlg setAllowedFileTypes:[PcsxrDiscHandler utisCanHandle]]; 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:[NSArray arrayWithObjects:@"com.alcohol-soft.mdfdisc", @"com.codeplex.pcsxr.cuefile", @"com.apple.disk-image-ndif", @"public.iso-image", nil]]; + [openDlg setAllowedFileTypes:[PcsxrDiscHandler utisCanHandle]]; if ([openDlg runModal] == NSFileHandlingPanelOKButton) { NSArray* urls = [openDlg URLs]; @@ -472,29 +472,23 @@ 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<PcsxrFileHandle> *hand = nil; + BOOL isHandled = NO; if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.plugin"), (CFStringRef)utiFile)) { - PcsxrPluginHandler *hand = [[PcsxrPluginHandler alloc] init]; - BOOL isHandled = [hand handleFile:filename]; - [hand release]; - return isHandled; + hand = [[PcsxrPluginHandler alloc] init]; + isHandled = [hand handleFile:filename]; } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.memcard"), (CFStringRef)utiFile)) { - PcsxrMemCardHandler *hand = [[PcsxrMemCardHandler alloc] init]; - BOOL isHandled = [hand handleFile:filename]; - [hand release]; - return isHandled; + hand = [[PcsxrMemCardHandler alloc] init]; + isHandled = [hand handleFile:filename]; } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.freeze"), (CFStringRef)utiFile)) { - PcsxrFreezeStateHandler *hand = [[PcsxrFreezeStateHandler alloc] init]; - BOOL isHandled = [hand handleFile:filename]; - [hand release]; - return isHandled; + 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)) { - PcsxrDiscHandler *hand = [[PcsxrDiscHandler alloc] init]; - BOOL isHandled = [hand handleFile:HandleBinCue(filename)]; - [hand release]; - return isHandled; - } else { - return NO; + hand = [[PcsxrDiscHandler alloc] init]; + isHandled = [hand handleFile:HandleBinCue(filename)]; } + if (hand) [hand release]; + return isHandled; } @end |
