Skip to content

Commit

Permalink
Parse appinfo.vdf to find Proton versions (tkashkin#292, tkashkin#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkashkin authored and hagabaka committed Aug 23, 2019
1 parent 94ff468 commit 34b3c90
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 28 deletions.
14 changes: 7 additions & 7 deletions src/app.vala
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,13 @@ namespace GameHub
Providers.ImageProviders = { new Providers.Images.SteamGridDB(), new Providers.Images.JinxSGVI() };
Providers.DataProviders = { new Providers.Data.IGDB() };

CompatTool[] tools = { new Compat.WineWrap(), new Compat.Innoextract(), new Compat.DOSBox(), new Compat.ScummVM() };
foreach(var appid in Compat.Proton.APPIDS)
{
tools += new Compat.Proton(appid);
}
var proton_latest = new Compat.Proton(Compat.Proton.LATEST);

CompatTools = tools;
CompatTools = { new Compat.WineWrap(), new Compat.Innoextract(), new Compat.DOSBox(), new Compat.ScummVM(), proton_latest };

tools += new Compat.Proton(Compat.Proton.LATEST);
Compat.Proton.find_proton_versions();

CompatTool[] tools = CompatTools;

string[] wine_binaries = { "wine"/*, "wine64", "wine32"*/ };
string[] wine_arches = { "win64", "win32" };
Expand All @@ -173,6 +171,8 @@ namespace GameHub

CompatTools = tools;

proton_latest.init();

IconTheme.get_default().add_resource_path("/com/github/tkashkin/gamehub/icons");

screen = Screen.get_default();
Expand Down
88 changes: 79 additions & 9 deletions src/data/compat/Proton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,31 @@ You should have received a copy of the GNU General Public License
along with GameHub. If not, see <https://www.gnu.org/licenses/>.
*/

using GameHub.Utils;
using Gee;

using GameHub.Data.Sources.Steam;
using GameHub.Utils;

namespace GameHub.Data.Compat
{
public class Proton: Wine
{
public const string[] APPIDS = {"1054830", "996510", "961940", "930400", "858280"}; // 4.2, 3.16 Beta, 3.16, 3.7 Beta, 3.7
public const string LATEST = "latest";

public string appid { get; construct; }
public string appid { get; construct set; }
public string? appname { get; construct set; }

public bool is_latest { get; construct set; default = false; }

public Proton(string appid)
public Proton(string appid, string? appname=null)
{
Object(appid: appid, binary: "", arch: "");
Object(appid: appid, appname: appname, is_latest: appid == LATEST, binary: "", arch: "");
}

construct
{
id = @"proton_$(appid)";
name = "Proton";
name = appname ?? "Proton";
icon = "source-steam-symbolic";
installed = false;

Expand All @@ -64,8 +67,17 @@ namespace GameHub.Data.Compat
new CompatTool.BoolOption("/NOGUI", _("No GUI"), false)
};

if(appid == Proton.LATEST)
if(!is_latest)
{
init();
}
}

public void init()
{
if(is_latest)
{
name = "Proton (latest)";
foreach(var tool in CompatTools)
{
if(tool is Proton)
Expand All @@ -74,7 +86,6 @@ namespace GameHub.Data.Compat
if(proton.installed)
{
appid = proton.appid;
name = "Proton (latest)";
executable = proton.executable;
installed = true;
wine_binary = proton.wine_binary;
Expand All @@ -90,12 +101,16 @@ namespace GameHub.Data.Compat
{
if(proton_dir != null)
{
name = proton_dir.get_basename();
name = appname ?? proton_dir.get_basename();
executable = proton_dir.get_child("proton");
installed = executable.query_exists();
wine_binary = proton_dir.get_child("dist/bin/wine");
}
}
else
{
name = appname ?? "Proton";
}
}

if(installed)
Expand Down Expand Up @@ -228,5 +243,60 @@ namespace GameHub.Data.Compat
yield Utils.run_thread({ executable.get_path(), "run", cmd.get_path() }, runnable.install_dir.get_path(), prepare_env(runnable), false, true);
}
}

public void install_app()
{
if(!is_latest && !installed)
{
Steam.install_app(appid);
}
}

public static void find_proton_versions()
{
if(Steam.instance == null) return;

Steam.instance.load_appinfo();

if(Steam.instance.appinfo == null) return;

ArrayList<Proton> versions = new ArrayList<Proton>();

foreach(var app_node in Steam.instance.appinfo.nodes.values)
{
if(app_node != null && app_node is BinaryVDF.ListNode)
{
var app = (BinaryVDF.ListNode) app_node;
var common = (BinaryVDF.ListNode) app.get_nested({"appinfo", "common"});

if(common != null)
{
var name = ((BinaryVDF.StringNode) common.get("name")).value;
var type = ((BinaryVDF.StringNode) common.get("type")).value;

if(type.down() == "tool" && name.down().has_prefix("proton "))
{
versions.add(new Proton(app.key, name));
}
}
}
}

if(versions.size > 0)
{
versions.sort((first, second) => {
return int.parse(second.appid) - int.parse(first.appid);
});

CompatTool[] tools = CompatTools;

foreach(var proton in versions)
{
tools += proton;
}

CompatTools = tools;
}
}
}
}
24 changes: 20 additions & 4 deletions src/data/sources/steam/Steam.vala
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ namespace GameHub.Data.Sources.Steam

private bool? installed = null;

private BinaryVDF.ListNode? appinfo;
private BinaryVDF.ListNode? packageinfo;
public BinaryVDF.ListNode? appinfo;
public BinaryVDF.ListNode? packageinfo;

public bool is_authenticated_in_steam_client
{
Expand Down Expand Up @@ -200,6 +200,18 @@ namespace GameHub.Data.Sources.Steam
return Settings.Auth.Steam.instance.authenticated && is_authenticated_in_steam_client;
}

public void load_appinfo()
{
if(appinfo == null)
{
appinfo = new AppInfoVDF(FSUtils.find_case_insensitive(FSUtils.file(FSUtils.Paths.Steam.Home), FSUtils.Paths.Steam.AppInfoVDF)).read();
}
if(packageinfo == null)
{
packageinfo = new PackageInfoVDF(FSUtils.find_case_insensitive(FSUtils.file(FSUtils.Paths.Steam.Home), FSUtils.Paths.Steam.PackageInfoVDF)).read();
}
}

private ArrayList<Game> _games = new ArrayList<Game>(Game.is_equal);

public override ArrayList<Game> games { get { return _games; } }
Expand All @@ -216,8 +228,7 @@ namespace GameHub.Data.Sources.Steam
Utils.thread("SteamLoading", () => {
_games.clear();

appinfo = new AppInfoVDF(FSUtils.find_case_insensitive(FSUtils.file(FSUtils.Paths.Steam.Home), FSUtils.Paths.Steam.AppInfoVDF)).read();
packageinfo = new PackageInfoVDF(FSUtils.find_case_insensitive(FSUtils.file(FSUtils.Paths.Steam.Home), FSUtils.Paths.Steam.PackageInfoVDF)).read();
load_appinfo();

var cached = Tables.Games.get_all(this);
games_count = 0;
Expand Down Expand Up @@ -313,6 +324,11 @@ namespace GameHub.Data.Sources.Steam
return pkgs;
}

public static void install_app(string appid)
{
Utils.open_uri(@"steam://install/$(appid)");
}

public static void install_multiple_apps(string[] appids)
{
if(instance.packageinfo == null) return;
Expand Down
2 changes: 1 addition & 1 deletion src/data/sources/steam/SteamGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ namespace GameHub.Data.Sources.Steam

public override async void install(Runnable.Installer.InstallMode install_mode=Runnable.Installer.InstallMode.INTERACTIVE)
{
Utils.open_uri(@"steam://install/$(id)");
Steam.install_app(id);
update_status();
}

Expand Down
Loading

0 comments on commit 34b3c90

Please sign in to comment.