Skip to content

Commit

Permalink
UI improvements
Browse files Browse the repository at this point in the history
Reenabled game installation, saving and running
  • Loading branch information
tkashkin committed Aug 11, 2020
1 parent 86e59c3 commit 86788a0
Show file tree
Hide file tree
Showing 31 changed files with 227 additions and 171 deletions.
2 changes: 1 addition & 1 deletion data/share/tweaks/overlays/mangohud.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"MANGOHUD_CONFIG": "${option:read_cfg},${option:hud},${option:media_player},${option:vsync},${option:gl_vsync},${option:position},${option:fps_limit}"
},
"options": {
"general": {
"hud": {
"name": "HUD elements",
"description": "Select HUD elements to show",
"type": "list",
Expand Down
13 changes: 12 additions & 1 deletion res/styles/common/widgets/settings/SettingsGroup.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
.settings-group
{
padding: 8px;
}
.settings-group-standalone-title
{
margin-top: 8px;
margin-left: 8px;
margin-right: 8px;
}

.settings-dialog .settings-group
{
padding: 12px 18px;
}
Expand All @@ -9,7 +20,7 @@
font-weight: bold;
margin-bottom: 6px;
}
.settings-group-standalone-title
.settings-dialog .settings-group-standalone-title
{
margin-top: 12px;
margin-left: 18px;
Expand Down
4 changes: 2 additions & 2 deletions src/data/compat/CustomScript.vala
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace GameHub.Data.Compat
});*/

runnable.cast<Traits.Game.SupportsTweaks>(game => {
task.tweaks(game.get_enabled_tweaks(this));
task.tweaks(game.tweaks, game, this);
});
yield task.sync_thread();
}
Expand All @@ -130,7 +130,7 @@ namespace GameHub.Data.Compat
var task = Utils.exec(cmd).dir(dir.get_path());
runnable.cast<Traits.Game.SupportsTweaks>(game => {
task.tweaks(game.get_enabled_tweaks(this));
task.tweaks(game.tweaks, game, this);
});
yield task.sync_thread();
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/compat/DOSBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ namespace GameHub.Data.Compat

var task = Utils.exec(combine_cmd_with_args(cmd, runnable)).dir(wdir.get_path());
runnable.cast<Traits.Game.SupportsTweaks>(game => {
task.tweaks(game.get_enabled_tweaks(this));
task.tweaks(game.tweaks, game, this);
});
yield task.sync_thread();
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/compat/Proton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace GameHub.Data.Compat
}
var task = Utils.exec(combine_cmd_with_args(cmd, runnable, args)).dir(dir.get_path()).env(prepare_env(runnable, parse_opts));
runnable.cast<Traits.Game.SupportsTweaks>(game => {
task.tweaks(game.get_enabled_tweaks(this));
task.tweaks(game.tweaks, game, this);
});
yield task.sync_thread();
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/compat/ScummVM.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace GameHub.Data.Compat

var task = Utils.exec(combine_cmd_with_args(cmd, runnable)).dir(dir.get_path());
runnable.cast<Traits.Game.SupportsTweaks>(game => {
task.tweaks(game.get_enabled_tweaks(this));
task.tweaks(game.tweaks, game, this);
});
yield task.sync_thread();
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/compat/Wine.vala
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace GameHub.Data.Compat
}
var task = Utils.exec(combine_cmd_with_args(cmd, runnable, args)).dir(dir.get_path()).env(prepare_env(runnable, parse_opts));
runnable.cast<Traits.Game.SupportsTweaks>(game => {
task.tweaks(game.get_enabled_tweaks(this));
task.tweaks(game.tweaks, game, this);
});
yield task.sync_thread();
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/compat/WineWrap.vala
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace GameHub.Data.Compat

var task = Utils.exec(combine_cmd_with_args(cmd, runnable)).dir(runnable.work_dir.get_path());
runnable.cast<Traits.Game.SupportsTweaks>(game => {
task.tweaks(game.get_enabled_tweaks(this));
task.tweaks(game.tweaks, game, this);
});
yield task.sync_thread();
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/runnables/Game.vala
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace GameHub.Data.Runnables

public override void save()
{
//Tables.Games.add(this);
Tables.Games.add(this);
}

public async void run_or_install(bool show_compat=false)
Expand Down
2 changes: 1 addition & 1 deletion src/data/runnables/Runnable.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace GameHub.Data.Runnables
// Run

public bool is_running { get; set; default = false; }
public virtual async void run(){ assert_not_reached(); }
public abstract async void run();

public bool can_be_launched_base(bool is_launch_attempt=false)
{
Expand Down
2 changes: 2 additions & 0 deletions src/data/runnables/tasks/install/InstallTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ namespace GameHub.Data.Runnables.Tasks.Install
runnable.save();
runnable.update_status();
}
info("[InstallTask.install] Starting installation of %s; installer: '%s'; install_dir: `%s`", runnable != null ? runnable.full_id : "(null)", selected_installer.id, install_dir.get_path());
yield selected_installer.install(this);
}

