From b53dc1e20061be3a8035f10e95b57c4c60bee3c8 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 27 Sep 2020 20:31:51 +0200 Subject: Add IProfile::iniFilePath(). --- src/profile.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/profile.cpp') diff --git a/src/profile.cpp b/src/profile.cpp index c1e30c22..238454d5 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -889,6 +889,31 @@ QString Profile::getIniFileName() const return m_Directory.absoluteFilePath(iniFiles[0]); } +QString Profile::iniFilePath(QString iniFile) const +{ + // This is the file to which the given iniFile would be mapped, as + // an absolute file path: + QString targetIniFile = m_GamePlugin->gameDirectory().absoluteFilePath(iniFile); + + bool isGameIni = false; + for (auto gameIni : m_GamePlugin->iniFiles()) { + // We compare the target file, not the actual ones: + if (m_GamePlugin->gameDirectory().absoluteFilePath(gameIni) == targetIniFile) { + isGameIni = true; + break; + } + } + + // Local-settings are not enabled, or the iniFile is not in the list of INI + // files for the current game. + if (!localSettingsEnabled() || !isGameIni) { + return m_GamePlugin->documentsDirectory().absoluteFilePath(iniFile); + } + + // If we reach here, the file is in the profile: + return m_Directory.absoluteFilePath(QFileInfo(targetIniFile).fileName()); +} + QString Profile::getProfileTweaks() const { return QDir::cleanPath(m_Directory.absoluteFilePath(ToQString(AppConfig::profileTweakIni()))); -- cgit v1.3.1 From 7c651f6d8697bc572e521046c7f514baf96cacb3 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 27 Sep 2020 20:56:55 +0200 Subject: Rename iniFilePath() -> absoluteIniFilePath(). --- src/profile.cpp | 2 +- src/profile.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/profile.cpp') diff --git a/src/profile.cpp b/src/profile.cpp index 238454d5..97d31e69 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -889,7 +889,7 @@ QString Profile::getIniFileName() const return m_Directory.absoluteFilePath(iniFiles[0]); } -QString Profile::iniFilePath(QString iniFile) const +QString Profile::absoluteIniFilePath(QString iniFile) const { // This is the file to which the given iniFile would be mapped, as // an absolute file path: diff --git a/src/profile.h b/src/profile.h index 9592ba04..b8628276 100644 --- a/src/profile.h +++ b/src/profile.h @@ -203,7 +203,7 @@ public: * * @return the absolute path for the given INI file for this profile. */ - QString iniFilePath(QString iniFile) const override; + QString absoluteIniFilePath(QString iniFile) const override; /** * @return the path of the tweak ini in this profile -- cgit v1.3.1 From 39b7f4abe972fb6bfbaea7764b81402099b5a0db Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Sun, 27 Sep 2020 20:59:54 +0200 Subject: Fix gameDirectory() -> documentsDirectory(). Use QFileInfo more properly. --- src/profile.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/profile.cpp') diff --git a/src/profile.cpp b/src/profile.cpp index 97d31e69..6bf282d0 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -893,12 +893,12 @@ QString Profile::absoluteIniFilePath(QString iniFile) const { // This is the file to which the given iniFile would be mapped, as // an absolute file path: - QString targetIniFile = m_GamePlugin->gameDirectory().absoluteFilePath(iniFile); + QFileInfo targetIniFile(m_GamePlugin->documentsDirectory(), iniFile); bool isGameIni = false; for (auto gameIni : m_GamePlugin->iniFiles()) { // We compare the target file, not the actual ones: - if (m_GamePlugin->gameDirectory().absoluteFilePath(gameIni) == targetIniFile) { + if (QFileInfo(m_GamePlugin->documentsDirectory(), gameIni) == targetIniFile) { isGameIni = true; break; } @@ -907,11 +907,11 @@ QString Profile::absoluteIniFilePath(QString iniFile) const // Local-settings are not enabled, or the iniFile is not in the list of INI // files for the current game. if (!localSettingsEnabled() || !isGameIni) { - return m_GamePlugin->documentsDirectory().absoluteFilePath(iniFile); + return targetIniFile.absoluteFilePath(); } // If we reach here, the file is in the profile: - return m_Directory.absoluteFilePath(QFileInfo(targetIniFile).fileName()); + return m_Directory.absoluteFilePath(targetIniFile.fileName()); } QString Profile::getProfileTweaks() const -- cgit v1.3.1