summaryrefslogtreecommitdiff
path: root/macosx/PcsxrController.m
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-09-16 20:31:07 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-09-16 20:31:07 +0000
commita5a97b02c0205f0cc98327389ec88672ddd769f2 (patch)
treee1b7254679180d8e9413c3b10fb8b2e3c91691aa /macosx/PcsxrController.m
parent481101a05a77e2cc5b22cc94a5319748aeb5c031 (diff)
downloadpcsxr-a5a97b02c0205f0cc98327389ec88672ddd769f2.tar.gz
Wait for a new physical CD to be inserted when ejecting the CD on OS X.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@87220 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/PcsxrController.m')
-rwxr-xr-xmacosx/PcsxrController.m75
1 files changed, 60 insertions, 15 deletions
diff --git a/macosx/PcsxrController.m b/macosx/PcsxrController.m
index a2d6ba93..f517ba3d 100755
--- a/macosx/PcsxrController.m
+++ b/macosx/PcsxrController.m
@@ -9,6 +9,8 @@
#import "PcsxrFreezeStateHandler.h"
#import "PcsxrCheatHandler.h"
#import "LaunchArg.h"
+#include <DiskArbitration/DiskArbitration.h>
+#include <IOKit/storage/IOCDMedia.h>
#include "psxcommon.h"
#include "plugins.h"
#include "misc.h"
@@ -52,6 +54,7 @@ void ShowHelpAndExit(FILE* output, int exitCode)
@property (strong) NSMutableArray *skipFiles;
@property (strong) NSWindow *preferenceWindow;
@property (strong) NSWindow *cheatWindow;
+@property (nonatomic) DASessionRef diskSession;
@end
@implementation PcsxrController
@@ -91,13 +94,43 @@ void ShowHelpAndExit(FILE* output, int exitCode)
PSXflags.wasPausedBeforeBGSwitch = wasPausedBeforeBGSwitch;
}
-- (IBAction)ejectCD:(id)sender
+@synthesize diskSession = _diskSession;
+- (void)setDiskSession:(DASessionRef)diskSession
{
- NSMutableString *deviceName;
- NSTask *ejectTask;
- NSRange rdiskRange;
+ if (diskSession == _diskSession) {
+ return;
+ }
+ if (_diskSession) {
+ CFRelease(_diskSession);
+ }if (diskSession) {
+ _diskSession = diskSession;
+ CFRetain(diskSession);
+ }
+}
- BOOL wasPaused = [EmuThread pauseSafe];
+static BOOL wasPaused;
+static void PSXDiscAppearedCallback(DADiskRef disk, void *context)
+{
+ PcsxrController *theSelf = (__bridge PcsxrController*)context;
+
+ SetCdOpenCaseTime(time(NULL) + 2);
+ LidInterrupt();
+
+ /* and open new cd */
+ if ([EmuThread active])
+ CDR_open();
+
+ if (!wasPaused) {
+ [EmuThread resume];
+ }
+
+ DASessionUnscheduleFromRunLoop(theSelf.diskSession, CFRunLoopGetMain(), kCFRunLoopCommonModes);
+ theSelf.diskSession = NULL;
+}
+
+- (IBAction)ejectCD:(id)sender
+{
+ wasPaused = [EmuThread pauseSafe];
/* close connection to current cd */
if ([EmuThread active])
@@ -117,10 +150,20 @@ void ShowHelpAndExit(FILE* output, int exitCode)
SetCdOpenCaseTime(time(NULL) + 2);
LidInterrupt();
}
+
+ if ([EmuThread active])
+ CDR_open();
+
+ if (!wasPaused) {
+ [EmuThread resume];
+ }
} else {
- char *driveLetter = CDR_getDriveLetter();
+ NSMutableString *deviceName;
+ NSTask *ejectTask;
+ NSRange rdiskRange;
+ char *driveLetter = CDR_getDriveLetter();
- if (driveLetter != nil) {
+ if (driveLetter != NULL) {
deviceName = [NSMutableString stringWithString:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:driveLetter length:strlen(driveLetter)]];
// delete the 'r' in 'rdisk'
@@ -133,14 +176,16 @@ void ShowHelpAndExit(FILE* output, int exitCode)
ejectTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:@[@"eject", deviceName]];
[ejectTask waitUntilExit];
}
- }
-
- /* and open new cd */
- if ([EmuThread active])
- CDR_open();
-
- if (!wasPaused) {
- [EmuThread resume];
+ DASessionRef tmpSession = DASessionCreate(kCFAllocatorDefault);
+ CFDictionaryRef match = CFBridgingRetain(@{(NSString*)kDADiskDescriptionMediaKindKey : @(kIOCDMediaClass),
+ (NSString*)kDADiskDescriptionMediaWholeKey : @YES});
+ DARegisterDiskAppearedCallback(tmpSession, match, PSXDiscAppearedCallback, (__bridge void*)self);
+ CFRelease(match);
+
+ DASessionScheduleWithRunLoop(tmpSession, CFRunLoopGetMain(), kCFRunLoopCommonModes);
+
+ self.diskSession = tmpSession;
+ CFRelease(tmpSession);
}
}