From ba9e90fb7182d0d72c2c2537b4cedac36fc9db6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 22 Jun 2024 08:29:21 +0200 Subject: [PATCH] Update following gamebryo updates for myGamesPath() in game feature. (#11) --- src/enderalsedataarchives.cpp | 8 +-- src/enderalsedataarchives.h | 4 +- src/enderalselocalsavegames.cpp | 104 +------------------------------- src/enderalselocalsavegames.h | 17 ++---- src/game_enderalse_en.ts | 4 +- src/gameenderalse.cpp | 13 +--- src/gameenderalse.h | 1 - 7 files changed, 14 insertions(+), 137 deletions(-) diff --git a/src/enderalsedataarchives.cpp b/src/enderalsedataarchives.cpp index 4082d4f..9f15d3d 100644 --- a/src/enderalsedataarchives.cpp +++ b/src/enderalsedataarchives.cpp @@ -3,10 +3,6 @@ #include "iprofile.h" #include -EnderalSEDataArchives::EnderalSEDataArchives(const QDir& myGamesDir) - : GamebryoDataArchives(myGamesDir) -{} - QStringList EnderalSEDataArchives::vanillaArchives() const { return {"Skyrim - Textures0.bsa", @@ -43,7 +39,7 @@ QStringList EnderalSEDataArchives::archives(const MOBase::IProfile* profile) con QString iniFile = profile->localSettingsEnabled() ? QDir(profile->absolutePath()).absoluteFilePath("enderal.ini") - : m_LocalGameDir.absoluteFilePath("enderal.ini"); + : localGameDirectory().absoluteFilePath("enderal.ini"); result.append(getArchivesFromKey(iniFile, "SResourceArchiveList", 512)); result.append(getArchivesFromKey(iniFile, "SResourceArchiveList2", 512)); @@ -57,7 +53,7 @@ void EnderalSEDataArchives::writeArchiveList(MOBase::IProfile* profile, QString iniFile = profile->localSettingsEnabled() ? QDir(profile->absolutePath()).absoluteFilePath("enderal.ini") - : m_LocalGameDir.absoluteFilePath("enderal.ini"); + : localGameDirectory().absoluteFilePath("enderal.ini"); if (list.length() > 511) { int splitIdx = list.lastIndexOf(",", 512); setArchivesToKey(iniFile, "SResourceArchiveList", list.mid(0, splitIdx)); diff --git a/src/enderalsedataarchives.h b/src/enderalsedataarchives.h index 4048444..4c51e93 100644 --- a/src/enderalsedataarchives.h +++ b/src/enderalsedataarchives.h @@ -12,11 +12,9 @@ class IProfile; class EnderalSEDataArchives : public GamebryoDataArchives { - public: - EnderalSEDataArchives(const QDir& myGamesDir); + using GamebryoDataArchives::GamebryoDataArchives; -public: virtual QStringList vanillaArchives() const override; virtual QStringList archives(const MOBase::IProfile* profile) const override; diff --git a/src/enderalselocalsavegames.cpp b/src/enderalselocalsavegames.cpp index b3aa254..fafa739 100644 --- a/src/enderalselocalsavegames.cpp +++ b/src/enderalselocalsavegames.cpp @@ -17,108 +17,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "enderalselocalsavegames.h" -#include "registry.h" -#include -#include -#include -#include -#include -static const QString LocalSavesDummy = "..\\Enderal Special Edition\\__MO_Saves\\"; - -EnderalSELocalSavegames::EnderalSELocalSavegames(const QDir& myGamesDir, - const QString& iniFileName) - : m_LocalSavesDir(myGamesDir.absoluteFilePath(LocalSavesDummy)), - m_LocalGameDir(myGamesDir.absolutePath()), m_IniFileName(iniFileName) -{} - -MappingType EnderalSELocalSavegames::mappings(const QDir& profileSaveDir) const +QString EnderalSELocalSavegames::localSavesDummy() const { - return {{profileSaveDir.absolutePath(), m_LocalSavesDir.absolutePath(), true, true}}; -} - -bool EnderalSELocalSavegames::prepareProfile(MOBase::IProfile* profile) -{ - bool enable = profile->localSavesEnabled(); - - QString basePath = profile->localSettingsEnabled() ? profile->absolutePath() - : m_LocalGameDir.absolutePath(); - QString iniFilePath = basePath + "/" + m_IniFileName; - QString saveIni = profile->absolutePath() + "/" + "savepath.ini"; - - // Get the current sLocalSavePath - WCHAR currentPath[MAX_PATH]; - GetPrivateProfileStringW(L"General", L"sLocalSavePath", L"SKIP_ME", currentPath, - MAX_PATH, iniFilePath.toStdWString().c_str()); - bool alreadyEnabled = - wcscmp(currentPath, LocalSavesDummy.toStdWString().c_str()) == 0; - - // Get the current bUseMyGamesDirectory - WCHAR currentMyGames[MAX_PATH]; - GetPrivateProfileStringW(L"General", L"bUseMyGamesDirectory", L"SKIP_ME", - currentMyGames, MAX_PATH, - iniFilePath.toStdWString().c_str()); - - // Create the __MO_Saves directory if local saves are enabled and it doesn't exist - if (enable) { - QDir saves = QDir(m_LocalGameDir.absolutePath() + "/" + LocalSavesDummy); - if (!saves.exists()) { - saves.mkdir("."); - } - } - - // Set the path to __MO_Saves if it's not already - if (enable && !alreadyEnabled) { - // If the path is not blank, save it to savepath.ini - if (wcscmp(currentPath, L"SKIP_ME") != 0) { - MOBase::WriteRegistryValue(L"General", L"sLocalSavePath", currentPath, - saveIni.toStdWString().c_str()); - } - if (wcscmp(currentMyGames, L"SKIP_ME") != 0) { - MOBase::WriteRegistryValue(L"General", L"bUseMyGamesDirectory", currentMyGames, - saveIni.toStdWString().c_str()); - } - MOBase::WriteRegistryValue(L"General", L"sLocalSavePath", - LocalSavesDummy.toStdWString().c_str(), - iniFilePath.toStdWString().c_str()); - MOBase::WriteRegistryValue(L"General", L"bUseMyGamesDirectory", L"1", - iniFilePath.toStdWString().c_str()); - } - - // Get rid of the local saves setting if it's still there - if (!enable && alreadyEnabled) { - // If savepath.ini exists, use it and delete it - if (QFile::exists(saveIni)) { - WCHAR savedPath[MAX_PATH]; - WCHAR savedMyGames[MAX_PATH]; - GetPrivateProfileStringW(L"General", L"sLocalSavePath", L"DELETE_ME", savedPath, - MAX_PATH, saveIni.toStdWString().c_str()); - GetPrivateProfileStringW(L"General", L"bUseMyGamesDirectory", L"DELETE_ME", - savedMyGames, MAX_PATH, saveIni.toStdWString().c_str()); - if (wcscmp(savedPath, L"DELETE_ME") != 0) { - MOBase::WriteRegistryValue(L"General", L"sLocalSavePath", savedPath, - iniFilePath.toStdWString().c_str()); - } else { - MOBase::WriteRegistryValue(L"General", L"sLocalSavePath", NULL, - iniFilePath.toStdWString().c_str()); - } - if (wcscmp(savedMyGames, L"DELETE_ME") != 0) { - MOBase::WriteRegistryValue(L"General", L"bUseMyGamesDirectory", savedMyGames, - iniFilePath.toStdWString().c_str()); - } else { - MOBase::WriteRegistryValue(L"General", L"bUseMyGamesDirectory", NULL, - iniFilePath.toStdWString().c_str()); - } - QFile::remove(saveIni); - } - // Otherwise just delete the setting - else { - MOBase::WriteRegistryValue(L"General", L"sLocalSavePath", NULL, - iniFilePath.toStdWString().c_str()); - MOBase::WriteRegistryValue(L"General", L"bUseMyGamesDirectory", NULL, - iniFilePath.toStdWString().c_str()); - } - } - - return enable != alreadyEnabled; + return "..\\Enderal Special Edition\\__MO_Saves\\"; } diff --git a/src/enderalselocalsavegames.h b/src/enderalselocalsavegames.h index 78b4d04..f0d14ad 100644 --- a/src/enderalselocalsavegames.h +++ b/src/enderalselocalsavegames.h @@ -1,24 +1,17 @@ #ifndef ENDERALSELOCALSAVEGAMES_H #define ENDERALSELOCALSAVEGAMES_H -#include +#include -#include #include -class EnderalSELocalSavegames : public MOBase::LocalSavegames +class EnderalSELocalSavegames : public GamebryoLocalSavegames { - public: - EnderalSELocalSavegames(const QDir& myGamesDir, const QString& iniFileName); + using GamebryoLocalSavegames::GamebryoLocalSavegames; - virtual MappingType mappings(const QDir& profileSaveDir) const override; - virtual bool prepareProfile(MOBase::IProfile* profile) override; - -private: - QDir m_LocalSavesDir; - QDir m_LocalGameDir; - QString m_IniFileName; +protected: + QString localSavesDummy() const override; }; #endif // ENDERALSELOCALSAVEGAMES_H diff --git a/src/game_enderalse_en.ts b/src/game_enderalse_en.ts index 540fe0e..4c8b5a2 100644 --- a/src/game_enderalse_en.ts +++ b/src/game_enderalse_en.ts @@ -4,12 +4,12 @@ GameEnderalSE - + Enderal Special Edition Support Plugin - + Adds support for the game Enderal Special Edition. diff --git a/src/gameenderalse.cpp b/src/gameenderalse.cpp index 8feed75..3713fa2 100644 --- a/src/gameenderalse.cpp +++ b/src/gameenderalse.cpp @@ -84,9 +84,6 @@ void GameEnderalSE::setGamePath(const QString& path) m_GamePath = path; checkVariants(); m_MyGamesPath = determineMyGamesPath(gameDirectoryName()); - registerFeature(std::make_shared(myGamesPath())); - registerFeature( - std::make_shared(myGamesPath(), "Enderal.ini")); } QDir GameEnderalSE::savesDirectory() const @@ -94,11 +91,6 @@ QDir GameEnderalSE::savesDirectory() const return QDir(m_MyGamesPath + "/Saves"); } -QString GameEnderalSE::myGamesPath() const -{ - return m_MyGamesPath; -} - bool GameEnderalSE::isInstalled() const { return !m_GamePath.isEmpty(); @@ -110,11 +102,10 @@ bool GameEnderalSE::init(IOrganizer* moInfo) return false; } - auto dataArchives = std::make_shared(myGamesPath()); + auto dataArchives = std::make_shared(this); registerFeature(std::make_shared(this)); registerFeature(dataArchives); - registerFeature( - std::make_shared(myGamesPath(), "enderal.ini")); + registerFeature(std::make_shared(this, "enderal.ini")); registerFeature(std::make_shared(this)); registerFeature(std::make_shared(moInfo->gameFeatures())); registerFeature(std::make_shared(this)); diff --git a/src/gameenderalse.h b/src/gameenderalse.h index 51d7764..754951d 100644 --- a/src/gameenderalse.h +++ b/src/gameenderalse.h @@ -65,7 +65,6 @@ protected: QDir documentsDirectory() const; QDir savesDirectory() const; QFileInfo findInGameFolder(const QString& relativePath) const; - QString myGamesPath() const; void checkVariants(); void setVariant(QString variant);