From 9e31068b53da96ad4f07bb89a7739cd4ce0b58d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 9 Jun 2024 13:55:34 +0200 Subject: [PATCH 1/4] Remove appveyor.yml. --- appveyor.yml | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 6c8d00b..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\installer_fomod_csharp.dll - name: installer_fomod_csharp_dll -- path: vsbuild\src\RelWithDebInfo\installer_fomod_csharp.pdb - name: installer_fomod_csharp_pdb -- path: vsbuild\src\RelWithDebInfo\installer_fomod_csharp.lib - name: installer_fomod_csharp_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 From f45b25a7b347ae5a42ca86ae60a47b177e9caf6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 9 Jun 2024 13:55:35 +0200 Subject: [PATCH 2/4] Format files and add .gitattributes and .clang-format. --- .clang-format | 41 +++++++++++++ .gitattributes | 7 +++ src/base_script.cpp | 4 +- src/base_script.h | 18 +++--- src/csharp_interface.cpp | 4 +- src/csharp_interface.h | 54 ++++++++--------- src/csharp_utils.h | 6 +- src/installer_fomod_csharp.cpp | 47 +++++++++------ src/installer_fomod_csharp.h | 60 +++++++++---------- src/installer_fomod_postdialog.h | 31 +++++----- src/installer_fomod_predialog.h | 25 ++++---- src/psettings.h | 37 ++++++------ src/xml_info_reader.h | 100 +++++++++++++++---------------- 13 files changed, 253 insertions(+), 181 deletions(-) create mode 100644 .clang-format create mode 100644 .gitattributes 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/src/base_script.cpp b/src/base_script.cpp index aeedf00..0826612 100644 --- a/src/base_script.cpp +++ b/src/base_script.cpp @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see . */ +// clang-format off + #include "base_script.h" #include @@ -678,4 +680,4 @@ namespace CSharp { return true; } -} \ No newline at end of file +} diff --git a/src/base_script.h b/src/base_script.h index 2dab450..065e5ec 100644 --- a/src/base_script.h +++ b/src/base_script.h @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see . */ +// clang-format off + #ifndef BASE_SCRIPT_H #define BASE_SCRIPT_H @@ -268,7 +270,7 @@ namespace CSharp { /// The items, previews, and descriptions are repectively ordered. In other words, /// the i-th item in uses the i-th preview in /// and the i-th description in . - /// + /// /// Similarly, the idices return as results correspond to the indices of the items in /// . /// @@ -294,7 +296,7 @@ namespace CSharp { /// The items, previews, and descriptions are repectively ordered. In other words, /// the i-th item in uses the i-th preview in /// and the i-th description in . - /// + /// /// Similarly, the idices return as results correspond to the indices of the items in /// . /// @@ -492,7 +494,7 @@ namespace CSharp { /// The specified value as a string. /// static String^ GetPrefsIniString(String^ p_strSection, String^ p_strKey) { - // This looks wrong? Yes! But that's what used in other mod managers... + // This looks wrong? Yes! But that's what used in other mod managers... return GetIniString("FalloutPrefs.ini", p_strSection, p_strKey); } @@ -504,7 +506,7 @@ namespace CSharp { /// The specified value as an integer. /// static int GetPrefsIniInt(String^ p_strSection, String^ p_strKey) { - // This looks wrong? Yes! But that's what used in other mod managers... + // This looks wrong? Yes! But that's what used in other mod managers... return GetIniInt("FalloutPrefs.ini", p_strSection, p_strKey); } @@ -520,7 +522,7 @@ namespace CSharp { static bool EditIni(String^ p_strSettingsFileName, String^ p_strSection, String^ p_strKey, String^ p_strValue); /// - /// Sets the specified value in the Fallout.ini file to the given value. + /// Sets the specified value in the Fallout.ini file to the given value. /// /// The section in the Ini file to edit. /// The key in the Ini file to edit. @@ -541,10 +543,10 @@ namespace CSharp { } // BaseScript cannot be in a namespace: -public ref struct SelectOption: public CSharp::SelectOption { - SelectOption(System::String^ item, System::String^ preview, System::String^ desc) : +public ref struct SelectOption: public CSharp::SelectOption { + SelectOption(System::String^ item, System::String^ preview, System::String^ desc) : CSharp::SelectOption(item, preview, desc) { } }; public ref class BaseScript: public CSharp::BaseScriptImpl { }; -#endif \ No newline at end of file +#endif diff --git a/src/csharp_interface.cpp b/src/csharp_interface.cpp index 8edc896..fe5ea6e 100644 --- a/src/csharp_interface.cpp +++ b/src/csharp_interface.cpp @@ -1,3 +1,5 @@ +// clang-format off + #include "csharp_interface.h" #include @@ -153,4 +155,4 @@ namespace CSharp { return postInstall(tree); } -} \ No newline at end of file +} diff --git a/src/csharp_interface.h b/src/csharp_interface.h index f5b4680..fa209ca 100644 --- a/src/csharp_interface.h +++ b/src/csharp_interface.h @@ -6,35 +6,35 @@ #include "ifiletree.h" #include "iplugininstaller.h" -namespace CSharp { +namespace CSharp +{ - void init(MOBase::IOrganizer* moInfo); +void init(MOBase::IOrganizer* moInfo); - /** - * @brief Initialize the C# interface before starting an installation. - * - * @param installer The FOMOD C# installer. - * @param manager The installation manager from the installer. - * @param parentWidget The parent widget from the installer. - * @param tree The archive tree. - * @param extractedEntries A map from extracted entries to their extracted path. - */ - void beforeInstall( - MOBase::IPlugin const* installer, - MOBase::IInstallationManager* manager, - QWidget* parentWidget, - std::shared_ptr tree, +/** + * @brief Initialize the C# interface before starting an installation. + * + * @param installer The FOMOD C# installer. + * @param manager The installation manager from the installer. + * @param parentWidget The parent widget from the installer. + * @param tree The archive tree. + * @param extractedEntries A map from extracted entries to their extracted path. + */ +void beforeInstall( + MOBase::IPlugin const* installer, MOBase::IInstallationManager* manager, + QWidget* parentWidget, std::shared_ptr tree, std::map, QString> extractedEntries); - /** - * @brief Clear the C# interface after an installation. - * - * @param scriptPath Path to the script to execute. - * @param tree Reference where the final tree will be stored (in case of success. - * - * @return the installation result after performing post-installation. - */ - MOBase::IPluginInstaller::EInstallResult executeCSharpScript(QString scriptPath, std::shared_ptr& tree); +/** + * @brief Clear the C# interface after an installation. + * + * @param scriptPath Path to the script to execute. + * @param tree Reference where the final tree will be stored (in case of success. + * + * @return the installation result after performing post-installation. + */ +MOBase::IPluginInstaller::EInstallResult +executeCSharpScript(QString scriptPath, std::shared_ptr& tree); -} -#endif \ No newline at end of file +} // namespace CSharp +#endif diff --git a/src/csharp_utils.h b/src/csharp_utils.h index a816eda..5ede874 100644 --- a/src/csharp_utils.h +++ b/src/csharp_utils.h @@ -1,3 +1,5 @@ +// clang-format off + #ifndef CSHARP_UTILS_H #define CSHARP_UTILS_H @@ -17,7 +19,7 @@ namespace CSharp { */ inline std::string to_string(System::String^ value) { return msclr::interop::marshal_as(value); - } + } inline std::wstring to_wstring(System::String^ value) { return msclr::interop::marshal_as(value); } @@ -36,4 +38,4 @@ namespace CSharp { } -#endif \ No newline at end of file +#endif diff --git a/src/installer_fomod_csharp.cpp b/src/installer_fomod_csharp.cpp index 8b31780..ba461f4 100644 --- a/src/installer_fomod_csharp.cpp +++ b/src/installer_fomod_csharp.cpp @@ -17,20 +17,22 @@ along with Mod Organizer. If not, see . #include "iinstallationmanager.h" +#include "csharp_interface.h" +#include "installer_fomod_csharp.h" #include "installer_fomod_predialog.h" #include "xml_info_reader.h" -#include "installer_fomod_csharp.h" -#include "csharp_interface.h" using namespace MOBase; -bool InstallerFomodCSharp::init(IOrganizer* moInfo) { +bool InstallerFomodCSharp::init(IOrganizer* moInfo) +{ m_MOInfo = moInfo; CSharp::init(moInfo); return true; } -std::shared_ptr InstallerFomodCSharp::findFomodDirectory(std::shared_ptr tree) const +std::shared_ptr +InstallerFomodCSharp::findFomodDirectory(std::shared_ptr tree) const { auto entry = tree->find("fomod", FileTreeEntry::DIRECTORY); @@ -55,7 +57,9 @@ std::shared_ptr InstallerFomodCSharp::findFomodDirectory(std::s return findFomodDirectory(tree->at(0)->astree()); } -std::shared_ptr InstallerFomodCSharp::findScriptFile(std::shared_ptr tree) const { +std::shared_ptr +InstallerFomodCSharp::findScriptFile(std::shared_ptr tree) const +{ auto fomodDirectory = findFomodDirectory(tree); if (fomodDirectory == nullptr) { @@ -71,7 +75,9 @@ std::shared_ptr InstallerFomodCSharp::findScriptFile(std::s return nullptr; } -std::shared_ptr InstallerFomodCSharp::findInfoFile(std::shared_ptr tree) const { +std::shared_ptr +InstallerFomodCSharp::findInfoFile(std::shared_ptr tree) const +{ auto fomodDirectory = findFomodDirectory(tree); if (fomodDirectory == nullptr) { @@ -87,14 +93,19 @@ std::shared_ptr InstallerFomodCSharp::findInfoFile(std::sha return nullptr; } -bool InstallerFomodCSharp::isArchiveSupported(std::shared_ptr tree) const { +bool InstallerFomodCSharp::isArchiveSupported( + std::shared_ptr tree) const +{ return findScriptFile(tree) != nullptr; } -InstallerFomodCSharp::EInstallResult InstallerFomodCSharp::install(MOBase::GuessedValue& modName, std::shared_ptr& tree, - QString& version, int& modID) +InstallerFomodCSharp::EInstallResult +InstallerFomodCSharp::install(MOBase::GuessedValue& modName, + std::shared_ptr& tree, + QString& version, int& modID) { - static std::set imageSuffixes{ "png", "jpg", "jpeg", "gif", "bmp" }; + static std::set imageSuffixes{"png", "jpg", "jpeg", + "gif", "bmp"}; // Extract the script file: auto scriptFile = findScriptFile(tree); @@ -106,7 +117,7 @@ InstallerFomodCSharp::EInstallResult InstallerFomodCSharp::install(MOBase::Guess auto infoFile = findInfoFile(tree); // Set containing everything to extract except the script and the info file: - std::set> toExtractSet{ scriptFile }; + std::set> toExtractSet{scriptFile}; if (infoFile != nullptr) { toExtractSet.insert(infoFile); @@ -118,7 +129,7 @@ InstallerFomodCSharp::EInstallResult InstallerFomodCSharp::install(MOBase::Guess toExtractSet.insert(entry); } return IFileTree::WalkReturn::CONTINUE; - }); + }); // Extract everything from the fomod/ folder: auto fomodFolder = findFomodDirectory(tree); @@ -127,7 +138,7 @@ InstallerFomodCSharp::EInstallResult InstallerFomodCSharp::install(MOBase::Guess toExtractSet.insert(entry); } return IFileTree::WalkReturn::CONTINUE; - }); + }); // Convert to vector: std::vector toExtract(std::begin(toExtractSet), std::end(toExtractSet)); @@ -166,8 +177,7 @@ InstallerFomodCSharp::EInstallResult InstallerFomodCSharp::install(MOBase::Guess if (dialog.manualRequested()) { modName.update(dialog.getName(), GUESS_USER); return EInstallResult::RESULT_MANUALREQUESTED; - } - else { + } else { return EInstallResult::RESULT_CANCELED; } } @@ -175,6 +185,9 @@ InstallerFomodCSharp::EInstallResult InstallerFomodCSharp::install(MOBase::Guess // Run the C# script: const QString scriptPath = entryToPath[scriptFile]; - CSharp::beforeInstall(this, manager(), parentWidget(), std::const_pointer_cast(scriptFile->parent()->parent()), std::move(entryToPath)); + CSharp::beforeInstall( + this, manager(), parentWidget(), + std::const_pointer_cast(scriptFile->parent()->parent()), + std::move(entryToPath)); return CSharp::executeCSharpScript(scriptPath, tree); -} \ No newline at end of file +} diff --git a/src/installer_fomod_csharp.h b/src/installer_fomod_csharp.h index 382dd13..166b966 100644 --- a/src/installer_fomod_csharp.h +++ b/src/installer_fomod_csharp.h @@ -20,67 +20,65 @@ along with Mod Organizer. If not, see . #include "iplugininstallersimple.h" -class InstallerFomodCSharp : public MOBase::IPluginInstallerSimple +class InstallerFomodCSharp : public MOBase::IPluginInstallerSimple { Q_OBJECT Q_INTERFACES(MOBase::IPlugin MOBase::IPluginInstaller MOBase::IPluginInstallerSimple) Q_PLUGIN_METADATA(IID "org.holt59.InstallerFomodCSharp") public: - - InstallerFomodCSharp() { } + InstallerFomodCSharp() {} virtual bool init(MOBase::IOrganizer* moInfo) override; - virtual QString name() const override { - return "Fomod Installer C#"; - } + virtual QString name() const override { return "Fomod Installer C#"; } - virtual QString localizedName() const override { - return tr("Fomod Installer C#"); - } + virtual QString localizedName() const override { return tr("Fomod Installer C#"); } - virtual QString author() const override { - return "Holt59"; - } + virtual QString author() const override { return "Holt59"; } - virtual QString description() const override { + virtual QString description() const override + { return tr("Installer for C# based FOMOD archives."); } - virtual MOBase::VersionInfo version() const override { + virtual MOBase::VersionInfo version() const override + { return MOBase::VersionInfo(1, 0, 0, MOBase::VersionInfo::RELEASE_BETA); } - virtual QList settings() const override { + virtual QList settings() const override + { return { - MOBase::PluginSetting("enabled", "check to enable this plugin", QVariant(true)), - MOBase::PluginSetting("prefer", "prefer this over the NCC based plugin", QVariant(true)) - }; + MOBase::PluginSetting("enabled", "check to enable this plugin", QVariant(true)), + MOBase::PluginSetting("prefer", "prefer this over the NCC based plugin", + QVariant(true))}; } - virtual unsigned int priority() const override { + virtual unsigned int priority() const override + { // It's the same priority as the FOMOD installer but those should never conflict: return m_MOInfo->pluginSetting(name(), "prefer").toBool() ? 110 : 90; } - virtual bool isManualInstaller() const override { - return false; - } + virtual bool isManualInstaller() const override { return false; } - virtual bool isArchiveSupported(std::shared_ptr tree) const override; + virtual bool + isArchiveSupported(std::shared_ptr tree) const override; - virtual EInstallResult install(MOBase::GuessedValue& modName, std::shared_ptr& tree, - QString& version, int& modID) override; + virtual EInstallResult install(MOBase::GuessedValue& modName, + std::shared_ptr& tree, + QString& version, int& modID) override; private: - MOBase::IOrganizer* m_MOInfo; - std::shared_ptr findFomodDirectory(std::shared_ptr tree) const; - std::shared_ptr findScriptFile(std::shared_ptr tree) const; - std::shared_ptr findInfoFile(std::shared_ptr tree) const; - + std::shared_ptr + findFomodDirectory(std::shared_ptr tree) const; + std::shared_ptr + findScriptFile(std::shared_ptr tree) const; + std::shared_ptr + findInfoFile(std::shared_ptr tree) const; }; -#endif \ No newline at end of file +#endif diff --git a/src/installer_fomod_postdialog.h b/src/installer_fomod_postdialog.h index ae19a90..9804610 100644 --- a/src/installer_fomod_postdialog.h +++ b/src/installer_fomod_postdialog.h @@ -16,8 +16,8 @@ class InstallerFomodPostDialog : public QDialog Q_OBJECT public: - - enum class Result { + enum class Result + { APPLY, DISCARD, MOVE, @@ -29,13 +29,14 @@ class InstallerFomodPostDialog : public QDialog * @param preset suggested name for the mod * @param parent parent widget **/ - explicit InstallerFomodPostDialog(QWidget* parent = 0) : - QDialog(parent), ui(new Ui::FomodCSharpPostDialog) { + explicit InstallerFomodPostDialog(QWidget* parent = 0) + : QDialog(parent), ui(new Ui::FomodCSharpPostDialog) + { ui->setupUi(this); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); } - ~InstallerFomodPostDialog() { } + ~InstallerFomodPostDialog() {} /** * @return the result of this dialog if the user did not cancel. @@ -45,7 +46,8 @@ class InstallerFomodPostDialog : public QDialog /** * */ - void setIniSettings(std::map const& settings) { + void setIniSettings(std::map const& settings) + { for (auto p : settings) { QTextEdit* widget = new QTextEdit(this); widget->append(p.second.toString()); @@ -56,29 +58,30 @@ class InstallerFomodPostDialog : public QDialog private slots: - void on_discardBtn_clicked() { + void on_discardBtn_clicked() + { m_Result = Result::DISCARD; this->accept(); } - void on_applyBtn_clicked() { + void on_applyBtn_clicked() + { m_Result = Result::APPLY; this->accept(); } - void on_moveBtn_clicked() { + void on_moveBtn_clicked() + { m_Result = Result::MOVE; this->accept(); } - void on_cancelBtn_clicked() { - this->reject(); - } + void on_cancelBtn_clicked() { this->reject(); } private: std::unique_ptr ui; - Result m_Result{ Result::APPLY }; + Result m_Result{Result::APPLY}; }; -#endif \ No newline at end of file +#endif diff --git a/src/installer_fomod_predialog.h b/src/installer_fomod_predialog.h index 3903c68..4c5dbd3 100644 --- a/src/installer_fomod_predialog.h +++ b/src/installer_fomod_predialog.h @@ -7,7 +7,6 @@ #include - /** * @brief Dialog for the installation of a simple archive * a simple archive is one that doesn't require any manual changes to work correctly @@ -23,13 +22,16 @@ class InstallerFomodPredialog : public QDialog * @param preset suggested name for the mod * @param parent parent widget **/ - explicit InstallerFomodPredialog(const MOBase::GuessedValue& preset, QWidget* parent = 0) : - QDialog(parent), ui(new Ui::FomodCSharpPredialog), m_Manual(false) { + explicit InstallerFomodPredialog(const MOBase::GuessedValue& preset, + QWidget* parent = 0) + : QDialog(parent), ui(new Ui::FomodCSharpPredialog), m_Manual(false) + { ui->setupUi(this); setWindowTitle(preset + " - " + windowTitle()); - for (auto iter = preset.variants().begin(); iter != preset.variants().end(); ++iter) { + for (auto iter = preset.variants().begin(); iter != preset.variants().end(); + ++iter) { ui->nameCombo->addItem(*iter); } @@ -38,7 +40,7 @@ class InstallerFomodPredialog : public QDialog ui->nameCombo->completer()->setCaseSensitivity(Qt::CaseSensitive); } - ~InstallerFomodPredialog() { } + ~InstallerFomodPredialog() {} /** * @return true if the user requested a manual installation. @@ -52,15 +54,12 @@ class InstallerFomodPredialog : public QDialog private slots: - void on_okBtn_clicked() { - this->accept(); - } + void on_okBtn_clicked() { this->accept(); } - void on_cancelBtn_clicked() { - this->reject(); - } + void on_cancelBtn_clicked() { this->reject(); } - void on_manualBtn_clicked() { + void on_manualBtn_clicked() + { m_Manual = true; this->reject(); } @@ -70,4 +69,4 @@ private slots: bool m_Manual; }; -#endif \ No newline at end of file +#endif diff --git a/src/psettings.h b/src/psettings.h index 7319c1a..649c7da 100644 --- a/src/psettings.h +++ b/src/psettings.h @@ -1,9 +1,9 @@ #ifndef PSETTINGS_H #define PSETTINGS_H -#include -#include #include +#include +#include /** * This is a small class that can be used to store INI settings in memory since @@ -11,15 +11,15 @@ * * It is a much simpler structure since it stores everything as string. */ -struct PSettings { +struct PSettings +{ /** * */ PSettings() = default; -public: // Value read/write. - +public: // Value read/write. /** * @brief Set the value of the given section/key. * @@ -27,7 +27,8 @@ struct PSettings { * @param key The key of the value. * @param value The value to set. */ - void setValue(QString section, QString key, QString value) { + void setValue(QString section, QString key, QString value) + { m_Values[std::make_pair(section, key)] = value; } @@ -37,9 +38,11 @@ struct PSettings { * @param section The section of the value. * @param key The key of the value. * - * @return the corresponding value, or an empty string if the section/key does not exist. + * @return the corresponding value, or an empty string if the section/key does not + * exist. */ - QString value(QString section, QString key) const { + QString value(QString section, QString key) const + { auto it = m_Values.find(std::make_pair(section, key)); return it == m_Values.end() ? QString() : it->second; } @@ -52,19 +55,20 @@ struct PSettings { * * @return true if the section/key exist. */ - bool hasValue(QString section, QString key) const { + bool hasValue(QString section, QString key) const + { return m_Values.find(std::make_pair(section, key)) != m_Values.end(); } -public: // Output: - +public: // Output: /** * @brief Convert this PSettings to a string. * * @return a string representing the content of a valid INI file corresponding * to this PSettings. */ - QString toString() const { + QString toString() const + { QString result = ""; QString cSection; for (auto& p : m_Values) { @@ -85,12 +89,12 @@ struct PSettings { * * @param settings The settings to update. */ - void update(QSettings& settings) const { + void update(QSettings& settings) const + { for (auto& p : m_Values) { if (p.first.first == "General") { settings.setValue(p.first.second, p.second); - } - else { + } else { settings.setValue(p.first.first + "/" + p.first.second, p.second); } } @@ -99,7 +103,6 @@ struct PSettings { private: // Map from to value: std::map, QString> m_Values; - }; -#endif // !PSETTINGS_H +#endif // !PSETTINGS_H diff --git a/src/xml_info_reader.h b/src/xml_info_reader.h index 3f447ac..0170fcf 100644 --- a/src/xml_info_reader.h +++ b/src/xml_info_reader.h @@ -1,36 +1,37 @@ #ifndef XML_INFO_READER_H #define XML_INFO_READER_H -#include -#include -#include -#include #include +#include +#include #include +#include +#include -#include "utility.h" #include "log.h" +#include "utility.h" // This is from installer_fomod, but should probably not be duplicated here. -struct FomodInfoReader: QObject { +struct FomodInfoReader : QObject +{ Q_OBJECT public: - - struct XmlParseError : MOBase::Exception { - XmlParseError(const QString& message): MOBase::Exception(message) {} + struct XmlParseError : MOBase::Exception + { + XmlParseError(const QString& message) : MOBase::Exception(message) {} }; static QByteArray skipXmlHeader(QIODevice& file) { - static const unsigned char UTF16LE_BOM[] = { 0xFF, 0xFE }; - static const unsigned char UTF16BE_BOM[] = { 0xFE, 0xFF }; - static const unsigned char UTF8_BOM[] = { 0xEF, 0xBB, 0xBF }; - static const unsigned char UTF16LE[] = { 0x3C, 0x00, 0x3F, 0x00 }; - static const unsigned char UTF16BE[] = { 0x00, 0x3C, 0x00, 0x3F }; - static const unsigned char UTF8[] = { 0x3C, 0x3F, 0x78, 0x6D }; + static const unsigned char UTF16LE_BOM[] = {0xFF, 0xFE}; + static const unsigned char UTF16BE_BOM[] = {0xFE, 0xFF}; + static const unsigned char UTF8_BOM[] = {0xEF, 0xBB, 0xBF}; + static const unsigned char UTF16LE[] = {0x3C, 0x00, 0x3F, 0x00}; + static const unsigned char UTF16BE[] = {0x00, 0x3C, 0x00, 0x3F}; + static const unsigned char UTF8[] = {0x3C, 0x3F, 0x78, 0x6D}; file.seek(0); QByteArray rawBytes = file.read(4); @@ -39,24 +40,19 @@ struct FomodInfoReader: QObject { if (rawBytes.startsWith((const char*)UTF16LE_BOM)) { stream.setEncoding(QStringEncoder::Encoding::Utf16LE); bom = 2; - } - else if (rawBytes.startsWith((const char*)UTF16BE_BOM)) { + } else if (rawBytes.startsWith((const char*)UTF16BE_BOM)) { stream.setEncoding(QStringEncoder::Encoding::Utf16BE); bom = 2; - } - else if (rawBytes.startsWith((const char*)UTF8_BOM)) { + } else if (rawBytes.startsWith((const char*)UTF8_BOM)) { stream.setEncoding(QStringEncoder::Encoding::Utf8); bom = 3; - } - else if (rawBytes.startsWith(QByteArray((const char*)UTF16LE, 4))) { + } else if (rawBytes.startsWith(QByteArray((const char*)UTF16LE, 4))) { stream.setEncoding(QStringEncoder::Encoding::Utf16LE); - } - else if (rawBytes.startsWith(QByteArray((const char*)UTF16BE, 4))) { + } else if (rawBytes.startsWith(QByteArray((const char*)UTF16BE, 4))) { stream.setEncoding(QStringEncoder::Encoding::Utf16BE); - } - else if (rawBytes.startsWith(QByteArray((const char*)UTF8, 4))) { + } else if (rawBytes.startsWith(QByteArray((const char*)UTF8, 4))) { stream.setEncoding(QStringEncoder::Encoding::Utf8); - } // otherwise maybe the textstream knows the encoding? + } // otherwise maybe the textstream knows the encoding? stream.seek(bom); QString header = stream.readLine(); @@ -70,18 +66,20 @@ struct FomodInfoReader: QObject { } template - static auto readXml(QFile& file, Fn &&fn) + static auto readXml(QFile& file, Fn&& fn) { // List of encodings to try: - static const std::vector encodings{ QStringConverter::Utf16, QStringConverter::Utf8, QStringConverter::Latin1 }; + static const std::vector encodings{ + QStringConverter::Utf16, QStringConverter::Utf8, QStringConverter::Latin1}; std::string errorMessage; try { QXmlStreamReader reader(&file); return fn(reader); - } - catch (const XmlParseError& e) { - MOBase::log::warn("The {} in this file is incorrectly encoded ({}). Applying heuristics...", file.fileName(), e.what()); + } catch (const XmlParseError& e) { + MOBase::log::warn( + "The {} in this file is incorrectly encoded ({}). Applying heuristics...", + file.fileName(), e.what()); } // nmm's xml parser is less strict than the one from qt and allows files with @@ -91,50 +89,52 @@ struct FomodInfoReader: QObject { // try parsing the file with several encodings to support broken files for (auto encoding : encodings) { - MOBase::log::debug("Trying encoding {} for {}... ", QStringConverter::nameForEncoding(encoding), file.fileName()); + MOBase::log::debug("Trying encoding {} for {}... ", + QStringConverter::nameForEncoding(encoding), file.fileName()); try { QStringEncoder encoder(encoding); - QXmlStreamReader reader(encoder.encode(QString("").arg(encoder.name())) + headerlessData); + QXmlStreamReader reader( + encoder.encode(QString("") + .arg(encoder.name())) + + headerlessData); MOBase::log::debug("Interpreting {} as {}.", file.fileName(), encoder.name()); return fn(reader); - } - catch (const XmlParseError& e) { - MOBase::log::debug("Not {}: {}.", QStringConverter::nameForEncoding(encoding), e.what()); + } catch (const XmlParseError& e) { + MOBase::log::debug("Not {}: {}.", QStringConverter::nameForEncoding(encoding), + e.what()); } } - throw XmlParseError(tr("Failed to parse %1. See console for details.").arg(file.fileName())); + throw XmlParseError( + tr("Failed to parse %1. See console for details.").arg(file.fileName())); } static std::tuple parseInfo(QXmlStreamReader& reader) { - std::tuple info{ "", -1, "" }; + std::tuple info{"", -1, ""}; while (!reader.atEnd()) { switch (reader.readNext()) { case QXmlStreamReader::StartElement: { if (reader.name().toString() == "Name") { std::get<0>(info) = reader.readElementText(); - } - else if (reader.name().toString() == "Author") { - } - else if (reader.name().toString() == "Version") { + } else if (reader.name().toString() == "Author") { + } else if (reader.name().toString() == "Version") { std::get<2>(info) = reader.readElementText(); - } - else if (reader.name().toString() == "Id") { + } else if (reader.name().toString() == "Id") { std::get<1>(info) = reader.readElementText().toInt(); + } else if (reader.name().toString() == "Website") { } - else if (reader.name().toString() == "Website") { - } } break; - default: {} break; + default: { + } break; } } if (reader.hasError()) { - throw XmlParseError(QString("%1 in line %2").arg(reader.errorString()).arg(reader.lineNumber())); + throw XmlParseError( + QString("%1 in line %2").arg(reader.errorString()).arg(reader.lineNumber())); } return info; } - }; -#endif \ No newline at end of file +#endif From 796fefd963b94e66bf7db560595f02fa24124993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 9 Jun 2024 13:55:35 +0200 Subject: [PATCH 3/4] Add .git-blame-ignore-revs. --- .git-blame-ignore-revs | 1 + 1 file changed, 1 insertion(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..a26d6d2 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1 @@ +f45b25a7b347ae5a42ca86ae60a47b177e9caf6e From e7bb3f2aabf4d14a2b38471162413806212fc113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 9 Jun 2024 13:55:35 +0200 Subject: [PATCH 4/4] Add github actions. --- .github/workflows/build.yml | 16 ++++++++++++++++ .github/workflows/linting.yml | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/linting.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3185e6a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,16 @@ +name: Build Installer FOMOD C# Plugin + +on: + push: + branches: master + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + runs-on: windows-2022 + steps: + - name: Build Installer FOMOD C# Plugin + uses: ModOrganizer2/build-with-mob-action@master + with: + mo2-dependencies: cmake_common uibase diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..80d5fd4 --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,16 @@ +name: Lint Installer FOMOD C# Plugin + +on: + push: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Check format + uses: ModOrganizer2/check-formatting-action@master + with: + check-path: "."