From a0cb500ff0cc40e48536c22ebb7bb2f5009e1def Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 10 Jan 2021 20:44:59 +0100 Subject: Fix setting game path for games with executable in subfolder. --- src/settingsdialogpaths.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/settingsdialogpaths.cpp') diff --git a/src/settingsdialogpaths.cpp b/src/settingsdialogpaths.cpp index eb334541..66ba8129 100644 --- a/src/settingsdialogpaths.cpp +++ b/src/settingsdialogpaths.cpp @@ -90,14 +90,27 @@ void PathsSettingsTab::update() settings().paths().setBase(""); } + const auto binaryPath = settings().game().plugin()->binaryName(); QFileInfo oldGameExe( - settings().game().plugin()->gameDirectory().absoluteFilePath( - settings().game().plugin()->binaryName())); - + settings().game().plugin()->gameDirectory().absoluteFilePath(binaryPath)); QFileInfo newGameExe(ui->managedGameDirEdit->text()); if (oldGameExe != newGameExe) { - settings().game().setDirectory(newGameExe.absolutePath()); + QDir folder = newGameExe.absoluteDir(); + while (folder.exists() && !folder.isRoot() + && QFileInfo(folder.filePath(binaryPath)) != newGameExe) { + folder.cdUp(); + } + + if (folder.exists(binaryPath)) { + settings().game().setDirectory(folder.absolutePath()); + } + else { + QMessageBox::warning(parentWidget(), QObject::tr("Error"), + QObject::tr("Failed to extract the game folder from \"%1\". Your version of the game " + "might not be supported by the current game plugin.").arg(newGameExe.absoluteFilePath())); + + } } } -- cgit v1.3.1 From 97ac1ce9994d88934e316182c33aab31ad2c79b6 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 11 Jan 2021 13:14:24 +0100 Subject: Warn users that game path is invalid after choosing it rather than when applying setting. --- src/settingsdialogpaths.cpp | 54 +++++++++++++++++++++++---------------------- src/settingsdialogpaths.h | 2 ++ 2 files changed, 30 insertions(+), 26 deletions(-) (limited to 'src/settingsdialogpaths.cpp') diff --git a/src/settingsdialogpaths.cpp b/src/settingsdialogpaths.cpp index 66ba8129..197f1807 100644 --- a/src/settingsdialogpaths.cpp +++ b/src/settingsdialogpaths.cpp @@ -4,13 +4,12 @@ #include PathsSettingsTab::PathsSettingsTab(Settings& s, SettingsDialog& d) - : SettingsTab(s, d) + : SettingsTab(s, d), m_gameDir(settings().game().plugin()->gameDirectory()) { ui->baseDirEdit->setText(settings().paths().base()); ui->managedGameDirEdit->setText( - settings().game().plugin()->gameDirectory().absoluteFilePath( - settings().game().plugin()->binaryName())); + QDir::toNativeSeparators(m_gameDir.absoluteFilePath(settings().game().plugin()->binaryName()))); QString basePath = settings().paths().base(); QDir baseDir(basePath); @@ -90,27 +89,8 @@ void PathsSettingsTab::update() settings().paths().setBase(""); } - const auto binaryPath = settings().game().plugin()->binaryName(); - QFileInfo oldGameExe( - settings().game().plugin()->gameDirectory().absoluteFilePath(binaryPath)); - QFileInfo newGameExe(ui->managedGameDirEdit->text()); - - if (oldGameExe != newGameExe) { - QDir folder = newGameExe.absoluteDir(); - while (folder.exists() && !folder.isRoot() - && QFileInfo(folder.filePath(binaryPath)) != newGameExe) { - folder.cdUp(); - } - - if (folder.exists(binaryPath)) { - settings().game().setDirectory(folder.absolutePath()); - } - else { - QMessageBox::warning(parentWidget(), QObject::tr("Error"), - QObject::tr("Failed to extract the game folder from \"%1\". Your version of the game " - "might not be supported by the current game plugin.").arg(newGameExe.absoluteFilePath())); - - } + if (m_gameDir != settings().game().plugin()->gameDirectory()) { + settings().game().setDirectory(m_gameDir.absolutePath()); } } @@ -183,8 +163,30 @@ void PathsSettingsTab::on_browseGameDirBtn_clicked() QFileInfo oldGameExe(ui->managedGameDirEdit->text()); QString temp = QFileDialog::getOpenFileName(&dialog(), QObject::tr("Select game executable"), oldGameExe.absolutePath(), oldGameExe.fileName()); - if (!temp.isEmpty()) { - ui->managedGameDirEdit->setText(temp); + + if (temp.isEmpty()) { + return; + } + + QFileInfo newExe(temp); + const auto binaryPath = settings().game().plugin()->binaryName(); + QDir folder = newExe.absoluteDir(); + while (folder.exists() && !folder.isRoot() + && QFileInfo(folder.filePath(binaryPath)) != newExe) { + folder.cdUp(); + } + + if (folder.exists(binaryPath)) { + m_gameDir = folder; + ui->managedGameDirEdit->setText( + QDir::toNativeSeparators(m_gameDir.absoluteFilePath(settings().game().plugin()->binaryName()))); + } + else { + QMessageBox::warning(parentWidget(), QObject::tr("Error"), + QObject::tr("The given path was not recognized as a valid game installation. " + "The current game plugin requires the executable to be in a \"%1\" subfolder of the game directory.") + .arg(QFileInfo(binaryPath).path())); + } } diff --git a/src/settingsdialogpaths.h b/src/settingsdialogpaths.h index a2073188..9562289b 100644 --- a/src/settingsdialogpaths.h +++ b/src/settingsdialogpaths.h @@ -27,6 +27,8 @@ private: void on_profilesDirEdit_editingFinished(); void normalizePath(QLineEdit *lineEdit); + + QDir m_gameDir; }; #endif // SETTINGSDIALOGPATHS_H -- cgit v1.3.1 From bc9cb3794225d9b13eb26747e3eee0b54fc45cd6 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Wed, 13 Jan 2021 20:36:11 +0100 Subject: Add comment for cdUp(). --- src/settingsdialogpaths.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/settingsdialogpaths.cpp') diff --git a/src/settingsdialogpaths.cpp b/src/settingsdialogpaths.cpp index 197f1807..aafa750c 100644 --- a/src/settingsdialogpaths.cpp +++ b/src/settingsdialogpaths.cpp @@ -168,6 +168,13 @@ void PathsSettingsTab::on_browseGameDirBtn_clicked() return; } + // we need to find the game folder corresponding to the executable + // + // some game plugins have executable in subfolder, e.g. bin/game.exe, + // so we need to go up the parent folders until the concatenation of + // the folder and the binary path equals the game executable specified + // by the user + // QFileInfo newExe(temp); const auto binaryPath = settings().game().plugin()->binaryName(); QDir folder = newExe.absoluteDir(); -- cgit v1.3.1