mirror of
https://github.com/Alia5/GlosSI.git
synced 2024-10-30 15:20:38 +00:00
Rename "standalone mode" -> "global mode"
This commit is contained in:
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,285 +31,331 @@ 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
|
||||||
|
{
|
||||||
|
bool launch = false;
|
||||||
|
std::wstring launchPath;
|
||||||
|
std::wstring launchAppArgs;
|
||||||
|
bool closeOnExit = true;
|
||||||
|
bool waitForChildProcs = true;
|
||||||
|
bool isUWP = false;
|
||||||
|
bool ignoreLauncher = true;
|
||||||
|
bool killLauncher = false;
|
||||||
|
std::vector<std::wstring> launcherProcesses{};
|
||||||
|
} launch;
|
||||||
|
|
||||||
inline struct Launch {
|
inline struct Devices
|
||||||
bool launch = false;
|
{
|
||||||
std::wstring launchPath;
|
bool hideDevices = true;
|
||||||
std::wstring launchAppArgs;
|
bool realDeviceIds = false;
|
||||||
bool closeOnExit = true;
|
} devices;
|
||||||
bool waitForChildProcs = true;
|
|
||||||
bool isUWP = false;
|
|
||||||
bool ignoreLauncher = true;
|
|
||||||
bool killLauncher = false;
|
|
||||||
std::vector<std::wstring> launcherProcesses{};
|
|
||||||
} launch;
|
|
||||||
|
|
||||||
inline struct Devices {
|
inline struct Window
|
||||||
bool hideDevices = true;
|
{
|
||||||
bool realDeviceIds = false;
|
bool windowMode = false;
|
||||||
} devices;
|
int maxFps = 0;
|
||||||
|
float scale = 0.f;
|
||||||
|
bool disableOverlay = false;
|
||||||
|
bool hideAltTab = true;
|
||||||
|
bool disableGlosSIOverlay = false;
|
||||||
|
} window;
|
||||||
|
|
||||||
inline struct Window {
|
inline struct Controller
|
||||||
bool windowMode = false;
|
{
|
||||||
int maxFps = 0;
|
int maxControllers = 1;
|
||||||
float scale = 0.f;
|
bool allowDesktopConfig = false;
|
||||||
bool disableOverlay = false;
|
bool emulateDS4 = false;
|
||||||
bool hideAltTab = true;
|
} controller;
|
||||||
bool disableGlosSIOverlay = false;
|
|
||||||
} window;
|
|
||||||
|
|
||||||
inline struct Controller {
|
inline struct Common
|
||||||
int maxControllers = 1;
|
{
|
||||||
bool allowDesktopConfig = false;
|
bool no_uwp_overlay = false;
|
||||||
bool emulateDS4 = false;
|
bool disable_watchdog = false;
|
||||||
} controller;
|
bool extendedLogging = false;
|
||||||
|
std::wstring name;
|
||||||
|
std::wstring icon;
|
||||||
|
int version;
|
||||||
|
std::wstring steamPath;
|
||||||
|
std::wstring steamUserId;
|
||||||
|
std::wstring globalModeGameId; /* = L"12605636929694728192"; */
|
||||||
|
bool globalModeUseGamepadUI = false;
|
||||||
|
bool allowGlobalMode = true;
|
||||||
|
} common;
|
||||||
|
|
||||||
inline struct Common {
|
inline const std::map<std::wstring, std::function<void()>> cmd_args = {
|
||||||
bool no_uwp_overlay = false;
|
{L"-disableuwpoverlay", [&]()
|
||||||
bool disable_watchdog = false;
|
{ common.no_uwp_overlay = true; }},
|
||||||
bool extendedLogging = false;
|
{L"-disablewatchdog", [&]()
|
||||||
std::wstring name;
|
{ common.disable_watchdog = true; }},
|
||||||
std::wstring icon;
|
{L"-ignorelauncher", [&]()
|
||||||
int version;
|
{ launch.ignoreLauncher = true; }},
|
||||||
std::wstring steamPath;
|
{L"-window", [&]()
|
||||||
std::wstring steamUserId;
|
{ window.windowMode = true; }},
|
||||||
std::wstring standaloneModeGameId; /* = L"12605636929694728192"; */
|
{L"-extendedLogging", [&]()
|
||||||
bool standaloneUseGamepadUI = false;
|
{ common.extendedLogging = true; }},
|
||||||
bool allowStandAlone = true;
|
{L"-globalModeUseGamepadUI", [&]()
|
||||||
} common;
|
{ common.globalModeUseGamepadUI = true; }},
|
||||||
|
{L"-disallowGlobalMode", [&]()
|
||||||
|
{ common.allowGlobalMode = false; }},
|
||||||
|
};
|
||||||
|
|
||||||
inline const std::map<std::wstring, std::function<void()>> cmd_args = {
|
inline std::filesystem::path settings_path_ = "";
|
||||||
{L"-disableuwpoverlay", [&]() { common.no_uwp_overlay = true; }},
|
|
||||||
{L"-disablewatchdog", [&]() { common.disable_watchdog = true; }},
|
|
||||||
{L"-ignorelauncher", [&]() { launch.ignoreLauncher = true; }},
|
|
||||||
{L"-window", [&]() { window.windowMode = true; }},
|
|
||||||
{L"-extendedLogging", [&]() { common.extendedLogging = true; }},
|
|
||||||
{L"-standaloneUseGamepadUI", [&]() { common.standaloneUseGamepadUI = true; }},
|
|
||||||
{L"-disallowStandAlone", [&]() { common.allowStandAlone = false; }},
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
inline bool isWin10 = false;
|
inline bool isWin10 = false;
|
||||||
|
|
||||||
inline void checkWinVer()
|
inline void checkWinVer()
|
||||||
{
|
{
|
||||||
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 {
|
}
|
||||||
spdlog::info("Running on Windows 11; Winver: {}.{}.{}", VN.dwMajorVersion, VN.dwMinorVersion, VN.dwBuildNumber);
|
else
|
||||||
}
|
{
|
||||||
}
|
spdlog::info("Running on Windows 11; Winver: {}.{}.{}", VN.dwMajorVersion, VN.dwMinorVersion, VN.dwBuildNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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
|
||||||
return;
|
{
|
||||||
}
|
if (object.is_null() || object.empty() || object.at(key).empty() || object.at(key).is_null())
|
||||||
if constexpr (std::is_same_v<T, std::wstring>) {
|
{
|
||||||
value = util::string::to_wstring(object[key].get<std::string>());
|
return;
|
||||||
}
|
}
|
||||||
else {
|
if constexpr (std::is_same_v<T, std::wstring>)
|
||||||
value = object[key];
|
{
|
||||||
}
|
value = util::string::to_wstring(object[key].get<std::string>());
|
||||||
}
|
}
|
||||||
catch (const nlohmann::json::exception& e) {
|
else
|
||||||
e.id == 403
|
{
|
||||||
? spdlog::trace("Err parsing \"{}\"; {}", key, e.what())
|
value = object[key];
|
||||||
: spdlog::warn("Err parsing \"{}\"; {}", key, e.what());
|
}
|
||||||
|
}
|
||||||
|
catch (const nlohmann::json::exception &e)
|
||||||
|
{
|
||||||
|
e.id == 403
|
||||||
|
? spdlog::trace("Err parsing \"{}\"; {}", key, e.what())
|
||||||
|
: spdlog::warn("Err parsing \"{}\"; {}", key, e.what());
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
spdlog::warn("Err parsing \"{}\"; {}", key, e.what());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
int version;
|
||||||
catch (const std::exception& e) {
|
safeParseValue(json, "version", version);
|
||||||
spdlog::warn("Err parsing \"{}\"; {}", key, e.what());
|
if (version != 1)
|
||||||
}
|
{ // TODO: versioning stuff
|
||||||
};
|
spdlog::warn("Config version doesn't match application version.");
|
||||||
|
}
|
||||||
|
|
||||||
int version;
|
// TODO: make this as much generic as fits in about the same amount of code if one would parse every value separately.
|
||||||
safeParseValue(json, "version", version);
|
try
|
||||||
if (version != 1) { // TODO: versioning stuff
|
{
|
||||||
spdlog::warn("Config version doesn't match application version.");
|
if (const auto launchconf = json["launch"]; !launchconf.is_null() && !launchconf.empty() && launchconf.is_object())
|
||||||
}
|
{
|
||||||
|
safeParseValue(launchconf, "launch", launch.launch);
|
||||||
|
safeParseValue(launchconf, "launchPath", launch.launchPath);
|
||||||
|
safeParseValue(launchconf, "launchAppArgs", launch.launchAppArgs);
|
||||||
|
safeParseValue(launchconf, "closeOnExit", launch.closeOnExit);
|
||||||
|
safeParseValue(launchconf, "waitForChildProcs", launch.waitForChildProcs);
|
||||||
|
safeParseValue(launchconf, "killLauncher", launch.killLauncher);
|
||||||
|
safeParseValue(launchconf, "ignoreLauncher", launch.ignoreLauncher);
|
||||||
|
|
||||||
// TODO: make this as much generic as fits in about the same amount of code if one would parse every value separately.
|
if (launchconf.contains("launcherProcesses") && launchconf["launcherProcesses"].is_array())
|
||||||
try {
|
{
|
||||||
if (const auto launchconf = json["launch"]; !launchconf.is_null() && !launchconf.empty() && launchconf.is_object()) {
|
if (const auto launcherProcs = launchconf["launcherProcesses"];
|
||||||
safeParseValue(launchconf, "launch", launch.launch);
|
!launcherProcs.is_null() && !launcherProcs.empty() && launcherProcs.is_array())
|
||||||
safeParseValue(launchconf, "launchPath", launch.launchPath);
|
{
|
||||||
safeParseValue(launchconf, "launchAppArgs", launch.launchAppArgs);
|
launch.launcherProcesses.clear();
|
||||||
safeParseValue(launchconf, "closeOnExit", launch.closeOnExit);
|
launch.launcherProcesses.reserve(launcherProcs.size());
|
||||||
safeParseValue(launchconf, "waitForChildProcs", launch.waitForChildProcs);
|
for (auto &proc : launcherProcs)
|
||||||
safeParseValue(launchconf, "killLauncher", launch.killLauncher);
|
{
|
||||||
safeParseValue(launchconf, "ignoreLauncher", launch.ignoreLauncher);
|
launch.launcherProcesses.push_back(util::string::to_wstring(proc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (launchconf.contains("launcherProcesses") && launchconf["launcherProcesses"].is_array()) {
|
if (const auto devconf = json["devices"]; !devconf.is_null() && !devconf.empty() && devconf.is_object())
|
||||||
if (const auto launcherProcs = launchconf["launcherProcesses"];
|
{
|
||||||
!launcherProcs.is_null() && !launcherProcs.empty() && launcherProcs.is_array()) {
|
safeParseValue(devconf, "hideDevices", devices.hideDevices);
|
||||||
launch.launcherProcesses.clear();
|
safeParseValue(devconf, "realDeviceIds", devices.realDeviceIds);
|
||||||
launch.launcherProcesses.reserve(launcherProcs.size());
|
}
|
||||||
for (auto& proc : launcherProcs) {
|
|
||||||
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 winconf = json["window"]; !winconf.is_null() && !winconf.empty() && winconf.is_object())
|
||||||
safeParseValue(devconf, "hideDevices", devices.hideDevices);
|
{
|
||||||
safeParseValue(devconf, "realDeviceIds", devices.realDeviceIds);
|
safeParseValue(winconf, "windowMode", window.windowMode);
|
||||||
}
|
safeParseValue(winconf, "maxFps", window.maxFps);
|
||||||
|
safeParseValue(winconf, "scale", window.scale);
|
||||||
|
safeParseValue(winconf, "disableOverlay", window.disableOverlay);
|
||||||
|
safeParseValue(winconf, "hideAltTab", window.hideAltTab);
|
||||||
|
safeParseValue(winconf, "disableGlosSIOverlay", window.disableGlosSIOverlay);
|
||||||
|
}
|
||||||
|
|
||||||
if (const auto winconf = json["window"]; !winconf.is_null() && !winconf.empty() && winconf.is_object()) {
|
if (const auto controllerConf = json["controller"]; !controllerConf.is_null() && !controllerConf.empty() && controllerConf.is_object())
|
||||||
safeParseValue(winconf, "windowMode", window.windowMode);
|
{
|
||||||
safeParseValue(winconf, "maxFps", window.maxFps);
|
safeParseValue(controllerConf, "maxControllers", controller.maxControllers);
|
||||||
safeParseValue(winconf, "scale", window.scale);
|
safeParseValue(controllerConf, "allowDesktopConfig", controller.allowDesktopConfig);
|
||||||
safeParseValue(winconf, "disableOverlay", window.disableOverlay);
|
safeParseValue(controllerConf, "emulateDS4", controller.emulateDS4);
|
||||||
safeParseValue(winconf, "hideAltTab", window.hideAltTab);
|
}
|
||||||
safeParseValue(winconf, "disableGlosSIOverlay", window.disableGlosSIOverlay);
|
safeParseValue(json, "extendedLogging", common.extendedLogging);
|
||||||
}
|
safeParseValue(json, "name", common.name);
|
||||||
|
safeParseValue(json, "icon", common.icon);
|
||||||
|
safeParseValue(json, "version", common.version);
|
||||||
|
|
||||||
if (const auto controllerConf = json["controller"]; !controllerConf.is_null() && !controllerConf.empty() && controllerConf.is_object()) {
|
safeParseValue(json, "steamPath", common.steamPath);
|
||||||
safeParseValue(controllerConf, "maxControllers", controller.maxControllers);
|
safeParseValue(json, "steamUserId", common.steamUserId);
|
||||||
safeParseValue(controllerConf, "allowDesktopConfig", controller.allowDesktopConfig);
|
|
||||||
safeParseValue(controllerConf, "emulateDS4", controller.emulateDS4);
|
|
||||||
}
|
|
||||||
safeParseValue(json, "extendedLogging", common.extendedLogging);
|
|
||||||
safeParseValue(json, "name", common.name);
|
|
||||||
safeParseValue(json, "icon", common.icon);
|
|
||||||
safeParseValue(json, "version", common.version);
|
|
||||||
|
|
||||||
safeParseValue(json, "steamPath", common.steamPath);
|
safeParseValue(json, "globalModeGameId", common.globalModeGameId);
|
||||||
safeParseValue(json, "steamUserId", common.steamUserId);
|
safeParseValue(json, "globalModeUseGamepadUI", common.globalModeUseGamepadUI);
|
||||||
|
}
|
||||||
|
catch (const nlohmann::json::exception &e)
|
||||||
|
{
|
||||||
|
spdlog::warn("Err parsing config: {}", e.what());
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
spdlog::warn("Err parsing config: {}", e.what());
|
||||||
|
}
|
||||||
|
if (launch.launch)
|
||||||
|
{
|
||||||
|
launch.isUWP = checkIsUwp(launch.launchPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
safeParseValue(json, "standaloneModeGameId", common.standaloneModeGameId);
|
inline void Parse(const std::vector<std::wstring> &args)
|
||||||
safeParseValue(json, "standaloneUseGamepadUI", common.standaloneUseGamepadUI);
|
{
|
||||||
}
|
std::wstring configName;
|
||||||
catch (const nlohmann::json::exception& e) {
|
std::vector<std::function<void()>> cli_overrides;
|
||||||
spdlog::warn("Err parsing config: {}", e.what());
|
for (const auto &arg : args)
|
||||||
}
|
{
|
||||||
catch (const std::exception& e) {
|
if (arg.empty())
|
||||||
spdlog::warn("Err parsing config: {}", e.what());
|
{
|
||||||
}
|
continue;
|
||||||
if (launch.launch) {
|
}
|
||||||
launch.isUWP = checkIsUwp(launch.launchPath);
|
if (cmd_args.contains(arg))
|
||||||
}
|
{
|
||||||
}
|
cli_overrides.push_back(cmd_args.at(arg));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
configName += L" " + std::wstring(arg.begin(), arg.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!configName.empty())
|
||||||
|
{
|
||||||
|
if (configName[0] == L' ')
|
||||||
|
{
|
||||||
|
configName.erase(configName.begin());
|
||||||
|
}
|
||||||
|
if (!configName.ends_with(L".json"))
|
||||||
|
{
|
||||||
|
configName += L".json";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto path = util::path::getDataDirPath();
|
||||||
|
if (!configName.empty())
|
||||||
|
{
|
||||||
|
path /= "Targets";
|
||||||
|
path /= configName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spdlog::info("No config file specified, using default");
|
||||||
|
path /= "default.json";
|
||||||
|
}
|
||||||
|
|
||||||
inline void Parse(const std::vector<std::wstring>& args)
|
std::ifstream json_file;
|
||||||
{
|
json_file.open(path);
|
||||||
std::wstring configName;
|
if (!json_file.is_open())
|
||||||
std::vector<std::function<void()>> cli_overrides;
|
{
|
||||||
for (const auto& arg : args) {
|
spdlog::error(L"Couldn't open settings file {}", path.wstring());
|
||||||
if (arg.empty()) {
|
spdlog::debug(L"Using sane defaults...");
|
||||||
continue;
|
for (const auto &ovr : cli_overrides)
|
||||||
}
|
{
|
||||||
if (cmd_args.contains(arg))
|
ovr();
|
||||||
{
|
}
|
||||||
cli_overrides.push_back(cmd_args.at(arg));
|
return;
|
||||||
}
|
}
|
||||||
else {
|
settings_path_ = path;
|
||||||
configName += L" " + std::wstring(arg.begin(), arg.end());
|
const auto &json = nlohmann::json::parse(json_file);
|
||||||
}
|
Parse(json);
|
||||||
}
|
|
||||||
if (!configName.empty()) {
|
|
||||||
if (configName[0] == L' ') {
|
|
||||||
configName.erase(configName.begin());
|
|
||||||
}
|
|
||||||
if (!configName.ends_with(L".json")) {
|
|
||||||
configName += L".json";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
auto path = util::path::getDataDirPath();
|
|
||||||
if (!configName.empty()) {
|
|
||||||
path /= "Targets";
|
|
||||||
path /= configName;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
spdlog::info("No config file specified, using default");
|
|
||||||
path /= "default.json";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream json_file;
|
for (const auto &ovr : cli_overrides)
|
||||||
json_file.open(path);
|
{
|
||||||
if (!json_file.is_open()) {
|
ovr();
|
||||||
spdlog::error(L"Couldn't open settings file {}", path.wstring());
|
}
|
||||||
spdlog::debug(L"Using sane defaults...");
|
spdlog::debug("Read config file \"{}\"; config: {}", path.string(), json.dump());
|
||||||
for (const auto& ovr : cli_overrides) {
|
json_file.close();
|
||||||
ovr();
|
}
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
settings_path_ = path;
|
|
||||||
const auto& json = nlohmann::json::parse(json_file);
|
|
||||||
Parse(json);
|
|
||||||
|
|
||||||
for (const auto& ovr : cli_overrides) {
|
inline nlohmann::json toJson()
|
||||||
ovr();
|
{
|
||||||
}
|
nlohmann::json json;
|
||||||
spdlog::debug("Read config file \"{}\"; config: {}", path.string(), json.dump());
|
json["version"] = 1;
|
||||||
json_file.close();
|
json["launch"]["launch"] = launch.launch;
|
||||||
}
|
json["launch"]["launchPath"] = launch.launchPath;
|
||||||
|
json["launch"]["launchAppArgs"] = launch.launchAppArgs;
|
||||||
|
json["launch"]["closeOnExit"] = launch.closeOnExit;
|
||||||
|
json["launch"]["waitForChildProcs"] = launch.waitForChildProcs;
|
||||||
|
json["devices"]["hideDevices"] = devices.hideDevices;
|
||||||
|
json["devices"]["realDeviceIds"] = devices.realDeviceIds;
|
||||||
|
json["window"]["windowMode"] = window.windowMode;
|
||||||
|
json["window"]["maxFps"] = window.maxFps;
|
||||||
|
json["window"]["scale"] = window.scale;
|
||||||
|
json["window"]["disableOverlay"] = window.disableOverlay;
|
||||||
|
json["window"]["hideAltTab"] = window.hideAltTab;
|
||||||
|
json["controller"]["maxControllers"] = controller.maxControllers;
|
||||||
|
json["controller"]["allowDesktopConfig"] = controller.allowDesktopConfig;
|
||||||
|
json["controller"]["emulateDS4"] = controller.emulateDS4;
|
||||||
|
|
||||||
inline nlohmann::json toJson()
|
json["extendedLogging"] = common.extendedLogging;
|
||||||
{
|
json["name"] = common.name;
|
||||||
nlohmann::json json;
|
json["icon"] = common.icon;
|
||||||
json["version"] = 1;
|
json["version"] = common.version;
|
||||||
json["launch"]["launch"] = launch.launch;
|
return json;
|
||||||
json["launch"]["launchPath"] = launch.launchPath;
|
}
|
||||||
json["launch"]["launchAppArgs"] = launch.launchAppArgs;
|
|
||||||
json["launch"]["closeOnExit"] = launch.closeOnExit;
|
|
||||||
json["launch"]["waitForChildProcs"] = launch.waitForChildProcs;
|
|
||||||
json["devices"]["hideDevices"] = devices.hideDevices;
|
|
||||||
json["devices"]["realDeviceIds"] = devices.realDeviceIds;
|
|
||||||
json["window"]["windowMode"] = window.windowMode;
|
|
||||||
json["window"]["maxFps"] = window.maxFps;
|
|
||||||
json["window"]["scale"] = window.scale;
|
|
||||||
json["window"]["disableOverlay"] = window.disableOverlay;
|
|
||||||
json["window"]["hideAltTab"] = window.hideAltTab;
|
|
||||||
json["controller"]["maxControllers"] = controller.maxControllers;
|
|
||||||
json["controller"]["allowDesktopConfig"] = controller.allowDesktopConfig;
|
|
||||||
json["controller"]["emulateDS4"] = controller.emulateDS4;
|
|
||||||
|
|
||||||
json["extendedLogging"] = common.extendedLogging;
|
inline void StoreSettings()
|
||||||
json["name"] = common.name;
|
{
|
||||||
json["icon"] = common.icon;
|
const auto &json = toJson();
|
||||||
json["version"] = common.version;
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void StoreSettings()
|
std::ofstream json_file;
|
||||||
{
|
json_file.open(settings_path_);
|
||||||
const auto& json = toJson();
|
if (!json_file.is_open())
|
||||||
|
{
|
||||||
std::ofstream json_file;
|
spdlog::error(L"Couldn't open settings file {}", settings_path_.wstring());
|
||||||
json_file.open(settings_path_);
|
return;
|
||||||
if (!json_file.is_open()) {
|
}
|
||||||
spdlog::error(L"Couldn't open settings file {}", settings_path_.wstring());
|
json_file << json.dump(4);
|
||||||
return;
|
json_file.close();
|
||||||
}
|
}
|
||||||
json_file << json.dump(4);
|
|
||||||
json_file.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
Loading…
Reference in New Issue
Block a user