From 72ea9ee015dbc7186614214988a9846d03f4903d Mon Sep 17 00:00:00 2001 From: tekgator Date: Sun, 11 Sep 2022 12:12:44 +1000 Subject: [PATCH 1/2] Remove ExecutablePath from ILauncher --- CHANGELOG.md | 11 ++++ GameLib.Core/ILauncher.cs | 6 --- .../ViewModels/LauncherViewModel.cs | 7 ++- .../GameLib.Demo.Wpf/Views/LauncherView.xaml | 54 ++++--------------- .../BattleNetGameFactory.cs | 10 ++-- .../BattleNetLauncher.cs | 20 +++---- .../GameLib.Plugin.Epic/EpicLauncher.cs | 20 +++---- .../GameLib.Plugin.Gog/GogGameFactory.cs | 6 +-- .../GameLib.Plugin.Gog/GogLauncher.cs | 18 +++---- .../GameLib.Plugin.Origin/OriginLauncher.cs | 20 +++---- .../RockstarGameFactory.cs | 2 +- .../RockstarLauncher.cs | 20 +++---- .../GameLib.Plugin.Steam/SteamLauncher.cs | 20 +++---- .../GameLib.Plugin.Ubisoft/UbisoftLauncher.cs | 18 +++---- 14 files changed, 87 insertions(+), 145 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf70059..bdd7563 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [1.3.1] - 2022-11-09 +### Fixed +- Activate parallel processing of installed games + +### Deleted +- Remove "ExecutablePath" from ILauncher interface + +### Changed +- "Executable" on ILauncher interface returns the executable including the path + + ## [1.3.0] - 2022-11-09 ### Added - Add Rockstar Games plugin for interacting with Rockstar Games launcher and games diff --git a/GameLib.Core/ILauncher.cs b/GameLib.Core/ILauncher.cs index 27a16e1..de00050 100644 --- a/GameLib.Core/ILauncher.cs +++ b/GameLib.Core/ILauncher.cs @@ -46,12 +46,6 @@ public interface ILauncher /// The executable including the path of the Launcher
/// if not (properly) installed /// - public string ExecutablePath { get; } - - /// - /// The executable name of the Launcher
- /// if not (properly) installed - ///
public string Executable { get; } /// diff --git a/GameLib.Demo/GameLib.Demo.Wpf/ViewModels/LauncherViewModel.cs b/GameLib.Demo/GameLib.Demo.Wpf/ViewModels/LauncherViewModel.cs index 9de4334..b7ddad1 100644 --- a/GameLib.Demo/GameLib.Demo.Wpf/ViewModels/LauncherViewModel.cs +++ b/GameLib.Demo/GameLib.Demo.Wpf/ViewModels/LauncherViewModel.cs @@ -36,7 +36,6 @@ public partial class LauncherViewModel : ViewModelBase [ObservableProperty] private string _isRunningLogo = CrossImagePath; - public LauncherViewModel(LauncherManager launcherManager) { LoadData(launcherManager); @@ -111,7 +110,7 @@ public static void RunLauncher(ILauncher? launcher) Process.Start(new ProcessStartInfo() { UseShellExecute = true, - FileName = launcher.ExecutablePath + FileName = launcher.Executable }); } catch { /* ignore */ } @@ -122,8 +121,8 @@ public static void OpenPath(ILauncher? launcher) { switch (launcher) { - case not null when !string.IsNullOrEmpty(launcher.ExecutablePath): - Process.Start("explorer.exe", $"/select,\"{launcher.ExecutablePath}\""); + case not null when !string.IsNullOrEmpty(launcher.Executable): + Process.Start("explorer.exe", $"/select,\"{launcher.Executable}\""); break; case not null when !string.IsNullOrEmpty(launcher.InstallDir): diff --git a/GameLib.Demo/GameLib.Demo.Wpf/Views/LauncherView.xaml b/GameLib.Demo/GameLib.Demo.Wpf/Views/LauncherView.xaml index 48a973b..930bbe8 100644 --- a/GameLib.Demo/GameLib.Demo.Wpf/Views/LauncherView.xaml +++ b/GameLib.Demo/GameLib.Demo.Wpf/Views/LauncherView.xaml @@ -314,18 +314,18 @@ - + + Text="Executable: " /> + Text="{Binding SelectedLauncher.Executable, Mode=OneWay}" /> - - - - - - - - GetGames(ILauncher launcher, Cancellati var catalog = GetCatalog(); return DeserializeProductInstalls() - //.AsParallel() - //.WithCancellation(cancellationToken) + .AsParallel() + .WithCancellation(cancellationToken) .Select(product => BattleNetGameBuiler(launcher, product)) .Where(game => game is not null) .Select(game => AddLauncherId(launcher, game)) @@ -90,7 +90,7 @@ private static BattleNetGame BattleNetGameBuiler(ILauncher launcher, ProductInst InstallDir = PathUtil.Sanitize(productInstall.Settings.installPath) ?? string.Empty, WorkingDir = PathUtil.Sanitize(productInstall.Settings.installPath) ?? string.Empty, InstallDate = PathUtil.GetCreationTime(productInstall.Settings.installPath) ?? DateTime.MinValue, - LaunchString = $"\"{launcher.ExecutablePath}\" --game={productInstall.productCode.ToUpper()}", + LaunchString = $"\"{launcher.Executable}\" --game={productInstall.productCode.ToUpper()}", ProductCode = productInstall.productCode ?? string.Empty, PlayRegion = productInstall.Settings.playRegion ?? string.Empty, SpeechLanguage = productInstall.Settings.selectedSpeechLanguage ?? string.Empty, @@ -119,7 +119,7 @@ private static BattleNetGame AddCatalogData(ILauncher launcher, BattleNetGame ga if (!string.IsNullOrEmpty(catalogItem.ProductId)) { game.ProductCode = catalogItem.ProductId; - game.LaunchString = $"\"{launcher.ExecutablePath}\" --exec=\"launch {game.ProductCode}\""; + game.LaunchString = $"\"{launcher.Executable}\" --exec=\"launch {game.ProductCode}\""; } game.Executable = catalogItem.Executables.FirstOrDefault(defaultValue: string.Empty); @@ -130,6 +130,4 @@ private static BattleNetGame AddCatalogData(ILauncher launcher, BattleNetGame ga return game; } - - } diff --git a/GameLib.Plugin/GameLib.Plugin.BattleNet/BattleNetLauncher.cs b/GameLib.Plugin/GameLib.Plugin.BattleNet/BattleNetLauncher.cs index 99efd12..74cef00 100644 --- a/GameLib.Plugin/GameLib.Plugin.BattleNet/BattleNetLauncher.cs +++ b/GameLib.Plugin/GameLib.Plugin.BattleNet/BattleNetLauncher.cs @@ -28,43 +28,39 @@ public BattleNetLauncher(LauncherOptions? launcherOptions) public bool IsInstalled { get; private set; } - public bool IsRunning => ProcessUtil.IsProcessRunning(ExecutablePath); + public bool IsRunning => ProcessUtil.IsProcessRunning(Executable); public string InstallDir { get; private set; } = string.Empty; - public string ExecutablePath { get; private set; } = string.Empty; - public string Executable { get; private set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public IEnumerable Games { get; private set; } = Enumerable.Empty(); public void Refresh(CancellationToken cancellationToken = default) { - ExecutablePath = string.Empty; Executable = string.Empty; InstallDir = string.Empty; IsInstalled = false; Games = Enumerable.Empty(); - ExecutablePath = GetExecutable() ?? string.Empty; - if (!string.IsNullOrEmpty(ExecutablePath)) + Executable = GetExecutable() ?? string.Empty; + if (!string.IsNullOrEmpty(Executable)) { - Executable = Path.GetFileName(ExecutablePath); - InstallDir = Path.GetDirectoryName(ExecutablePath) ?? string.Empty; - IsInstalled = File.Exists(ExecutablePath); + InstallDir = Path.GetDirectoryName(Executable) ?? string.Empty; + IsInstalled = File.Exists(Executable); Games = BattleNetGameFactory.GetGames(this, cancellationToken); } } - public bool Start() => IsRunning || ProcessUtil.StartProcess(ExecutablePath); + public bool Start() => IsRunning || ProcessUtil.StartProcess(Executable); public void Stop() { if (IsRunning) { - Process.Start(ExecutablePath, "--exec=shutdown"); + Process.Start(Executable, "--exec=shutdown"); } } #endregion diff --git a/GameLib.Plugin/GameLib.Plugin.Epic/EpicLauncher.cs b/GameLib.Plugin/GameLib.Plugin.Epic/EpicLauncher.cs index 8351604..e3c8972 100644 --- a/GameLib.Plugin/GameLib.Plugin.Epic/EpicLauncher.cs +++ b/GameLib.Plugin/GameLib.Plugin.Epic/EpicLauncher.cs @@ -28,42 +28,38 @@ public EpicLauncher(LauncherOptions? launcherOptions) public bool IsInstalled { get; private set; } - public bool IsRunning => ProcessUtil.IsProcessRunning(ExecutablePath); + public bool IsRunning => ProcessUtil.IsProcessRunning(Executable); public string InstallDir { get; private set; } = string.Empty; - public string ExecutablePath { get; private set; } = string.Empty; - public string Executable { get; private set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public IEnumerable Games { get; private set; } = Enumerable.Empty(); - public bool Start() => IsRunning || ProcessUtil.StartProcess(ExecutablePath); + public bool Start() => IsRunning || ProcessUtil.StartProcess(Executable); public void Stop() { if (IsRunning) { - ProcessUtil.StopProcess(ExecutablePath); + ProcessUtil.StopProcess(Executable); } } public void Refresh(CancellationToken cancellationToken = default) { - ExecutablePath = string.Empty; Executable = string.Empty; InstallDir = string.Empty; IsInstalled = false; Games = Enumerable.Empty(); - ExecutablePath = GetExecutable() ?? string.Empty; - if (!string.IsNullOrEmpty(ExecutablePath)) + Executable = GetExecutable() ?? string.Empty; + if (!string.IsNullOrEmpty(Executable)) { - Executable = Path.GetFileName(ExecutablePath); - InstallDir = Path.GetDirectoryName(ExecutablePath) ?? string.Empty; - IsInstalled = File.Exists(ExecutablePath); + InstallDir = Path.GetDirectoryName(Executable) ?? string.Empty; + IsInstalled = File.Exists(Executable); Games = EpicGameFactory.GetGames(this, cancellationToken); } } diff --git a/GameLib.Plugin/GameLib.Plugin.Gog/GogGameFactory.cs b/GameLib.Plugin/GameLib.Plugin.Gog/GogGameFactory.cs index f137bfd..4ce876b 100644 --- a/GameLib.Plugin/GameLib.Plugin.Gog/GogGameFactory.cs +++ b/GameLib.Plugin/GameLib.Plugin.Gog/GogGameFactory.cs @@ -23,7 +23,7 @@ public static IEnumerable GetGames(ILauncher launcher, CancellationToke return regKey.GetSubKeyNames() .AsParallel() .WithCancellation(cancellationToken) - .Select(gameId => LoadFromRegistry(launcher.ExecutablePath, gameId)) + .Select(gameId => LoadFromRegistry(launcher, gameId)) .Where(game => game is not null) .Select(game => AddLauncherId(launcher, game!)) .ToList()!; @@ -41,7 +41,7 @@ private static GogGame AddLauncherId(ILauncher launcher, GogGame game) /// /// Load the GoG game registry entry into a object /// - private static GogGame? LoadFromRegistry(string launcherExecutable, string gameId) + private static GogGame? LoadFromRegistry(ILauncher launcher, string gameId) { using var regKey = RegistryUtil.GetKey(RegistryHive.LocalMachine, $@"SOFTWARE\GOG.com\Games\{gameId}"); if (regKey is null) @@ -84,7 +84,7 @@ private static GogGame AddLauncherId(ILauncher launcher, GogGame game) } game.InstallDir = Path.GetDirectoryName(game.ExecutablePath) ?? string.Empty; - game.LaunchString = $"\"{launcherExecutable}\" /command=runGame /gameId={game.Id}"; + game.LaunchString = $"\"{launcher.Executable}\" /command=runGame /gameId={game.Id}"; if (!string.IsNullOrEmpty(game.WorkingDir)) { game.LaunchString += $" /path=\"{game.WorkingDir}\""; diff --git a/GameLib.Plugin/GameLib.Plugin.Gog/GogLauncher.cs b/GameLib.Plugin/GameLib.Plugin.Gog/GogLauncher.cs index 4ac9615..34f0d16 100644 --- a/GameLib.Plugin/GameLib.Plugin.Gog/GogLauncher.cs +++ b/GameLib.Plugin/GameLib.Plugin.Gog/GogLauncher.cs @@ -33,39 +33,35 @@ public GogLauncher(LauncherOptions? launcherOptions) public string InstallDir { get; private set; } = string.Empty; - public string ExecutablePath { get; private set; } = string.Empty; - public string Executable { get; private set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public IEnumerable Games { get; private set; } = Enumerable.Empty(); public void Refresh(CancellationToken cancellationToken = default) { - ExecutablePath = string.Empty; Executable = string.Empty; InstallDir = string.Empty; IsInstalled = false; Games = Enumerable.Empty(); - ExecutablePath = GetExecutable() ?? string.Empty; - if (!string.IsNullOrEmpty(ExecutablePath)) + Executable = GetExecutable() ?? string.Empty; + if (!string.IsNullOrEmpty(Executable)) { - Executable = Path.GetFileName(ExecutablePath); - InstallDir = Path.GetDirectoryName(ExecutablePath) ?? string.Empty; - IsInstalled = File.Exists(ExecutablePath); + InstallDir = Path.GetDirectoryName(Executable) ?? string.Empty; + IsInstalled = File.Exists(Executable); Games = GogGameFactory.GetGames(this, cancellationToken); } } - public bool Start() => IsRunning || ProcessUtil.StartProcess(ExecutablePath); + public bool Start() => IsRunning || ProcessUtil.StartProcess(Executable); public void Stop() { if (IsRunning) { - Process.Start(ExecutablePath, "/command=shutdown"); + Process.Start(Executable, "/command=shutdown"); } } #endregion diff --git a/GameLib.Plugin/GameLib.Plugin.Origin/OriginLauncher.cs b/GameLib.Plugin/GameLib.Plugin.Origin/OriginLauncher.cs index ed5fe71..2b2a367 100644 --- a/GameLib.Plugin/GameLib.Plugin.Origin/OriginLauncher.cs +++ b/GameLib.Plugin/GameLib.Plugin.Origin/OriginLauncher.cs @@ -28,42 +28,38 @@ public OriginLauncher(LauncherOptions? launcherOptions) public bool IsInstalled { get; private set; } - public bool IsRunning => ProcessUtil.IsProcessRunning(ExecutablePath); + public bool IsRunning => ProcessUtil.IsProcessRunning(Executable); public string InstallDir { get; private set; } = string.Empty; - public string ExecutablePath { get; private set; } = string.Empty; - public string Executable { get; private set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public IEnumerable Games { get; private set; } = Enumerable.Empty(); - public bool Start() => IsRunning || ProcessUtil.StartProcess(ExecutablePath); + public bool Start() => IsRunning || ProcessUtil.StartProcess(Executable); public void Stop() { if (IsRunning) { - ProcessUtil.StopProcess(ExecutablePath); + ProcessUtil.StopProcess(Executable); } } public void Refresh(CancellationToken cancellationToken = default) { - ExecutablePath = string.Empty; Executable = string.Empty; InstallDir = string.Empty; IsInstalled = false; Games = Enumerable.Empty(); - ExecutablePath = GetExecutable() ?? string.Empty; - if (!string.IsNullOrEmpty(ExecutablePath)) + Executable = GetExecutable() ?? string.Empty; + if (!string.IsNullOrEmpty(Executable)) { - Executable = Path.GetFileName(ExecutablePath); - InstallDir = Path.GetDirectoryName(ExecutablePath) ?? string.Empty; - IsInstalled = File.Exists(ExecutablePath); + InstallDir = Path.GetDirectoryName(Executable) ?? string.Empty; + IsInstalled = File.Exists(Executable); Games = OriginGameFactory.GetGames(this, cancellationToken); } } diff --git a/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarGameFactory.cs b/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarGameFactory.cs index dd75f9f..8689739 100644 --- a/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarGameFactory.cs +++ b/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarGameFactory.cs @@ -77,7 +77,7 @@ private static RockstarGame AddLauncherId(ILauncher launcher, RockstarGame game) game.Executable = Path.GetFileName(game.ExecutablePath); } - game.LaunchString = $"\"{launcher.ExecutablePath}\" -launchTitleInFolder \"{game.InstallDir}\""; + game.LaunchString = $"\"{launcher.Executable}\" -launchTitleInFolder \"{game.InstallDir}\""; return game; } diff --git a/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarLauncher.cs b/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarLauncher.cs index 0769fae..619e17b 100644 --- a/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarLauncher.cs +++ b/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarLauncher.cs @@ -28,36 +28,32 @@ public RockstarLauncher(LauncherOptions? launcherOptions) public bool IsInstalled { get; private set; } - public bool IsRunning => ProcessUtil.IsProcessRunning(ExecutablePath); + public bool IsRunning => ProcessUtil.IsProcessRunning(Executable); public string InstallDir { get; private set; } = string.Empty; - public string ExecutablePath { get; private set; } = string.Empty; - public string Executable { get; private set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public IEnumerable Games { get; private set; } = Enumerable.Empty(); - public bool Start() => IsRunning || ProcessUtil.StartProcess(ExecutablePath); + public bool Start() => IsRunning || ProcessUtil.StartProcess(Executable); - public void Stop() => ProcessUtil.StopProcess(ExecutablePath); + public void Stop() => ProcessUtil.StopProcess(Executable); public void Refresh(CancellationToken cancellationToken = default) { - ExecutablePath = string.Empty; Executable = string.Empty; InstallDir = string.Empty; IsInstalled = false; Games = Enumerable.Empty(); - ExecutablePath = GetExecutable() ?? string.Empty; - if (!string.IsNullOrEmpty(ExecutablePath)) + Executable = GetExecutable() ?? string.Empty; + if (!string.IsNullOrEmpty(Executable)) { - Executable = Path.GetFileName(ExecutablePath); - InstallDir = Path.GetDirectoryName(ExecutablePath) ?? string.Empty; - IsInstalled = File.Exists(ExecutablePath); + InstallDir = Path.GetDirectoryName(Executable) ?? string.Empty; + IsInstalled = File.Exists(Executable); Games = RockstarGameFactory.GetGames(this, cancellationToken); } } diff --git a/GameLib.Plugin/GameLib.Plugin.Steam/SteamLauncher.cs b/GameLib.Plugin/GameLib.Plugin.Steam/SteamLauncher.cs index 7adf992..faec138 100644 --- a/GameLib.Plugin/GameLib.Plugin.Steam/SteamLauncher.cs +++ b/GameLib.Plugin/GameLib.Plugin.Steam/SteamLauncher.cs @@ -30,43 +30,39 @@ public SteamLauncher(LauncherOptions? launcherOptions) public bool IsInstalled { get; private set; } - public bool IsRunning => ProcessUtil.IsProcessRunning(ExecutablePath); + public bool IsRunning => ProcessUtil.IsProcessRunning(Executable); public string InstallDir { get; private set; } = string.Empty; - public string ExecutablePath { get; private set; } = string.Empty; - public string Executable { get; private set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public IEnumerable Games { get; private set; } = Enumerable.Empty(); - public bool Start() => IsRunning || ProcessUtil.StartProcess(ExecutablePath); + public bool Start() => IsRunning || ProcessUtil.StartProcess(Executable); public void Stop() { if (IsRunning) { - Process.Start(ExecutablePath, "-shutdown"); + Process.Start(Executable, "-shutdown"); } } public void Refresh(CancellationToken cancellationToken = default) { - ExecutablePath = string.Empty; Executable = string.Empty; InstallDir = string.Empty; IsInstalled = false; Libraries = Enumerable.Empty(); Games = Enumerable.Empty(); - ExecutablePath = GetExecutable() ?? string.Empty; - if (!string.IsNullOrEmpty(ExecutablePath)) + Executable = GetExecutable() ?? string.Empty; + if (!string.IsNullOrEmpty(Executable)) { - Executable = Path.GetFileName(ExecutablePath); - InstallDir = Path.GetDirectoryName(ExecutablePath) ?? string.Empty; - IsInstalled = File.Exists(ExecutablePath); + InstallDir = Path.GetDirectoryName(Executable) ?? string.Empty; + IsInstalled = File.Exists(Executable); Libraries = SteamLibraryFactory.GetLibraries(InstallDir); Games = SteamGameFactory.GetGames(this, Libraries); } diff --git a/GameLib.Plugin/GameLib.Plugin.Ubisoft/UbisoftLauncher.cs b/GameLib.Plugin/GameLib.Plugin.Ubisoft/UbisoftLauncher.cs index 5e89232..2492162 100644 --- a/GameLib.Plugin/GameLib.Plugin.Ubisoft/UbisoftLauncher.cs +++ b/GameLib.Plugin/GameLib.Plugin.Ubisoft/UbisoftLauncher.cs @@ -32,35 +32,31 @@ public UbisoftLauncher(LauncherOptions? launcherOptions) public string InstallDir { get; private set; } = string.Empty; - public string ExecutablePath { get; private set; } = string.Empty; - public string Executable { get; private set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public IEnumerable Games { get; private set; } = Enumerable.Empty(); public void Refresh(CancellationToken cancellationToken = default) { - ExecutablePath = string.Empty; Executable = string.Empty; InstallDir = string.Empty; IsInstalled = false; Games = Enumerable.Empty(); - ExecutablePath = GetExecutable() ?? string.Empty; - if (!string.IsNullOrEmpty(ExecutablePath)) + Executable = GetExecutable() ?? string.Empty; + if (!string.IsNullOrEmpty(Executable)) { - Executable = Path.GetFileName(ExecutablePath); - InstallDir = Path.GetDirectoryName(ExecutablePath) ?? string.Empty; - IsInstalled = File.Exists(ExecutablePath); + InstallDir = Path.GetDirectoryName(Executable) ?? string.Empty; + IsInstalled = File.Exists(Executable); Games = UbisoftGameFactory.GetGames(this, cancellationToken); } } - public bool Start() => IsRunning || ProcessUtil.StartProcess(ExecutablePath); + public bool Start() => IsRunning || ProcessUtil.StartProcess(Executable); - public void Stop() => ProcessUtil.StopProcess(ExecutablePath); + public void Stop() => ProcessUtil.StopProcess(Executable); #endregion #region Private methods From 90277a2ff072b043fe25a37645a69ec9a8c8d692 Mon Sep 17 00:00:00 2001 From: tekgator Date: Sun, 11 Sep 2022 14:44:10 +1000 Subject: [PATCH 2/2] Remove ExecutablePath from IGame --- CHANGELOG.md | 4 +- GameLib.Core/IGame.cs | 5 -- .../ViewModels/GameViewModel.cs | 5 +- .../GameLib.Demo.Wpf/Views/GameView.xaml | 59 +++++-------------- .../GameLib.Demo.Wpf/Views/LauncherView.xaml | 12 ++-- .../BattleNetGameFactory.cs | 6 +- .../Model/BattleNetGame.cs | 4 +- .../GameLib.Plugin.Epic/EpicGameFactory.cs | 2 +- .../GameLib.Plugin.Epic/Model/EpicGame.cs | 3 +- .../GameLib.Plugin.Gog/GogGameFactory.cs | 5 +- .../GameLib.Plugin.Gog/Model/GogGame.cs | 3 +- .../GameLib.Plugin.Origin/Model/OriginGame.cs | 3 +- .../OriginGameFactory.cs | 38 ++++++------ .../Model/RockstarGame.cs | 13 +--- .../RockstarGameFactory.cs | 12 +--- .../GameLib.Plugin.Steam/Model/SteamGame.cs | 3 +- .../GameLib.Plugin.Steam/SteamGameFactory.cs | 5 +- .../Model/UbisoftGame.cs | 3 +- .../UbisoftGameFactory.cs | 7 +-- 19 files changed, 64 insertions(+), 128 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd7563..ef4f0b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,15 @@ All notable changes to this project will be documented in this file. ## [1.3.1] - 2022-11-09 ### Fixed -- Activate parallel processing of installed games +- Activate parallel processing of installed games for Battle.net and Rockstar Games ### Deleted - Remove "ExecutablePath" from ILauncher interface +- Remove "ExecutablePath" from IGame interface ### Changed - "Executable" on ILauncher interface returns the executable including the path +- "Executable" on IGame interface returns the executable including the path ## [1.3.0] - 2022-11-09 diff --git a/GameLib.Core/IGame.cs b/GameLib.Core/IGame.cs index 44c6230..c887034 100644 --- a/GameLib.Core/IGame.cs +++ b/GameLib.Core/IGame.cs @@ -27,11 +27,6 @@ public interface IGame /// /// Executable name including the full Path /// - public string ExecutablePath { get; } - - /// - /// Just the executable name - /// public string Executable { get; } /// diff --git a/GameLib.Demo/GameLib.Demo.Wpf/ViewModels/GameViewModel.cs b/GameLib.Demo/GameLib.Demo.Wpf/ViewModels/GameViewModel.cs index 96dfa96..7e04a80 100644 --- a/GameLib.Demo/GameLib.Demo.Wpf/ViewModels/GameViewModel.cs +++ b/GameLib.Demo/GameLib.Demo.Wpf/ViewModels/GameViewModel.cs @@ -94,7 +94,6 @@ public void RefreshGameIsRunning() OnPropertyChanged(nameof(SelectedGame)); } - [RelayCommand] public static void RunGame(IGame? game) { @@ -114,9 +113,8 @@ public static void RunGame(IGame? game) Process.Start(new ProcessStartInfo() { UseShellExecute = true, - FileName = game.ExecutablePath, + FileName = game.Executable, WorkingDirectory = game.WorkingDir - }); } catch { /* ignore */ } @@ -173,5 +171,4 @@ public static void CopyToClipboard(string? text) Clipboard.SetText(text); } - } \ No newline at end of file diff --git a/GameLib.Demo/GameLib.Demo.Wpf/Views/GameView.xaml b/GameLib.Demo/GameLib.Demo.Wpf/Views/GameView.xaml index 4291b8d..14dd5dc 100644 --- a/GameLib.Demo/GameLib.Demo.Wpf/Views/GameView.xaml +++ b/GameLib.Demo/GameLib.Demo.Wpf/Views/GameView.xaml @@ -389,18 +389,18 @@ - + + Text="Executable: " /> + Text="{Binding SelectedGame.Executable, Mode=OneWay}" /> - - - + ToolTip="Copy to clipboard" + Visibility="{Binding SelectedLauncher.IsInstalled, Converter={StaticResource BooleanToVisibilityConverter}}"> + ToolTip="Open in explorer" + Visibility="{Binding SelectedLauncher.IsInstalled, Converter={StaticResource BooleanToVisibilityConverter}}"> + ToolTip="Copy to clipboard" + Visibility="{Binding SelectedLauncher.IsInstalled, Converter={StaticResource BooleanToVisibilityConverter}}"> + ToolTip="Refresh" + Visibility="{Binding SelectedLauncher.IsInstalled, Converter={StaticResource BooleanToVisibilityConverter}}"> PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public string WorkingDir { get; internal set; } = string.Empty; diff --git a/GameLib.Plugin/GameLib.Plugin.Epic/EpicGameFactory.cs b/GameLib.Plugin/GameLib.Plugin.Epic/EpicGameFactory.cs index 662c3c8..f2b8287 100644 --- a/GameLib.Plugin/GameLib.Plugin.Epic/EpicGameFactory.cs +++ b/GameLib.Plugin/GameLib.Plugin.Epic/EpicGameFactory.cs @@ -83,7 +83,7 @@ private static EpicGame AddLauncherId(ILauncher launcher, EpicGame game) var game = deserializedEpicGame.EpicGameBuilder(); - game.ExecutablePath = Path.Combine(PathUtil.Sanitize(game.InstallDir)!, game.Executable); + game.Executable = Path.Combine(PathUtil.Sanitize(game.InstallDir)!, game.Executable); game.LaunchString = $"com.epicgames.launcher://apps/{game.Id}?action=launch&silent=true"; game.InstallDate = PathUtil.GetCreationTime(game.InstallDir) ?? DateTime.MinValue; diff --git a/GameLib.Plugin/GameLib.Plugin.Epic/Model/EpicGame.cs b/GameLib.Plugin/GameLib.Plugin.Epic/Model/EpicGame.cs index 40cba4a..875a241 100644 --- a/GameLib.Plugin/GameLib.Plugin.Epic/Model/EpicGame.cs +++ b/GameLib.Plugin/GameLib.Plugin.Epic/Model/EpicGame.cs @@ -11,9 +11,8 @@ public class EpicGame : IGame public Guid LauncherId { get; internal set; } = Guid.Empty; public string Name { get; internal set; } = string.Empty; public string InstallDir { get; internal set; } = string.Empty; - public string ExecutablePath { get; internal set; } = string.Empty; public string Executable { get; internal set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public string WorkingDir { get; internal set; } = string.Empty; public string LaunchString { get; internal set; } = string.Empty; public DateTime InstallDate { get; internal set; } = DateTime.MinValue; diff --git a/GameLib.Plugin/GameLib.Plugin.Gog/GogGameFactory.cs b/GameLib.Plugin/GameLib.Plugin.Gog/GogGameFactory.cs index 4ce876b..aafcb1b 100644 --- a/GameLib.Plugin/GameLib.Plugin.Gog/GogGameFactory.cs +++ b/GameLib.Plugin/GameLib.Plugin.Gog/GogGameFactory.cs @@ -53,8 +53,7 @@ private static GogGame AddLauncherId(ILauncher launcher, GogGame game) { Id = (string)regKey.GetValue("gameID", string.Empty)!, Name = (string)regKey.GetValue("gameName", string.Empty)!, - ExecutablePath = (string)regKey.GetValue("exe", string.Empty)!, - Executable = (string)regKey.GetValue("exeFile", string.Empty)!, + Executable = (string)regKey.GetValue("exe", string.Empty)!, WorkingDir = (string)regKey.GetValue("workingDir", string.Empty)!, InstallDate = DateTime.TryParseExact( (string)regKey.GetValue("INSTALLDATE", string.Empty)!, "yyyy-MM-dd HH:mm:ss", @@ -83,7 +82,7 @@ private static GogGame AddLauncherId(ILauncher launcher, GogGame game) return null; } - game.InstallDir = Path.GetDirectoryName(game.ExecutablePath) ?? string.Empty; + game.InstallDir = Path.GetDirectoryName(game.Executable) ?? string.Empty; game.LaunchString = $"\"{launcher.Executable}\" /command=runGame /gameId={game.Id}"; if (!string.IsNullOrEmpty(game.WorkingDir)) { diff --git a/GameLib.Plugin/GameLib.Plugin.Gog/Model/GogGame.cs b/GameLib.Plugin/GameLib.Plugin.Gog/Model/GogGame.cs index cc426cc..8d299e9 100644 --- a/GameLib.Plugin/GameLib.Plugin.Gog/Model/GogGame.cs +++ b/GameLib.Plugin/GameLib.Plugin.Gog/Model/GogGame.cs @@ -11,9 +11,8 @@ public class GogGame : IGame public Guid LauncherId { get; internal set; } = Guid.Empty; public string Name { get; internal set; } = string.Empty; public string InstallDir { get; internal set; } = string.Empty; - public string ExecutablePath { get; internal set; } = string.Empty; public string Executable { get; internal set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public string WorkingDir { get; internal set; } = string.Empty; public string LaunchString { get; internal set; } = string.Empty; public DateTime InstallDate { get; internal set; } = DateTime.MinValue; diff --git a/GameLib.Plugin/GameLib.Plugin.Origin/Model/OriginGame.cs b/GameLib.Plugin/GameLib.Plugin.Origin/Model/OriginGame.cs index aaad083..3a794f9 100644 --- a/GameLib.Plugin/GameLib.Plugin.Origin/Model/OriginGame.cs +++ b/GameLib.Plugin/GameLib.Plugin.Origin/Model/OriginGame.cs @@ -11,9 +11,8 @@ public class OriginGame : IGame public Guid LauncherId { get; internal set; } = Guid.Empty; public string Name { get; internal set; } = string.Empty; public string InstallDir { get; internal set; } = string.Empty; - public string ExecutablePath { get; internal set; } = string.Empty; public string Executable { get; internal set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public string WorkingDir { get; internal set; } = string.Empty; public string LaunchString { get; internal set; } = string.Empty; public DateTime InstallDate { get; internal set; } = DateTime.MinValue; diff --git a/GameLib.Plugin/GameLib.Plugin.Origin/OriginGameFactory.cs b/GameLib.Plugin/GameLib.Plugin.Origin/OriginGameFactory.cs index f318beb..a3b0f11 100644 --- a/GameLib.Plugin/GameLib.Plugin.Origin/OriginGameFactory.cs +++ b/GameLib.Plugin/GameLib.Plugin.Origin/OriginGameFactory.cs @@ -98,10 +98,9 @@ private static OriginGame AddLocalCatalogData(OriginGame game) game.Locale = RegistryUtil.GetValue(RegistryHive.LocalMachine, $@"SOFTWARE\Origin Games\{contendIds[0]}", "Locale", string.Empty)!; } - if (!string.IsNullOrEmpty(game.ExecutablePath)) + if (!string.IsNullOrEmpty(game.Executable)) { - game.WorkingDir = Path.GetDirectoryName(game.ExecutablePath) ?? string.Empty; - game.Executable = Path.GetFileName(game.ExecutablePath); + game.WorkingDir = Path.GetDirectoryName(game.Executable) ?? string.Empty; } return game; @@ -137,24 +136,22 @@ private static bool AddFromLocalDipManifestData(OriginGame game, string installe contendIds.AddRange(diPManifest.contentIDs); } - if (string.IsNullOrEmpty(game.ExecutablePath)) + if (string.IsNullOrEmpty(game.Executable)) { var filePath = diPManifest.runtime?.FirstOrDefault(defaultValue: null)?.filePath; if (!string.IsNullOrEmpty(filePath)) { - game.ExecutablePath = filePath; + game.Executable = filePath; if (filePath.StartsWith('[') && filePath.Contains(']')) { - game.ExecutablePath = PathUtil.Sanitize(Path.Combine(game.InstallDir, filePath[(filePath.LastIndexOf(']') + 1)..]))!; - game.WorkingDir = Path.GetDirectoryName(game.ExecutablePath) ?? string.Empty; - game.Executable = Path.GetFileName(game.ExecutablePath); + game.Executable = PathUtil.Sanitize(Path.Combine(game.InstallDir, filePath[(filePath.LastIndexOf(']') + 1)..]))!; + game.WorkingDir = Path.GetDirectoryName(game.Executable) ?? string.Empty; } - if (!PathUtil.IsExecutable(game.ExecutablePath) && !File.Exists(game.ExecutablePath)) + if (!PathUtil.IsExecutable(game.Executable) && !File.Exists(game.Executable)) { - game.ExecutablePath = string.Empty; - game.WorkingDir = string.Empty; game.Executable = string.Empty; + game.WorkingDir = string.Empty; } } } @@ -205,7 +202,7 @@ private static OriginGame AddOnlineData(ILauncher launcher, OriginGame game) return game; } - if (!string.IsNullOrEmpty(game.Name) && !string.IsNullOrEmpty(game.ExecutablePath)) + if (!string.IsNullOrEmpty(game.Name) && !string.IsNullOrEmpty(game.Executable)) { return game; } @@ -235,34 +232,33 @@ private static OriginGame AddOnlineData(ILauncher launcher, OriginGame game) game.Name = manifest.ItemName ?? game.Name; } - if (string.IsNullOrEmpty(game.ExecutablePath) && manifest.Publishing?.SoftwareList?.Software is not null) + if (string.IsNullOrEmpty(game.Executable) && manifest.Publishing?.SoftwareList?.Software is not null) { foreach (var item in manifest.Publishing.SoftwareList.Software .Where(p => p.SoftwarePlatform is null || p.SoftwarePlatform.Contains(Os)) .OrderByDescending(p => (p.FulfillmentAttributes?.ProcessorArchitecture ?? string.Empty).Contains(OsArch.ToString()))) { - var filePath = item.FulfillmentAttributes?.ExecutePathOverride ?? game.ExecutablePath; + var filePath = item.FulfillmentAttributes?.ExecutePathOverride ?? game.Executable; if (!string.IsNullOrEmpty(filePath)) { - game.ExecutablePath = filePath; + game.Executable = filePath; if (filePath.StartsWith('[') && filePath.Contains(']')) { - game.ExecutablePath = Path.Combine(game.InstallDir, PathUtil.Sanitize(filePath[(filePath.LastIndexOf(']') + 1)..])!); + game.Executable = Path.Combine(game.InstallDir, PathUtil.Sanitize(filePath[(filePath.LastIndexOf(']') + 1)..])!); } - if (PathUtil.IsExecutable(game.ExecutablePath) && File.Exists(game.ExecutablePath)) + if (PathUtil.IsExecutable(game.Executable) && File.Exists(game.Executable)) { break; } - game.ExecutablePath = string.Empty; + game.Executable = string.Empty; } } - if (!string.IsNullOrEmpty(game.ExecutablePath)) + if (!string.IsNullOrEmpty(game.Executable)) { - game.WorkingDir = Path.GetDirectoryName(game.ExecutablePath) ?? string.Empty; - game.Executable = Path.GetFileName(game.ExecutablePath); + game.WorkingDir = Path.GetDirectoryName(game.Executable) ?? string.Empty; } } diff --git a/GameLib.Plugin/GameLib.Plugin.Rockstar/Model/RockstarGame.cs b/GameLib.Plugin/GameLib.Plugin.Rockstar/Model/RockstarGame.cs index 52cecbe..4b021f2 100644 --- a/GameLib.Plugin/GameLib.Plugin.Rockstar/Model/RockstarGame.cs +++ b/GameLib.Plugin/GameLib.Plugin.Rockstar/Model/RockstarGame.cs @@ -8,25 +8,14 @@ public class RockstarGame : IGame { #region Interface implementations public string Id { get; internal set; } = string.Empty; - public Guid LauncherId { get; internal set; } = Guid.Empty; - public string Name { get; internal set; } = string.Empty; - public string InstallDir { get; internal set; } = string.Empty; - - public string ExecutablePath { get; internal set; } = string.Empty; - public string Executable { get; internal set; } = string.Empty; - - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); - + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public string WorkingDir { get; internal set; } = string.Empty; - public string LaunchString { get; internal set; } = string.Empty; - public DateTime InstallDate { get; internal set; } = DateTime.MinValue; - public bool IsRunning => ProcessUtil.IsProcessRunning(Executable); #endregion diff --git a/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarGameFactory.cs b/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarGameFactory.cs index 8689739..d55214d 100644 --- a/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarGameFactory.cs +++ b/GameLib.Plugin/GameLib.Plugin.Rockstar/RockstarGameFactory.cs @@ -20,8 +20,8 @@ public static IEnumerable GetGames(ILauncher launcher, Cancellatio } return regKey.GetSubKeyNames() - //.AsParallel() - //.WithCancellation(cancellationToken) + .AsParallel() + .WithCancellation(cancellationToken) .Select(gameId => LoadFromRegistry(launcher, gameId)) .Where(game => game is not null) .Select(game => AddLauncherId(launcher, game!)) @@ -66,17 +66,11 @@ private static RockstarGame AddLauncherId(ILauncher launcher, RockstarGame game) if (launcher.LauncherOptions.SearchGameConfigStore) { - game.ExecutablePath = RegistryUtil.SearchGameConfigStore(game.InstallDir) ?? string.Empty; + game.Executable = RegistryUtil.SearchGameConfigStore(game.InstallDir) ?? string.Empty; } game.WorkingDir = game.InstallDir; game.InstallDate = PathUtil.GetCreationTime(game.InstallDir) ?? DateTime.MinValue; - - if (!string.IsNullOrEmpty(game.ExecutablePath)) - { - game.Executable = Path.GetFileName(game.ExecutablePath); - } - game.LaunchString = $"\"{launcher.Executable}\" -launchTitleInFolder \"{game.InstallDir}\""; return game; diff --git a/GameLib.Plugin/GameLib.Plugin.Steam/Model/SteamGame.cs b/GameLib.Plugin/GameLib.Plugin.Steam/Model/SteamGame.cs index 43b6b8d..a39bc57 100644 --- a/GameLib.Plugin/GameLib.Plugin.Steam/Model/SteamGame.cs +++ b/GameLib.Plugin/GameLib.Plugin.Steam/Model/SteamGame.cs @@ -12,9 +12,8 @@ public class SteamGame : IGame public Guid LauncherId { get; internal set; } = Guid.Empty; public string Name { get; internal set; } = string.Empty; public string InstallDir { get; internal set; } = string.Empty; - public string ExecutablePath { get; internal set; } = string.Empty; public string Executable { get; internal set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public string WorkingDir { get; internal set; } = string.Empty; public string LaunchString { get; internal set; } = string.Empty; public DateTime InstallDate { get; internal set; } = DateTime.MinValue; diff --git a/GameLib.Plugin/GameLib.Plugin.Steam/SteamGameFactory.cs b/GameLib.Plugin/GameLib.Plugin.Steam/SteamGameFactory.cs index 10e559f..e09cf29 100644 --- a/GameLib.Plugin/GameLib.Plugin.Steam/SteamGameFactory.cs +++ b/GameLib.Plugin/GameLib.Plugin.Steam/SteamGameFactory.cs @@ -123,8 +123,7 @@ private static SteamGame AddCatalogData(SteamGame game, string appsPath, SteamCa return game; } - game.ExecutablePath = Path.Combine(appsPath, "common", game.InstallDir, PathUtil.Sanitize(launcher.Executable)!); - game.Executable = Path.GetFileName(game.ExecutablePath); + game.Executable = Path.Combine(appsPath, "common", game.InstallDir, PathUtil.Sanitize(launcher.Executable)!); if (!string.IsNullOrEmpty(launcher.WorkingDir)) { @@ -133,7 +132,7 @@ private static SteamGame AddCatalogData(SteamGame game, string appsPath, SteamCa if (string.IsNullOrEmpty(game.WorkingDir)) { - game.WorkingDir = Path.GetDirectoryName(game.ExecutablePath) ?? string.Empty; + game.WorkingDir = Path.GetDirectoryName(game.Executable) ?? string.Empty; } return game; diff --git a/GameLib.Plugin/GameLib.Plugin.Ubisoft/Model/UbisoftGame.cs b/GameLib.Plugin/GameLib.Plugin.Ubisoft/Model/UbisoftGame.cs index 1175935..65054ba 100644 --- a/GameLib.Plugin/GameLib.Plugin.Ubisoft/Model/UbisoftGame.cs +++ b/GameLib.Plugin/GameLib.Plugin.Ubisoft/Model/UbisoftGame.cs @@ -11,9 +11,8 @@ public class UbisoftGame : IGame public Guid LauncherId { get; internal set; } = Guid.Empty; public string Name { get; internal set; } = string.Empty; public string InstallDir { get; internal set; } = string.Empty; - public string ExecutablePath { get; internal set; } = string.Empty; public string Executable { get; internal set; } = string.Empty; - public Icon? ExecutableIcon => PathUtil.GetFileIcon(ExecutablePath); + public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable); public string WorkingDir { get; internal set; } = string.Empty; public string LaunchString { get; internal set; } = string.Empty; public DateTime InstallDate { get; internal set; } = DateTime.MinValue; diff --git a/GameLib.Plugin/GameLib.Plugin.Ubisoft/UbisoftGameFactory.cs b/GameLib.Plugin/GameLib.Plugin.Ubisoft/UbisoftGameFactory.cs index b337da1..17df723 100644 --- a/GameLib.Plugin/GameLib.Plugin.Ubisoft/UbisoftGameFactory.cs +++ b/GameLib.Plugin/GameLib.Plugin.Ubisoft/UbisoftGameFactory.cs @@ -108,21 +108,20 @@ private static UbisoftGame AddCatalogData(UbisoftGame game, UbisoftCatalog? cata foreach (var exe in exeList .Where(p => !string.IsNullOrEmpty(p.path?.relative))) { - game.ExecutablePath = PathUtil.Sanitize(Path.Combine(game.InstallDir, exe.path!.relative!))!; + game.Executable = PathUtil.Sanitize(Path.Combine(game.InstallDir, exe.path!.relative!))!; game.Name = exe.shortcut_name ?? game.Name; - game.WorkingDir = Path.GetDirectoryName(game.ExecutablePath) ?? string.Empty; + game.WorkingDir = Path.GetDirectoryName(game.Executable) ?? string.Empty; if (exe.working_directory?.register?.StartsWith("HKEY") == false) { game.WorkingDir = PathUtil.Sanitize(exe.working_directory.register)!; } - if (!PathUtil.IsExecutable(game.ExecutablePath)) + if (!PathUtil.IsExecutable(game.Executable)) { continue; } - game.Executable = Path.GetFileName(game.ExecutablePath) ?? string.Empty; break; } }