diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index 918fa1073..a9e86cd7f 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -149,6 +149,11 @@ QStringList InstanceList::getLinkedInstancesById(const QString& id) const return linkedInstances; } +QString InstanceList::getInstanceRootById(const InstanceId& id) const +{ + return FS::PathCombine(m_instDir, id); +} + int InstanceList::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent); @@ -627,7 +632,7 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id) loadGroupList(); } - auto instanceRoot = FS::PathCombine(m_instDir, id); + auto instanceRoot = getInstanceRootById(id); auto instanceSettings = std::make_shared(FS::PathCombine(instanceRoot, "instance.cfg")); InstancePtr inst; diff --git a/launcher/InstanceList.h b/launcher/InstanceList.h index c85fe55c7..b04a289d2 100644 --- a/launcher/InstanceList.h +++ b/launcher/InstanceList.h @@ -152,6 +152,7 @@ class InstanceList : public QAbstractListModel { QMimeData* mimeData(const QModelIndexList& indexes) const override; QStringList getLinkedInstancesById(const QString& id) const; + QString getInstanceRootById(const InstanceId& id) const; signals: void dataIsInvalid(); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index a9473ac15..f413ac05d 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -564,6 +565,67 @@ void MainWindow::showInstanceContextMenu(const QPoint& pos) myMenu.exec(view->mapToGlobal(pos)); } +void MainWindow::updateInstanceRoot() +{ + QString renamingMode = APPLICATION->settings()->get("InstRenamingMode").toString(); + if (renamingMode == "MetadataOnly") + return; + + auto oldRoot = m_selectedInstance->instanceRoot(); + auto newID = m_selectedInstance->name(); + auto newRoot = APPLICATION->instances()->getInstanceRootById(newID); + if (oldRoot == newRoot) + return; + + // Check for conflict + if (QDir(newRoot).exists()) { + QMessageBox::warning(this, tr("Cannot rename instance"), + tr("New instance root (%1) already exists.
Only the metadata will be renamed.").arg(newRoot)); + return; + } + + // Ask if we should rename + if (renamingMode == "AskEverytime") { + QMessageBox messageBox(this); + messageBox.setText(tr("Do you want to also rename the instance\'s physical directory?")); + messageBox.setInformativeText(tr("The following renaming operation will be performed:
" + " - Old instance root: %1
" + " - New instance root: %2") + .arg(oldRoot, newRoot)); + messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + messageBox.setDefaultButton(QMessageBox::Yes); + messageBox.setIcon(QMessageBox::Question); + + auto checkBox = new QCheckBox(tr("&Remember my choice"), this); + checkBox->setChecked(true); + messageBox.setCheckBox(checkBox); + + auto res = messageBox.exec(); + if (checkBox->isChecked()) { + if (res == QMessageBox::Yes) + APPLICATION->settings()->set("InstRenamingMode", "PhysicalDir"); + else + APPLICATION->settings()->set("InstRenamingMode", "MetadataOnly"); + } + if (res == QMessageBox::No) + return; + } + + // Now we can confirm that a renaming is happening + auto ret = QFile::rename(oldRoot, newRoot); + if (!ret) { + QMessageBox::warning(this, tr("Cannot rename instance"), + tr("An error occurred when performing the following renaming operation:
" + " - Old instance root: %1
" + " - New instance root: %2
" + "Only the metadata is renamed.") + .arg(oldRoot, newRoot)); + return; + } + refreshInstances(); + setSelectedInstanceById(newID); +} + void MainWindow::updateMainToolBar() { ui->menuBar->setVisible(APPLICATION->settings()->get("MenuBarInsteadOfToolBar").toBool()); @@ -1703,6 +1765,7 @@ void MainWindow::instanceDataChanged(const QModelIndex& topLeft, const QModelInd QItemSelection test(topLeft, bottomRight); if (test.contains(current)) { instanceChanged(current, current); + updateInstanceRoot(); } } diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index 0e692eda7..9ac1d39e0 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -176,6 +176,8 @@ class MainWindow : public QMainWindow { void showInstanceContextMenu(const QPoint&); + void updateInstanceRoot(); + void updateMainToolBar(); void updateLaunchButton(); diff --git a/launcher/ui/pages/global/LauncherPage.cpp b/launcher/ui/pages/global/LauncherPage.cpp index fab1bfe38..db37d548a 100644 --- a/launcher/ui/pages/global/LauncherPage.cpp +++ b/launcher/ui/pages/global/LauncherPage.cpp @@ -241,7 +241,7 @@ void LauncherPage::applySettings() s->set("MoveModsFromDownloadsDir", ui->downloadsDirMoveCheckBox->isChecked()); // Instance - auto sortMode = (InstSortMode) ui->viewSortingComboBox->currentIndex(); + auto sortMode = (InstSortMode)ui->viewSortingComboBox->currentIndex(); switch (sortMode) { case Sort_LastLaunch: s->set("InstSortMode", "LastLaunch"); @@ -252,7 +252,7 @@ void LauncherPage::applySettings() break; } - auto renamingMode = (InstRenamingMode) ui->renamingBehaviorComboBox->currentIndex(); + auto renamingMode = (InstRenamingMode)ui->renamingBehaviorComboBox->currentIndex(); switch (renamingMode) { case Rename_Metadata: s->set("InstRenamingMode", "MetadataOnly"); @@ -334,7 +334,7 @@ void LauncherPage::loadSettings() InstRenamingMode renamingModeEnum; if (renamingMode == "MetadataOnly") { renamingModeEnum = Rename_Metadata; - } else if (renamingMode == "PhysicalDir"){ + } else if (renamingMode == "PhysicalDir") { renamingModeEnum = Rename_Physical; } else { renamingModeEnum = Rename_Ask; diff --git a/launcher/ui/pages/global/LauncherPage.ui b/launcher/ui/pages/global/LauncherPage.ui index 01aad7af7..c1ba1d428 100644 --- a/launcher/ui/pages/global/LauncherPage.ui +++ b/launcher/ui/pages/global/LauncherPage.ui @@ -701,8 +701,6 @@ numberOfConcurrentDownloadsSpinBox numberOfManualRetriesSpinBox timeoutSecondsSpinBox - sortLastLaunchedComboBox - sortByNameBtn catOpacitySpinBox preferMenuBarCheckBox lineLimitSpinBox