diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..6098e1f --- /dev/null +++ b/.clang-format @@ -0,0 +1,41 @@ +--- +# We'll use defaults from the LLVM style, but with 4 columns indentation. +BasedOnStyle: LLVM +IndentWidth: 2 +--- +Language: Cpp +DeriveLineEnding: false +UseCRLF: true +DerivePointerAlignment: false +PointerAlignment: Left +AlignConsecutiveAssignments: true +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: Empty +AlwaysBreakTemplateDeclarations: Yes +AccessModifierOffset: -2 +AlignTrailingComments: true +SpacesBeforeTrailingComments: 2 +NamespaceIndentation: Inner +MaxEmptyLinesToKeep: 1 +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: false + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: true +ColumnLimit: 88 +ForEachMacros: ['Q_FOREACH', 'foreach'] diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f869712 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +*.cpp text eol=crlf +*.h text eol=crlf diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..54468d5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,17 @@ +name: Build Nehrim Plugin + +on: + push: + branches: master + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + runs-on: windows-2022 + steps: + - name: Build Nehrim Plugin + uses: ModOrganizer2/build-with-mob-action@master + with: + mo2-third-parties: fmt gtest spdlog boost lz4 + mo2-dependencies: cmake_common uibase game_gamebryo diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..006464f --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,17 @@ +name: Lint Nehrim Plugin + +on: + push: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run clang-format + uses: jidicula/clang-format-action@v4.11.0 + with: + clang-format-version: "15" + check-path: "." diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 763c046..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,40 +0,0 @@ -version: 1.0.{build} -skip_branch_with_pr: true -image: Visual Studio 2019 -environment: - WEBHOOK_URL: - secure: gOKbXaZM9ImtMD5XrYITvdyZUW/az082G9OIN1EC1Vbg57wBaeLhi49uGjxPw5GVujHku6kxN6ab89zhbS5GVeluR76GM83IbKV4Sh7udXzoYZZdg6YudtYHzdhCgUeiedpswbuczTq9ceIkkfSEWZuh/lMAAVVwvcGsJAnoPFw= -build_script: -- pwsh: >- - $ErrorActionPreference = 'Stop' - - git clone --depth=1 --no-single-branch https://github.com/ModOrganizer2/modorganizer-umbrella.git c:\projects\modorganizer-umbrella - - New-Item -ItemType Directory -Path c:\projects\modorganizer-build - - cd c:\projects\modorganizer-umbrella - - ($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH -eq $null) ? ($branch = $env:APPVEYOR_REPO_BRANCH) : ($branch = $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH) - - git checkout $(git show-ref --verify --quiet refs/remotes/origin/${branch} || echo '-b') ${branch} - - C:\Python37-x64\python.exe unimake.py -d c:\projects\modorganizer-build -s Appveyor_Build=True ${env:APPVEYOR_PROJECT_NAME} - - if($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode ) } -artifacts: -- path: vsbuild\src\RelWithDebInfo\game_enderal.dll - name: game_enderal_dll -- path: vsbuild\src\RelWithDebInfo\game_enderal.pdb - name: game_enderal_pdb -- path: vsbuild\src\RelWithDebInfo\game_enderale.lib - name: game_enderal_lib -on_success: - - ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER - - ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1 - - ps: ./send.ps1 success $env:WEBHOOK_URL -on_failure: - - ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER - - ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stdout.log - - ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stderr.log - - ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1 - - ps: ./send.ps1 failure $env:WEBHOOK_URL \ No newline at end of file diff --git a/src/SConscript b/src/SConscript deleted file mode 100644 index 55e5539..0000000 --- a/src/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -Import('qt_env') - -env = qt_env.Clone() - -env.AppendUnique(CPPDEFINES = [ 'GAMEENDERAL_LIBRARY' ]) - -env.RequiresGamebryo() - -env.AppendUnique(LIBS = [ 'Version' ]) - -lib = env.SharedLibrary('gameEnderal', env.Glob('*.cpp')) -env.InstallModule(lib) - -res = env['QT_USED_MODULES'] -Return('res') diff --git a/src/enderalbsainvalidation.cpp b/src/enderalbsainvalidation.cpp index 97891a2..bcc368f 100644 --- a/src/enderalbsainvalidation.cpp +++ b/src/enderalbsainvalidation.cpp @@ -1,9 +1,9 @@ #include "enderalbsainvalidation.h" -EnderalBSAInvalidation::EnderalBSAInvalidation(DataArchives *dataArchives, MOBase::IPluginGame const *game) - : GamebryoBSAInvalidation(dataArchives, "enderal.ini", game) -{ -} +EnderalBSAInvalidation::EnderalBSAInvalidation(DataArchives* dataArchives, + MOBase::IPluginGame const* game) + : GamebryoBSAInvalidation(dataArchives, "enderal.ini", game) +{} QString EnderalBSAInvalidation::invalidationBSAName() const { diff --git a/src/enderalbsainvalidation.h b/src/enderalbsainvalidation.h index d8fd37a..a3d6ef3 100644 --- a/src/enderalbsainvalidation.h +++ b/src/enderalbsainvalidation.h @@ -1,23 +1,19 @@ #ifndef ENDERALBSAINVALIDATION_H #define ENDERALBSAINVALIDATION_H - -#include "gamebryobsainvalidation.h" #include "enderaldataarchives.h" +#include "gamebryobsainvalidation.h" #include class EnderalBSAInvalidation : public GamebryoBSAInvalidation { public: - - EnderalBSAInvalidation(DataArchives *dataArchives, MOBase::IPluginGame const *game); + EnderalBSAInvalidation(DataArchives* dataArchives, MOBase::IPluginGame const* game); private: - virtual QString invalidationBSAName() const override; virtual unsigned long bsaVersion() const override; - }; -#endif // ENDERALBSAINVALIDATION_H +#endif // ENDERALBSAINVALIDATION_H diff --git a/src/enderaldataarchives.cpp b/src/enderaldataarchives.cpp index 9fa38f9..a153a87 100644 --- a/src/enderaldataarchives.cpp +++ b/src/enderaldataarchives.cpp @@ -1,49 +1,41 @@ #include "enderaldataarchives.h" #include -EnderalDataArchives::EnderalDataArchives(const QDir &myGamesDir) : - GamebryoDataArchives(myGamesDir) -{ -} +EnderalDataArchives::EnderalDataArchives(const QDir& myGamesDir) + : GamebryoDataArchives(myGamesDir) +{} QStringList EnderalDataArchives::vanillaArchives() const { - return { "Skyrim - Misc.bsa" - , "Skyrim - Shaders.bsa" - , "Skyrim - Textures.bsa" - , "Skyrim - Interface.bsa" - , "Skyrim - Animations.bsa" - , "Skyrim - Meshes.bsa" - , "Skyrim - Sounds.bsa" - , "E - Meshes.bsa" - , "E - Music.bsa" - , "E - Scripts.bsa" - , "E - Sounds.bsa" - , "E - Textures1.bsa" - , "E - Textures2.bsa" - , "E - Textures3.bsa" - , "L - Textures.bsa" - , "L - Voices.bsa" - }; + return {"Skyrim - Misc.bsa", "Skyrim - Shaders.bsa", "Skyrim - Textures.bsa", + "Skyrim - Interface.bsa", "Skyrim - Animations.bsa", "Skyrim - Meshes.bsa", + "Skyrim - Sounds.bsa", "E - Meshes.bsa", "E - Music.bsa", + "E - Scripts.bsa", "E - Sounds.bsa", "E - Textures1.bsa", + "E - Textures2.bsa", "E - Textures3.bsa", "L - Textures.bsa", + "L - Voices.bsa"}; } - -QStringList EnderalDataArchives::archives(const MOBase::IProfile *profile) const +QStringList EnderalDataArchives::archives(const MOBase::IProfile* profile) const { QStringList result; - QString iniFile = profile->localSettingsEnabled() ? QDir(profile->absolutePath()).absoluteFilePath("enderal.ini") : m_LocalGameDir.absoluteFilePath("enderal.ini"); + QString iniFile = profile->localSettingsEnabled() + ? QDir(profile->absolutePath()).absoluteFilePath("enderal.ini") + : m_LocalGameDir.absoluteFilePath("enderal.ini"); result.append(getArchivesFromKey(iniFile, "SResourceArchiveList")); result.append(getArchivesFromKey(iniFile, "SResourceArchiveList2")); return result; } -void EnderalDataArchives::writeArchiveList(MOBase::IProfile *profile, const QStringList &before) +void EnderalDataArchives::writeArchiveList(MOBase::IProfile* profile, + const QStringList& before) { QString list = before.join(", "); - QString iniFile = profile->localSettingsEnabled() ? QDir(profile->absolutePath()).absoluteFilePath("enderal.ini") : m_LocalGameDir.absoluteFilePath("enderal.ini"); + QString iniFile = profile->localSettingsEnabled() + ? QDir(profile->absolutePath()).absoluteFilePath("enderal.ini") + : m_LocalGameDir.absoluteFilePath("enderal.ini"); if (list.length() > 255) { int splitIdx = list.lastIndexOf(",", 256); setArchivesToKey(iniFile, "SResourceArchiveList", list.mid(0, splitIdx)); diff --git a/src/enderaldataarchives.h b/src/enderaldataarchives.h index 32a7dc3..3120a83 100644 --- a/src/enderaldataarchives.h +++ b/src/enderaldataarchives.h @@ -1,28 +1,25 @@ #ifndef ENDERALDATAARCHIVES_H #define ENDERALDATAARCHIVES_H - -#include -#include +#include #include #include -#include +#include +#include class EnderalDataArchives : public GamebryoDataArchives { public: - EnderalDataArchives(const QDir &myGamesDir); + EnderalDataArchives(const QDir& myGamesDir); public: - virtual QStringList vanillaArchives() const override; - virtual QStringList archives(const MOBase::IProfile *profile) const override; + virtual QStringList archives(const MOBase::IProfile* profile) const override; private: - - virtual void writeArchiveList(MOBase::IProfile *profile, const QStringList &before) override; - + virtual void writeArchiveList(MOBase::IProfile* profile, + const QStringList& before) override; }; -#endif // ENDERALDATAARCHIVES_H +#endif // ENDERALDATAARCHIVES_H diff --git a/src/enderalgameplugins.cpp b/src/enderalgameplugins.cpp index 2d537c8..cd8048e 100644 --- a/src/enderalgameplugins.cpp +++ b/src/enderalgameplugins.cpp @@ -1,44 +1,44 @@ #include "enderalgameplugins.h" -#include -#include #include #include +#include #include #include -#include #include +#include - +using MOBase::IOrganizer; using MOBase::IPluginGame; using MOBase::IPluginList; -using MOBase::IOrganizer; -using MOBase::SafeWriteFile; using MOBase::reportError; +using MOBase::SafeWriteFile; -EnderalGamePlugins::EnderalGamePlugins(IOrganizer *organizer) +EnderalGamePlugins::EnderalGamePlugins(IOrganizer* organizer) : GamebryoGamePlugins(organizer) {} -void EnderalGamePlugins::readPluginLists(MOBase::IPluginList *pluginList) { - QString loadOrderPath = - organizer()->profile()->absolutePath() + "/loadorder.txt"; - QString pluginsPath = organizer()->profile()->absolutePath() + "/plugins.txt"; +void EnderalGamePlugins::readPluginLists(MOBase::IPluginList* pluginList) +{ + QString loadOrderPath = organizer()->profile()->absolutePath() + "/loadorder.txt"; + QString pluginsPath = organizer()->profile()->absolutePath() + "/plugins.txt"; - bool loadOrderIsNew = !m_LastRead.isValid() || - !QFileInfo(loadOrderPath).exists() || - QFileInfo(loadOrderPath).lastModified() > m_LastRead; - bool pluginsIsNew = !m_LastRead.isValid() || - QFileInfo(pluginsPath).lastModified() > m_LastRead; + bool loadOrderIsNew = !m_LastRead.isValid() || !QFileInfo(loadOrderPath).exists() || + QFileInfo(loadOrderPath).lastModified() > m_LastRead; + bool pluginsIsNew = + !m_LastRead.isValid() || QFileInfo(pluginsPath).lastModified() > m_LastRead; if (pluginsIsNew && !loadOrderIsNew) { - // If the plugins is new but not loadorder, we must reparse the load order from the plugin files + // If the plugins is new but not loadorder, we must reparse the load order from the + // plugin files - //removed because returned loadorder was incorrect and did not account for plugins that were already disabled before. + // removed because returned loadorder was incorrect and did not account for plugins + // that were already disabled before. /*QStringList loadOrder = readPluginList(pluginList); pluginList->setLoadOrder(loadOrder);*/ - //Fix me: we are ignoring order changes in plugins.txt favouring loadorder.txt in all cases (plugins.txt should have precedence) + // Fix me: we are ignoring order changes in plugins.txt favouring loadorder.txt in + // all cases (plugins.txt should have precedence) QStringList loadOrder = readLoadOrderList(pluginList, loadOrderPath); pluginList->setLoadOrder(loadOrder); readPluginList(pluginList); @@ -52,70 +52,72 @@ void EnderalGamePlugins::readPluginLists(MOBase::IPluginList *pluginList) { m_LastRead = QDateTime::currentDateTime(); } -//TODO: return value is incorrect and should be ignored (it's not currently used -QStringList EnderalGamePlugins::readPluginList(MOBase::IPluginList *pluginList) +// TODO: return value is incorrect and should be ignored (it's not currently used +QStringList EnderalGamePlugins::readPluginList(MOBase::IPluginList* pluginList) { - QStringList plugins = pluginList->pluginNames(); - QStringList primaryPlugins = organizer()->managedGame()->primaryPlugins(); - QStringList loadOrder(plugins); + QStringList plugins = pluginList->pluginNames(); + QStringList primaryPlugins = organizer()->managedGame()->primaryPlugins(); + QStringList loadOrder(plugins); - for (const QString &pluginName : primaryPlugins) { - if (pluginList->state(pluginName) != IPluginList::STATE_MISSING) { - pluginList->setState(pluginName, IPluginList::STATE_ACTIVE); - } + for (const QString& pluginName : primaryPlugins) { + if (pluginList->state(pluginName) != IPluginList::STATE_MISSING) { + pluginList->setState(pluginName, IPluginList::STATE_ACTIVE); + } + } + + // Do not sort the primary plugins. Their load order should be locked as defined in + // "primaryPlugins". + const QStringList pluginsClone(plugins); + for (QString plugin : pluginsClone) { + if (primaryPlugins.contains(plugin, Qt::CaseInsensitive)) + plugins.removeAll(plugin); + } + + // Determine plugin active state by the plugins.txt file. + bool pluginsTxtExists = true; + QString filePath = organizer()->profile()->absolutePath() + "/plugins.txt"; + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + pluginsTxtExists = false; + } + ON_BLOCK_EXIT([&]() { + qDebug("close %s", qUtf8Printable(filePath)); + file.close(); + }); + + if (file.size() == 0) { + // MO stores at least a header in the file. if it's completely empty the + // file is broken + pluginsTxtExists = false; + } + + if (pluginsTxtExists) { + while (!file.atEnd()) { + QByteArray line = file.readLine(); + QString pluginName; + if ((line.size() > 0) && (line.at(0) != '#')) { + pluginName = QStringEncoder(QStringConverter::Encoding::System) + .encode(line.trimmed().constData()); + } + if (pluginName.size() > 0) { + pluginList->setState(pluginName, IPluginList::STATE_ACTIVE); + plugins.removeAll(pluginName); + // we already have the old loadorder and we ignore the positions in plugins.txt + // (needs fix) loadOrder.append(pluginName); + } } - // Do not sort the primary plugins. Their load order should be locked as defined in "primaryPlugins". - const QStringList pluginsClone(plugins); - for (QString plugin : pluginsClone) { - if (primaryPlugins.contains(plugin, Qt::CaseInsensitive)) - plugins.removeAll(plugin); + file.close(); + + // we removed each plugin found in the file, so what's left are inactive mods + for (const QString& pluginName : plugins) { + pluginList->setState(pluginName, IPluginList::STATE_INACTIVE); } - - // Determine plugin active state by the plugins.txt file. - bool pluginsTxtExists = true; - QString filePath = organizer()->profile()->absolutePath() + "/plugins.txt"; - QFile file(filePath); - if (!file.open(QIODevice::ReadOnly)) { - pluginsTxtExists = false; + } else { + for (const QString& pluginName : plugins) { + pluginList->setState(pluginName, IPluginList::STATE_INACTIVE); } - ON_BLOCK_EXIT([&]() { - qDebug("close %s", qUtf8Printable(filePath)); - file.close(); - }); + } - if (file.size() == 0) { - // MO stores at least a header in the file. if it's completely empty the - // file is broken - pluginsTxtExists = false; - } - - if (pluginsTxtExists) { - while (!file.atEnd()) { - QByteArray line = file.readLine(); - QString pluginName; - if ((line.size() > 0) && (line.at(0) != '#')) { - pluginName = QStringEncoder(QStringConverter::Encoding::System).encode(line.trimmed().constData()); - } - if (pluginName.size() > 0) { - pluginList->setState(pluginName, IPluginList::STATE_ACTIVE); - plugins.removeAll(pluginName); - //we already have the old loadorder and we ignore the positions in plugins.txt (needs fix) - //loadOrder.append(pluginName); - } - } - - file.close(); - - // we removed each plugin found in the file, so what's left are inactive mods - for (const QString &pluginName : plugins) { - pluginList->setState(pluginName, IPluginList::STATE_INACTIVE); - } - } else { - for (const QString &pluginName : plugins) { - pluginList->setState(pluginName, IPluginList::STATE_INACTIVE); - } - } - - return loadOrder; + return loadOrder; } diff --git a/src/enderalgameplugins.h b/src/enderalgameplugins.h index 2b685eb..f78904d 100644 --- a/src/enderalgameplugins.h +++ b/src/enderalgameplugins.h @@ -1,25 +1,23 @@ #ifndef _ENDERALGAMEPLUGINS_H #define _ENDERALGAMEPLUGINS_H - #include -#include #include +#include #include - class EnderalGamePlugins : public GamebryoGamePlugins { public: - EnderalGamePlugins(MOBase::IOrganizer *organizer); + EnderalGamePlugins(MOBase::IOrganizer* organizer); - virtual void readPluginLists(MOBase::IPluginList *pluginList) override; + virtual void readPluginLists(MOBase::IPluginList* pluginList) override; protected: - virtual QStringList readPluginList(MOBase::IPluginList *pluginList) override; + virtual QStringList readPluginList(MOBase::IPluginList* pluginList) override; private: - std::map m_LastSaveHash; + std::map m_LastSaveHash; }; -#endif // _ENDERALSEGAMEPLUGINS_H +#endif // _ENDERALSEGAMEPLUGINS_H diff --git a/src/enderallocalsavegames.cpp b/src/enderallocalsavegames.cpp index 4a59342..115bb36 100644 --- a/src/enderallocalsavegames.cpp +++ b/src/enderallocalsavegames.cpp @@ -16,57 +16,48 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - #include "enderallocalsavegames.h" #include "registry.h" -#include #include -#include +#include #include #include - +#include static const QString LocalSavesDummy = "..\\Enderal\\__MO_Saves\\"; - -EnderalLocalSavegames::EnderalLocalSavegames(const QDir &myGamesDir, - const QString &iniFileName) - : m_LocalSavesDir(myGamesDir.absoluteFilePath(LocalSavesDummy)) - , m_LocalGameDir(myGamesDir.absolutePath()) - , m_IniFileName(iniFileName) +EnderalLocalSavegames::EnderalLocalSavegames(const QDir& myGamesDir, + const QString& iniFileName) + : m_LocalSavesDir(myGamesDir.absoluteFilePath(LocalSavesDummy)), + m_LocalGameDir(myGamesDir.absolutePath()), m_IniFileName(iniFileName) {} - -MappingType EnderalLocalSavegames::mappings(const QDir &profileSaveDir) const +MappingType EnderalLocalSavegames::mappings(const QDir& profileSaveDir) const { - return {{ - profileSaveDir.absolutePath(), - m_LocalSavesDir.absolutePath(), - true, - true - }}; + return {{profileSaveDir.absolutePath(), m_LocalSavesDir.absolutePath(), true, true}}; } - -bool EnderalLocalSavegames::prepareProfile(MOBase::IProfile *profile) +bool EnderalLocalSavegames::prepareProfile(MOBase::IProfile* profile) { bool enable = profile->localSavesEnabled(); - QString basePath - = profile->localSettingsEnabled() - ? profile->absolutePath() - : m_LocalGameDir.absolutePath(); + QString basePath = profile->localSettingsEnabled() ? profile->absolutePath() + : m_LocalGameDir.absolutePath(); QString iniFilePath = basePath + "/" + m_IniFileName; - QString saveIni = profile->absolutePath() + "/" + "savepath.ini"; + 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; + 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()); + 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) { @@ -80,13 +71,18 @@ bool EnderalLocalSavegames::prepareProfile(MOBase::IProfile *profile) 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()); + 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"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()); + 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 @@ -95,26 +91,32 @@ bool EnderalLocalSavegames::prepareProfile(MOBase::IProfile *profile) 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()); + 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()); + 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()); + 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()); + MOBase::WriteRegistryValue(L"General", L"sLocalSavePath", NULL, + iniFilePath.toStdWString().c_str()); + MOBase::WriteRegistryValue(L"General", L"bUseMyGamesDirectory", NULL, + iniFilePath.toStdWString().c_str()); } } diff --git a/src/enderallocalsavegames.h b/src/enderallocalsavegames.h index 9ade8d4..fcc5d0e 100644 --- a/src/enderallocalsavegames.h +++ b/src/enderallocalsavegames.h @@ -16,11 +16,9 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - #ifndef ENDERALLOCALSAVEGAMES_H #define ENDERALLOCALSAVEGAMES_H - #include #include @@ -30,18 +28,15 @@ class EnderalLocalSavegames : public LocalSavegames { public: - EnderalLocalSavegames(const QDir &myGamesDir, const QString &iniFileName); + EnderalLocalSavegames(const QDir& myGamesDir, const QString& iniFileName); - virtual MappingType mappings(const QDir &profileSaveDir) const override; - virtual bool prepareProfile(MOBase::IProfile *profile) override; + 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; - }; - -#endif // ENDERALLOCALSAVEGAMES_H +#endif // ENDERALLOCALSAVEGAMES_H diff --git a/src/enderalmoddatachecker.h b/src/enderalmoddatachecker.h index 3940b55..55f8aac 100644 --- a/src/enderalmoddatachecker.h +++ b/src/enderalmoddatachecker.h @@ -9,21 +9,41 @@ public: using GamebryoModDataChecker::GamebryoModDataChecker; protected: - virtual const FileNameSet& possibleFolderNames() const override { - static FileNameSet result{ - "fonts", "interface", "menus", "meshes", "music", "scripts", "shaders", - "sound", "strings", "textures", "trees", "video", "facegen", "materials", - "skse", "distantlod", "asi", "Tools", "MCM", "distantland", "mits", - "dllplugins", "SkyProc Patchers", "CalienteTools", "NetScriptFramework", "shadersfx" - }; + virtual const FileNameSet& possibleFolderNames() const override + { + static FileNameSet result{"fonts", + "interface", + "menus", + "meshes", + "music", + "scripts", + "shaders", + "sound", + "strings", + "textures", + "trees", + "video", + "facegen", + "materials", + "skse", + "distantlod", + "asi", + "Tools", + "MCM", + "distantland", + "mits", + "dllplugins", + "SkyProc Patchers", + "CalienteTools", + "NetScriptFramework", + "shadersfx"}; return result; } - virtual const FileNameSet& possibleFileExtensions() const override { - static FileNameSet result{ - "esp", "esm", "bsa", "modgroups", "ini" - }; + virtual const FileNameSet& possibleFileExtensions() const override + { + static FileNameSet result{"esp", "esm", "bsa", "modgroups", "ini"}; return result; } }; -#endif // ENDERAL_MODATACHECKER_H +#endif // ENDERAL_MODATACHECKER_H diff --git a/src/enderalmoddatacontent.h b/src/enderalmoddatacontent.h index e6de058..47b45b9 100644 --- a/src/enderalmoddatacontent.h +++ b/src/enderalmoddatacontent.h @@ -5,11 +5,10 @@ #include // Like Skyrim, Enderal does not need any change from the default feature: -class EnderalModDataContent : public GamebryoModDataContent { +class EnderalModDataContent : public GamebryoModDataContent +{ public: - using GamebryoModDataContent::GamebryoModDataContent; - }; -#endif // ENDERAL_MODDATACONTENT_H +#endif // ENDERAL_MODDATACONTENT_H diff --git a/src/enderalsavegame.cpp b/src/enderalsavegame.cpp index 04f70cc..a8d36fc 100644 --- a/src/enderalsavegame.cpp +++ b/src/enderalsavegame.cpp @@ -4,32 +4,28 @@ #include "gameenderal.h" -EnderalSaveGame::EnderalSaveGame(QString const &fileName, GameEnderal const *game) : - GamebryoSaveGame(fileName, game) +EnderalSaveGame::EnderalSaveGame(QString const& fileName, GameEnderal const* game) + : GamebryoSaveGame(fileName, game) { FileWrapper file(getFilepath(), "TESV_SAVEGAME"); FILETIME ftime; fetchInformationFields(file, m_SaveNumber, m_PCName, m_PCLevel, m_PCLocation, ftime); - //A file time is a 64-bit value that represents the number of 100-nanosecond - //intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC). - //So we need to convert that to something useful + // A file time is a 64-bit value that represents the number of 100-nanosecond + // intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal + // Time (UTC). So we need to convert that to something useful SYSTEMTIME ctime; ::FileTimeToSystemTime(&ftime, &ctime); setCreationTime(ctime); } - -void EnderalSaveGame::fetchInformationFields(FileWrapper& file, - unsigned long& saveNumber, - QString& playerName, - unsigned short& playerLevel, - QString& playerLocation, - FILETIME& creationTime) const +void EnderalSaveGame::fetchInformationFields( + FileWrapper& file, unsigned long& saveNumber, QString& playerName, + unsigned short& playerLevel, QString& playerLocation, FILETIME& creationTime) const { - file.skip(); // header size - file.skip(); // header version + file.skip(); // header size + file.skip(); // header version file.read(saveNumber); file.read(playerName); @@ -44,10 +40,10 @@ void EnderalSaveGame::fetchInformationFields(FileWrapper& file, file.read(timeOfDay); QString race; - file.read(race); // race name (i.e. BretonRace) + file.read(race); // race name (i.e. BretonRace) - file.skip(); // Player gender (0 = male) - file.skip(2); // experience gathered, experience required + file.skip(); // Player gender (0 = male) + file.skip(2); // experience gathered, experience required file.read(creationTime); } @@ -63,14 +59,14 @@ std::unique_ptr EnderalSaveGame::fetchDataFields() unsigned long dummySaveNumber; FILETIME dummyTime; - fetchInformationFields(file, dummySaveNumber, dummyName, dummyLevel, - dummyLocation, dummyTime); + fetchInformationFields(file, dummySaveNumber, dummyName, dummyLevel, dummyLocation, + dummyTime); } fields->Screenshot = file.readImage(); - file.skip(); // form version - file.skip(); // plugin info size + file.skip(); // form version + file.skip(); // plugin info size fields->Plugins = file.readPlugins(); diff --git a/src/enderalsavegame.h b/src/enderalsavegame.h index 54f79fd..22b29c0 100644 --- a/src/enderalsavegame.h +++ b/src/enderalsavegame.h @@ -10,19 +10,15 @@ class GameEnderal; class EnderalSaveGame : public GamebryoSaveGame { public: - EnderalSaveGame(QString const &fileName, GameEnderal const *game); + EnderalSaveGame(QString const& fileName, GameEnderal const* game); protected: - // Fetch easy-to-access information. - void fetchInformationFields(FileWrapper& wrapper, - unsigned long& saveNumber, - QString& playerName, - unsigned short& playerLevel, - QString& playerLocation, - FILETIME& creationTime) const; + void fetchInformationFields(FileWrapper& wrapper, unsigned long& saveNumber, + QString& playerName, unsigned short& playerLevel, + QString& playerLocation, FILETIME& creationTime) const; std::unique_ptr fetchDataFields() const override; }; -#endif // ENDERALSAVEGAME_H +#endif // ENDERALSAVEGAME_H diff --git a/src/enderalscriptextender.cpp b/src/enderalscriptextender.cpp index 25f14ab..ff3864b 100644 --- a/src/enderalscriptextender.cpp +++ b/src/enderalscriptextender.cpp @@ -3,10 +3,9 @@ #include #include -EnderalScriptExtender::EnderalScriptExtender(GameGamebryo const *game) : - GamebryoScriptExtender(game) -{ -} +EnderalScriptExtender::EnderalScriptExtender(GameGamebryo const* game) + : GamebryoScriptExtender(game) +{} QString EnderalScriptExtender::BinaryName() const { diff --git a/src/enderalscriptextender.h b/src/enderalscriptextender.h index cab8209..7d0d027 100644 --- a/src/enderalscriptextender.h +++ b/src/enderalscriptextender.h @@ -8,11 +8,10 @@ class GameGamebryo; class EnderalScriptExtender : public GamebryoScriptExtender { public: - EnderalScriptExtender(const GameGamebryo *game); + EnderalScriptExtender(const GameGamebryo* game); virtual QString BinaryName() const override; virtual QString PluginPath() const override; - }; -#endif // ENDERALSCRIPTEXTENDER_H +#endif // ENDERALSCRIPTEXTENDER_H diff --git a/src/gameEnderal.pro b/src/gameEnderal.pro deleted file mode 100644 index 32302ff..0000000 --- a/src/gameEnderal.pro +++ /dev/null @@ -1,49 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2014-11-15T15:36:33 -# -#------------------------------------------------- - - -TARGET = gameEnderal -TEMPLATE = lib - -CONFIG += plugins -CONFIG += dll -DEFINES += GAMESKYRIM_LIBRARY - -SOURCES += gameenderal.cpp \ - enderalbsainvalidation.cpp \ - enderalscriptextender.cpp \ - enderaldataarchives.cpp \ - enderalsavegame.cpp \ - enderalsavegameinfo.cpp - -HEADERS += gameenderal.h \ - enderalbsainvalidation.h \ - enderalscriptextender.h \ - enderaldataarchives.h \ - enderalsavegame.h \ - enderalsavegameinfo.h - -CONFIG(debug, debug|release) { - LIBS += -L"$${OUT_PWD}/../gameGamebryo/debug" - PRE_TARGETDEPS += \ - $$OUT_PWD/../gameGamebryo/debug/gameGamebryo.lib -} else { - LIBS += -L"$${OUT_PWD}/../gameGamebryo/release" - PRE_TARGETDEPS += \ - $$OUT_PWD/../gameGamebryo/release/gameGamebryo.lib -} - -include(../plugin_template.pri) - -INCLUDEPATH += "$${BOOSTPATH}" "$${PWD}/../gamefeatures" "$${PWD}/../gamegamebryo" - -LIBS += -ladvapi32 -lole32 -lgameGamebryo - -OTHER_FILES += \ - gameenderal.json\ - SConscript \ - CMakeLists.txt - diff --git a/src/gameenderal.cpp b/src/gameenderal.cpp index 1e2320b..11f200b 100644 --- a/src/gameenderal.cpp +++ b/src/gameenderal.cpp @@ -1,31 +1,29 @@ #include "gameenderal.h" #include "enderalbsainvalidation.h" -#include "enderalscriptextender.h" #include "enderaldataarchives.h" #include "enderalgameplugins.h" #include "enderallocalsavegames.h" #include "enderalmoddatachecker.h" #include "enderalmoddatacontent.h" #include "enderalsavegame.h" - +#include "enderalscriptextender.h" #include "executableinfo.h" #include "pluginsetting.h" -#include "utility.h" #include "steamutility.h" +#include "utility.h" #include -#include #include +#include #include #include #include -#include #include - +#include #include #include @@ -38,244 +36,247 @@ using namespace MOBase; -GameEnderal::GameEnderal() -{ -} +GameEnderal::GameEnderal() {} bool GameEnderal::init(IOrganizer* moInfo) { - if (!GameGamebryo::init(moInfo)) { - return false; - } + if (!GameGamebryo::init(moInfo)) { + return false; + } - registerFeature(new EnderalScriptExtender(this)); - registerFeature(new EnderalDataArchives(myGamesPath())); - registerFeature(new EnderalBSAInvalidation(feature(), this)); - registerFeature(new GamebryoSaveGameInfo(this)); - registerFeature(new EnderalLocalSavegames(myGamesPath(), "enderal.ini")); - registerFeature(new EnderalModDataChecker(this)); - registerFeature(new EnderalModDataContent(this)); - registerFeature(new EnderalGamePlugins(moInfo)); - registerFeature(new GamebryoUnmangedMods(this)); - return true; + registerFeature(new EnderalScriptExtender(this)); + registerFeature(new EnderalDataArchives(myGamesPath())); + registerFeature( + new EnderalBSAInvalidation(feature(), this)); + registerFeature(new GamebryoSaveGameInfo(this)); + registerFeature( + new EnderalLocalSavegames(myGamesPath(), "enderal.ini")); + registerFeature(new EnderalModDataChecker(this)); + registerFeature(new EnderalModDataContent(this)); + registerFeature(new EnderalGamePlugins(moInfo)); + registerFeature(new GamebryoUnmangedMods(this)); + return true; } QString GameEnderal::gameName() const { - return "Enderal"; + return "Enderal"; } QList GameEnderal::executables() const { - return QList() - //<< ExecutableInfo("SKSE", findInGameFolder(feature()->loaderName())) - //<< ExecutableInfo("SBW", findInGameFolder("SBW.exe")) - << ExecutableInfo("Enderal (SKSE)", findInGameFolder(binaryName())) - << ExecutableInfo("Enderal Launcher", findInGameFolder(getLauncherName())) - << ExecutableInfo("BOSS", findInGameFolder("BOSS/BOSS.exe")) - << ExecutableInfo("LOOT", QFileInfo(getLootPath())).withArgument("--game=\"Enderal\"") - << ExecutableInfo("Creation Kit", findInGameFolder("CreationKit.exe")).withSteamAppId("202480") - ; + return QList() + //<< ExecutableInfo("SKSE", + // findInGameFolder(feature()->loaderName())) + //<< ExecutableInfo("SBW", findInGameFolder("SBW.exe")) + << ExecutableInfo("Enderal (SKSE)", findInGameFolder(binaryName())) + << ExecutableInfo("Enderal Launcher", findInGameFolder(getLauncherName())) + << ExecutableInfo("BOSS", findInGameFolder("BOSS/BOSS.exe")) + << ExecutableInfo("LOOT", QFileInfo(getLootPath())) + .withArgument("--game=\"Enderal\"") + << ExecutableInfo("Creation Kit", findInGameFolder("CreationKit.exe")) + .withSteamAppId("202480"); } QList GameEnderal::executableForcedLoads() const { - return QList(); + return QList(); } QString GameEnderal::name() const { - return "Enderal Support Plugin"; + return "Enderal Support Plugin"; } QString GameEnderal::localizedName() const { - return tr("Enderal Support Plugin"); + return tr("Enderal Support Plugin"); } QString GameEnderal::author() const { - return "AL12"; + return "AL12"; } QString GameEnderal::description() const { - return tr("Adds support for the game Enderal"); + return tr("Adds support for the game Enderal"); } MOBase::VersionInfo GameEnderal::version() const { - return VersionInfo(1, 3, 0, VersionInfo::RELEASE_FINAL); + return VersionInfo(1, 3, 0, VersionInfo::RELEASE_FINAL); } QList GameEnderal::settings() const { - QList results; - results.push_back(PluginSetting("sse_downloads", "allow Skyrim SE downloads", QVariant(false))); - return results; + QList results; + results.push_back( + PluginSetting("sse_downloads", "allow Skyrim SE downloads", QVariant(false))); + return results; } void GameEnderal::initializeProfile(const QDir& path, ProfileSettings settings) const { - if (settings.testFlag(IPluginGame::MODS)) { - copyToProfile(localAppFolder() + "/enderal", path, "plugins.txt"); - } + if (settings.testFlag(IPluginGame::MODS)) { + copyToProfile(localAppFolder() + "/enderal", path, "plugins.txt"); + } - if (settings.testFlag(IPluginGame::CONFIGURATION)) { - if (settings.testFlag(IPluginGame::PREFER_DEFAULTS) - || !QFileInfo(myGamesPath() + "/enderal.ini").exists()) { + if (settings.testFlag(IPluginGame::CONFIGURATION)) { + if (settings.testFlag(IPluginGame::PREFER_DEFAULTS) || + !QFileInfo(myGamesPath() + "/enderal.ini").exists()) { - //there is no default ini, actually they are going to put them in for us! - copyToProfile(gameDirectory().absolutePath(), path, "enderal_default.ini", "enderal.ini"); - copyToProfile(gameDirectory().absolutePath(), path, "enderalprefs_default.ini", "enderalprefs.ini"); - } - else { - copyToProfile(myGamesPath(), path, "enderal.ini"); - copyToProfile(myGamesPath(), path, "enderalprefs.ini"); - } - } + // there is no default ini, actually they are going to put them in for us! + copyToProfile(gameDirectory().absolutePath(), path, "enderal_default.ini", + "enderal.ini"); + copyToProfile(gameDirectory().absolutePath(), path, "enderalprefs_default.ini", + "enderalprefs.ini"); + } else { + copyToProfile(myGamesPath(), path, "enderal.ini"); + copyToProfile(myGamesPath(), path, "enderalprefs.ini"); + } + } } bool GameEnderal::looksValid(QDir const& path) const { - // we need to check both launcher and binary because the binary also exists for - // Skyrim and the launcher for Enderal SE - return path.exists(getLauncherName()) && path.exists(binaryName()); + // we need to check both launcher and binary because the binary also exists for + // Skyrim and the launcher for Enderal SE + return path.exists(getLauncherName()) && path.exists(binaryName()); } QIcon GameEnderal::gameIcon() const { - return MOBase::iconForExecutable(gameDirectory().absoluteFilePath(getLauncherName())); + return MOBase::iconForExecutable(gameDirectory().absoluteFilePath(getLauncherName())); } QString GameEnderal::savegameExtension() const { - return "ess"; + return "ess"; } QString GameEnderal::savegameSEExtension() const { - return "skse"; + return "skse"; } -std::shared_ptr GameEnderal::makeSaveGame(QString filepath) const +std::shared_ptr +GameEnderal::makeSaveGame(QString filepath) const { - return std::make_shared(filepath, this); + return std::make_shared(filepath, this); } - QString GameEnderal::steamAPPId() const { - return "933480"; + return "933480"; } QStringList GameEnderal::primaryPlugins() const { - return { "Skyrim.esm", "Enderal - Forgotten Stories.esm", "Update.esm" }; + return {"Skyrim.esm", "Enderal - Forgotten Stories.esm", "Update.esm"}; } QString GameEnderal::binaryName() const { - return "skse_loader.exe"; + return "skse_loader.exe"; } QString GameEnderal::getLauncherName() const { - return "Enderal Launcher.exe"; + return "Enderal Launcher.exe"; } QString GameEnderal::gameShortName() const { - return "Enderal"; + return "Enderal"; } QString GameEnderal::gameNexusName() const { - return "enderal"; + return "enderal"; } QStringList GameEnderal::primarySources() const { - return { "Skyrim" }; + return {"Skyrim"}; } QStringList GameEnderal::validShortNames() const { - QStringList results; - results.push_back("Skyrim"); - if (m_Organizer->pluginSetting(name(), "sse_downloads").toBool()) - { - results.push_back("SkyrimSE"); - } - return results; + QStringList results; + results.push_back("Skyrim"); + if (m_Organizer->pluginSetting(name(), "sse_downloads").toBool()) { + results.push_back("SkyrimSE"); + } + return results; } QStringList GameEnderal::iniFiles() const { - return { "enderal.ini", "enderalprefs.ini" }; + return {"enderal.ini", "enderalprefs.ini"}; } QStringList GameEnderal::DLCPlugins() const { - return {}; + return {}; } -namespace { - //Note: This is ripped off from shared/util. And in an upcoming move, the fomod - //installer requires something similar. I suspect I should abstract this out - //into gamebryo (or lower level) - //Unused for Enderal +namespace +{ +// Note: This is ripped off from shared/util. And in an upcoming move, the fomod +// installer requires something similar. I suspect I should abstract this out +// into gamebryo (or lower level) +// Unused for Enderal - VS_FIXEDFILEINFO GetFileVersion(const std::wstring& fileName) - { - DWORD handle = 0UL; - DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle); - if (size == 0) { - throw std::runtime_error("failed to determine file version info size"); - } +VS_FIXEDFILEINFO GetFileVersion(const std::wstring& fileName) +{ + DWORD handle = 0UL; + DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle); + if (size == 0) { + throw std::runtime_error("failed to determine file version info size"); + } - std::vector buffer(size); - handle = 0UL; - if (!::GetFileVersionInfoW(fileName.c_str(), handle, size, buffer.data())) { - throw std::runtime_error("failed to determine file version info"); - } + std::vector buffer(size); + handle = 0UL; + if (!::GetFileVersionInfoW(fileName.c_str(), handle, size, buffer.data())) { + throw std::runtime_error("failed to determine file version info"); + } - void* versionInfoPtr = nullptr; - UINT versionInfoLength = 0; - if (!::VerQueryValue(buffer.data(), L"\\", &versionInfoPtr, &versionInfoLength)) { - throw std::runtime_error("failed to determine file version"); - } - - return *static_cast(versionInfoPtr); - } + void* versionInfoPtr = nullptr; + UINT versionInfoLength = 0; + if (!::VerQueryValue(buffer.data(), L"\\", &versionInfoPtr, &versionInfoLength)) { + throw std::runtime_error("failed to determine file version"); + } + return *static_cast(versionInfoPtr); } +} // namespace + IPluginGame::LoadOrderMechanism GameEnderal::loadOrderMechanism() const { - return LoadOrderMechanism::PluginsTxt; + return LoadOrderMechanism::PluginsTxt; } - int GameEnderal::nexusModOrganizerID() const { - return 0; + return 0; } int GameEnderal::nexusGameID() const { - return 0; + return 0; } QString GameEnderal::identifyGamePath() const { - QString path = "Software\\SureAI\\Enderal"; - QString result; - try { - result = findInRegistry(HKEY_CURRENT_USER, path.toStdWString().c_str(), L"Install_Path"); - } - catch (MOBase::MyException) { - result = MOBase::findSteamGame("Enderal", "Data\\Enderal - Forgotten Stories.esm"); - } - return result; + QString path = "Software\\SureAI\\Enderal"; + QString result; + try { + result = + findInRegistry(HKEY_CURRENT_USER, path.toStdWString().c_str(), L"Install_Path"); + } catch (MOBase::MyException) { + result = MOBase::findSteamGame("Enderal", "Data\\Enderal - Forgotten Stories.esm"); + } + return result; } diff --git a/src/gameenderal.h b/src/gameenderal.h index 195c5d0..fb0a377 100644 --- a/src/gameenderal.h +++ b/src/gameenderal.h @@ -8,55 +8,54 @@ class GameEnderal : public GameGamebryo { - Q_OBJECT -#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) - Q_PLUGIN_METADATA(IID "org.tannin.GameEnderal" FILE "gameenderal.json") + Q_OBJECT +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + Q_PLUGIN_METADATA(IID "org.tannin.GameEnderal" FILE "gameenderal.json") #endif public: + GameEnderal(); - GameEnderal(); + virtual bool init(MOBase::IOrganizer* moInfo) override; - virtual bool init(MOBase::IOrganizer* moInfo) override; +public: // IPluginGame interface + virtual QString gameName() const override; + virtual QList executables() const override; + virtual QList + executableForcedLoads() const override; + virtual void initializeProfile(const QDir& path, + ProfileSettings settings) const override; + virtual QString steamAPPId() const override; + virtual QStringList primaryPlugins() const override; + virtual QString binaryName() const override; + virtual QString getLauncherName() const override; + virtual QString gameShortName() const override; + virtual QStringList validShortNames() const override; + virtual QString gameNexusName() const override; + virtual QStringList primarySources() const override; + virtual QStringList iniFiles() const override; + virtual QStringList DLCPlugins() const override; + virtual LoadOrderMechanism loadOrderMechanism() const override; + virtual int nexusModOrganizerID() const override; + virtual int nexusGameID() const override; + virtual bool looksValid(QDir const&) const override; + virtual QIcon gameIcon() const override; -public: // IPluginGame interface - - virtual QString gameName() const override; - virtual QList executables() const override; - virtual QList executableForcedLoads() const override; - virtual void initializeProfile(const QDir& path, ProfileSettings settings) const override; - virtual QString steamAPPId() const override; - virtual QStringList primaryPlugins() const override; - virtual QString binaryName() const override; - virtual QString getLauncherName() const override; - virtual QString gameShortName() const override; - virtual QStringList validShortNames() const override; - virtual QString gameNexusName() const override; - virtual QStringList primarySources() const override; - virtual QStringList iniFiles() const override; - virtual QStringList DLCPlugins() const override; - virtual LoadOrderMechanism loadOrderMechanism() const override; - virtual int nexusModOrganizerID() const override; - virtual int nexusGameID() const override; - virtual bool looksValid(QDir const&) const override; - virtual QIcon gameIcon() const override; - -public: // IPlugin interface - - virtual QString name() const override; - virtual QString localizedName() const override; - virtual QString author() const override; - virtual QString description() const override; - virtual MOBase::VersionInfo version() const override; - virtual QList settings() const override; +public: // IPlugin interface + virtual QString name() const override; + virtual QString localizedName() const override; + virtual QString author() const override; + virtual QString description() const override; + virtual MOBase::VersionInfo version() const override; + virtual QList settings() const override; protected: + virtual QString savegameExtension() const override; + virtual QString savegameSEExtension() const override; + virtual std::shared_ptr + makeSaveGame(QString filepath) const override; - virtual QString savegameExtension() const override; - virtual QString savegameSEExtension() const override; - virtual std::shared_ptr makeSaveGame(QString filepath) const override; - - virtual QString identifyGamePath() const override; + virtual QString identifyGamePath() const override; }; -#endif // GAMEENDERAL_H +#endif // GAMEENDERAL_H