@@ -277,6 +277,68 @@ - (void)applicationWillUnhide:(NSNotification *)notification {
277277 [self .emulatorVC start ];
278278}
279279
280+ - (BOOL )application : (NSApplication *)sender openFile : (nonnull NSString *)filename {
281+ // scan slots for floppy and hard drive controllers
282+ CardManager &cardManager = GetCardMgr ();
283+ BOOL success = NO ;
284+ int firstDisk2Slot = -1 ;
285+ int firstHDDSlot = -1 ;
286+ for (int slot = SLOT0; slot < NUM_SLOTS; slot++) {
287+ const SS_CARDTYPE cardType = cardManager.QuerySlot (slot);
288+ if (cardType == CT_GenericHDD) {
289+ if (firstHDDSlot < 0 ) {
290+ firstHDDSlot = slot;
291+ }
292+ // unplug all hard disks
293+ HarddiskInterfaceCard *hddCard = dynamic_cast <HarddiskInterfaceCard *>(cardManager.GetObj (slot));
294+ for (int idx = HARDDISK_1; idx < NUM_HARDDISKS; idx++) {
295+ hddCard->Unplug (idx);
296+ }
297+ }
298+ else if (cardType == CT_Disk2) {
299+ if (firstDisk2Slot < 0 ) {
300+ firstDisk2Slot = slot;
301+ }
302+ // eject all floppy disks
303+ Disk2InterfaceCard *disk2Card = dynamic_cast <Disk2InterfaceCard*>(cardManager.GetObj (slot));
304+ for (int idx = DRIVE_1; idx < NUM_DRIVES; idx++) {
305+ disk2Card->EjectDisk (idx);
306+ }
307+ }
308+ }
309+
310+ std::string fn (filename.UTF8String );
311+ if (firstHDDSlot >= 0 && [filename.lowercaseString hasSuffix: @" .hdv" ]) {
312+ HarddiskInterfaceCard *hddCard = dynamic_cast <HarddiskInterfaceCard *>(cardManager.GetObj (firstHDDSlot));
313+ if (hddCard->Insert (HARDDISK_1, fn)) {
314+ NSLog (@" Loaded '%@ ' as HDD 1" , filename);
315+ success = YES ;
316+ }
317+ else {
318+ NSLog (@" Failed to '%@ ' as HDD" , filename);
319+ }
320+ }
321+ else if (firstDisk2Slot >= 0 ) {
322+ Disk2InterfaceCard *disk2Card = dynamic_cast <Disk2InterfaceCard*>(cardManager.GetObj (firstDisk2Slot));
323+ const ImageError_e error = disk2Card->InsertDisk (DRIVE_1, fn, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE);
324+ if (error == eIMAGE_ERROR_NONE) {
325+ NSLog (@" Loaded '%@ ' into slot %d drive 1" , filename, firstDisk2Slot);
326+ success = YES ;
327+ }
328+ else {
329+ NSLog (@" Failed to load '%@ ' into slot %d drive 1 due to error %d " ,
330+ filename, firstDisk2Slot, error);
331+ disk2Card->NotifyInvalidImage (1 , fn, error);
332+ }
333+ }
334+
335+ [self reconfigureDrives ];
336+ [self updateDriveLights ];
337+ [self .emulatorVC reboot ];
338+
339+ return success;
340+ }
341+
280342#pragma mark - NSWindowDelegate
281343
282344- (BOOL )windowShouldClose : (NSWindow *)sender {
0 commit comments