diff --git a/pcsx2-qt/MainWindow.cpp b/pcsx2-qt/MainWindow.cpp index 47341f2cb8..2069b02b77 100644 --- a/pcsx2-qt/MainWindow.cpp +++ b/pcsx2-qt/MainWindow.cpp @@ -2168,57 +2168,56 @@ void MainWindow::dragEnterEvent(QDragEnterEvent* event) } void MainWindow::dropEvent(QDropEvent* event) +{ + if (startFile(getFilenameFromMimeData(event->mimeData()))) + event->acceptProposedAction(); +} + +bool MainWindow::startFile(const QString& filename) { const auto mcLock = pauseAndLockVM(); // Check if memcard is busy, deny request if so if (shouldAbortForMemcardBusy(mcLock)) { - return; + return false; } - const QString filename(getFilenameFromMimeData(event->mimeData())); - const std::string filename_str(filename.toStdString()); + std::string filename_str = filename.toStdString(); + if (VMManager::IsSaveStateFileName(filename_str)) { - event->acceptProposedAction(); - // can't load a save state without a current VM if (s_vm_valid) g_emu_thread->loadState(filename); else QMessageBox::critical(this, tr("Load State Failed"), tr("Cannot load a save state without a running VM.")); - return; + return true; } if (!VMManager::IsLoadableFileName(filename_str)) - return; + return false; // if we're already running, do a disc change, otherwise start if (!s_vm_valid) { - event->acceptProposedAction(); doStartFile(std::nullopt, filename); - return; + return true; } if (VMManager::IsDiscFileName(filename_str) || VMManager::IsBlockDumpFileName(filename_str)) { - event->acceptProposedAction(); doDiscChange(CDVD_SourceType::Iso, filename); } else if (VMManager::IsElfFileName(filename_str)) { const auto lock = pauseAndLockVM(); - event->acceptProposedAction(); - - if (QMessageBox::question(this, tr("Confirm Reset"), - tr("The new ELF cannot be loaded without resetting the virtual machine. Do you want to reset the virtual machine now?")) != - QMessageBox::Yes) + if (QMessageBox::Yes != QMessageBox::question(this, tr("Confirm Reset"), + tr("The new ELF cannot be loaded without resetting the virtual machine. Do you want to reset the virtual machine now?"))) { - return; + return true; } g_emu_thread->setELFOverride(filename); @@ -2226,17 +2225,15 @@ void MainWindow::dropEvent(QDropEvent* event) } else if (VMManager::IsGSDumpFileName(filename_str)) { - event->acceptProposedAction(); - if (!GSDumpReplayer::IsReplayingDump()) { QMessageBox::critical(this, tr("Error"), tr("Cannot change from game to GS dump without shutting down first.")); - return; } g_emu_thread->changeGSDump(filename); switchToEmulationView(); } + return true; } void MainWindow::moveEvent(QMoveEvent* event) diff --git a/pcsx2-qt/MainWindow.h b/pcsx2-qt/MainWindow.h index 5e3763d5e9..0c05e2ec5f 100644 --- a/pcsx2-qt/MainWindow.h +++ b/pcsx2-qt/MainWindow.h @@ -103,6 +103,9 @@ public: /// Rescans a single file. NOTE: Happens on UI thread. void rescanFile(const std::string& path); + /// Start a file from a user action (e.g. dragging a file onto the main window or with macOS open with) + bool startFile(const QString& path); + void doSettings(const char* category = nullptr); void doGameSettings(const char* category = nullptr); diff --git a/pcsx2-qt/QtHost.cpp b/pcsx2-qt/QtHost.cpp index c1f5ae4074..f59a302a64 100644 --- a/pcsx2-qt/QtHost.cpp +++ b/pcsx2-qt/QtHost.cpp @@ -2327,6 +2327,24 @@ bool QtHost::RunSetupWizard() return true; } +class PCSX2MainApplication : public QApplication { +public: + using QApplication::QApplication; + + bool event(QEvent* event) override { + if (event->type() == QEvent::FileOpen) + { + QFileOpenEvent* open = static_cast(event); + const QUrl url = open->url(); + if (url.isLocalFile()) + return g_main_window->startFile(url.toLocalFile()); + else + return false; // No URL schemas currently supported + } + return QApplication::event(event); + } +}; + int main(int argc, char* argv[]) { CrashHandler::Install(); @@ -2336,7 +2354,7 @@ int main(int argc, char* argv[]) QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QtHost::RegisterTypes(); - QApplication app(argc, argv); + PCSX2MainApplication app(argc, argv); #ifndef _WIN32 if (!PerformEarlyHardwareChecks())