Workaround for crash with older version of jsoncpp

This commit is contained in:
Sude 2017-10-12 00:29:04 +03:00
parent b0a90f6c60
commit 257946dbc1
3 changed files with 26 additions and 2 deletions

View File

@ -71,6 +71,7 @@ namespace Util
void parseOptionString(const std::string &option_string, std::vector<unsigned int> &priority, unsigned int &type, const std::vector<GlobalConstants::optionsStruct>& 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<typename ... Args> std::string formattedString(const std::string& format, Args ... args)
{

View File

@ -410,7 +410,7 @@ std::vector<gameFile> 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<gameFile> 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;

View File

@ -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;
}