diff --git a/launcher/InstanceDirUpdate.cpp b/launcher/InstanceDirUpdate.cpp index f24adb642..0b61ddb88 100644 --- a/launcher/InstanceDirUpdate.cpp +++ b/launcher/InstanceDirUpdate.cpp @@ -40,11 +40,15 @@ #include #include +#include "Application.h" #include "FileSystem.h" -bool askToUpdateInstanceDirName(SettingsObjectPtr globalSettings, InstancePtr instance, QWidget* parent) +#include "InstanceList.h" +#include "ui/dialogs/CustomMessageBox.h" + +bool askToUpdateInstanceDirName(InstancePtr instance, QWidget* parent) { - QString renamingMode = globalSettings->get("InstRenamingMode").toString(); + QString renamingMode = APPLICATION->settings()->get("InstRenamingMode").toString(); if (renamingMode == "MetadataOnly") return false; @@ -76,24 +80,47 @@ bool askToUpdateInstanceDirName(SettingsObjectPtr globalSettings, InstancePtr in auto res = messageBox.exec(); if (checkBox->isChecked()) { if (res == QMessageBox::Yes) - globalSettings->set("InstRenamingMode", "PhysicalDir"); + APPLICATION->settings()->set("InstRenamingMode", "PhysicalDir"); else - globalSettings->set("InstRenamingMode", "MetadataOnly"); + APPLICATION->settings()->set("InstRenamingMode", "MetadataOnly"); } if (res == QMessageBox::No) return false; } + // Check for linked instances + if (!checkLinkedInstances(instance->id(), parent)) + return false; + // Now we can confirm that a renaming is happening auto ret = QFile::rename(oldRoot, newRoot); if (!ret) { QMessageBox::warning(parent, QObject::tr("Cannot rename instance"), QObject::tr("An error occurred when performing the following renaming operation:
" - " - Old instance root: %1
" - " - New instance root: %2
" - "Only the metadata is renamed.") + " - Old instance root: %1
" + " - New instance root: %2
" + "Only the metadata is renamed.") .arg(oldRoot, newRoot)); return false; } return true; } + +bool checkLinkedInstances(const QString& id, QWidget* parent) +{ + auto linkedInstances = APPLICATION->instances()->getLinkedInstancesById(id); + if (!linkedInstances.empty()) { + auto response = CustomMessageBox::selectable(parent, QObject::tr("There are linked instances"), + QObject::tr("The following instance(s) might reference files in this instance:\n\n" + "%1\n\n" + "Deleting it could break the other instance(s), \n\n" + "Do you wish to proceed?", + nullptr, linkedInstances.count()) + .arg(linkedInstances.join("\n")), + QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) + ->exec(); + if (response != QMessageBox::Yes) + return false; + } + return true; +} diff --git a/launcher/InstanceDirUpdate.h b/launcher/InstanceDirUpdate.h index fc0931779..0059d8b7b 100644 --- a/launcher/InstanceDirUpdate.h +++ b/launcher/InstanceDirUpdate.h @@ -40,4 +40,7 @@ #include "BaseInstance.h" /// Update instanceRoot to make it sync with name/id; return true if a refresh is needed -bool askToUpdateInstanceDirName(SettingsObjectPtr globalSettings, InstancePtr instance, QWidget* parent); +bool askToUpdateInstanceDirName(InstancePtr instance, QWidget* parent); + +/// Check if there are linked instances, and display a warning; return true if the operation should proceed +bool checkLinkedInstances(const QString& id, QWidget* parent); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 23cd6f8c8..d5a2b477d 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1379,20 +1379,8 @@ void MainWindow::on_actionDeleteInstance_triggered() if (response != QMessageBox::Yes) return; - auto linkedInstances = APPLICATION->instances()->getLinkedInstancesById(id); - if (!linkedInstances.empty()) { - response = CustomMessageBox::selectable(this, tr("There are linked instances"), - tr("The following instance(s) might reference files in this instance:\n\n" - "%1\n\n" - "Deleting it could break the other instance(s), \n\n" - "Do you wish to proceed?", - nullptr, linkedInstances.count()) - .arg(linkedInstances.join("\n")), - QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) - ->exec(); - if (response != QMessageBox::Yes) - return; - } + if (!checkLinkedInstances(id, this)) + return; if (APPLICATION->instances()->trashInstance(id)) { ui->actionUndoTrashInstance->setEnabled(APPLICATION->instances()->trashedSomething()); @@ -1705,7 +1693,7 @@ void MainWindow::instanceDataChanged(const QModelIndex& topLeft, const QModelInd QItemSelection test(topLeft, bottomRight); if (test.contains(current)) { instanceChanged(current, current); - if (m_selectedInstance && askToUpdateInstanceDirName(APPLICATION->settings(), m_selectedInstance, this)) { + if (m_selectedInstance && askToUpdateInstanceDirName(m_selectedInstance, this)) { auto newID = m_selectedInstance->name(); refreshInstances(); setSelectedInstanceById(newID);