Skip to content

Commit

Permalink
Save version of used installer (GOG only) (tkashkin#148)
Browse files Browse the repository at this point in the history
Show updates indicator for updated GOG games (tkashkin#78)


Former-commit-id: b479cbd
  • Loading branch information
tkashkin committed Dec 2, 2018
1 parent 145ca77 commit 355e277
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 8 deletions.
3 changes: 3 additions & 0 deletions data/icons/icons.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<file alias="scalable/actions/gh-tag-favorites-symbolic.svg">symbolic/tags/tag-favorites.svg</file>
<file alias="scalable/actions/gh-tag-hidden-symbolic.svg">symbolic/tags/tag-hidden.svg</file>

<file alias="scalable/actions/gh-game-favorite-symbolic.svg">symbolic/game-favorite.svg</file>
<file alias="scalable/actions/gh-game-updated-symbolic.svg">symbolic/game-updated.svg</file>

<file alias="scalable/actions/controller-button-a.svg">normal/controller/a.svg</file>
<file alias="scalable/actions/controller-button-b.svg">normal/controller/b.svg</file>
<file alias="scalable/actions/controller-button-x.svg">normal/controller/x.svg</file>
Expand Down
4 changes: 4 additions & 0 deletions data/icons/symbolic/game-favorite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions data/icons/symbolic/game-updated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/data/Emulator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ namespace GameHub.Data
public class Installer: Runnable.Installer
{
private string emu_name;
public override string name { get { return emu_name; } }
public override string name { owned get { return emu_name; } }

public Installer(Emulator emu, File installer)
{
Expand Down
41 changes: 41 additions & 0 deletions src/data/Game.vala
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,47 @@ namespace GameHub.Data

public virtual async void update_game_info(){}

protected void update_version()
{
if(install_dir == null || !install_dir.query_exists()) return;

var file = install_dir.get_child(FSUtils.GAMEHUB_DIR).get_child("version");
if(file != null && file.query_exists())
{
try
{
string ver;
FileUtils.get_contents(file.get_path(), out ver);
version = ver;
}
catch(Error e)
{
warning("[Game.update_version] Error while reading version: %s", e.message);
}
}
}

public void save_version(string ver)
{
version = ver;

if(install_dir == null || !install_dir.query_exists()) return;

var file = install_dir.get_child(FSUtils.GAMEHUB_DIR).get_child("version");
if(file != null)
{
try
{
FSUtils.mkdir(file.get_parent().get_path());
FileUtils.set_contents(file.get_path(), ver);
}
catch(Error e)
{
warning("[Game.update_version] Error while reading version: %s", e.message);
}
}
}

protected Game.Status _status = new Game.Status(Game.State.UNINSTALLED, null, null);
public signal void status_change(Game.Status status);
public signal void tags_update();
Expand Down
8 changes: 7 additions & 1 deletion src/data/Runnable.vala
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,9 @@ namespace GameHub.Data
public Platform platform { get; protected set; default = CurrentPlatform; }
public ArrayList<Part> parts { get; protected set; default = new ArrayList<Part>(); }
public int64 full_size { get; protected set; default = 0; }
public string? version { get; protected set; }

public virtual string name { get { return id; } }
public virtual string name { owned get { return id; } }

public async void install(Runnable runnable, bool dl_only, CompatTool? tool=null)
{
Expand Down Expand Up @@ -479,6 +480,11 @@ namespace GameHub.Data
{
runnable.choose_executable();
}

if(game != null && version != null)
{
game.save_version(version);
}
}
catch(IOError.CANCELLED e){}
catch(Error e)
Expand Down
8 changes: 8 additions & 0 deletions src/data/sources/gog/GOG.vala
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ namespace GameHub.Data.Sources.GOG
Idle.add(() => { game_loaded(game, false); return Source.REMOVE; });
}
}

var g_index = _games.index_of(game);
if(g_index >= 0 && g_index < _games.size)
{
var go = g.get_object();
((GOGGame) _games.get(g_index)).has_updates = go.has_member("updates") && go.get_int_member("updates") > 0;
}

if(is_new_game) games_count++;
}

Expand Down
11 changes: 10 additions & 1 deletion src/data/sources/gog/GOGGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace GameHub.Data.Sources.GOG

public File? bonus_content_dir { get; protected set; default = null; }

public bool has_updates { get; set; default = false; }

private bool game_info_updated = false;

public GOGGame.default(){}
Expand Down Expand Up @@ -73,6 +75,8 @@ namespace GameHub.Data.Sources.GOG
}
}

has_updates = json_obj.has_member("updates") && json_obj.get_int_member("updates") > 0;

install_dir = FSUtils.file(FSUtils.Paths.GOG.Games, escaped_name);
executable_path = "$game_dir/start.sh";
update_status();
Expand Down Expand Up @@ -378,6 +382,10 @@ namespace GameHub.Data.Sources.GOG
warning("[GOGGame.update_status] Error while reading gameinfo: %s", e.message);
}
}
else
{
update_version();
}

string g = name;
string? d = null;
Expand Down Expand Up @@ -490,7 +498,7 @@ namespace GameHub.Data.Sources.GOG
public string lang;
public string lang_full;

public override string name { get { return lang_full; } }
public override string name { owned get { return lang_full + (version != null ? " (" + version + ")" : ""); } }

public Installer(GOGGame game, Json.Object json)
{
Expand All @@ -510,6 +518,7 @@ namespace GameHub.Data.Sources.GOG
}

full_size = json.get_int_member("total_size");
version = json.get_string_member("version");

