Skip to content

Commit

Permalink
Merge pull request #3 from Marplex/feature/epicgames_ui_implementation
Browse files Browse the repository at this point in the history
Implemented some other features in the client
  • Loading branch information
dotevo authored Feb 8, 2021
2 parents 4446b93 + eb81ef4 commit d41a05e
Show file tree
Hide file tree
Showing 12 changed files with 442 additions and 52 deletions.
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
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
78 changes: 60 additions & 18 deletions src/data/sources/epicgames/EpicGames.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ 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 Regex regex = /\*\s*([^(]*)\s\(App\sname:\s([a-zA-Z0-9]+),\sversion:\s([^)]*)\)/;
private Settings.Auth.EpicGames settings;
private FSUtils.Paths.Settings paths = FSUtils.Paths.Settings.instance;

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


Expand All @@ -50,42 +53,72 @@ namespace GameHub.Data.Sources.EpicGames
{
instance = this;
legendary_wrapper = new LegendaryWrapper();
settings = Settings.Auth.EpicGames.instance;
}

public override bool is_installed(bool refresh)
{
debug("[EpicGames] is_installed: NOT IMPLEMENTED");
return true;
/*
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()
{
debug("[EpicGames] install: NOT IMPLEMENTED");
return true;
}

public override async bool authenticate()
{
debug("[EpicGames] authenticate: NOT IMPLEMENTED");
return true;
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()
{
debug("[EpicGames] is_authenticated: NOT IMPLEMENTED");
return true;
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 true;
}

public async bool refresh_token()
{
debug("[EpicGames] refresh_token: NOT IMPLEMENTED");
return true;
return false;
}

private ArrayList<Game> _games = new ArrayList<Game>(Game.is_equal);
Expand Down Expand Up @@ -133,6 +166,15 @@ namespace GameHub.Data.Sources.EpicGames
{
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)
Expand Down
73 changes: 60 additions & 13 deletions src/data/sources/epicgames/EpicGamesGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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 Gtk;

using Gee;
using GameHub.Data.DB;
Expand Down Expand Up @@ -50,11 +51,10 @@ namespace GameHub.Data.Sources.EpicGames
public override void update_status()
{
var state = Game.State.UNINSTALLED;
if (((EpicGames)source).legendary_wrapper.is_installed(id)) {
if (((EpicGames) source).legendary_wrapper.is_installed(id)) {
state = Game.State.INSTALLED;
debug ("New installed game: \tname = %s\t", name);
} else {

debug ("New not installed game: \tname = %s\t", name);
}

Expand Down Expand Up @@ -116,52 +116,99 @@ namespace GameHub.Data.Sources.EpicGames
}
public override async void uninstall()
{
((EpicGames)source).legendary_wrapper.uninstall(id);
((EpicGames) source).legendary_wrapper.uninstall(id);
update_status();
}

public override async void run()
{
((EpicGames)source).legendary_wrapper.run(id);
((EpicGames) source).legendary_wrapper.run(id);

}

public override void import(bool update=true)
{
var chooser = new FileChooserDialog(_("Select directory"), GameHub.UI.Windows.MainWindow.instance, FileChooserAction.SELECT_FOLDER);

chooser.add_button(_("Cancel"), ResponseType.CANCEL);
var select_btn = chooser.add_button(_("Select"), ResponseType.ACCEPT);

select_btn.get_style_context().add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION);
select_btn.grab_default();

if(chooser.run() == ResponseType.ACCEPT)
{
install_dir = chooser.get_file();
((EpicGames) source).legendary_wrapper.import_game(id, install_dir.get_path());

if(update) {
update_status();
save();
}
}

chooser.destroy();
}

public class EpicGamesInstaller: Runnable.Installer
{
private FSUtils.Paths.Settings paths = FSUtils.Paths.Settings.instance;
public EpicGamesGame game;
public override string name { owned get { return "TEST"; } }
private EpicGames epic;
public override string name { owned get { return game.name; } }

private int64 _full_size = 0;
public override int64 full_size {
get {
if(_full_size != 0) return _full_size;
else {
var size = epic.legendary_wrapper.get_install_size (game.id);
_full_size = size;
return _full_size;
}

}
set {}
}

public EpicGamesInstaller(EpicGamesGame game, string id)
{
this.game = game;
id = id;
platform = Platform.CURRENT;
epic = (EpicGames)(game.source);
}

public override async void install(Runnable runnable, CompatTool? tool=null)
{

EpicGamesGame? game = null;
if(runnable is EpicGamesGame)
{
game = runnable as EpicGamesGame;
}

EpicGames epic = (EpicGames)(game.source);

Utils.thread("EpicGamesGame.Installer", () => {
game.status = new Game.Status(Game.State.DOWNLOADING, game, null);

EpicDownload ed = new EpicDownload(game.id);
game.status = new Game.Status(Game.State.DOWNLOADING, game, ed);

ed.cancelled.connect(() => {
epic.legendary_wrapper.cancel_installation();
});

var game_folder = (paths.epic_games == null || paths.epic_games == "") ? null : paths.epic_games;
epic.legendary_wrapper.install(game.id, game_folder, progress => {
ed.status = new EpicDownload.EpicStatus(progress / 100);
game.status = new Game.Status(Game.State.DOWNLOADING, game, ed);
});

epic.legendary_wrapper.install(game.id);
Idle.add(install.callback);
});
yield;

if(game != null) game.status = new Game.Status(Game.State.INSTALLED, game, null);

runnable.update_status();

debug("install");
game.update_status();
}
}
}
Expand Down
Loading

0 comments on commit d41a05e

Please sign in to comment.