Vortex Compilation game folder location commands

This commit is contained in:
Justin Swanson 2019-11-16 19:42:42 -06:00
parent 228bb3d070
commit dec8707ff2
4 changed files with 53 additions and 0 deletions

View File

@ -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;
}
/// <summary>
@ -16,6 +18,11 @@ namespace Wabbajack.Common
/// </summary>
public class GOGHandler
{
private static readonly Lazy<GOGHandler> instance = new Lazy<GOGHandler>(
() => 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<GOGGame>();
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);
}
}

View File

@ -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;
}
/// <summary>
@ -18,6 +20,11 @@ namespace Wabbajack.Common
/// </summary>
public class SteamHandler
{
private static readonly Lazy<SteamHandler> instance = new Lazy<SteamHandler>(
() => new SteamHandler(true),
isThreadSafe: true);
public static SteamHandler Instance => instance.Value;
private const string SteamRegKey = @"Software\Valve\Steam";
/// <summary>
@ -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);
});
});

View File

@ -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;
}
}
}

View File

@ -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">
<Image Margin="1" Source="../../Resources/Icons/steam.png" />
@ -88,6 +89,7 @@
<Button
Grid.Column="1"
Background="Transparent"
Command="{Binding FindGameInGogCommand}"
Style="{StaticResource CircleButtonStyle}"
ToolTip="Attempt to locate game in GoG">
<Image Margin="1" Source="../../Resources/Icons/gog.png" />