diff --git a/Wabbajack.Common/GOGHandler.cs b/Wabbajack.Common/GOGHandler.cs index 72ae196b..520eea7f 100644 --- a/Wabbajack.Common/GOGHandler.cs +++ b/Wabbajack.Common/GOGHandler.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Win32; @@ -9,6 +10,7 @@ namespace Wabbajack.Common public int GameID; public string Path; public string GameName; + public Game? Game; } /// @@ -16,6 +18,11 @@ namespace Wabbajack.Common /// public class GOGHandler { + private static readonly Lazy instance = new Lazy( + () => new GOGHandler(true), + isThreadSafe: true); + public static GOGHandler Instance => instance.Value; + private const string GOGRegKey = @"Software\GOG.com\Games"; private const string GOG64RegKey = @"Software\WOW6432Node\GOG.com\Games"; @@ -47,6 +54,7 @@ namespace Wabbajack.Common public void LoadAllGames() { Games = new HashSet(); + if (this.GOGKey == null) return; string[] keys = GOGKey.GetSubKeyNames(); foreach (var key in keys) { @@ -57,6 +65,9 @@ namespace Wabbajack.Common Path = GOGKey.OpenSubKey(key)?.GetValue("PATH").ToString() }; + game.Game = GameRegistry.Games.Values + .FirstOrDefault(g => g.GOGIDs.Contains(game.GameID))?.Game; + Games.Add(game); } } diff --git a/Wabbajack.Common/SteamHandler.cs b/Wabbajack.Common/SteamHandler.cs index 541ba286..087bcac1 100644 --- a/Wabbajack.Common/SteamHandler.cs +++ b/Wabbajack.Common/SteamHandler.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -11,6 +12,7 @@ namespace Wabbajack.Common public int AppId; public string Name; public string InstallDir; + public Game? Game; } /// @@ -18,6 +20,11 @@ namespace Wabbajack.Common /// public class SteamHandler { + private static readonly Lazy instance = new Lazy( + () => new SteamHandler(true), + isThreadSafe: true); + public static SteamHandler Instance => instance.Value; + private const string SteamRegKey = @"Software\Valve\Steam"; /// @@ -95,6 +102,8 @@ namespace Wabbajack.Common steamGame.InstallDir = Path.Combine(p, "common", GetVdfValue(l)); }); + steamGame.Game = GameRegistry.Games.Values + .FirstOrDefault(g => g.SteamIDs.Contains(steamGame.AppId))?.Game; games.Add(steamGame); }); }); diff --git a/Wabbajack/View Models/Compilers/VortexCompilerVM.cs b/Wabbajack/View Models/Compilers/VortexCompilerVM.cs index 4ef996c4..ca858a1a 100644 --- a/Wabbajack/View Models/Compilers/VortexCompilerVM.cs +++ b/Wabbajack/View Models/Compilers/VortexCompilerVM.cs @@ -45,6 +45,10 @@ namespace Wabbajack [Reactive] public FilePickerVM StagingLocation { get; set; } + public ICommand FindGameInSteamCommand { get; } + + public ICommand FindGameInGogCommand { get; } + public VortexCompilerVM(CompilerVM parent) { this.GameLocation = new FilePickerVM() @@ -129,11 +133,22 @@ namespace Wabbajack .Pairwise() .Subscribe(pair => { + // Save old if (pair.Previous != null) { pair.Previous.GameLocation = this.GameLocation.TargetPath; } + + // Load new this.GameLocation.TargetPath = pair.Current?.GameLocation ?? null; + if (string.IsNullOrWhiteSpace(this.GameLocation.TargetPath)) + { + this.SetGameToSteamLocation(); + } + if (string.IsNullOrWhiteSpace(this.GameLocation.TargetPath)) + { + this.SetGameToGogLocation(); + } }) .DisposeWith(this.CompositeDisposable); @@ -155,6 +170,10 @@ namespace Wabbajack // Save to property .ObserveOnGuiThread() .ToProperty(this, nameof(this.ModlistSettings)); + + // Find game commands + this.FindGameInSteamCommand = ReactiveCommand.Create(SetGameToSteamLocation); + this.FindGameInGogCommand = ReactiveCommand.Create(SetGameToGogLocation); } public void Unload() @@ -164,5 +183,17 @@ namespace Wabbajack settings.LastCompiledGame = this.SelectedGame.Game; this.ModlistSettings?.Save(); } + + private void SetGameToSteamLocation() + { + var steamGame = SteamHandler.Instance.Games.FirstOrDefault(g => g.Game.HasValue && g.Game == this.SelectedGame.Game); + this.GameLocation.TargetPath = steamGame?.InstallDir; + } + + private void SetGameToGogLocation() + { + var gogGame = GOGHandler.Instance.Games.FirstOrDefault(g => g.Game.HasValue && g.Game == this.SelectedGame.Game); + this.GameLocation.TargetPath = gogGame?.Path; + } } } \ No newline at end of file diff --git a/Wabbajack/Views/Compilers/VortexCompilerConfigView.xaml b/Wabbajack/Views/Compilers/VortexCompilerConfigView.xaml index bc1f3d34..61dd01a1 100644 --- a/Wabbajack/Views/Compilers/VortexCompilerConfigView.xaml +++ b/Wabbajack/Views/Compilers/VortexCompilerConfigView.xaml @@ -81,6 +81,7 @@ Grid.Column="0" Margin="0,0,5,0" Background="Transparent" + Command="{Binding FindGameInSteamCommand}" Style="{StaticResource CircleButtonStyle}" ToolTip="Attempt to locate the game in Steam"> @@ -88,6 +89,7 @@