From aa3980513ca4d8c4f89d5ef0285b6238576223b7 Mon Sep 17 00:00:00 2001 From: JPersson77 Date: Mon, 27 Nov 2023 12:31:15 +0100 Subject: [PATCH] Error handling of illegal json added --- Common/Common.cpp | 2 +- Common/Common.h | 2 +- LGTV Companion Service/Service.cpp | 3 ++- LGTV Companion Service/Session.cpp | 39 ++++++++++++++++++------------ LGTV Companion Setup/Product.wxs | 2 +- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Common/Common.cpp b/Common/Common.cpp index fb65236..8834e58 100644 --- a/Common/Common.cpp +++ b/Common/Common.cpp @@ -149,7 +149,7 @@ std::vector common::GetOwnIP(void) int CIDR = 0; int m; inet_pton(AF_INET, szNetMask, &m); - while (m) { + while (m > 0) { CIDR += (m & 0x01); m = m >> 1; } diff --git a/Common/Common.h b/Common/Common.h index 4ea0360..dc8cbad 100644 --- a/Common/Common.h +++ b/Common/Common.h @@ -24,7 +24,7 @@ // common general application definitions #define APPNAME L"LGTV Companion" -#define APP_VERSION L"3.2.7" +#define APP_VERSION L"3.2.9" #define CONFIG_FILE L"config.json" #define LOG_FILE L"Log.txt" #define WINDOW_CLASS_UNIQUE L"YOLOx0x0x0181818" diff --git a/LGTV Companion Service/Service.cpp b/LGTV Companion Service/Service.cpp index 879863d..e75c1b6 100644 --- a/LGTV Companion Service/Service.cpp +++ b/LGTV Companion Service/Service.cpp @@ -1024,7 +1024,8 @@ void NamedPipeCallback(std::wstring message) else log += device_state; Log(log); - SessionManager.SaveTopologyConfiguration(); + if(Settings.Prefs.KeepTopologyOnBoot) + SessionManager.SaveTopologyConfiguration(); CreateEvent_system(EVENT_SYSTEM_TOPOLOGY); } else diff --git a/LGTV Companion Service/Session.cpp b/LGTV Companion Service/Session.cpp index 90c047a..3bd887d 100644 --- a/LGTV Companion Service/Session.cpp +++ b/LGTV Companion Service/Session.cpp @@ -352,27 +352,36 @@ std::string CSessionManager::LoadSavedTopologyConfiguration(void) std::ifstream i(file.c_str()); if (i.is_open()) { - nlohmann::json j; - nlohmann::json topology_json; - i >> topology_json; - i.close(); - // Read version of the preferences file. If this key is found it is assumed the config file has been populated - j = topology_json[JSON_PREFS_NODE][JSON_VERSION]; - if (!j.empty() && j.is_number()) + try { - j = topology_json[JSON_PREFS_NODE][JSON_TOPOLOGY_NODE]; - if (!j.empty() && j.size() > 0) + nlohmann::json j; + nlohmann::json topology_json; + i >> topology_json; + i.close(); + // Read version of the preferences file. If this key is found it is assumed the config file has been populated + j = topology_json[JSON_PREFS_NODE][JSON_VERSION]; + if (!j.empty() && j.is_number()) { - for (auto& str : j.items()) + j = topology_json[JSON_PREFS_NODE][JSON_TOPOLOGY_NODE]; + if (!j.empty() && j.size() > 0) { - if (str.value().is_string()) + for (auto& str : j.items()) { - std::string temp = str.value().get(); - devices.push_back(temp); + if (str.value().is_string()) + { + std::string temp = str.value().get(); + devices.push_back(temp); + } } - } + } + return SetTopology(devices); } - return SetTopology(devices); + } + catch (std::exception const& e) + { + std::string s = "Error parsing topology configuration file: "; + s += e.what(); + return s; } return "Invalid topology configuration file."; } diff --git a/LGTV Companion Setup/Product.wxs b/LGTV Companion Setup/Product.wxs index 5ee7397..0f2894c 100644 --- a/LGTV Companion Setup/Product.wxs +++ b/LGTV Companion Setup/Product.wxs @@ -3,7 +3,7 @@ - +