Skip to content

Commit

Permalink
Custom emulator support (tkashkin#103)
Browse files Browse the repository at this point in the history
Download only mode (tkashkin#107)
  • Loading branch information
tkashkin committed Oct 26, 2018
1 parent 226fc5c commit 4150ba2
Show file tree
Hide file tree
Showing 28 changed files with 1,410 additions and 416 deletions.
8 changes: 7 additions & 1 deletion data/GameHub.css
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,14 @@ button.file label
padding: 0 2px;
}

checkbutton, checkbutton check
checkbutton:not(.default-padding), checkbutton:not(.default-padding) check
{
padding: 0;
margin: 0;
}

dialog .sidebar,
dialog .sidebar list
{
background: transparent;
}
2 changes: 1 addition & 1 deletion src/app.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace GameHub

GameSources = { new Steam(), new GOG(), new Humble(), new Trove(), new User() };

CompatTool[] tools = { new Compat.CustomScript(), new Compat.Innoextract(), new Compat.DOSBox(), new Compat.RetroArch() };
CompatTool[] tools = { new Compat.CustomScript(), new Compat.CustomEmulator(), new Compat.Innoextract(), new Compat.DOSBox(), new Compat.RetroArch() };
foreach(var appid in Compat.Proton.APPIDS)
{
tools += new Compat.Proton(appid);
Expand Down
12 changes: 7 additions & 5 deletions src/data/CompatTool.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ namespace GameHub.Data
public Action[]? actions = null;

public virtual bool can_install(Game game) { return false; }
public virtual bool can_run(Game game) { return false; }
public virtual bool can_run(Runnable game) { return false; }

public virtual File get_install_root(Game game) { return game.install_dir; }
public virtual File get_install_root(Runnable game) { return game.install_dir; }

public virtual async void install(Game game, File installer){}
public virtual async void run(Game game){}
public virtual async void run(Runnable game){}
public virtual async void run_emulator(Emulator emu, Game game){}

public abstract class Option: Object
{
Expand Down Expand Up @@ -89,7 +90,7 @@ namespace GameHub.Data

public class Action: Object
{
public delegate void Delegate(Game game);
public delegate void Delegate(Runnable game);
public string name { get; construct; }
public string description { get; construct; }
private Delegate action;
Expand All @@ -98,11 +99,12 @@ namespace GameHub.Data
Object(name: name, description: description);
this.action = (owned) action;
}
public void invoke(Game game)
public void invoke(Runnable game)
{
action(game);
}
}
}

public static CompatTool[] CompatTools;
}
167 changes: 167 additions & 0 deletions src/data/Emulator.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
This file is part of GameHub.
Copyright (C) 2018 Anatoliy Kashkin
GameHub is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GameHub is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GameHub. If not, see <https://www.gnu.org/licenses/>.
*/

using Gee;
using GameHub.Data.DB;
using GameHub.Utils;

namespace GameHub.Data
{
public class Emulator: Runnable
{
private bool is_removed = false;
public signal void removed();

public Emulator.empty(){}

public Emulator(string name, File exec, string args, string? compat=null)
{
this.name = name;

executable = exec;
arguments = args;

compat_tool = compat;
force_compat = compat != null;

update_status();
}

public Emulator.from_db(Sqlite.Statement s)
{
id = Tables.Emulators.ID.get(s);
name = Tables.Emulators.NAME.get(s);
install_dir = FSUtils.file(Tables.Emulators.INSTALL_PATH.get(s));
executable = FSUtils.file(Tables.Emulators.EXECUTABLE.get(s));
compat_tool = Tables.Emulators.COMPAT_TOOL.get(s);
compat_tool_settings = Tables.Emulators.COMPAT_TOOL_SETTINGS.get(s);
arguments = Tables.Emulators.ARGUMENTS.get(s);

update_status();
}

public void remove()
{
is_removed = true;
Tables.Emulators.remove(this);
removed();
}

public override void save()
{
update_status();

if(is_removed || name == null || executable == null) return;

Tables.Emulators.add(this);
}

public override void update_status()
{
if(is_removed || name == null || executable == null) return;

id = Utils.md5(name);

platforms.clear();
platforms.add(Platform.LINUX);

install_dir = executable.get_parent();
}

public string[] get_args(Game? game=null, File? exec=null)
{
string[] result_args = {};

if(exec != null)
{
result_args += exec.get_path();
}

if(arguments != null && arguments.length > 0)
{
var variables = new HashMap<string, string>();
variables.set("emu", name.replace(": ", " - ").replace(":", ""));
variables.set("emu_dir", install_dir.get_path());
variables.set("game", game.name.replace(": ", " - ").replace(":", ""));
variables.set("file", game.executable.get_path());
variables.set("game_dir", game.install_dir.get_path());
var args = arguments.split(" ");
foreach(var arg in args)
{
if(game != null && arg == "$game_args")
{
var game_args = game.arguments.split(" ");
foreach(var game_arg in game_args)
{
result_args += game_arg;
}
continue;
}
if("$" in arg)
{
arg = FSUtils.expand(arg, null, variables);
}
result_args += arg;
}
}

return result_args;
}

public override async void run()
{
if(!RunnableIsLaunched && executable.query_exists())
{
RunnableIsLaunched = true;

yield Utils.run_thread(get_args(null, executable), executable.get_parent().get_path(), null, true);

RunnableIsLaunched = false;
}
}

public async void run_game(Game game)
{
if(use_compat)
{
yield run_game_compat(game);
return;
}

if(executable.query_exists() && game.executable.query_exists())
{
yield Utils.run_thread(get_args(game, executable), executable.get_parent().get_path(), null, true);
}
}

public async void run_game_compat(Game game)
{
new UI.Dialogs.CompatRunDialog(this, false, game);
}

public static bool is_equal(Emulator first, Emulator second)
{
return first == second || first.id == second.id;
}

public static uint hash(Emulator emu)
{
return str_hash(emu.id);
}
}
}
Loading

0 comments on commit 4150ba2

Please sign in to comment.