From 8f6c4ad5eec543435a40b2fb2341b100cf476b06 Mon Sep 17 00:00:00 2001 From: flb Date: Thu, 6 Jan 2022 01:42:31 +0100 Subject: [PATCH] fix pc color swap crash --- source/color_swapper.cpp | 43 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/source/color_swapper.cpp b/source/color_swapper.cpp index 639bc5e..28e710d 100644 --- a/source/color_swapper.cpp +++ b/source/color_swapper.cpp @@ -288,33 +288,34 @@ namespace PC { std::fstream profilesFile; nlohmann::ordered_json profilesJson; download::getRequest(PC_COLOR_URL, profilesJson); - profilesJson += fs::parseJsonFile(path); if (profilesJson.empty()) { profilesJson = {{{"BTN", "e6e6e6"}, {"BODY", "2d2d2d"}, {"name", "Default black"}}}; } - for (const auto& x : profilesJson.items()) { - std::string name = x.value()["name"]; - std::vector values = { - std::string(x.value()["BODY"]), - std::string(x.value()["BTN"])}; - properData = true; - for (auto& str : values) { - if (!isHexaAnd3Bytes(str)) { - properData = false; + for (const auto& profiles : {fs::parseJsonFile(path), profilesJson}) { + for (const auto& x : profiles.items()) { + std::string name = x.value()["name"]; + std::vector values = { + std::string(x.value()["BODY"]), + std::string(x.value()["BTN"])}; + properData = true; + for (auto& str : values) { + if (!isHexaAnd3Bytes(str)) { + properData = false; + } } - } - if (properData) { - if (name == "") name = "Unamed"; - auto profile = std::make_pair(name, (std::vector){ - hexToBGR(values[0]), - hexToBGR(values[1])}); - if (name == BACKUP) { - res.push_front(profile); - } - else { - res.push_back(profile); + if (properData) { + if (name == "") name = "Unamed"; + auto profile = std::make_pair(name, (std::vector){ + hexToBGR(values[0]), + hexToBGR(values[1])}); + if (name == BACKUP) { + res.push_front(profile); + } + else { + res.push_back(profile); + } } } }