Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Epic Games support #377

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions data/com.github.tkashkin.gamehub.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@
</key>
</schema>

<schema path="@SCHEMA_PATH@/auth/epicgames/" id="@SCHEMA_ID@.auth.epicgames">
<key name="enabled" type="b">
<default>true</default>
<summary>Is EpicGames enabled</summary>
</key>
<key name="authenticated" type="b">
<default>false</default>
<summary>Is user authenticated</summary>
</key>
<key name="sid" type="s">
<default>''</default>
<summary>EpicGames access sid</summary>
</key>
</schema>

<schema path="@SCHEMA_PATH@/auth/gog/" id="@SCHEMA_ID@.auth.gog">
<key name="enabled" type="b">
<default>true</default>
Expand Down Expand Up @@ -221,6 +236,14 @@
<default>'~/Games/itch'</default>
<summary>itch.io games directory</summary>
</key>
<key name="legendary-command" type="s">
<default>'legendary'</default>
<summary>Legendary client command</summary>
</key>
<key name="epic-games" type="s">
<default>'~/legendary'</default>
<summary>EpicGames games directory</summary>
</key>
</schema>

<!-- Paths / Collection -->
Expand Down
1 change: 1 addition & 0 deletions data/icons/icons.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<gresource prefix="/com/github/tkashkin/gamehub/icons">
<file alias="scalable/actions/sources-all-symbolic.svg">symbolic/sources/sources-all.svg</file>
<file alias="scalable/actions/source-steam-symbolic.svg">symbolic/sources/steam.svg</file>
<file alias="scalable/actions/source-epicgames-symbolic.svg">symbolic/sources/epicgames.svg</file>
<file alias="scalable/actions/source-gog-symbolic.svg">symbolic/sources/gog.svg</file>
<file alias="scalable/actions/source-humble-symbolic.svg">symbolic/sources/humble.svg</file>
<file alias="scalable/actions/source-humble-trove-symbolic.svg">symbolic/sources/humble-trove.svg</file>
Expand Down
30 changes: 30 additions & 0 deletions data/icons/symbolic/sources/epicgames.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/app.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ using Gee;
using GameHub.Data;
using GameHub.Data.DB;
using GameHub.Data.Sources.Steam;
using GameHub.Data.Sources.EpicGames;
using GameHub.Data.Sources.GOG;
using GameHub.Data.Sources.Humble;
using GameHub.Data.Sources.Itch;
Expand Down Expand Up @@ -141,7 +142,7 @@ namespace GameHub
ImageCache.init();
Database.create();

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

Providers.ImageProviders = { new Providers.Images.Steam(), new Providers.Images.SteamGridDB(), new Providers.Images.JinxSGVI() };
Providers.DataProviders = { new Providers.Data.IGDB() };
Expand Down
1 change: 1 addition & 0 deletions src/data/GameSource.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using Gee;
using GameHub.Utils;
using GameHub.Data.Sources.Steam;
using GameHub.Data.Sources.GOG;
using GameHub.Data.Sources.EpicGames;

