Skip to content

Commit

Permalink
Wine/Proton improvements
Browse files Browse the repository at this point in the history
Bugfixes for tkashkin#106
  • Loading branch information
tkashkin committed Nov 3, 2018
1 parent 0f374be commit f4a4847
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/data/CompatTool.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace GameHub.Data

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

public abstract class Option: Object
{
Expand Down
38 changes: 25 additions & 13 deletions src/data/Emulator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ namespace GameHub.Data

public Emulator.empty(){}

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

install_dir = dir;

executable = exec;
arguments = args;

Expand Down Expand Up @@ -81,8 +83,6 @@ namespace GameHub.Data

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

install_dir = executable.get_parent();
}

public override async void install()
Expand Down Expand Up @@ -125,18 +125,30 @@ namespace GameHub.Data
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());
if(game != null)
{
variables.set("game", game.name.replace(": ", " - ").replace(":", ""));
variables.set("file", game.executable.get_path());
variables.set("game_dir", game.install_dir.get_path());
}
else
{
variables.set("game", "");
variables.set("file", "");
variables.set("game_dir", "");
}
var args = arguments.split(" ");
foreach(var arg in args)
{
if(game != null && arg == "$game_args")
if(arg == "$game_args")
{
var game_args = game.arguments.split(" ");
foreach(var game_arg in game_args)
if(game != null)
{
result_args += game_arg;
var game_args = game.arguments.split(" ");
foreach(var game_arg in game_args)
{
result_args += game_arg;
}
}
continue;
}
Expand All @@ -163,21 +175,21 @@ namespace GameHub.Data
}
}

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

if(executable.query_exists() && game.executable.query_exists())
if(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)
public async void run_game_compat(Game? game)
{
new UI.Dialogs.CompatRunDialog(this, false, game);
}
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 @@ -91,15 +91,15 @@ GH_GAME_NAME_ESCAPED="${10}"
}
}

public override async void run_emulator(Emulator emu, Game game)
public override async void run_emulator(Emulator emu, Game? game)
{
var gh_dir = FSUtils.mkdir(emu.install_dir.get_path(), COMPAT_DATA_DIR);
var script = gh_dir.get_child(SCRIPT);
if(script.query_exists())
{
Utils.run({"chmod", "+x", script.get_path()});
var executable_path = emu.executable != null ? emu.executable.get_path() : "null";
var game_executable_path = game.executable != null ? game.executable.get_path() : "null";
var game_executable_path = game != null && game.executable != null ? game.executable.get_path() : "null";
string[] cmd = { script.get_path(), executable_path, emu.id, emu.name, game_executable_path, game.id, game.full_id, game.name, game.escaped_name };
yield Utils.run_thread(cmd, emu.install_dir.get_path());
}
Expand Down
44 changes: 43 additions & 1 deletion src/data/compat/Proton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ namespace GameHub.Data.Compat
}),
new CompatTool.Action("regedit", _("Run regedit"), r => {
wineutil.begin(null, r, "regedit");
}),
new CompatTool.Action("kill", _("Kill apps in prefix"), r => {
wineboot.begin(null, r, {"-k"});
})
};
}
Expand All @@ -90,7 +93,13 @@ namespace GameHub.Data.Compat

protected override File get_wineprefix(Runnable runnable)
{
return FSUtils.mkdir(runnable.install_dir.get_path(), @"$(COMPAT_DATA_DIR)/$(id)/pfx");
var prefix = FSUtils.mkdir(runnable.install_dir.get_path(), @"$(COMPAT_DATA_DIR)/$(id)/pfx");
var dosdevices = prefix.get_child("dosdevices");
if(dosdevices.get_child("c:").query_exists() && !dosdevices.get_child("d:").query_exists())
{
Utils.run({"ln", "-nsf", "../../../../", "d:"}, dosdevices.get_path());
}
return prefix;
}

protected override string[] prepare_env(Runnable runnable, bool parse_opts=true)
Expand Down Expand Up @@ -119,5 +128,38 @@ namespace GameHub.Data.Compat

return env;
}

protected override async void wineboot(File? wineprefix, Runnable runnable, string[]? args=null)
{
yield wineutil_proton(wineprefix, runnable, "wineboot", args);
}

