From 16c70e4cdedc6875d217ae715b3215066b8dd5a2 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Sat, 22 May 2021 15:20:12 +0100 Subject: [PATCH] Fix https://github.com/audetto/AppleWin/issues/29 Signed-off-by: Andrea Odetti --- source/frontends/sdl/processfile.cpp | 68 ++++++++++++++++------------ source/frontends/sdl/processfile.h | 2 +- source/frontends/sdl/sdlframe.cpp | 2 +- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/source/frontends/sdl/processfile.cpp b/source/frontends/sdl/processfile.cpp index f199d16e..4ec738cf 100644 --- a/source/frontends/sdl/processfile.cpp +++ b/source/frontends/sdl/processfile.cpp @@ -8,49 +8,57 @@ #include "Core.h" #include "Harddisk.h" +namespace +{ + + void insertDisk(sa2::SDLFrame * frame, const char * filename, const size_t dragAndDropSlot, const size_t dragAndDropDrive) + { + CardManager & cardManager = GetCardMgr(); + const SS_CARDTYPE cardInSlot = cardManager.QuerySlot(dragAndDropSlot); + switch (cardInSlot) + { + case CT_Disk2: + { + Disk2InterfaceCard * card2 = dynamic_cast(cardManager.GetObj(dragAndDropSlot)); + const ImageError_e error = card2->InsertDisk(dragAndDropDrive, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); + if (error != eIMAGE_ERROR_NONE) + { + card2->NotifyInvalidImage(dragAndDropDrive, filename, error); + } + break; + } + case CT_GenericHDD: + { + if (!HD_Insert(dragAndDropDrive, filename)) + { + frame->FrameMessageBox("Invalid HD image", "ERROR", MB_OK); + } + break; + } + default: + { + frame->FrameMessageBox("Invalid D&D target", "ERROR", MB_OK); + } + } + } +} + namespace sa2 { - void processFile(SDLFrame * frame, const char * filename, const size_t dragAndDropSlot) + void processFile(SDLFrame * frame, const char * filename, const size_t dragAndDropSlot, const size_t dragAndDropDrive) { const char * yaml = ".yaml"; if (strlen(filename) > strlen(yaml) && !strcmp(filename + strlen(filename) - strlen(yaml), yaml)) { common2::setSnapshotFilename(filename, true); - frame->ResetSpeed(); } else { - CardManager & cardManager = GetCardMgr(); - SS_CARDTYPE cardInSlot = cardManager.QuerySlot(dragAndDropSlot); - switch (cardInSlot) - { - case CT_Disk2: - { - // for now we insert in DRIVE_1 - Disk2InterfaceCard * card2 = dynamic_cast(cardManager.GetObj(dragAndDropSlot)); - const ImageError_e error = card2->InsertDisk(dragAndDropSlot, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); - if (error != eIMAGE_ERROR_NONE) - { - card2->NotifyInvalidImage(dragAndDropSlot, filename, error); - } - break; - } - case CT_GenericHDD: - { - if (!HD_Insert(dragAndDropSlot, filename)) - { - frame->FrameMessageBox("Invalid HD image", "ERROR", MB_OK); - } - break; - } - default: - { - frame->FrameMessageBox("Invalid D&D target", "ERROR", MB_OK); - } - } + insertDisk(frame, filename, dragAndDropSlot, dragAndDropDrive); } + frame->ResetSpeed(); } } diff --git a/source/frontends/sdl/processfile.h b/source/frontends/sdl/processfile.h index 911c2bb5..32b067c1 100644 --- a/source/frontends/sdl/processfile.h +++ b/source/frontends/sdl/processfile.h @@ -2,5 +2,5 @@ namespace sa2 { class SDLFrame; - void processFile(SDLFrame * frame, const char * filename, const size_t dragAndDropSlot); + void processFile(SDLFrame * frame, const char * filename, const size_t dragAndDropSlot, const size_t dragAndDropDrive); } diff --git a/source/frontends/sdl/sdlframe.cpp b/source/frontends/sdl/sdlframe.cpp index 38031a7f..26387c43 100644 --- a/source/frontends/sdl/sdlframe.cpp +++ b/source/frontends/sdl/sdlframe.cpp @@ -317,7 +317,7 @@ namespace sa2 void SDLFrame::ProcessDropEvent(const SDL_DropEvent & drop) { - processFile(this, drop.file, myDragAndDropSlot); + processFile(this, drop.file, myDragAndDropSlot, myDragAndDropDrive); } void SDLFrame::ProcessKeyDown(const SDL_KeyboardEvent & key)