Skip to content

Commit

Permalink
Fix running Game.update_game_info() multiple times in threads (tkashk…
Browse files Browse the repository at this point in the history
  • Loading branch information
tkashkin committed Apr 14, 2019
1 parent 79de66d commit 7a4f9e1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
11 changes: 10 additions & 1 deletion src/data/sources/gog/GOGGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace GameHub.Data.Sources.GOG
}
}

private bool game_info_updating = false;
private bool game_info_updated = false;

public GOGGame.default(){}
Expand Down Expand Up @@ -141,6 +142,9 @@ namespace GameHub.Data.Sources.GOG

public override async void update_game_info()
{
if(game_info_updating) return;
game_info_updating = true;

update_status();

mount_overlays();
Expand Down Expand Up @@ -171,7 +175,11 @@ namespace GameHub.Data.Sources.GOG
else icon = image;
}

if(game_info_updated) return;
if(game_info_updated)
{
game_info_updating = false;
return;
}

is_installable = root != null && root.get_node_type() == Json.NodeType.OBJECT
&& root.get_object().has_member("is_installable") && root.get_object().get_boolean_member("is_installable");
Expand Down Expand Up @@ -275,6 +283,7 @@ namespace GameHub.Data.Sources.GOG
update_status();

game_info_updated = true;
game_info_updating = false;
}

public override async void install()
Expand Down
41 changes: 35 additions & 6 deletions src/data/sources/humble/HumbleGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace GameHub.Data.Sources.Humble
{
public string order_id;

private bool game_info_updating = false;
private bool game_info_updated = false;
private bool game_info_refreshed = false;

Expand Down Expand Up @@ -177,6 +178,9 @@ namespace GameHub.Data.Sources.Humble

public override async void update_game_info()
{
if(game_info_updating) return;
game_info_updating = true;

update_status();

mount_overlays();
Expand All @@ -192,7 +196,11 @@ namespace GameHub.Data.Sources.Humble
image = icon;
}

if(game_info_updated) return;
if(game_info_updated)
{
game_info_updating = false;
return;
}

if(info == null || info.length == 0)
{
Expand All @@ -202,11 +210,23 @@ namespace GameHub.Data.Sources.Humble
headers["Cookie"] = @"$(Humble.AUTH_COOKIE)=\"$(token)\";";

var root_node = yield Parser.parse_remote_json_file_async(@"https://www.humblebundle.com/api/v1/order/$(order_id)?ajax=true", "GET", null, headers);
if(root_node == null || root_node.get_node_type() != Json.NodeType.OBJECT) return;
if(root_node == null || root_node.get_node_type() != Json.NodeType.OBJECT)
{
game_info_updating = false;
return;
}
var root = root_node.get_object();
if(root == null) return;
if(root == null)
{
game_info_updating = false;
return;
}
var products = root.get_array_member("subproducts");
if(products == null) return;
if(products == null)
{
game_info_updating = false;
return;
}
foreach(var product_node in products.get_elements())
{
if(product_node.get_object().get_string_member("machine_name") != id) continue;
Expand All @@ -216,10 +236,18 @@ namespace GameHub.Data.Sources.Humble
}

var product_node = Parser.parse_json(info);
if(product_node == null || product_node.get_node_type() != Json.NodeType.OBJECT) return;
if(product_node == null || product_node.get_node_type() != Json.NodeType.OBJECT)
{
game_info_updating = false;
return;
}

var product = product_node.get_object();
if(product == null) return;
if(product == null)
{
game_info_updating = false;
return;
}

if(product.has_member("description-text"))
{
Expand All @@ -235,6 +263,7 @@ namespace GameHub.Data.Sources.Humble
update_status();

game_info_updated = true;
game_info_updating = false;
}

private async void update_installers()
Expand Down
17 changes: 15 additions & 2 deletions src/data/sources/steam/SteamGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace GameHub.Data.Sources.Steam
{
private int metadata_tries = 0;

private bool game_info_updating = false;
private bool game_info_updated = false;

public bool is_updating { get; set; default = false; }
Expand Down Expand Up @@ -103,6 +104,9 @@ namespace GameHub.Data.Sources.Steam

public override async void update_game_info()
{
if(game_info_updating) return;
game_info_updating = true;

update_status();

if(image == null || image == "")
Expand All @@ -128,7 +132,11 @@ namespace GameHub.Data.Sources.Steam
Steam.find_app_install_dir(id, out dir);
install_dir = dir;

if(game_info_updated) return;
if(game_info_updated)
{
game_info_updating = false;
return;
}

if(info_detailed == null || info_detailed.length == 0)
{
Expand All @@ -152,6 +160,7 @@ namespace GameHub.Data.Sources.Steam
debug("[SteamGame] %s: no app data for '%s', store page does not exist", id, name);
}
game_info_updated = true;
game_info_updating = false;
return;
}

Expand All @@ -167,6 +176,7 @@ namespace GameHub.Data.Sources.Steam
if(metadata_tries > 0)
{
game_info_updated = true;
game_info_updating = false;
return;
}
}
Expand All @@ -187,6 +197,7 @@ namespace GameHub.Data.Sources.Steam
platforms.add(Platform.WINDOWS);
save();
game_info_updated = true;
game_info_updating = false;
return;
}

Expand All @@ -200,8 +211,10 @@ namespace GameHub.Data.Sources.Steam

save();

game_info_updated = true;
update_status();

game_info_updated = true;
game_info_updating = false;
}

public override void update_status()
Expand Down
1 change: 1 addition & 0 deletions src/data/sources/user/UserGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ namespace GameHub.Data.Sources.User
var i = Parser.parse_json(info).get_object();
installer = new Installer(this, File.new_for_path(i.get_string_member("installer")));
}

save();
}

Expand Down

0 comments on commit 7a4f9e1

Please sign in to comment.