From 257946dbc183d9c65e8e56bfb6c9319f5f15a26d Mon Sep 17 00:00:00 2001 From: Sude Date: Thu, 12 Oct 2017 00:29:04 +0300 Subject: [PATCH] Workaround for crash with older version of jsoncpp --- include/util.h | 1 + src/galaxyapi.cpp | 4 ++-- src/util.cpp | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/util.h b/include/util.h index c3ee2cc..57a5f3b 100644 --- a/include/util.h +++ b/include/util.h @@ -71,6 +71,7 @@ namespace Util void parseOptionString(const std::string &option_string, std::vector &priority, unsigned int &type, const std::vector& options); std::string getLocalFileHash(const std::string& xml_dir, const std::string& filepath, const std::string& gamename = std::string()); void shortenStringToTerminalWidth(std::string& str); + std::string getJsonUIntValueAsString(const Json::Value& json); template std::string formattedString(const std::string& format, Args ... args) { diff --git a/src/galaxyapi.cpp b/src/galaxyapi.cpp index 198b434..dac74d0 100644 --- a/src/galaxyapi.cpp +++ b/src/galaxyapi.cpp @@ -410,7 +410,7 @@ std::vector galaxyAPI::installerJsonNodeToGameFileVector(const std::st gf.language = iLanguage; gf.name = name; gf.path = path; - gf.size = fileNode["size"].asString(); + gf.size = Util::getJsonUIntValueAsString(fileNode["size"]); gf.updated = 0; // assume not updated gf.galaxy_downlink_json_url = downlink; @@ -499,7 +499,7 @@ std::vector galaxyAPI::extraJsonNodeToGameFileVector(const std::string gf.id = fileNode["id"].asString(); gf.name = name; gf.path = path; - gf.size = fileNode["size"].asString(); + gf.size = Util::getJsonUIntValueAsString(fileNode["size"]); gf.updated = 0; // assume not updated gf.galaxy_downlink_json_url = downlink; diff --git a/src/util.cpp b/src/util.cpp index 416a69b..f23a80c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -590,3 +590,26 @@ void Util::shortenStringToTerminalWidth(std::string& str) str.replace(str.begin()+pos1, str.begin()+pos2, "..."); } } + +std::string Util::getJsonUIntValueAsString(const Json::Value& json_value) +{ + std::string value; + try + { + value = json_value.asString(); + } + catch (...) + { + try + { + uintmax_t value_uint = json_value.asLargestUInt(); + value = std::to_string(value_uint); + } + catch (...) + { + value = ""; + } + } + + return value; +}