GlosSITarget: support loading default-config if no config was specified

pull/183/head
Peter Repukat 2 years ago
parent 14f87f19e2
commit 555221ad18

@ -114,25 +114,35 @@ inline void checkWinVer()
inline void Parse(std::wstring arg1) inline void Parse(std::wstring arg1)
{ {
if (!arg1.ends_with(L".json")) { const auto config_specified = !std::views::filter(arg1, [](const auto& ch) {
arg1 += L".json"; return ch != ' ';
}).empty();
if (config_specified) {
if (!arg1.ends_with(L".json")) {
arg1 += L".json";
}
} }
std::filesystem::path path(arg1); std::filesystem::path path = std::filesystem::temp_directory_path()
if (path.has_extension() && !std::filesystem::exists(path)) { .parent_path()
path = std::filesystem::temp_directory_path() .parent_path()
.parent_path() .parent_path();
.parent_path()
.parent_path(); path /= "Roaming";
path /= "GlosSI";
path /= "Roaming"; if (config_specified) {
path /= "GlosSI";
path /= "Targets"; path /= "Targets";
path /= arg1; path /= arg1;
} }
else {
spdlog::info("No config file specified, using default");
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...");
return; return;
} }
settings_path_ = path; settings_path_ = path;

Loading…
Cancel
Save