Skip to content

Commit

Permalink
Fix custom compat emulator (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucki authored Dec 4, 2021
1 parent 24656fe commit 27fbdce
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
53 changes: 52 additions & 1 deletion src/data/Emulator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,58 @@ namespace GameHub.Data
public signal void removed();

public override File? executable { owned get; set; }
public override File? work_dir { owned get; set; }
// public override File? work_dir { owned get; set; }
public string? work_dir_path;
public override File? work_dir
{
owned get
{
if(install_dir == null) return null;
if(work_dir_path == null || work_dir_path.length == 0) return install_dir;
return get_file(work_dir_path);
}
set
{
if(value != null && value.query_exists() && install_dir != null && install_dir.query_exists())
{
File[] dirs = { install_dir };
foreach(var dir in dirs)
{
if(value.get_path().has_prefix(dir.get_path()))
{
work_dir_path = value.get_path().replace(dir.get_path(), "$game_dir/");
break;
}
}
}
else
{
work_dir_path = null;
}
save();
}
}
public File? get_file(string? p)
{
if(p == null || p.length == 0 || install_dir == null) return null;
var path = p;
if(!path.has_prefix("$game_dir/") && !path.has_prefix("/"))
{
path = "$game_dir/" + path;
}
File[] dirs = { install_dir };
var variables = new HashMap<string, string>();
foreach(var dir in dirs)
{
variables.set("game_dir", dir.get_path());
var file = FSUtils.file(path, null, variables);
if(file != null && file.query_exists())
{
return file;
}
}
return null;
}
public Installer? installer;

public string? game_executable_pattern { get; set; }
Expand Down
16 changes: 12 additions & 4 deletions src/ui/dialogs/CompatRunDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,21 @@ namespace GameHub.UI.Dialogs

if(game is Emulator)
{
emulated_game.is_running = true;
emulated_game.update_status();
if(emulated_game != null)
{
emulated_game.is_running = true;
emulated_game.update_status();
}

compat_tool_picker.selected.run_emulator.begin(game as Emulator, emulated_game, launch_in_game_dir, (obj, res) => {
compat_tool_picker.selected.run_emulator.end(res);
Timeout.add_seconds(1, () => {
Runnable.IsLaunched = game.is_running = emulated_game.is_running = false;
emulated_game.update_status();
Runnable.IsLaunched = game.is_running = false;
if(emulated_game != null)
{
emulated_game.update_status();
emulated_game.is_running = false;
}
return Source.REMOVE;
});
destroy();
Expand Down

0 comments on commit 27fbdce

Please sign in to comment.