From e0e428ce38ff5662089036a6bbf017a3b39f478f Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Sun, 20 Nov 2022 00:28:35 +0800 Subject: [PATCH] fix: add support for CLI and drag and drop Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- launcher/Application.cpp | 35 +-------------------------- launcher/ui/MainWindow.cpp | 48 +++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 9258aec48..0fbe4ae2c 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -66,7 +66,6 @@ #include "ui/setupwizard/PasteWizardPage.h" #include "ui/dialogs/CustomMessageBox.h" -#include "ui/dialogs/ImportResourcePackDialog.h" #include "ui/pagedialog/PageDialog.h" @@ -98,12 +97,6 @@ #include "java/JavaUtils.h" #include -#include -#include -#include -#include -#include -#include #include "updater/UpdateChecker.h" @@ -938,33 +931,7 @@ bool Application::event(QEvent* event) if (event->type() == QEvent::FileOpen) { auto ev = static_cast(event); - - ResourcePack rp{ QFileInfo(ev->file()) }; - TexturePack tp{ QFileInfo(ev->file()) }; - - ImportResourcePackDialog dlg(APPLICATION->m_mainWindow); - - if (ResourcePackUtils::process(rp) && rp.valid()) { - dlg.exec(); - - if (dlg.result() == QDialog::Accepted) { - qDebug() << "Selected instance to import resource pack into: " << dlg.selectedInstanceKey; - auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); - auto instanceButBuffed = std::dynamic_pointer_cast(instance); - instanceButBuffed->resourcePackList()->installResource(ev->file()); - } - } else if (TexturePackUtils::process(tp) && tp.valid()) { - dlg.exec(); - - if (dlg.result() == QDialog::Accepted) { - qDebug() << "Selected instance to import texture pack into: " << dlg.selectedInstanceKey; - auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); - auto instanceButBuffed = std::dynamic_pointer_cast(instance); - instanceButBuffed->texturePackList()->installResource(ev->file()); - } - } else { - m_mainWindow->droppedURLs({ ev->url() }); - } + m_mainWindow->droppedURLs({ ev->url() }); } return QApplication::event(event); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 929f2a85c..ed61777e5 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -106,8 +106,16 @@ #include "ui/dialogs/UpdateDialog.h" #include "ui/dialogs/EditAccountDialog.h" #include "ui/dialogs/ExportInstanceDialog.h" +#include "ui/dialogs/ImportResourcePackDialog.h" #include "ui/themes/ITheme.h" +#include +#include +#include +#include +#include +#include + #include "UpdateController.h" #include "KonamiCode.h" @@ -1794,16 +1802,40 @@ void MainWindow::on_actionAddInstance_triggered() void MainWindow::droppedURLs(QList urls) { - for(auto & url:urls) - { - if(url.isLocalFile()) - { - addInstance(url.toLocalFile()); - } - else - { + for (auto& url : urls) { + if (url.isLocalFile()) { + auto localFileName = url.toLocalFile(); + + ResourcePack rp{ QFileInfo(localFileName) }; + TexturePack tp{ QFileInfo(localFileName) }; + + ImportResourcePackDialog dlg(this); + + if (ResourcePackUtils::process(rp) && rp.valid()) { + dlg.exec(); + + if (dlg.result() == QDialog::Accepted) { + qDebug() << "Selected instance to import resource pack into: " << dlg.selectedInstanceKey; + auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); + auto instanceButBuffed = std::dynamic_pointer_cast(instance); + instanceButBuffed->resourcePackList()->installResource(localFileName); + } + } else if (TexturePackUtils::process(tp) && tp.valid()) { + dlg.exec(); + + if (dlg.result() == QDialog::Accepted) { + qDebug() << "Selected instance to import texture pack into: " << dlg.selectedInstanceKey; + auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey); + auto instanceButBuffed = std::dynamic_pointer_cast(instance); + instanceButBuffed->texturePackList()->installResource(localFileName); + } + } else { + addInstance(localFileName); + } + } else { addInstance(url.toString()); } + // Only process one dropped file... break; }