Skip to content

Commit

Permalink
Merge pull request #51 from KrystianLesniak/develop
Browse files Browse the repository at this point in the history
Release: 1.9.0
  • Loading branch information
KrystianLesniak authored Feb 29, 2024
2 parents 81d9435 + ea3370f commit c0db3cf
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GamesLauncher is a plugin for [Flow launcher](https://github.com/Flow-Launcher/F
* Steam
* Epic Games Launcher
* Xbox
* GOG Galaxy
* EA app
* Ubisoft Connect
* Amazon Games
Expand Down
1 change: 1 addition & 0 deletions src/GamesLauncher.Common/Settings/MainSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public class MainSettings
public bool SynchronizeAmazon { get; set; } = true;
public bool SynchronizeUbisoft { get; set; } = true;
public bool SynchronizeEaApp { get; set; } = true;
public bool SynchronizeGogGalaxy { get; set; } = true;
}
}
1 change: 1 addition & 0 deletions src/GamesLauncher.Platforms/GamesLauncher.Platforms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GameFinder.StoreHandlers.GOG" Version="4.0.0" />
<PackageReference Include="GameFinder.StoreHandlers.Steam" Version="4.0.0" />
<PackageReference Include="GameFinder.StoreHandlers.Xbox" Version="4.0.0" />
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.5" />
Expand Down
4 changes: 4 additions & 0 deletions src/GamesLauncher.Platforms/PlatformsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using GamesLauncher.Platforms.SyncEngines.Common.Interfaces;
using GamesLauncher.Platforms.SyncEngines.EaApp;
using GamesLauncher.Platforms.SyncEngines.Epic;
using GamesLauncher.Platforms.SyncEngines.Gog;
using GamesLauncher.Platforms.SyncEngines.Steam;
using GamesLauncher.Platforms.SyncEngines.Ubisoft;
using System.Diagnostics;
Expand Down Expand Up @@ -74,6 +75,9 @@ private IEnumerable<ISyncEngine> InitializeEngines(MainSettings settings)
if (settings.SynchronizeEaApp)
engines.Add(new EaAppSyncEngine(publicApi));

if(settings.SynchronizeGogGalaxy)
engines.Add(new GogSyncEngine(publicApi));

engines.Add(new ShortcutsSyncEngine(publicApi));

return engines;
Expand Down
29 changes: 29 additions & 0 deletions src/GamesLauncher.Platforms/SyncEngines/Gog/GogGalaxyClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using GamesLauncher.Platforms.SyncEngines.Common.ControlPanelUninstall;

namespace GamesLauncher.Platforms.SyncEngines.Gog
{
internal class GogGalaxyClient
{
internal string IconPath { get; private set; } = string.Empty;
internal string ExePath { get; private set; } = string.Empty;

internal static async Task<GogGalaxyClient?> GetIfInstalled()
{
var gogUninstall = (await ControlPanelUninstall.GetPrograms()).Where(x => x.DisplayName == "GOG GALAXY").FirstOrDefault();

if (gogUninstall is null)
return null;

var clientExeLocation = Path.Combine(gogUninstall.InstallLocation, "GalaxyClient.exe");

if (!File.Exists(clientExeLocation))
return null;

return new GogGalaxyClient
{
ExePath = clientExeLocation,
IconPath = Path.Combine(gogUninstall.InstallLocation, "Icons", "default.ico")
};
}
}
}
100 changes: 100 additions & 0 deletions src/GamesLauncher.Platforms/SyncEngines/Gog/GogSyncEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using Flow.Launcher.Plugin;
using GameFinder.Common;
using GameFinder.RegistryUtils;
using GameFinder.StoreHandlers.GOG;
using GamesLauncher.Platforms.SyncEngines.Common.Interfaces;
using NexusMods.Paths;

