diff --git a/macosx/.DS_Store b/macosx/.DS_Store index ebac474f..3489d03d 100644 Binary files a/macosx/.DS_Store and b/macosx/.DS_Store differ diff --git a/macosx/Snes9x/AppDelegate.m b/macosx/Snes9x/AppDelegate.m index da826e80..4a43b776 100644 --- a/macosx/Snes9x/AppDelegate.m +++ b/macosx/Snes9x/AppDelegate.m @@ -17,6 +17,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.s9xEngine = [S9xEngine new]; + [self importRecentItems]; } @@ -24,6 +25,30 @@ // Insert code here to tear down your application } +- (void)importRecentItems +{ + const NSInteger maxRecents = 20; + + for (NSInteger i = maxRecents - 1; i >= 0; --i) + { + NSString *key = [NSString stringWithFormat:@"RecentItem_%02tu", i]; + NSString *recentItem = [NSUserDefaults.standardUserDefaults objectForKey:key]; + + if (recentItem != nil) + { + [NSDocumentController.sharedDocumentController noteNewRecentDocumentURL:[NSURL fileURLWithPath:recentItem]]; + [NSUserDefaults.standardUserDefaults removeObjectForKey:key]; + } + } + + [[NSUserDefaults standardUserDefaults] synchronize]; +} + +- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename +{ + return [self openURL:[NSURL fileURLWithPath:filename]]; +} + - (IBAction)openDocument:(id)sender { NSOpenPanel* panel = [NSOpenPanel new]; @@ -31,8 +56,19 @@ if ( response == NSModalResponseOK ) { - [self.s9xEngine loadROM:panel.URL]; + [self openURL:panel.URL]; } } +- (BOOL)openURL:(NSURL *)url +{ + if ([self.s9xEngine loadROM:url]) + { + [NSDocumentController.sharedDocumentController noteNewRecentDocumentURL:url]; + return YES; + } + + return NO; +} + @end diff --git a/macosx/mac-os.h b/macosx/mac-os.h index b39964a0..b5828071 100644 --- a/macosx/mac-os.h +++ b/macosx/mac-os.h @@ -168,7 +168,6 @@ extern os_unfair_lock keyLock; extern NSOpenGLView *s9xView; -void AddRecentItem (NSURL *); void AdjustMenus (void); void UpdateMenuCommandStatus (Boolean); void ApplyNSRTHeaderControllers (void); @@ -183,7 +182,7 @@ uint64 GetMicroseconds(void); - (void)start; -- (void)loadROM:(NSURL *)fileURL; +- (BOOL)loadROM:(NSURL *)fileURL; @end diff --git a/macosx/mac-os.mm b/macosx/mac-os.mm index b06371da..0f485d6e 100644 --- a/macosx/mac-os.mm +++ b/macosx/mac-os.mm @@ -335,9 +335,6 @@ static ButtonCommand btncmd[] = static void Initialize (void); static void Deinitialize (void); static void InitAutofire (void); -static void InitRecentItems (void); -static void DeinitRecentItems (void); -static void ClearRecentItems (void); static void ProcessInput (void); static void ResizeGameWindow (void); static void ChangeAutofireSettings (int, int); @@ -999,125 +996,6 @@ static inline void EmulationLoop (void) // return (result); //} // -static void InitRecentItems (void) -{ - CFStringRef keyRef, pathRef; - int count; - char key[32]; - - count = 0; - - for (int i = 0; i <= kRecentMenu_MAX; i++) - recentItem[i] = NULL; - - for (int i = 0; i < kRecentMenu_MAX; i++) - { - sprintf(key, "RecentItem_%02d", i); - keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding()); - if (keyRef) - { - pathRef = (CFStringRef) CFPreferencesCopyAppValue(keyRef, kCFPreferencesCurrentApplication); - if (pathRef) - { - recentItem[count] = pathRef; - count++; - } - - CFRelease(keyRef); - } - } -} -// -static void DeinitRecentItems (void) -{ - CFStringRef keyRef; - char key[32]; - - for (int i = 0; i < kRecentMenu_MAX; i++) - { - sprintf(key, "RecentItem_%02d", i); - keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding()); - if (keyRef) - { - if (recentItem[i]) - { - CFPreferencesSetAppValue(keyRef, recentItem[i], kCFPreferencesCurrentApplication); - CFRelease(recentItem[i]); - recentItem[i] = NULL; - } - else - CFPreferencesSetAppValue(keyRef, NULL, kCFPreferencesCurrentApplication); - - CFRelease(keyRef); - } - } - - CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication); -} - -static void ClearRecentItems (void) -{ - for (int i = 0; i < kRecentMenu_MAX; i++) - { - if (recentItem[i]) - { - CFRelease(recentItem[i]); - recentItem[i] = NULL; - } - } -} -// -void AddRecentItem (NSURL *url) -{ -// OSStatus err; -// char path[PATH_MAX + 1]; -// -// err = FSRefMakePath(ref, (unsigned char *) path, PATH_MAX); -// if (err == noErr) -// { -// CFStringRef pathRef; -// -// pathRef = CFStringCreateWithCString(kCFAllocatorDefault, path, kCFStringEncodingUTF8); -// if (pathRef) -// { -// int i, j; -// -// for (i = 0; i < kRecentMenu_MAX; i++) -// if (recentItem[i] && (CFStringCompare(pathRef, recentItem[i], 0) == 0)) -// break; -// -// if (i == kRecentMenu_MAX) -// { -// for (j = kRecentMenu_MAX - 1; j >= 0; j--) -// recentItem[j + 1] = recentItem[j]; -// -// if (recentItem[kRecentMenu_MAX]) -// { -// CFRelease(recentItem[kRecentMenu_MAX]); -// recentItem[kRecentMenu_MAX] = NULL; -// } -// -// recentItem[0] = pathRef; -// } -// else -// { -// CFRelease(pathRef); -// -// if (i > 0) -// { -// CFStringRef temp; -// -// temp = recentItem[i]; -// -// for (j = i - 1; j >= 0; j--) -// recentItem[j + 1] = recentItem[j]; -// -// recentItem[0] = temp; -// } -// } -// } -// } -} // //static void InitRecentMenu (void) //{ @@ -2923,8 +2801,6 @@ static void Initialize (void) InitMacSound(); SetUpHID(); - InitRecentItems(); - InitMultiCart(); autofire = (autofireRec[0].buttonMask || autofireRec[1].buttonMask) ? true : false; @@ -2960,7 +2836,6 @@ static void Deinitialize (void) deviceSetting = deviceSettingMaster; DeinitMultiCart(); - DeinitRecentItems(); SavePrefs(); ReleaseHID(); DeinitCheatFinder(); @@ -3283,7 +3158,7 @@ void QuitWithFatalError ( NSString *message) } } -- (void)loadROM:(NSURL *)fileURL +- (BOOL)loadROM:(NSURL *)fileURL { if ( SNES9X_OpenCart(fileURL) ) { @@ -3291,7 +3166,10 @@ void QuitWithFatalError ( NSString *message) s9xView.window.title = fileURL.lastPathComponent.stringByDeletingPathExtension; [s9xView.window makeKeyAndOrderFront:nil]; [self start]; + return YES; } + + return NO; } @end diff --git a/macosx/mac-snes9x.mm b/macosx/mac-snes9x.mm index d4bac756..48cb37b6 100755 --- a/macosx/mac-snes9x.mm +++ b/macosx/mac-snes9x.mm @@ -106,9 +106,6 @@ bool8 SNES9X_OpenCart (NSURL *inRef) ChangeTypeAndCreator(filename, 'CART', '~9X~'); - AddRecentItem(cartRef); - //BuildRecentMenu(); - ApplyNSRTHeaderControllers(); for (int a = 0; a < MAC_MAX_PLAYERS; a++)