mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-02-02 05:52:31 +01:00
Fix crash in Website::getGames
JSON value for updates can be null in some cases. For example when user owns a dlc but not the base game. This caused a crash due to std::stoi throwing std::invalid_argument exception
This commit is contained in:
parent
1d1855049c
commit
22f47de4fc
@ -163,7 +163,31 @@ std::vector<gameItem> Website::getGames()
|
|||||||
gameItem game;
|
gameItem game;
|
||||||
game.name = product["slug"].asString();
|
game.name = product["slug"].asString();
|
||||||
game.id = product["id"].isInt() ? std::to_string(product["id"].asInt()) : product["id"].asString();
|
game.id = product["id"].isInt() ? std::to_string(product["id"].asInt()) : product["id"].asString();
|
||||||
game.updates = product["updates"].isInt() ? product["updates"].asInt() : std::stoi(product["updates"].asString());
|
|
||||||
|
if (product.isMember("updates"))
|
||||||
|
{
|
||||||
|
if (product["updates"].isNull())
|
||||||
|
{
|
||||||
|
/* In some cases the value can be null.
|
||||||
|
* For example when user owns a dlc but not the base game
|
||||||
|
* https://github.com/Sude-/lgogdownloader/issues/101
|
||||||
|
* Assume that there are no updates in this case */
|
||||||
|
game.updates = 0;
|
||||||
|
}
|
||||||
|
else if (product["updates"].isInt())
|
||||||
|
game.updates = product["updates"].asInt();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
game.updates = std::stoi(product["updates"].asString());
|
||||||
|
}
|
||||||
|
catch (std::invalid_argument& e)
|
||||||
|
{
|
||||||
|
game.updates = 0; // Assume no updates
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int platform = 0;
|
unsigned int platform = 0;
|
||||||
if (product["worksOn"]["Windows"].asBool())
|
if (product["worksOn"]["Windows"].asBool())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user