Apply clang

This commit is contained in:
Jeremy Rimpo
2023-09-18 10:59:41 -05:00
parent 987eed53c4
commit dfac8a52f6
8 changed files with 1681 additions and 1636 deletions
+41
View File
@@ -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']
+339 -300
View File
File diff suppressed because it is too large Load Diff
+66 -65
View File
@@ -9,88 +9,89 @@
#include "loot/enum/game_type.h"
namespace loot {
constexpr inline std::string_view NEHRIM_STEAM_REGISTRY_KEY =
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App "
"1014940\\InstallLocation";
static constexpr const char* DEFAULT_MASTERLIST_BRANCH = "v0.21";
namespace loot
{
constexpr inline std::string_view NEHRIM_STEAM_REGISTRY_KEY =
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App "
"1014940\\InstallLocation";
static constexpr const char* DEFAULT_MASTERLIST_BRANCH = "v0.21";
enum struct GameId : uint8_t {
tes3,
tes4,
nehrim,
tes5,
enderal,
tes5se,
enderalse,
tes5vr,
fo3,
fonv,
fo4,
fo4vr
};
enum struct GameId : uint8_t
{
tes3,
tes4,
nehrim,
tes5,
enderal,
tes5se,
enderalse,
tes5vr,
fo3,
fonv,
fo4,
fo4vr
};
GameType GetGameType(const GameId gameId);
GameType GetGameType(const GameId gameId);
float GetMinimumHeaderVersion(const GameId gameId);
float GetMinimumHeaderVersion(const GameId gameId);
std::string GetPluginsFolderName(GameId gamiId);
std::string GetPluginsFolderName(GameId gamiId);
std::string ToString(const GameId gameId);
std::string ToString(const GameId gameId);
bool SupportsLightPlugins(const GameType gameType);
bool SupportsLightPlugins(const GameType gameType);
std::string GetMasterFilename(const GameId gameId);
std::string GetMasterFilename(const GameId gameId);
std::string GetGameName(const GameId gameId);
std::string GetGameName(const GameId gameId);
std::string GetDefaultMasterlistRepositoryName(GameId gameId);
std::string GetDefaultMasterlistRepositoryName(GameId gameId);
std::string GetDefaultMasterlistUrl(const std::string& repositoryName);
std::string GetDefaultMasterlistUrl(const GameId gameId);
std::string GetDefaultMasterlistUrl(const std::string& repositoryName);
std::string GetDefaultMasterlistUrl(const GameId gameId);
class GameSettings {
public:
GameSettings() = default;
explicit GameSettings(const GameId gameId,
const std::string& lootFolder = "");
class GameSettings
{
public:
GameSettings() = default;
explicit GameSettings(const GameId gameId, const std::string& lootFolder = "");
bool operator==(
const GameSettings& rhs) const; // Compares names and folder names.
bool operator==(const GameSettings& rhs) const; // Compares names and folder names.
GameId Id() const;
GameType Type() const;
std::string Name() const; //Returns the game's name, eg. "TES IV: Oblivion".
std::string FolderName() const;
std::string Master() const;
float MinimumHeaderVersion() const;
std::string MasterlistSource() const;
std::filesystem::path GamePath() const;
std::filesystem::path GameLocalPath() const;
std::filesystem::path DataPath() const;
GameId Id() const;
GameType Type() const;
std::string Name() const; // Returns the game's name, eg. "TES IV: Oblivion".
std::string FolderName() const;
std::string Master() const;
float MinimumHeaderVersion() const;
std::string MasterlistSource() const;
std::filesystem::path GamePath() const;
std::filesystem::path GameLocalPath() const;
std::filesystem::path DataPath() const;
GameSettings& SetName(const std::string& name);
GameSettings& SetMaster(const std::string& masterFile);
GameSettings& SetMinimumHeaderVersion(float minimumHeaderVersion);
GameSettings& SetMasterlistSource(const std::string& source);
GameSettings& SetGamePath(const std::filesystem::path& path);
GameSettings& SetGameLocalPath(const std::filesystem::path& GameLocalPath);
GameSettings& SetGameLocalFolder(const std::string& folderName);
GameSettings& SetName(const std::string& name);
GameSettings& SetMaster(const std::string& masterFile);
GameSettings& SetMinimumHeaderVersion(float minimumHeaderVersion);
GameSettings& SetMasterlistSource(const std::string& source);
GameSettings& SetGamePath(const std::filesystem::path& path);
GameSettings& SetGameLocalPath(const std::filesystem::path& GameLocalPath);
GameSettings& SetGameLocalFolder(const std::string& folderName);
private:
GameId id_{ GameId::tes4 };
GameType type_{ GameType::tes4 };
std::string name_;
std::string masterFile_;
float minimumHeaderVersion_{ 0.0f };
private:
GameId id_{GameId::tes4};
GameType type_{GameType::tes4};
std::string name_;
std::string masterFile_;
float minimumHeaderVersion_{0.0f};
std::string lootFolderName_;
std::string lootFolderName_;
std::string masterlistSource_;
std::string masterlistSource_;
std::filesystem::path gamePath_; //Path to the game's folder.
std::filesystem::path gameLocalPath_;
};
}
std::filesystem::path gamePath_; // Path to the game's folder.
std::filesystem::path gameLocalPath_;
};
} // namespace loot
#endif
+1095 -1126
View File
File diff suppressed because it is too large Load Diff
+78 -76
View File
@@ -1,100 +1,102 @@
#ifndef LOOTTHREAD_H
#define LOOTTHREAD_H
#include <lootcli/lootcli.h>
#include "game_settings.h"
#include <lootcli/lootcli.h>
namespace loot {
class Game;
namespace loot
{
class Game;
}
namespace lootcli
{
namespace lootcli {
loot::LogLevel toLootLogLevel(lootcli::LogLevels level);
lootcli::LogLevels fromLootLogLevel(loot::LogLevel level);
loot::LogLevel toLootLogLevel(lootcli::LogLevels level);
lootcli::LogLevels fromLootLogLevel(loot::LogLevel level);
class LOOTWorker
{
public:
explicit LOOTWorker();
class LOOTWorker
{
public:
explicit LOOTWorker();
void setGame(const std::string& gameName);
void setGamePath(const std::string& gamePath);
void setOutput(const std::string& outputPath);
void setPluginListPath(const std::string& pluginListPath);
void
setLanguageCode(const std::string& language_code); // Will add this when I figure out
// how languages work on MO
void setLogLevel(loot::LogLevel level);
void setGame(const std::string& gameName);
void setGamePath(const std::string& gamePath);
void setOutput(const std::string& outputPath);
void setPluginListPath(const std::string& pluginListPath);
void setLanguageCode(const std::string& language_code); //Will add this when I figure out how languages work on MO
void setLogLevel(loot::LogLevel level);
void setUpdateMasterlist(bool update);
void setUpdateMasterlist(bool update);
int run();
int run();
private:
void progress(Progress p);
void log(loot::LogLevel level, const std::string& message) const;
private:
void progress(Progress p);
void log(loot::LogLevel level, const std::string& message) const;
DWORD GetFile(const WCHAR* szUrl, const CHAR* szFileName);
void getSettings(const std::filesystem::path& file);
std::string getOldDefaultRepoUrl(loot::GameId gameType);
std::optional<std::string> GetLocalFolder(const toml::table& table);
bool IsNehrim(const toml::table& table);
bool IsEnderal(const toml::table& table, const std::string& expectedLocalFolder);
bool IsEnderal(const toml::table& table);
bool IsEnderalSE(const toml::table& table);
bool isLocalPath(const std::string& location, const std::string& filename);
bool isBranchCheckedOut(const std::filesystem::path& localGitRepo,
const std::string& branch);
std::optional<std::string> migrateMasterlistRepoSettings(loot::GameId gameType,
std::string url,
std::string branch);
std::string migrateMasterlistSource(const std::string& source);
DWORD GetFile(const WCHAR* szUrl, const CHAR* szFileName);
void getSettings(const std::filesystem::path& file);
std::string getOldDefaultRepoUrl(loot::GameId gameType);
std::optional<std::string> GetLocalFolder(const toml::table& table);
bool IsNehrim(const toml::table& table);
bool IsEnderal(const toml::table& table, const std::string& expectedLocalFolder);
bool IsEnderal(const toml::table& table);
bool IsEnderalSE(const toml::table& table);
bool isLocalPath(const std::string& location, const std::string& filename);
bool isBranchCheckedOut(const std::filesystem::path& localGitRepo,
const std::string& branch);
std::optional<std::string> migrateMasterlistRepoSettings(loot::GameId gameType, std::string url, std::string branch);
std::string migrateMasterlistSource(const std::string& source);
std::filesystem::path gamePath() const;
std::filesystem::path masterlistPath() const;
std::filesystem::path settingsPath() const;
std::filesystem::path userlistPath() const;
std::filesystem::path l10nPath() const;
std::filesystem::path dataPath() const;
std::filesystem::path gamePath() const;
std::filesystem::path masterlistPath() const;
std::filesystem::path settingsPath() const;
std::filesystem::path userlistPath() const;
std::filesystem::path l10nPath() const;
std::filesystem::path dataPath() const;
private:
// void handleErr(unsigned int resultCode, const char *description);
bool sort(loot::Game& game);
// const char *lootErrorString(unsigned int errorCode);
// template <typename T> T resolveVariable(HMODULE lib, const char *name);
// template <typename T> T resolveFunction(HMODULE lib, const char *name);
private:
private:
loot::GameId m_GameId;
std::string m_Language;
std::string m_GameName;
std::string m_GamePath;
std::string m_OutputPath;
std::string m_PluginListPath;
loot::LogLevel m_LogLevel;
bool m_UpdateMasterlist;
mutable std::recursive_mutex mutex_;
loot::GameSettings m_GameSettings;
std::chrono::high_resolution_clock::time_point m_startTime;
// void handleErr(unsigned int resultCode, const char *description);
bool sort(loot::Game& game);
//const char *lootErrorString(unsigned int errorCode);
//template <typename T> T resolveVariable(HMODULE lib, const char *name);
//template <typename T> T resolveFunction(HMODULE lib, const char *name);
std::string createJsonReport(loot::GameInterface& game,
const std::vector<std::string>& sortedPlugins) const;
private:
loot::GameId m_GameId;
std::string m_Language;
std::string m_GameName;
std::string m_GamePath;
std::string m_OutputPath;
std::string m_PluginListPath;
loot::LogLevel m_LogLevel;
bool m_UpdateMasterlist;
mutable std::recursive_mutex mutex_;
loot::GameSettings m_GameSettings;
std::chrono::high_resolution_clock::time_point m_startTime;
QJsonArray createPlugins(loot::GameInterface& game,
const std::vector<std::string>& sortedPlugins) const;
std::string createJsonReport(
loot::GameInterface& game,
const std::vector<std::string>& sortedPlugins) const;
QJsonValue createMessages(const std::vector<loot::Message>& list) const;
QJsonValue createDirty(const std::vector<loot::PluginCleaningData>& data) const;
QJsonValue createClean(const std::vector<loot::PluginCleaningData>& data) const;
QJsonArray createPlugins(
loot::GameInterface& game,
const std::vector<std::string>& sortedPlugins) const;
QJsonValue createIncompatibilities(loot::GameInterface& game,
const std::vector<loot::File>& data) const;
QJsonValue createMessages(const std::vector<loot::Message>& list) const;
QJsonValue createDirty(const std::vector<loot::PluginCleaningData>& data) const;
QJsonValue createClean(const std::vector<loot::PluginCleaningData>& data) const;
QJsonValue createMissingMasters(loot::GameInterface& game,
const std::string& pluginName) const;
};
QJsonValue createIncompatibilities(
loot::GameInterface& game, const std::vector<loot::File>& data) const;
} // namespace lootcli
QJsonValue createMissingMasters(
loot::GameInterface& game, const std::string& pluginName) const;
};
} // namespace
#endif // LOOTTHREAD_H
#endif // LOOTTHREAD_H
+30 -37
View File
@@ -3,48 +3,43 @@
using namespace std;
template <typename T>
T getParameter(const std::vector<std::string>& arguments, const std::string& key)
{
auto iter = std::find(arguments.begin(), arguments.end(), std::string("--") + key);
if ((iter != arguments.end())
&& ((iter + 1) != arguments.end())) {
return boost::lexical_cast<T>(*(iter + 1));
}
else {
throw std::runtime_error(std::string("argument missing " + key));
}
auto iter = std::find(arguments.begin(), arguments.end(), std::string("--") + key);
if ((iter != arguments.end()) && ((iter + 1) != arguments.end())) {
return boost::lexical_cast<T>(*(iter + 1));
} else {
throw std::runtime_error(std::string("argument missing " + key));
}
}
template <>
bool getParameter<bool>(const std::vector<std::string>& arguments, const std::string& key)
bool getParameter<bool>(const std::vector<std::string>& arguments,
const std::string& key)
{
auto iter = std::find(arguments.begin(), arguments.end(), std::string("--") + key);
if (iter != arguments.end()) {
return true;
}
else {
return false;
}
auto iter = std::find(arguments.begin(), arguments.end(), std::string("--") + key);
if (iter != arguments.end()) {
return true;
} else {
return false;
}
}
template <typename T>
T getOptionalParameter(const std::vector<std::string> &arguments, const std::string &key, T def)
T getOptionalParameter(const std::vector<std::string>& arguments,
const std::string& key, T def)
{
try
{
try {
return getParameter<T>(arguments, key);
}
catch(std::runtime_error&)
{
} catch (std::runtime_error&) {
return def;
}
}
loot::LogLevel getLogLevel(const std::vector<std::string>& arguments)
{
const auto s = getOptionalParameter<std::string>(arguments, "logLevel", "");
const auto s = getOptionalParameter<std::string>(arguments, "logLevel", "");
const auto level = lootcli::logLevelFromString(s);
return lootcli::toLootLogLevel(level);
@@ -57,23 +52,21 @@ int wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
std::vector<std::string> arguments;
int argc;
LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argv)
{
for (int i = 0; i < argc; ++i)
{
size_t num_converted;
std::vector<char> arg(wcslen(argv[i]) * sizeof(wchar_t) + 1);
if (argv) {
for (int i = 0; i < argc; ++i) {
size_t num_converted;
std::vector<char> arg(wcslen(argv[i]) * sizeof(wchar_t) + 1);
wcstombs_s(&num_converted, &(arg[0]), arg.size(), argv[i], arg.size() - 1);
wcstombs_s(&num_converted, &(arg[0]), arg.size(), argv[i], arg.size() - 1);
arguments.push_back(&(arg[0]));
}
arguments.push_back(&(arg[0]));
}
}
// design rationale: this was designed to have the actual loot stuff run in a separate thread. That turned
// out to be unnecessary atm.
// design rationale: this was designed to have the actual loot stuff run in a separate
// thread. That turned out to be unnecessary atm.
try {
lootcli::LOOTWorker worker;
@@ -91,7 +84,7 @@ int wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
}
return worker.run();
} catch (const std::exception &e) {
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what();
return 1;
}
+30 -30
View File
@@ -1,25 +1,25 @@
#pragma warning(disable: 4251) // neds to have dll-interface
#pragma warning(disable: 4355) // this used in initializer list
#pragma warning(disable: 4371) // layout may have changed
#pragma warning(disable: 4514) // unreferenced inline function removed
#pragma warning(disable: 4571) // catch semantics changed
#pragma warning(disable: 4619) // no warning X
#pragma warning(disable: 4623) // default constructor deleted
#pragma warning(disable: 4625) // copy constructor deleted
#pragma warning(disable: 4626) // copy assignment operator deleted
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4820) // padding
#pragma warning(disable: 4866) // left-to-right evaluation order
#pragma warning(disable: 4868) // left-to-right evaluation order
#pragma warning(disable: 5026) // move constructor deleted
#pragma warning(disable: 5027) // move assignment operator deleted
#pragma warning(disable: 5045) // spectre mitigation
#pragma warning(disable : 4251) // neds to have dll-interface
#pragma warning(disable : 4355) // this used in initializer list
#pragma warning(disable : 4371) // layout may have changed
#pragma warning(disable : 4514) // unreferenced inline function removed
#pragma warning(disable : 4571) // catch semantics changed
#pragma warning(disable : 4619) // no warning X
#pragma warning(disable : 4623) // default constructor deleted
#pragma warning(disable : 4625) // copy constructor deleted
#pragma warning(disable : 4626) // copy assignment operator deleted
#pragma warning(disable : 4710) // function not inlined
#pragma warning(disable : 4820) // padding
#pragma warning(disable : 4866) // left-to-right evaluation order
#pragma warning(disable : 4868) // left-to-right evaluation order
#pragma warning(disable : 5026) // move constructor deleted
#pragma warning(disable : 5027) // move assignment operator deleted
#pragma warning(disable : 5045) // spectre mitigation
#pragma warning(push, 3)
#pragma warning(disable: 4365) // signed/unsigned mismatch
#pragma warning(disable: 4774) // bad format string
#pragma warning(disable: 4946) // reinterpret_cast used between related classes
#pragma warning(disable: 4800) // implicit conversion
#pragma warning(disable : 4365) // signed/unsigned mismatch
#pragma warning(disable : 4774) // bad format string
#pragma warning(disable : 4946) // reinterpret_cast used between related classes
#pragma warning(disable : 4800) // implicit conversion
// std
#include <algorithm>
@@ -42,23 +42,23 @@
#include <vector>
// qt
#include <QDir>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QFileInfo>
#include <QDir>
// boost
#include <boost/algorithm/string.hpp>
//#include <boost/assign.hpp>
//#include <boost/format.hpp>
// #include <boost/assign.hpp>
// #include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/locale.hpp>
//#include <boost/log/core.hpp>
//#include <boost/log/expressions.hpp>
//#include <boost/log/trivial.hpp>
//#include <boost/log/utility/setup/console.hpp>
//#include <boost/log/utility/setup/file.hpp>
// #include <boost/log/core.hpp>
// #include <boost/log/expressions.hpp>
// #include <boost/log/trivial.hpp>
// #include <boost/log/utility/setup/console.hpp>
// #include <boost/log/utility/setup/file.hpp>
// loot
#include <loot/api.h>
@@ -69,8 +69,8 @@
// windows
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <Shlobj.h>
#include <Windows.h>
#include <fcntl.h>
#include <io.h>
#include <shellapi.h>
+2 -2
View File
@@ -1,4 +1,4 @@
#define LOOTCLI_VERSION_MAJOR 1
#define LOOTCLI_VERSION_MINOR 4
#define LOOTCLI_VERSION_MINOR 5
#define LOOTCLI_VERSION_MAINTENANCE 0
#define LOOTCLI_VERSION_STRING "1.4.0"
#define LOOTCLI_VERSION_STRING "1.5.0"