if(!json.has_member("files") || json.get_member("files").get_node_type() != Json.NodeType.ARRAY) return;

Expand Down
4 changes: 3 additions & 1 deletion src/data/sources/humble/HumbleGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ namespace GameHub.Data.Sources.Humble
}

installers_dir = FSUtils.file(FSUtils.Paths.Collection.Humble.expand_installers(name));

update_version();
}

public override async void update_game_info()
Expand Down Expand Up @@ -314,7 +316,7 @@ namespace GameHub.Data.Sources.Humble
public string? dl_id;
public Runnable.Installer.Part part;

public override string name { get { return dl_name; } }
public override string name { owned get { return dl_name; } }

public Installer(HumbleGame game, string machine_name, string? download_identifier, Platform platform, Json.Object download)
{
Expand Down
2 changes: 1 addition & 1 deletion src/data/sources/user/UserGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace GameHub.Data.Sources.User
public class Installer: Runnable.Installer
{
private string game_name;
public override string name { get { return game_name; } }
public override string name { owned get { return game_name; } }

public Installer(UserGame game, File installer)
{
Expand Down
32 changes: 31 additions & 1 deletion src/ui/views/GamesView/GameCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ namespace GameHub.UI.Views.GamesView
private Box src_icons;
private Image src_icon;

private Image favorite_icon;
private Image updated_icon;

private Box platform_icons;

private Box actions;
Expand Down Expand Up @@ -94,6 +97,18 @@ namespace GameHub.UI.Views.GamesView
label.lines = 3;
label.set_line_wrap(true);

favorite_icon = new Image.from_icon_name("gh-game-favorite-symbolic", IconSize.BUTTON);
favorite_icon.valign = Align.END;
favorite_icon.halign = Align.START;
favorite_icon.margin = 6;

updated_icon = new Image.from_icon_name("gh-game-updated-symbolic", IconSize.BUTTON);
updated_icon.valign = Align.END;
updated_icon.halign = Align.END;
updated_icon.margin = 6;

favorite_icon.pixel_size = updated_icon.pixel_size = 12;

status_label = new Label("");
status_label.get_style_context().add_class("status");
status_label.xpad = 8;
Expand Down Expand Up @@ -128,6 +143,8 @@ namespace GameHub.UI.Views.GamesView
content.add_overlay(info);
content.add_overlay(platform_icons);
content.add_overlay(src_icons);
content.add_overlay(favorite_icon);
content.add_overlay(updated_icon);
content.add_overlay(progress_bar);
content.add_overlay(running_indicator);

Expand Down Expand Up @@ -186,8 +203,9 @@ namespace GameHub.UI.Views.GamesView

game.status_change.connect(s => {
Idle.add(() => {
label.label = (game.has_tag(Tables.Tags.BUILTIN_FAVORITES) ? "" : "") + game.name;
label.label = game.name;
status_label.label = s.description;
favorite_icon.visible = game.has_tag(Tables.Tags.BUILTIN_FAVORITES);
switch(s.state)
{
case Game.State.UNINSTALLED:
Expand Down Expand Up @@ -240,6 +258,18 @@ namespace GameHub.UI.Views.GamesView
});
game.notify_property("image");

updated_icon.visible = false;
if(game is GameHub.Data.Sources.GOG.GOGGame)
{
game.notify["has-updates"].connect(() => {
Idle.add(() => {
updated_icon.visible = (game as GameHub.Data.Sources.GOG.GOGGame).has_updates;
return Source.REMOVE;
});
});
game.notify_property("has-updates");
}

Settings.UI.get_instance().notify["show-grid-icons"].connect(update);
}

Expand Down
29 changes: 27 additions & 2 deletions src/ui/views/GamesView/GameListRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,35 @@ namespace GameHub.UI.Views.GamesView

hbox.add(image);

var label_hbox = new Box(Orientation.HORIZONTAL, 4);

var favorite_icon = new Image.from_icon_name("gh-game-favorite-symbolic", IconSize.BUTTON);
var updated_icon = new Image.from_icon_name("gh-game-updated-symbolic", IconSize.BUTTON);
favorite_icon.margin_top = updated_icon.margin_top = 2;
favorite_icon.valign = updated_icon.valign = Align.CENTER;
favorite_icon.pixel_size = updated_icon.pixel_size = 8;

var label = new Label(game.name);
label.halign = Align.START;
label.get_style_context().add_class("category-label");

label_hbox.add(favorite_icon);
label_hbox.add(updated_icon);
label_hbox.add(label);

state_label = new Label(null);
state_label.halign = Align.START;

vbox.add(label);
vbox.add(label_hbox);
vbox.add(state_label);

hbox.add(vbox);

game.status_change.connect(s => {
Idle.add(() => {
label.label = (game.has_tag(Tables.Tags.BUILTIN_FAVORITES) ? "" : "") + game.name;
label.label = game.name;
state_label.label = s.description;
favorite_icon.visible = game.has_tag(Tables.Tags.BUILTIN_FAVORITES);
update_icon();
changed();
return Source.REMOVE;
Expand Down Expand Up @@ -101,6 +114,18 @@ namespace GameHub.UI.Views.GamesView
});

show_all();

updated_icon.visible = false;
if(game is GameHub.Data.Sources.GOG.GOGGame)
{
game.notify["has-updates"].connect(() => {
Idle.add(() => {
updated_icon.visible = (game as GameHub.Data.Sources.GOG.GOGGame).has_updates;
return Source.REMOVE;
});
});
game.notify_property("has-updates");
}
}

public override void show_all()
Expand Down

0 comments on commit 355e277

Please sign in to comment.