namespace GamesLauncher.Platforms.SyncEngines.Gog
{
internal class GogSyncEngine : ISyncEngine
{
public string PlatformName => "GOG Galaxy";
public IEnumerable<Game> SynchronizedGames { get; private set; } = Array.Empty<Game>();


private readonly GOGHandler handler = new (WindowsRegistry.Shared, FileSystem.Shared);
private readonly IPublicAPI publicApi;

public GogSyncEngine(IPublicAPI publicApi)
{
this.publicApi = publicApi;
}

public async Task SynchronizeGames()
{
var gogClient = await GogGalaxyClient.GetIfInstalled();
if (gogClient is null)
return;

var games = handler.FindAllGames().Where(x => x.IsGame()).Select(x => x.AsGame());
var syncedGames = new List<Game>();

foreach (var game in games)
{
syncedGames.Add(MapGogGameToGame(game, gogClient));
}

SynchronizedGames = syncedGames;
}

private Game MapGogGameToGame(GOGGame gogGame, GogGalaxyClient gogClient)
{
return new Game(
title: gogGame.Name,
runTask: GetGameRunTask(gogGame, gogClient),
iconPath: GetIconPath(gogGame, gogClient),
platform: PlatformName,
iconDelegate: null,
uninstallAction: GetGogUninstallTask(gogGame)
);
}

private Func<Task> GetGameRunTask(GOGGame gogGame, GogGalaxyClient gogClient)
{
var argString = $"/command=runGame /gameId={gogGame.Id} /path=\"{gogGame.Path}\"";

return async () =>
{
publicApi.ShellRun(argString, gogClient.ExePath);
await Task.CompletedTask;
};
}
private static string GetIconPath(GOGGame gogGame, GogGalaxyClient gogClient)
{
var icoPath = Path.Combine(gogGame.Path.ToString(), $"goggame-{gogGame.Id}.ico");

if (File.Exists(icoPath))
return icoPath;
else
return gogClient.IconPath;
}

private UninstallAction? GetGogUninstallTask(GOGGame gogGame)
{
var uninstallExe = Path.Combine(gogGame.Path.ToString(), "unins000.exe");

if (!File.Exists(uninstallExe))
return null;

return new UninstallAction(async () =>
{
var directory = Path.GetDirectoryName(uninstallExe);
var uninstallFileExe = Path.GetFileName(uninstallExe);
publicApi.ShellRun($"cd /d \"{directory}\" && start \"\" \"{uninstallFileExe}\"");
for (int i = 0; i < 12; i++)
{
var game = handler.FindAllGames().Where(x => x.IsGame()).Select(x => x.AsGame()).FirstOrDefault(x=> x.Id == gogGame.Id);
if (game is null)
break;
await Task.Delay(TimeSpan.FromSeconds(5));
}
await SynchronizeGames();
});
}
}
}
19 changes: 13 additions & 6 deletions src/GamesLauncher/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Expand All @@ -46,26 +47,32 @@
HorizontalAlignment="Left"
Content="Xbox" />
<CheckBox
x:Name="SynchronizeEaApp"
x:Name="SynchronizeGogGalaxy"
Grid.Row="4"
Margin="10,5,5,5"
HorizontalAlignment="Left"
Content="GOG Galaxy" />
<CheckBox
x:Name="SynchronizeEaApp"
Grid.Row="5"
Margin="10,5,5,5"
HorizontalAlignment="Left"
Content="EA app" />
<CheckBox
x:Name="SynchronizeUbisoft"
Grid.Row="5"
Grid.Row="6"
Margin="10,5,5,5"
HorizontalAlignment="Left"
Content="Ubisoft Connect" />
<CheckBox
x:Name="SynchronizeAmazon"
Grid.Row="6"
Grid.Row="7"
Margin="10,5,5,5"
HorizontalAlignment="Left"
Content="Amazon Games" />
<Button
Click="BtnOpenCustomShortcutsDirectory_Click"
Grid.Row="7"
Grid.Row="8"
Margin="10,5,5,5"
Padding="20,10,20,10"
HorizontalAlignment="Left"
Expand All @@ -76,7 +83,7 @@
</Button>
<Button
Click="BtnShowHiddenGames_Click"
Grid.Row="8"
Grid.Row="9"
Margin="10,5,5,5"
Padding="20,10,20,10"
HorizontalAlignment="Left"
Expand All @@ -85,7 +92,7 @@
<StackPanel
Name="HiddenGamesStackPanel"
Visibility="Collapsed"
Grid.Row="9">
Grid.Row="10">
<ListView
Name="HiddenGames"
Height="auto"
Expand Down
10 changes: 10 additions & 0 deletions src/GamesLauncher/Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private void SettingsView_OnLoaded(object sender, RoutedEventArgs re)
SynchronizeSteam.IsChecked = _settings.SynchronizeSteam;
SyncrhonizeEpic.IsChecked = _settings.SynchronizeEpicGamesStore;
SynchronizeXbox.IsChecked = _settings.SynchronizeXbox;
SynchronizeGogGalaxy.IsChecked = _settings.SynchronizeGogGalaxy;
SynchronizeEaApp.IsChecked = _settings.SynchronizeEaApp;
SynchronizeUbisoft.IsChecked = _settings.SynchronizeUbisoft;
SynchronizeAmazon.IsChecked = _settings.SynchronizeAmazon;
Expand Down Expand Up @@ -61,6 +62,15 @@ private void SettingsView_OnLoaded(object sender, RoutedEventArgs re)
_settings.SynchronizeXbox = false;
};

SynchronizeGogGalaxy.Checked += (o, e) =>
{
_settings.SynchronizeGogGalaxy = true;
};
SynchronizeGogGalaxy.Unchecked += (o, e) =>
{
_settings.SynchronizeGogGalaxy = false;
};

SynchronizeEaApp.Checked += (o, e) =>
{
_settings.SynchronizeEaApp = true;
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.8.0",
"Version": "1.9.0",
"Language": "csharp",
"Website": "https://github.com/KrystianLesniak/Flow.Launcher.Plugin.GamesLauncher",
"IcoPath": "icon.png",
Expand Down

0 comments on commit c0db3cf

Please sign in to comment.