namespace GameHub.Data
{
Expand Down
8 changes: 4 additions & 4 deletions src/data/Runnable.vala
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ namespace GameHub.Data

public abstract class Installer
{
public string id { get; protected set; }
public Platform platform { get; protected set; default = Platform.CURRENT; }
public int64 full_size { get; protected set; default = 0; }
public string? version { get; protected set; }
public string id { get; protected set; }
public Platform platform { get; protected set; default = Platform.CURRENT; }
public virtual int64 full_size { get; protected set; default = 0; }
public string? version { get; protected set; }

public virtual string name { owned get { return id; } }

Expand Down
9 changes: 9 additions & 0 deletions src/data/db/tables/Games.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using Sqlite;
using GameHub.Utils;

using GameHub.Data.Sources.Steam;
using GameHub.Data.Sources.EpicGames;
using GameHub.Data.Sources.GOG;
using GameHub.Data.Sources.Humble;
using GameHub.Data.Sources.Itch;
Expand Down Expand Up @@ -311,6 +312,10 @@ namespace GameHub.Data.DB.Tables
{
g = new SteamGame.from_db((Steam) s, st);
}
else if(s is EpicGames)
{
g = new EpicGamesGame.from_db((EpicGames) s, st);
}
else if(s is GOG)
{
g = new GOGGame.from_db((GOG) s, st);
Expand Down Expand Up @@ -396,6 +401,10 @@ namespace GameHub.Data.DB.Tables
{
g = new SteamGame.from_db((Steam) s, st);
}
else if(s is EpicGames)
{
g = new EpicGamesGame.from_db((EpicGames) s, st);
}
else if(s is GOG)
{
g = new GOGGame.from_db((GOG) s, st);
Expand Down
1 change: 1 addition & 0 deletions src/data/db/tables/IGDBData.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using GameHub.Utils;
using GameHub.Data.Sources.Steam;
using GameHub.Data.Sources.GOG;
using GameHub.Data.Sources.Humble;
using GameHub.Data.Sources.EpicGames;

namespace GameHub.Data.DB.Tables
{
Expand Down
1 change: 1 addition & 0 deletions src/data/db/tables/Tags.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using Sqlite;
using GameHub.Utils;

using GameHub.Data.Sources.Steam;
using GameHub.Data.Sources.EpicGames;
using GameHub.Data.Sources.GOG;
using GameHub.Data.Sources.Humble;

Expand Down
199 changes: 199 additions & 0 deletions src/data/sources/epicgames/EpicGames.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
This file is part of GameHub.
Copyright (C) 2018-2019 Anatoliy Kashkin
Copyright (C) 2020 Adam Jordanek

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.Sources.EpicGames
{
public class EpicGames: GameSource
{
public static EpicGames instance;

private bool? installed = null;
public File? legendary_executable = null;

public override string id { get { return "epicgames"; } }
public override string name { get { return "EpicGames"; } }
public override string icon { get { return "source-epicgames-symbolic"; } }

private Settings.Auth.EpicGames settings;
private FSUtils.Paths.Settings paths = FSUtils.Paths.Settings.instance;

public override bool enabled
{
get { return settings.enabled; }
set { settings.enabled = value; }
}


public LegendaryWrapper? legendary_wrapper { get; private set; }

public string? user_id { get; protected set; }
public string? user_name { get; protected set; }

public EpicGames()
{
instance = this;
legendary_wrapper = new LegendaryWrapper();
settings = Settings.Auth.EpicGames.instance;
}

public override bool is_installed(bool refresh)
{
/*
Epic games depends on
*/
if(installed != null && !refresh)
{
return (!) installed;
}

//check if legendary exists
var legendary = Utils.find_executable(paths.legendary_command);

if(legendary == null || !legendary.query_exists())
{
debug("[EpicGames] is_installed: Legendary not found");

}
else
{
debug("[EpicGames] is_installed: LegendaryYES");
}

legendary_executable = legendary;
installed = legendary_executable != null && legendary_executable.query_exists();

return (!) installed;
}

public override async bool install()
{
return true;
}

public override async bool authenticate()
{
debug("[EpicGames] Performing auth");
var username = yield legendary_wrapper.auth();
settings.authenticated = username != null;
if(username != null) {
user_name = username;
return true;
}else return false;
}

public override bool is_authenticated()
{
var result = legendary_wrapper.is_authenticated();
settings.authenticated = result;

if (result) {
legendary_wrapper.get_username.begin ((obj, res) => {
user_name = legendary_wrapper.get_username.end (res);
});
}

return result;
}

public override bool can_authenticate_automatically()
{
debug("[EpicGames] can_authenticate_automatically: NOT IMPLEMENTED");
return false;
}

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

public override ArrayList<Game> games { get { return _games; } }

public override async ArrayList<Game> load_games(Utils.FutureResult2<Game, bool>? game_loaded=null, Utils.Future? cache_loaded=null)
{
if(_games.size > 0)
{
return _games;
}

debug("[EpicGames] Load games");

Utils.thread("EpicGamesLoading", () => {
_games.clear();

games_count = 0;

var cached = Tables.Games.get_all(this);
if(cached.size > 0)
{
foreach(var g in cached)
{
if(!Settings.UI.Behavior.instance.merge_games || !Tables.Merges.is_game_merged(g))
{
_games.add(g);
if(game_loaded != null)
{
game_loaded(g, true);
}
}
games_count++;
}
}

if(cache_loaded != null)
{
cache_loaded();
}

var games = legendary_wrapper.getGames();
foreach(var game in games)
{
var g = new EpicGamesGame(this, game.name, game.id);
bool is_new_game = !_games.contains(g);
if(is_new_game && (!Settings.UI.Behavior.instance.merge_games || !Tables.Merges.is_game_merged(g)))
{
_games.add(g);
if(game_loaded != null)
{
game_loaded(g, false);
}
}

if(is_new_game) {
g.save();
if(game_loaded != null)
{
game_loaded(g, true);
}
_games.add(g);
games_count++;
} else {
var index = _games.index_of(g);
_games.get(index).update_status();
}
}
Idle.add(load_games.callback);
});
yield;
return _games;
}


}
}
Loading