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') 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