Skip to content

Commit

Permalink
Error handling of illegal json added
Browse files Browse the repository at this point in the history
  • Loading branch information
JPersson77 committed Nov 27, 2023
1 parent 287e786 commit aa39805
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ std::vector <std::string> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion LGTV Companion Service/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 24 additions & 15 deletions LGTV Companion Service/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>();
devices.push_back(temp);
if (str.value().is_string())
{
std::string temp = str.value().get<std::string>();
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.";
}
Expand Down
2 changes: 1 addition & 1 deletion LGTV Companion Setup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<?define LGTV Companion Service_TargetDir=$(var.LGTV Companion Service.TargetDir)?><?define LGTV Companion UI_TargetDir=$(var.LGTV Companion UI.TargetDir)?>
<Product Id="20FCC6AA-E52F-40C2-9CF4-64A867577BB8" Name="LGTV Companion" Language="1033" Version="3.2.7" Manufacturer="J Persson" UpgradeCode="0BA17E5B-11CE-491D-B1A1-05DD2D9F610A">
<Product Id="FE3672F9-3E71-4521-B1A7-680D6D220E99" Name="LGTV Companion" Language="1033" Version="3.2.9" Manufacturer="J Persson" UpgradeCode="0BA17E5B-11CE-491D-B1A1-05DD2D9F610A">
<Package Id="*" InstallerVersion="301" Compressed="yes" InstallScope="perMachine" Platform='x64' Description="LGTV Companion installer" InstallPrivileges="elevated" AdminImage="yes"/>
<Media Id="1" Cabinet="LGTVapp.cab" EmbedCab="yes" />

Expand Down

0 comments on commit aa39805

Please sign in to comment.