fix: add support for CLI and drag and drop

Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com>
This commit is contained in:
Ryan Cao 2022-11-20 00:28:35 +08:00
parent a99cd16422
commit e0e428ce38
No known key found for this signature in database
2 changed files with 41 additions and 42 deletions

View File

@ -66,7 +66,6 @@
#include "ui/setupwizard/PasteWizardPage.h" #include "ui/setupwizard/PasteWizardPage.h"
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
#include "ui/dialogs/ImportResourcePackDialog.h"
#include "ui/pagedialog/PageDialog.h" #include "ui/pagedialog/PageDialog.h"
@ -98,12 +97,6 @@
#include "java/JavaUtils.h" #include "java/JavaUtils.h"
#include <minecraft/MinecraftInstance.h> #include <minecraft/MinecraftInstance.h>
#include <minecraft/mod/ResourcePack.h>
#include <minecraft/mod/ResourcePackFolderModel.h>
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
#include <minecraft/mod/TexturePack.h>
#include <minecraft/mod/TexturePackFolderModel.h>
#include <minecraft/mod/tasks/LocalTexturePackParseTask.h>
#include "updater/UpdateChecker.h" #include "updater/UpdateChecker.h"
@ -938,34 +931,8 @@ bool Application::event(QEvent* event)
if (event->type() == QEvent::FileOpen) { if (event->type() == QEvent::FileOpen) {
auto ev = static_cast<QFileOpenEvent*>(event); auto ev = static_cast<QFileOpenEvent*>(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<MinecraftInstance>(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<MinecraftInstance>(instance);
instanceButBuffed->texturePackList()->installResource(ev->file());
}
} else {
m_mainWindow->droppedURLs({ ev->url() }); m_mainWindow->droppedURLs({ ev->url() });
} }
}
return QApplication::event(event); return QApplication::event(event);
} }

View File

@ -106,8 +106,16 @@
#include "ui/dialogs/UpdateDialog.h" #include "ui/dialogs/UpdateDialog.h"
#include "ui/dialogs/EditAccountDialog.h" #include "ui/dialogs/EditAccountDialog.h"
#include "ui/dialogs/ExportInstanceDialog.h" #include "ui/dialogs/ExportInstanceDialog.h"
#include "ui/dialogs/ImportResourcePackDialog.h"
#include "ui/themes/ITheme.h" #include "ui/themes/ITheme.h"
#include <minecraft/mod/ResourcePack.h>
#include <minecraft/mod/ResourcePackFolderModel.h>
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
#include <minecraft/mod/TexturePack.h>
#include <minecraft/mod/TexturePackFolderModel.h>
#include <minecraft/mod/tasks/LocalTexturePackParseTask.h>
#include "UpdateController.h" #include "UpdateController.h"
#include "KonamiCode.h" #include "KonamiCode.h"
@ -1794,16 +1802,40 @@ void MainWindow::on_actionAddInstance_triggered()
void MainWindow::droppedURLs(QList<QUrl> urls) void MainWindow::droppedURLs(QList<QUrl> urls)
{ {
for(auto & url:urls) for (auto& url : urls) {
{ if (url.isLocalFile()) {
if(url.isLocalFile()) auto localFileName = url.toLocalFile();
{
addInstance(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<MinecraftInstance>(instance);
instanceButBuffed->resourcePackList()->installResource(localFileName);
} }
else } 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<MinecraftInstance>(instance);
instanceButBuffed->texturePackList()->installResource(localFileName);
}
} else {
addInstance(localFileName);
}
} else {
addInstance(url.toString()); addInstance(url.toString());
} }
// Only process one dropped file... // Only process one dropped file...
break; break;
} }