protected async void wineutil_proton(File? wineprefix, Runnable runnable, string util="winecfg", string[]? args=null)
{
var env = prepare_env(runnable, false);
env = Environ.set_variable(env, "WINE", wine_binary.get_path());
env = Environ.set_variable(env, "WINEDLLOVERRIDES", "mshtml=d");
var prefix = wineprefix ?? get_wineprefix(runnable);
if(prefix != null && prefix.query_exists())
{
env = Environ.set_variable(env, "WINEPREFIX", prefix.get_path());
}
if(arch != null && arch.length > 0)
{
env = Environ.set_variable(env, "WINEARCH", arch);
}

string[] cmd = { executable.get_path(), "run", "wine", util };

if(args != null)
{
foreach(var arg in args)
{
cmd += arg;
}
}

yield Utils.run_thread(cmd, runnable.install_dir.get_path(), env);
}
}
}
36 changes: 31 additions & 5 deletions src/data/compat/Wine.vala
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ namespace GameHub.Data.Compat
}),
new CompatTool.Action("regedit", _("Run regedit"), r => {
wineutil.begin(null, r, "regedit");
}),
new CompatTool.Action("kill", _("Kill apps in prefix"), r => {
wineboot.begin(null, r, {"-k"});
})
};
}
}

public override bool can_install(Runnable runnable)
{
return installed && runnable != null && Platform.WINDOWS in runnable.platforms;
return can_run(runnable);
}

public override bool can_run(Runnable runnable)
Expand Down Expand Up @@ -108,16 +111,18 @@ namespace GameHub.Data.Compat
public override async void install(Runnable runnable, File installer)
{
if(!can_install(runnable) || (yield Runnable.Installer.guess_type(installer)) != Runnable.Installer.InstallerType.WINDOWS_EXECUTABLE) return;
yield wineboot(null, runnable);
yield exec(runnable, installer, installer.get_parent(), yield prepare_installer_args(runnable));
}

public override async void run(Runnable runnable)
{
if(!can_run(runnable)) return;
yield wineboot(null, runnable);
yield exec(runnable, runnable.executable, runnable.install_dir);
}

public override async void run_emulator(Emulator emu, Game runnable)
public override async void run_emulator(Emulator emu, Game? runnable)
{
if(!can_run(emu)) return;
yield exec(emu, emu.executable, emu.install_dir, emu.get_args(runnable));
Expand All @@ -135,7 +140,13 @@ namespace GameHub.Data.Compat

protected virtual File get_wineprefix(Runnable runnable)
{
return FSUtils.mkdir(runnable.install_dir.get_path(), @"$(COMPAT_DATA_DIR)/$(binary)_$(arch)");
var prefix = FSUtils.mkdir(runnable.install_dir.get_path(), @"$(COMPAT_DATA_DIR)/$(binary)_$(arch)");
var dosdevices = prefix.get_child("dosdevices");
if(dosdevices.get_child("c:").query_exists() && !dosdevices.get_child("d:").query_exists())
{
Utils.run({"ln", "-nsf", "../../../", "d:"}, dosdevices.get_path());
}
return prefix;
}

public override File get_install_root(Runnable runnable)
Expand All @@ -160,7 +171,12 @@ namespace GameHub.Data.Compat
return env;
}

protected async void wineutil(File? wineprefix, Runnable runnable, string util="winecfg")
protected virtual async void wineboot(File? wineprefix, Runnable runnable, string[]? args=null)
{
yield wineutil(wineprefix, runnable, "wineboot", args);
}

protected async void wineutil(File? wineprefix, Runnable runnable, string util="winecfg", string[]? args=null)
{
var env = Environ.get();
env = Environ.set_variable(env, "WINE", wine_binary.get_path());
Expand All @@ -175,7 +191,17 @@ namespace GameHub.Data.Compat
env = Environ.set_variable(env, "WINEARCH", arch);
}

yield Utils.run_thread({ wine_binary.get_path(), util }, runnable.install_dir.get_path(), env);
string[] cmd = { wine_binary.get_path(), util };

if(args != null)
{
foreach(var arg in args)
{
cmd += arg;
}
}

yield Utils.run_thread(cmd, runnable.install_dir.get_path(), env);
}

protected async void winetricks(File? wineprefix, Runnable runnable)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/CompatRunDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace GameHub.UI.Dialogs

RunnableIsLaunched = true;

if(game is Emulator && emulated_game != null)
if(game is Emulator)
{
compat_tool_picker.selected.run_emulator.begin(game as Emulator, emulated_game, (obj, res) => {
compat_tool_picker.selected.run_emulator.end(res);
Expand Down
1 change: 1 addition & 0 deletions src/ui/dialogs/InstallDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ namespace GameHub.UI.Dialogs
dl_only_check.visible = false;
import_btn.no_show_all = true;
import_btn.visible = false;
compat_tool_revealer.reveal_child = true;
}

if(compat_tool_revealer != null)
Expand Down
Loading

0 comments on commit f4a4847

Please sign in to comment.