Rename "standalone mode" -> "global mode"

pull/239/head
Peter Repukat 1 year ago
parent b86d548fc2
commit 54fb29a79d

@ -51,8 +51,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,1,2,0018002705604 FILEVERSION 0,1,2,0030000050130
PRODUCTVERSION 0,1,2,0018002705604 PRODUCTVERSION 0,1,2,0030000050130
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -69,12 +69,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "Peter Repukat - FlatspotSoftware" VALUE "CompanyName", "Peter Repukat - FlatspotSoftware"
VALUE "FileDescription", "GlosSI - Config" VALUE "FileDescription", "GlosSI - Config"
VALUE "FileVersion", "0.1.2.0-18-g27056b4" VALUE "FileVersion", "0.1.2.0-30-geb5f13f"
VALUE "InternalName", "GlosSIConfig" VALUE "InternalName", "GlosSIConfig"
VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware" VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware"
VALUE "OriginalFilename", "GlosSIConfig.exe" VALUE "OriginalFilename", "GlosSIConfig.exe"
VALUE "ProductName", "GlosSI" VALUE "ProductName", "GlosSI"
VALUE "ProductVersion", "0.1.2.0-18-g27056b4" VALUE "ProductVersion", "0.1.2.0-30-geb5f13f"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

@ -398,8 +398,8 @@ QVariantMap UIModel::getDefaultConf() const
QJsonValue::fromVariant(QString::fromStdWString(getSteamPath(false).wstring()))}, QJsonValue::fromVariant(QString::fromStdWString(getSteamPath(false).wstring()))},
{"steamUserId", {"steamUserId",
QJsonValue::fromVariant(QString::fromStdWString(getSteamUserId(false)))}, QJsonValue::fromVariant(QString::fromStdWString(getSteamUserId(false)))},
{"standaloneModeGameId", ""}, {"globalModeGameId", ""},
{"standaloneUseGamepadUI", false}, {"globalModeUseGamepadUI", false},
{"controller", QJsonObject{{"maxControllers", 1}, {"emulateDS4", false}, {"allowDesktopConfig", false}}}, {"controller", QJsonObject{{"maxControllers", 1}, {"emulateDS4", false}, {"allowDesktopConfig", false}}},
{"devices", {"devices",
QJsonObject{ QJsonObject{
@ -474,36 +474,36 @@ void UIModel::saveDefaultConf(QVariantMap conf) const
file.close(); file.close();
} }
Q_INVOKABLE QVariant UIModel::standaloneShortcutConf() { Q_INVOKABLE QVariant UIModel::globalModeShortcutConf() {
for (auto& target : targets_) { for (auto& target : targets_) {
const auto map = target.toMap(); const auto map = target.toMap();
if (map["name"] == "GlosSI Standalone/Desktop") { if (map["name"] == "GlosSI GlobalMode/Desktop") {
return target; return target;
} }
} }
return QVariant(); return QVariant();
} }
Q_INVOKABLE bool UIModel::standaloneModeShortcutExists() { Q_INVOKABLE bool UIModel::globalModeShortcutExists() {
const auto map = standaloneShortcutConf().toMap(); const auto map = globalModeShortcutConf().toMap();
if (map["name"] == "GlosSI Standalone/Desktop") { if (map["name"] == "GlosSI GlobalMode/Desktop") {
return true; return true;
} }
return false; return false;
} }
Q_INVOKABLE uint32_t UIModel::standaloneModeShortcutAppId() { Q_INVOKABLE uint32_t UIModel::globalModeShortcutAppId() {
if (!standaloneModeShortcutExists()) { if (!globalModeShortcutExists()) {
return 0; return 0;
} }
return getAppId(standaloneShortcutConf()); return getAppId(globalModeShortcutConf());
} }
Q_INVOKABLE QString UIModel::standaloneModeShortcutGameId() { Q_INVOKABLE QString UIModel::globalModeShortcutGameId() {
if (!standaloneModeShortcutExists()) { if (!globalModeShortcutExists()) {
return ""; return "";
} }
return getGameId(standaloneShortcutConf()); return getGameId(globalModeShortcutConf());
} }
#ifdef _WIN32 #ifdef _WIN32

@ -64,10 +64,10 @@ class UIModel : public QObject {
Q_INVOKABLE QVariantMap getDefaultConf() const; Q_INVOKABLE QVariantMap getDefaultConf() const;
Q_INVOKABLE void saveDefaultConf(QVariantMap conf) const; Q_INVOKABLE void saveDefaultConf(QVariantMap conf) const;
Q_INVOKABLE QVariant standaloneShortcutConf(); Q_INVOKABLE QVariant globalModeShortcutConf();
Q_INVOKABLE bool standaloneModeShortcutExists(); Q_INVOKABLE bool globalModeShortcutExists();
Q_INVOKABLE uint32_t standaloneModeShortcutAppId(); Q_INVOKABLE uint32_t globalModeShortcutAppId();
Q_INVOKABLE QString standaloneModeShortcutGameId(); Q_INVOKABLE QString globalModeShortcutGameId();
#ifdef _WIN32 #ifdef _WIN32
Q_INVOKABLE QVariantList uwpApps(); Q_INVOKABLE QVariantList uwpApps();

@ -140,10 +140,10 @@ Item {
Row { Row {
Row { Row {
CheckBox { CheckBox {
id: standaloneUseGamepadUI id: globalModeUseGamepadUI
text: qsTr("Use BPM for standalone-/desktop-mode") text: qsTr("Use BPM for global-/desktop-mode")
checked: config.standaloneUseGamepadUI checked: config.globalModeUseGamepadUI
onCheckedChanged: config.standaloneUseGamepadUI = checked onCheckedChanged: config.globalModeUseGamepadUI = checked
} }
} }
} }
@ -153,44 +153,44 @@ Item {
spacing: 16 spacing: 16
Label { Label {
topPadding: 8 topPadding: 8
id: standAloneGameIdLabel id: GlobalModeGameIdLabel
text: qsTr("StandaloneGameId") text: qsTr("GlobalMode GameId")
} }
FluentTextInput { FluentTextInput {
width: 128 width: 128
id: standAloneGameId id: GlobalModeGameId
enabled: false enabled: false
text: config.standaloneModeGameId text: config.globalModeGameId
onTextChanged: config.standaloneModeGameId = text onTextChanged: config.globalModeGameId = text
} }
Button { Button {
id: standAloneGameIdButton id: GlobalModeGameIdButton
text: qsTr("Create standalone-/desktop-mode shortcut") text: qsTr("Create global-/desktop-mode shortcut")
onClicked: { onClicked: {
const standaloneConf = uiModel.getDefaultConf(); const globalModeConf = uiModel.getDefaultConf();
standaloneConf.name = "GlosSI Standalone/Desktop"; globalModeConf.name = "GlosSI GlobalMode/Desktop";
standaloneConf.launch.launch = false; globalModeConf.launch.launch = false;
uiModel.addTarget(standaloneConf); uiModel.addTarget(globalModeConf);
if (uiModel.addToSteam(standaloneConf, "")) { if (uiModel.addToSteam(globalModeConf, "")) {
steamChangedDialog.open(); steamChangedDialog.open();
} }
const standaloneGID = uiModel.standaloneModeShortcutGameId(); const globalModeGID = uiModel.globalModeShortcutGameId();
standAloneGameId.text = standaloneGID; GlobalModeGameId.text = globalModeGID;
setTimeout(() => { setTimeout(() => {
uiModel.saveDefaultConf(config); uiModel.saveDefaultConf(config);
done(); done();
}, 10); }, 10);
} }
highlighted: true highlighted: true
visible: !uiModel.standaloneModeShortcutExists() visible: !uiModel.globalModeShortcutExists()
} }
Button { Button {
id: standAloneGameIdConfigButton id: GlobalModeGameIdConfigButton
text: qsTr("Open standalone-/desktop-mode controller config") text: qsTr("Open global-/desktop-mode controller config")
onClicked: { onClicked: {
Qt.openUrlExternally("steam://currentcontrollerconfig/" + uiModel.standaloneModeShortcutAppId() + "/"); Qt.openUrlExternally("steam://currentcontrollerconfig/" + uiModel.globalModeShortcutAppId() + "/");
} }
visible: uiModel.standaloneModeShortcutExists() visible: uiModel.globalModeShortcutExists()
} }
} }
} }

@ -215,25 +215,25 @@ void SteamTarget::focusWindow(WindowHandle hndl)
void SteamTarget::init_FuckingRenameMe() void SteamTarget::init_FuckingRenameMe()
{ {
if (!SteamOverlayDetector::IsSteamInjected()) { if (!SteamOverlayDetector::IsSteamInjected()) {
if (Settings::common.allowStandAlone) { if (Settings::common.allowGlobalMode) {
spdlog::warn("GlosSI not launched via Steam.\nEnabling EXPERIMENTAL global controller and overlay..."); spdlog::warn("GlosSI not launched via Steam.\nEnabling EXPERIMENTAL global controller and overlay...");
if (Settings::common.standaloneModeGameId == L"") { if (Settings::common.globalModeGameId == L"") {
spdlog::error("No game id set for standalone mode. Controller will use desktop-config!"); spdlog::error("No game id set for global mode. Controller will use desktop-config!");
} }
SetEnvironmentVariable(L"SteamAppId", L"0"); SetEnvironmentVariable(L"SteamAppId", L"0");
SetEnvironmentVariable(L"SteamClientLaunch", L"0"); SetEnvironmentVariable(L"SteamClientLaunch", L"0");
SetEnvironmentVariable(L"SteamEnv", L"1"); SetEnvironmentVariable(L"SteamEnv", L"1");
SetEnvironmentVariable(L"SteamPath", steam_path_.wstring().c_str()); SetEnvironmentVariable(L"SteamPath", steam_path_.wstring().c_str());
SetEnvironmentVariable(L"SteamTenfoot", Settings::common.standaloneUseGamepadUI ? L"1" : L"0"); SetEnvironmentVariable(L"SteamTenfoot", Settings::common.globalModeUseGamepadUI ? L"1" : L"0");
// SetEnvironmentVariable(L"SteamTenfootHybrid", L"1"); // SetEnvironmentVariable(L"SteamTenfootHybrid", L"1");
SetEnvironmentVariable(L"SteamGamepadUI", Settings::common.standaloneUseGamepadUI ? L"1" : L"0"); SetEnvironmentVariable(L"SteamGamepadUI", Settings::common.globalModeUseGamepadUI ? L"1" : L"0");
SetEnvironmentVariable(L"SteamGameId", Settings::common.standaloneModeGameId.c_str()); SetEnvironmentVariable(L"SteamGameId", Settings::common.globalModeGameId.c_str());
SetEnvironmentVariable(L"SteamOverlayGameId", Settings::common.standaloneModeGameId.c_str()); SetEnvironmentVariable(L"SteamOverlayGameId", Settings::common.globalModeGameId.c_str());
SetEnvironmentVariable(L"EnableConfiguratorSupport", L"15"); SetEnvironmentVariable(L"EnableConfiguratorSupport", L"15");
SetEnvironmentVariable(L"SteamStreamingForceWindowedD3D9", L"1"); SetEnvironmentVariable(L"SteamStreamingForceWindowedD3D9", L"1");
if (Settings::common.standaloneUseGamepadUI) { if (Settings::common.globalModeUseGamepadUI) {
system("start steam://open/bigpicture"); system("start steam://open/bigpicture");
auto steamwindow = FindWindow(L"Steam Big Picture Mode", nullptr); auto steamwindow = FindWindow(L"Steam Big Picture Mode", nullptr);
auto timer = sf::Clock{}; auto timer = sf::Clock{};

@ -3,7 +3,7 @@
!define APP_NAME "GlosSI" !define APP_NAME "GlosSI"
!define COMP_NAME "Peter Repukat - Flatspotsoftware" !define COMP_NAME "Peter Repukat - Flatspotsoftware"
!define WEB_SITE "https://glossi.flatspot.pictures/" !define WEB_SITE "https://glossi.flatspot.pictures/"
!define VERSION "0.1.2.0-18-g27056b4" !define VERSION "0.1.2.0-31-gd2b43ff"
!define COPYRIGHT "Peter Repukat - FlatspotSoftware © 2017-2022" !define COPYRIGHT "Peter Repukat - FlatspotSoftware © 2017-2022"
!define DESCRIPTION "SteamInput compatibility tool" !define DESCRIPTION "SteamInput compatibility tool"
!define INSTALLER_NAME "GlosSI-Installer.exe" !define INSTALLER_NAME "GlosSI-Installer.exe"

@ -31,10 +31,11 @@ limitations under the License.
#include "../common/nlohmann_json_wstring.h" #include "../common/nlohmann_json_wstring.h"
#include "../common/util.h" #include "../common/util.h"
namespace Settings
{
namespace Settings { inline struct Launch
{
inline struct Launch {
bool launch = false; bool launch = false;
std::wstring launchPath; std::wstring launchPath;
std::wstring launchAppArgs; std::wstring launchAppArgs;
@ -46,12 +47,14 @@ namespace Settings {
std::vector<std::wstring> launcherProcesses{}; std::vector<std::wstring> launcherProcesses{};
} launch; } launch;
inline struct Devices { inline struct Devices
{
bool hideDevices = true; bool hideDevices = true;
bool realDeviceIds = false; bool realDeviceIds = false;
} devices; } devices;
inline struct Window { inline struct Window
{
bool windowMode = false; bool windowMode = false;
int maxFps = 0; int maxFps = 0;
float scale = 0.f; float scale = 0.f;
@ -60,13 +63,15 @@ namespace Settings {
bool disableGlosSIOverlay = false; bool disableGlosSIOverlay = false;
} window; } window;
inline struct Controller { inline struct Controller
{
int maxControllers = 1; int maxControllers = 1;
bool allowDesktopConfig = false; bool allowDesktopConfig = false;
bool emulateDS4 = false; bool emulateDS4 = false;
} controller; } controller;
inline struct Common { inline struct Common
{
bool no_uwp_overlay = false; bool no_uwp_overlay = false;
bool disable_watchdog = false; bool disable_watchdog = false;
bool extendedLogging = false; bool extendedLogging = false;
@ -75,30 +80,39 @@ namespace Settings {
int version; int version;
std::wstring steamPath; std::wstring steamPath;
std::wstring steamUserId; std::wstring steamUserId;
std::wstring standaloneModeGameId; /* = L"12605636929694728192"; */ std::wstring globalModeGameId; /* = L"12605636929694728192"; */
bool standaloneUseGamepadUI = false; bool globalModeUseGamepadUI = false;
bool allowStandAlone = true; bool allowGlobalMode = true;
} common; } common;
inline const std::map<std::wstring, std::function<void()>> cmd_args = { inline const std::map<std::wstring, std::function<void()>> cmd_args = {
{L"-disableuwpoverlay", [&]() { common.no_uwp_overlay = true; }}, {L"-disableuwpoverlay", [&]()
{L"-disablewatchdog", [&]() { common.disable_watchdog = true; }}, { common.no_uwp_overlay = true; }},
{L"-ignorelauncher", [&]() { launch.ignoreLauncher = true; }}, {L"-disablewatchdog", [&]()
{L"-window", [&]() { window.windowMode = true; }}, { common.disable_watchdog = true; }},
{L"-extendedLogging", [&]() { common.extendedLogging = true; }}, {L"-ignorelauncher", [&]()
{L"-standaloneUseGamepadUI", [&]() { common.standaloneUseGamepadUI = true; }}, { launch.ignoreLauncher = true; }},
{L"-disallowStandAlone", [&]() { common.allowStandAlone = false; }}, {L"-window", [&]()
{ window.windowMode = true; }},
{L"-extendedLogging", [&]()
{ common.extendedLogging = true; }},
{L"-globalModeUseGamepadUI", [&]()
{ common.globalModeUseGamepadUI = true; }},
{L"-disallowGlobalMode", [&]()
{ common.allowGlobalMode = false; }},
}; };
inline std::filesystem::path settings_path_ = ""; inline std::filesystem::path settings_path_ = "";
inline bool checkIsUwp(const std::wstring &launch_path) inline bool checkIsUwp(const std::wstring &launch_path)
{ {
if (launch_path.find(L"://") != std::wstring::npos) { if (launch_path.find(L"://") != std::wstring::npos)
{
return false; return false;
} }
std::wsmatch m; std::wsmatch m;
if (!std::regex_search(launch_path, m, std::wregex(L"^.{1,5}:"))) { if (!std::regex_search(launch_path, m, std::wregex(L"^.{1,5}:")))
{
return true; return true;
} }
return false; return false;
@ -112,10 +126,12 @@ namespace Settings {
auto VN = util::win::GetRealOSVersion(); auto VN = util::win::GetRealOSVersion();
isWin10 = VN.dwBuildNumber < 22000; isWin10 = VN.dwBuildNumber < 22000;
if (isWin10) { if (isWin10)
{
spdlog::info("Running on Windows 10; Winver: {}.{}.{}", VN.dwMajorVersion, VN.dwMinorVersion, VN.dwBuildNumber); spdlog::info("Running on Windows 10; Winver: {}.{}.{}", VN.dwMajorVersion, VN.dwMinorVersion, VN.dwBuildNumber);
} }
else { else
{
spdlog::info("Running on Windows 11; Winver: {}.{}.{}", VN.dwMajorVersion, VN.dwMinorVersion, VN.dwBuildNumber); spdlog::info("Running on Windows 11; Winver: {}.{}.{}", VN.dwMajorVersion, VN.dwMinorVersion, VN.dwBuildNumber);
} }
} }
@ -123,38 +139,47 @@ namespace Settings {
inline void Parse(const nlohmann::basic_json<> &json) inline void Parse(const nlohmann::basic_json<> &json)
{ {
constexpr auto safeParseValue = []<typename T>(const auto & object, const auto & key, T & value) { constexpr auto safeParseValue = []<typename T>(const auto &object, const auto &key, T &value)
try { {
if (object.is_null() || object.empty() || object.at(key).empty() || object.at(key).is_null()) { try
{
if (object.is_null() || object.empty() || object.at(key).empty() || object.at(key).is_null())
{
return; return;
} }
if constexpr (std::is_same_v<T, std::wstring>) { if constexpr (std::is_same_v<T, std::wstring>)
{
value = util::string::to_wstring(object[key].get<std::string>()); value = util::string::to_wstring(object[key].get<std::string>());
} }
else { else
{
value = object[key]; value = object[key];
} }
} }
catch (const nlohmann::json::exception& e) { catch (const nlohmann::json::exception &e)
{
e.id == 403 e.id == 403
? spdlog::trace("Err parsing \"{}\"; {}", key, e.what()) ? spdlog::trace("Err parsing \"{}\"; {}", key, e.what())
: spdlog::warn("Err parsing \"{}\"; {}", key, e.what()); : spdlog::warn("Err parsing \"{}\"; {}", key, e.what());
} }
catch (const std::exception& e) { catch (const std::exception &e)
{
spdlog::warn("Err parsing \"{}\"; {}", key, e.what()); spdlog::warn("Err parsing \"{}\"; {}", key, e.what());
} }
}; };
int version; int version;
safeParseValue(json, "version", version); safeParseValue(json, "version", version);
if (version != 1) { // TODO: versioning stuff if (version != 1)
{ // TODO: versioning stuff
spdlog::warn("Config version doesn't match application version."); spdlog::warn("Config version doesn't match application version.");
} }
// TODO: make this as much generic as fits in about the same amount of code if one would parse every value separately. // TODO: make this as much generic as fits in about the same amount of code if one would parse every value separately.
try { try
if (const auto launchconf = json["launch"]; !launchconf.is_null() && !launchconf.empty() && launchconf.is_object()) { {
if (const auto launchconf = json["launch"]; !launchconf.is_null() && !launchconf.empty() && launchconf.is_object())
{
safeParseValue(launchconf, "launch", launch.launch); safeParseValue(launchconf, "launch", launch.launch);
safeParseValue(launchconf, "launchPath", launch.launchPath); safeParseValue(launchconf, "launchPath", launch.launchPath);
safeParseValue(launchconf, "launchAppArgs", launch.launchAppArgs); safeParseValue(launchconf, "launchAppArgs", launch.launchAppArgs);
@ -163,24 +188,29 @@ namespace Settings {
safeParseValue(launchconf, "killLauncher", launch.killLauncher); safeParseValue(launchconf, "killLauncher", launch.killLauncher);
safeParseValue(launchconf, "ignoreLauncher", launch.ignoreLauncher); safeParseValue(launchconf, "ignoreLauncher", launch.ignoreLauncher);
if (launchconf.contains("launcherProcesses") && launchconf["launcherProcesses"].is_array()) { if (launchconf.contains("launcherProcesses") && launchconf["launcherProcesses"].is_array())
{
if (const auto launcherProcs = launchconf["launcherProcesses"]; if (const auto launcherProcs = launchconf["launcherProcesses"];
!launcherProcs.is_null() && !launcherProcs.empty() && launcherProcs.is_array()) { !launcherProcs.is_null() && !launcherProcs.empty() && launcherProcs.is_array())
{
launch.launcherProcesses.clear(); launch.launcherProcesses.clear();
launch.launcherProcesses.reserve(launcherProcs.size()); launch.launcherProcesses.reserve(launcherProcs.size());
for (auto& proc : launcherProcs) { for (auto &proc : launcherProcs)
{
launch.launcherProcesses.push_back(util::string::to_wstring(proc)); launch.launcherProcesses.push_back(util::string::to_wstring(proc));
} }
} }
} }
} }
if (const auto devconf = json["devices"]; !devconf.is_null() && !devconf.empty() && devconf.is_object()) { if (const auto devconf = json["devices"]; !devconf.is_null() && !devconf.empty() && devconf.is_object())
{
safeParseValue(devconf, "hideDevices", devices.hideDevices); safeParseValue(devconf, "hideDevices", devices.hideDevices);
safeParseValue(devconf, "realDeviceIds", devices.realDeviceIds); safeParseValue(devconf, "realDeviceIds", devices.realDeviceIds);
} }
if (const auto winconf = json["window"]; !winconf.is_null() && !winconf.empty() && winconf.is_object()) { if (const auto winconf = json["window"]; !winconf.is_null() && !winconf.empty() && winconf.is_object())
{
safeParseValue(winconf, "windowMode", window.windowMode); safeParseValue(winconf, "windowMode", window.windowMode);
safeParseValue(winconf, "maxFps", window.maxFps); safeParseValue(winconf, "maxFps", window.maxFps);
safeParseValue(winconf, "scale", window.scale); safeParseValue(winconf, "scale", window.scale);
@ -189,7 +219,8 @@ namespace Settings {
safeParseValue(winconf, "disableGlosSIOverlay", window.disableGlosSIOverlay); safeParseValue(winconf, "disableGlosSIOverlay", window.disableGlosSIOverlay);
} }
if (const auto controllerConf = json["controller"]; !controllerConf.is_null() && !controllerConf.empty() && controllerConf.is_object()) { if (const auto controllerConf = json["controller"]; !controllerConf.is_null() && !controllerConf.empty() && controllerConf.is_object())
{
safeParseValue(controllerConf, "maxControllers", controller.maxControllers); safeParseValue(controllerConf, "maxControllers", controller.maxControllers);
safeParseValue(controllerConf, "allowDesktopConfig", controller.allowDesktopConfig); safeParseValue(controllerConf, "allowDesktopConfig", controller.allowDesktopConfig);
safeParseValue(controllerConf, "emulateDS4", controller.emulateDS4); safeParseValue(controllerConf, "emulateDS4", controller.emulateDS4);
@ -202,16 +233,19 @@ namespace Settings {
safeParseValue(json, "steamPath", common.steamPath); safeParseValue(json, "steamPath", common.steamPath);
safeParseValue(json, "steamUserId", common.steamUserId); safeParseValue(json, "steamUserId", common.steamUserId);
safeParseValue(json, "standaloneModeGameId", common.standaloneModeGameId); safeParseValue(json, "globalModeGameId", common.globalModeGameId);
safeParseValue(json, "standaloneUseGamepadUI", common.standaloneUseGamepadUI); safeParseValue(json, "globalModeUseGamepadUI", common.globalModeUseGamepadUI);
} }
catch (const nlohmann::json::exception& e) { catch (const nlohmann::json::exception &e)
{
spdlog::warn("Err parsing config: {}", e.what()); spdlog::warn("Err parsing config: {}", e.what());
} }
catch (const std::exception& e) { catch (const std::exception &e)
{
spdlog::warn("Err parsing config: {}", e.what()); spdlog::warn("Err parsing config: {}", e.what());
} }
if (launch.launch) { if (launch.launch)
{
launch.isUWP = checkIsUwp(launch.launchPath); launch.isUWP = checkIsUwp(launch.launchPath);
} }
} }
@ -220,42 +254,52 @@ namespace Settings {
{ {
std::wstring configName; std::wstring configName;
std::vector<std::function<void()>> cli_overrides; std::vector<std::function<void()>> cli_overrides;
for (const auto& arg : args) { for (const auto &arg : args)
if (arg.empty()) { {
if (arg.empty())
{
continue; continue;
} }
if (cmd_args.contains(arg)) if (cmd_args.contains(arg))
{ {
cli_overrides.push_back(cmd_args.at(arg)); cli_overrides.push_back(cmd_args.at(arg));
} }
else { else
{
configName += L" " + std::wstring(arg.begin(), arg.end()); configName += L" " + std::wstring(arg.begin(), arg.end());
} }
} }
if (!configName.empty()) { if (!configName.empty())
if (configName[0] == L' ') { {
if (configName[0] == L' ')
{
configName.erase(configName.begin()); configName.erase(configName.begin());
} }
if (!configName.ends_with(L".json")) { if (!configName.ends_with(L".json"))
{
configName += L".json"; configName += L".json";
} }
} }
auto path = util::path::getDataDirPath(); auto path = util::path::getDataDirPath();
if (!configName.empty()) { if (!configName.empty())
{
path /= "Targets"; path /= "Targets";
path /= configName; path /= configName;
} }
else { else
{
spdlog::info("No config file specified, using default"); spdlog::info("No config file specified, using default");
path /= "default.json"; path /= "default.json";
} }
std::ifstream json_file; std::ifstream json_file;
json_file.open(path); json_file.open(path);
if (!json_file.is_open()) { if (!json_file.is_open())
{
spdlog::error(L"Couldn't open settings file {}", path.wstring()); spdlog::error(L"Couldn't open settings file {}", path.wstring());
spdlog::debug(L"Using sane defaults..."); spdlog::debug(L"Using sane defaults...");
for (const auto& ovr : cli_overrides) { for (const auto &ovr : cli_overrides)
{
ovr(); ovr();
} }
return; return;
@ -264,7 +308,8 @@ namespace Settings {
const auto &json = nlohmann::json::parse(json_file); const auto &json = nlohmann::json::parse(json_file);
Parse(json); Parse(json);
for (const auto& ovr : cli_overrides) { for (const auto &ovr : cli_overrides)
{
ovr(); ovr();
} }
spdlog::debug("Read config file \"{}\"; config: {}", path.string(), json.dump()); spdlog::debug("Read config file \"{}\"; config: {}", path.string(), json.dump());
@ -304,7 +349,8 @@ namespace Settings {
std::ofstream json_file; std::ofstream json_file;
json_file.open(settings_path_); json_file.open(settings_path_);
if (!json_file.is_open()) { if (!json_file.is_open())
{
spdlog::error(L"Couldn't open settings file {}", settings_path_.wstring()); spdlog::error(L"Couldn't open settings file {}", settings_path_.wstring());
return; return;
} }

Loading…
Cancel
Save