aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-11-27 18:38:56 +0100
committerSefa Eyeoglu <contact@scrumplex.net>2022-11-27 18:38:56 +0100
commit236c196e681dcbf0547677260d141a7e48047b43 (patch)
tree19d5256c38f3b558896f440c05d1fea1da5f6ad3
parentbae0a0530bd5334a2f41ed234a20a064b5245232 (diff)
downloadPrismLauncher-236c196e681dcbf0547677260d141a7e48047b43.tar.gz
PrismLauncher-236c196e681dcbf0547677260d141a7e48047b43.tar.bz2
PrismLauncher-236c196e681dcbf0547677260d141a7e48047b43.zip
fix: improve code readability
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
-rw-r--r--launcher/ui/MainWindow.cpp56
1 files changed, 27 insertions, 29 deletions
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index 5d2a07f3..c3c4d10f 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -1801,39 +1801,37 @@ void MainWindow::on_actionAddInstance_triggered()
void MainWindow::droppedURLs(QList<QUrl> urls)
{
+ // NOTE: This loop only processes one dropped file!
for (auto& url : urls) {
- if (url.isLocalFile()) {
- auto localFileName = url.toLocalFile();
- QFileInfo localFileInfo(localFileName);
-
- ImportResourcePackDialog dlg(this);
-
- if (ResourcePackUtils::validate(localFileInfo)) {
- 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 if (TexturePackUtils::validate(localFileInfo)) {
- 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 {
+ if (!url.isLocalFile()) { // probably instance/modpack
addInstance(url.toString());
+ break;
}
- // Only process one dropped file...
+ auto localFileName = url.toLocalFile();
+ QFileInfo localFileInfo(localFileName);
+
+ bool isResourcePack = ResourcePackUtils::validate(localFileInfo);
+ bool isTexturePack = TexturePackUtils::validate(localFileInfo);
+
+ if (!isResourcePack && !isTexturePack) { // probably instance/modpack
+ addInstance(localFileName);
+ break;
+ }
+
+ ImportResourcePackDialog dlg(this);
+
+ if (dlg.exec() != QDialog::Accepted)
+ break;
+
+ qDebug() << "Adding resource/texture pack" << localFileName << "to" << dlg.selectedInstanceKey;
+
+ auto inst = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey);
+ auto minecraftInst = std::dynamic_pointer_cast<MinecraftInstance>(inst);
+ if (isResourcePack)
+ minecraftInst->resourcePackList()->installResource(localFileName);
+ else if (isTexturePack)
+ minecraftInst->texturePackList()->installResource(localFileName);
break;
}
}