public void finish()
{
info("[InstallTask.finish] Finishing installation of %s", runnable != null ? runnable.full_id : "(null)");
if(runnable != null)
{
var gh_marker = install_dir.get_child(".gamehub_" + runnable.id);
Expand Down
14 changes: 12 additions & 2 deletions src/data/runnables/tasks/install/Installer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace GameHub.Data.Runnables.Tasks.Install
if(file == null || !file.query_exists()) return false;
var type = installer_type ?? yield InstallerType.guess(file, can_be_data);

debug("[FileInstaller.install_file] Installing file: `%s`; installer_type: %s", file.get_path(), installer_type.to_string());

var file_path = file.get_path();
var install_dir_path = task.install_dir.get_path();

Expand Down Expand Up @@ -90,6 +92,8 @@ namespace GameHub.Data.Runnables.Tasks.Install
break;
}

FileUtils.chmod(file_path, 0755);

if(cmd != null)
{
try
Expand All @@ -98,7 +102,7 @@ namespace GameHub.Data.Runnables.Tasks.Install
}
catch(Error e)
{
warning("[FileInstaller.install_file] %s", e.message);
warning("[FileInstaller.install_file] Exec error: %s", e.message);
}
return false;
}
Expand Down Expand Up @@ -149,6 +153,8 @@ namespace GameHub.Data.Runnables.Tasks.Install
{
var files = yield download(task);

debug("[DownloadableInstaller.install] .download() returned %d files", files.size);

task.status = new InstallTask.Status();

if(files.size == 0) return false;
Expand Down Expand Up @@ -208,6 +214,9 @@ namespace GameHub.Data.Runnables.Tasks.Install
try
{
task.status = new InstallTask.Status(InstallTask.State.DOWNLOADING);
yield fetch_parts();

debug("[DownloadableInstaller.download] Starting (%d parts)", parts.size);

uint current_part = 1;
foreach(var part in parts)
Expand Down Expand Up @@ -242,6 +251,7 @@ namespace GameHub.Data.Runnables.Tasks.Install

if(part.checksum == null || file_checksum == null || part.checksum == file_checksum)
{
debug("[DownloadableInstaller.download] Downloaded `%s`; checksum: '%s' (matched)", file.get_path(), file_checksum != null ? file_checksum : "(null)");
files.add(file);
}
else
Expand Down Expand Up @@ -270,7 +280,7 @@ namespace GameHub.Data.Runnables.Tasks.Install
}
);

warning("Checksum mismatch in `%s`, skipping; expected: `%s`, actual: `%s`", file.get_basename(), part.checksum, file_checksum);
warning("Checksum mismatch in `%s`; expected: `%s`, actual: `%s`", file.get_basename(), part.checksum, file_checksum);
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/data/runnables/tasks/install/InstallerType.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ namespace GameHub.Data.Runnables.Tasks.Install
{
EXECUTABLE, WINDOWS_EXECUTABLE, ARCHIVE, WINDOWS_NSIS_INSTALLER, DATA;

public string to_string()
{
switch(this)
{
case EXECUTABLE: return "executable";
case WINDOWS_EXECUTABLE: return "windows_executable";
case ARCHIVE: return "archive";
case WINDOWS_NSIS_INSTALLER: return "windows_nsis_installer";
case DATA: return "data";
}
assert_not_reached();
}

public static InstallerType? from_mime(string? type)
{
if(type == null) return null;
Expand Down
4 changes: 3 additions & 1 deletion src/data/runnables/traits/HasExecutableFile.vala
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace GameHub.Data.Runnables.Traits
return can_be_launched_base(is_launch_attempt) && executable != null && executable.query_exists();
}

public virtual async void run()
protected async void run_executable()
{
if(!can_be_launched(true)) return;

Expand Down Expand Up @@ -188,6 +188,8 @@ namespace GameHub.Data.Runnables.Traits
var task = Utils.exec(full_cmd).override_runtime(true);
if(work_dir != null && work_dir.query_exists()) task.dir(work_dir.get_path());

cast<Traits.Game.SupportsTweaks>(game => task.tweaks(game.tweaks, game));

return task;
}
}
Expand Down
20 changes: 7 additions & 13 deletions src/data/runnables/traits/game/SupportsTweaks.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,20 @@ namespace GameHub.Data.Runnables.Traits.Game
{
public abstract TweakSet? tweaks { get; set; default = null; }

protected void dbinit_tweaks(Sqlite.Statement s)
protected void init_tweaks()
{
tweaks = new TweakSet.from_json(false, Parser.parse_json(Tables.Games.TWEAKS.get(s)));
tweaks = new TweakSet.from_json(false, null);
tweaks.changed.connect(() => {
save();
});
}

public Tweak[] get_enabled_tweaks(CompatTool? tool=null)
protected void dbinit_tweaks(Sqlite.Statement s)
{
Tweak[] enabled_tweaks = {};
var all_tweaks = Tweak.load_tweaks();
foreach(var tweak in all_tweaks.values)
{
if(tweaks.is_enabled(tweak.id) && tweak.is_applicable_to(this, tool))
{
enabled_tweaks += tweak;
}
}
return enabled_tweaks;
tweaks = new TweakSet.from_json(false, Parser.parse_json(Tables.Games.TWEAKS.get(s)));
tweaks.changed.connect(() => {
save();
});
}
}
}
15 changes: 10 additions & 5 deletions src/data/sources/gog/GOGGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ namespace GameHub.Data.Sources.GOG
has_updates = json_obj.has_member("updates") && json_obj.get_int_member("updates") > 0;

