Skip to content

Commit

Permalink
Merge pull request #27 from KrystianLesniak/develop
Browse files Browse the repository at this point in the history
Release: 1.4.3
  • Loading branch information
KrystianLesniak authored Oct 1, 2023
2 parents 7246c30 + 8b2f508 commit 8fde58b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/GamesLauncher.Platforms/GamesLauncher.Platforms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageReference Include="GameFinder.StoreHandlers.Xbox" Version="4.0.0" />
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.5" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.11" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 14 additions & 6 deletions src/GamesLauncher.Platforms/SyncEngines/Epic/EpicSyncEngine.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Flow.Launcher.Plugin;
using GamesLauncher.Platforms.SyncEngines.Epic.Models;
using Microsoft.Win32;
using System.Text.Json;
using System.Text.Json.Nodes;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;

namespace GamesLauncher.Platforms.SyncEngines.Epic
{
Expand Down Expand Up @@ -45,14 +46,21 @@ private static async Task<IEnumerable<EpicGame>> GetEpicGamesFromMetadata()

foreach (var metadataFile in Directory.EnumerateFiles(metadataDir, "*.item", SearchOption.AllDirectories))
{
using FileStream jsonFileStream = File.OpenRead(metadataFile);
var jsonNode = await JsonSerializer.DeserializeAsync<JsonNode>(jsonFileStream);
var fileContent = await File.ReadAllTextAsync(metadataFile);

var game = EpicGame.CreateFromJsonNode(jsonNode);
var jObject = JsonConvert.DeserializeObject<JObject>(fileContent, new JsonSerializerSettings
{
Error = delegate (object? sender, ErrorEventArgs args)
{
args.ErrorContext.Handled = true;
}
});


var game = EpicGame.CreateFromJObject(jObject);

if (game != null)
epicGames.Add(game);

}

return epicGames;
Expand Down
35 changes: 20 additions & 15 deletions src/GamesLauncher.Platforms/SyncEngines/Epic/Models/EpicGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json.Nodes;
using Newtonsoft.Json.Linq;

namespace GamesLauncher.Platforms.SyncEngines.Epic.Models
{
Expand All @@ -11,29 +11,34 @@ internal class EpicGame
public required string? InstallLocation { get; set; }
public required string? LaunchExecutable { get; set; }

internal static EpicGame? CreateFromJsonNode(JsonNode? node)
internal static EpicGame? CreateFromJObject(JObject? jObject)
{
if (node == null)
if (jObject == null)
return null;

var displayName = node[nameof(DisplayName)];
var catalogNamespace = node[nameof(CatalogNamespace)];
var catalogItemId = node[nameof(CatalogItemId)];
var appName = node[nameof(AppName)];
var installLocation = node[nameof(InstallLocation)];
var launchExecutable = node[nameof(LaunchExecutable)];
var displayName = jObject.Value<string?>(nameof(DisplayName));
var catalogNamespace = jObject.Value<string?>(nameof(CatalogNamespace));
var catalogItemId = jObject.Value<string?>(nameof(CatalogItemId));
var appName = jObject.Value<string?>(nameof(AppName));
var installLocation = jObject.Value<string?>(nameof(InstallLocation));
var launchExecutable = jObject.Value<string?>(nameof(LaunchExecutable));

if (displayName == null || catalogNamespace == null || catalogItemId == null || appName == null)
return null;

var isIncompleteInstall = jObject.Value<bool?>("bIsIncompleteInstall");

if (isIncompleteInstall == true)
return null;

return new EpicGame
{
DisplayName = displayName.GetValue<string>(),
CatalogNamespace = catalogNamespace.GetValue<string>(),
CatalogItemId = catalogItemId.GetValue<string>(),
AppName = appName.GetValue<string>(),
InstallLocation = installLocation?.GetValue<string>(),
LaunchExecutable = launchExecutable?.GetValue<string>(),
DisplayName = displayName,
CatalogNamespace = catalogNamespace,
CatalogItemId = catalogItemId,
AppName = appName,
InstallLocation = installLocation,
LaunchExecutable = launchExecutable,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/GamesLauncher/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name": "GamesLauncher",
"Description": "Search and launch games from multiple platforms like Steam, Epic Games, Xbox etc.",
"Author": "KrystianLesniak",
"Version": "1.4.2",
"Version": "1.4.3",
"Language": "csharp",
"Website": "https://github.com/KrystianLesniak/Flow.Launcher.Plugin.GamesLauncher",
"IcoPath": "icon.png",
Expand Down

0 comments on commit 8fde58b

Please sign in to comment.