summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikaƫl Capelle <capelle.mikael@gmail.com>2021-01-13 23:04:20 +0100
committerGitHub <noreply@github.com>2021-01-13 23:04:20 +0100
commitc3334e7b4d17f3005bd3c4dab8eee42b1e5510f8 (patch)
tree6b932f72419a7a9e460204e6beee21535e4c9fc7 /src
parent242125fdef3cb760b5b4fcacaedbcd81b13d3701 (diff)
parentbc9cb3794225d9b13eb26747e3eee0b54fc45cd6 (diff)
Merge pull request #1351 from Holt59/fix-set-gamepath
Fix setting game path for games with executable in subfolder.
Diffstat (limited to 'src')
-rw-r--r--src/settingsdialogpaths.cpp48
-rw-r--r--src/settingsdialogpaths.h2
2 files changed, 37 insertions, 13 deletions
diff --git a/src/settingsdialogpaths.cpp b/src/settingsdialogpaths.cpp
index eb334541..aafa750c 100644
--- a/src/settingsdialogpaths.cpp
+++ b/src/settingsdialogpaths.cpp
@@ -4,13 +4,12 @@
#include <iplugingame.h>
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,14 +89,8 @@ void PathsSettingsTab::update()
settings().paths().setBase("");
}
- QFileInfo oldGameExe(
- settings().game().plugin()->gameDirectory().absoluteFilePath(
- settings().game().plugin()->binaryName()));
-
- QFileInfo newGameExe(ui->managedGameDirEdit->text());
-
- if (oldGameExe != newGameExe) {
- settings().game().setDirectory(newGameExe.absolutePath());
+ if (m_gameDir != settings().game().plugin()->gameDirectory()) {
+ settings().game().setDirectory(m_gameDir.absolutePath());
}
}
@@ -170,8 +163,37 @@ 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;
+ }
+
+ // 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();
+ 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