install_dir = null;
executable_path = "$game_dir/start.sh";
work_dir_path = "$game_dir";
executable_path = "${install_dir}/start.sh";
work_dir_path = "${install_dir}";

init_tweaks();

mount_overlays.begin();
update_status();
Expand Down Expand Up @@ -292,6 +294,8 @@ namespace GameHub.Data.Sources.GOG
return installers;
}

public override async void run(){ yield run_executable(); }

public override async void uninstall()
{
if(install_dir != null && install_dir.query_exists())
Expand Down Expand Up @@ -578,7 +582,7 @@ namespace GameHub.Data.Sources.GOG
g = ((DLC) this).game.name;
d = game.name;
}
//installers_dir = FS.file(FS.Paths.Collection.GOG.expand_installers(g, d, platform)) ?? game.installers_dir;
installers_dir = FS.file(Settings.Paths.Collection.GOG.expand_installers(g, d, platform));

full_size = json.get_int_member("total_size");
version = json.get_string_member("version");
Expand All @@ -602,6 +606,8 @@ namespace GameHub.Data.Sources.GOG
Utils.thread("GOGGame.Installer.fetch_part", () => {
loading_count++;

debug("[GOGGame.Installer.fetch_part] Trying to fetch part %s; downlink: '%s'", id, downlink_url);

var root_node = Parser.parse_remote_json_file(downlink_url, "GET", ((GOG) game.source).user_token);
if(root_node != null && root_node.get_node_type() == Json.NodeType.OBJECT)
{
Expand Down Expand Up @@ -638,8 +644,7 @@ namespace GameHub.Data.Sources.GOG
}

var local = installers_dir.get_child(local_filename ?? "gog_" + game.id + "_" + this.id + "_" + id);

//parts.add(new Runnable.DownloadableInstaller.Part(id, url, size, remote, local, hash, hash_type));
parts.add(new Part(id, url, size, remote, local, hash, hash_type));
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/data/sources/humble/HumbleGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ namespace GameHub.Data.Sources.Humble
}

install_dir = null;
executable_path = "$game_dir/start.sh";
work_dir_path = "$game_dir";
executable_path = "${install_dir}/start.sh";
work_dir_path = "${install_dir}";
info_detailed = @"{\"order\":\"$(order_id)\"}";

init_tweaks();

mount_overlays.begin();
update_status();
}
Expand Down Expand Up @@ -365,6 +367,8 @@ namespace GameHub.Data.Sources.Humble
return refresh;
}

public override async void run(){ yield run_executable(); }

public override async void uninstall()
{
if(install_dir != null && install_dir.query_exists())
Expand Down
4 changes: 4 additions & 0 deletions src/data/sources/user/UserGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ namespace GameHub.Data.Sources.User

((User) source).add_game(this);

init_tweaks();

mount_overlays.begin();
update_status();
}
Expand Down Expand Up @@ -129,6 +131,8 @@ namespace GameHub.Data.Sources.User
yield;*/
}

public override async void run(){ yield run_executable(); }

public override async void uninstall()
{
yield umount_overlays();
Expand Down
4 changes: 3 additions & 1 deletion src/data/tweaks/Tweak.vala
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,16 @@ namespace GameHub.Data.Tweaks
return tweaks;
}

public static HashMap<string?, HashMap<string, Tweak>>? load_tweaks_grouped(bool refresh=false)
public delegate bool TweakFilterPredicate(Tweak tweak);
public static HashMap<string?, HashMap<string, Tweak>>? load_tweaks_grouped(bool refresh = false, TweakFilterPredicate? filter = null)
{
var tweaks = load_tweaks(refresh);
if(tweaks == null || tweaks.size == 0) return null;

var groups = new HashMap<string?, HashMap<string, Tweak>>();
foreach(var tweak in tweaks.entries)
{
if(filter != null && !filter(tweak.value)) continue;
if(!groups.has_key(tweak.value.group))
{
groups[tweak.value.group] = new HashMap<string, Tweak>();
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ sources = [

'ui/dialogs/GamePropertiesDialog/GamePropertiesDialog.vala',
'ui/dialogs/GamePropertiesDialog/tabs/General.vala',
'ui/dialogs/GamePropertiesDialog/tabs/Executable.vala',
'ui/dialogs/GamePropertiesDialog/tabs/Tweaks.vala',
'ui/dialogs/GamePropertiesDialog/tabs/Overlays.vala',

Expand Down
Loading

0 comments on commit 86788a0

Please sign in to comment.