Fix potential settings crash on launch

pull/179/head
Peter Repukat 2 years ago
parent 3c1587b5ed
commit 7c706945bc

@ -92,14 +92,8 @@ inline void Parse(std::wstring arg1)
return; return;
} }
settings_path_ = path; settings_path_ = path;
const auto json = nlohmann::json::parse(json_file);
if (json["version"] != 1) { // TODO: versioning stuff
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.
auto safeParseValue = [](const auto& object, const auto& key, auto& value) { auto safeParseValue = [](const auto& object, const auto& key, auto& value) {
try { try {
if (object.is_null() || object.empty() || object.at(key).empty() || object.at(key).is_null()) { if (object.is_null() || object.empty() || object.at(key).empty() || object.at(key).is_null()) {
return; return;
@ -123,6 +117,15 @@ inline void Parse(std::wstring arg1)
} }
}; };
const auto json = nlohmann::json::parse(json_file);
int version;
safeParseValue(json, "version" ,version);
if (version != 1) { // TODO: versioning stuff
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.
if (auto launchconf = json["launch"]; launchconf.is_object()) { if (auto launchconf = json["launch"]; launchconf.is_object()) {
safeParseValue(launchconf, "launch", launch.launch); safeParseValue(launchconf, "launch", launch.launch);
safeWStringParse(launchconf, "launchPath", launch.launchPath); safeWStringParse(launchconf, "launchPath", launch.launchPath);
@ -149,16 +152,7 @@ inline void Parse(std::wstring arg1)
safeParseValue(controllerConf, "emulateDS4", controller.emulateDS4); safeParseValue(controllerConf, "emulateDS4", controller.emulateDS4);
} }
try { safeParseValue(json, "extendedLogging", extendedLogging);
if (auto extlog = json["extendedLogging"]; extlog.is_boolean()) {
extendedLogging = extlog;
}
}
catch (...)
{
}
json_file.close(); json_file.close();

Loading…
Cancel
Save