mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
VortexCompilerVM cleanup
This commit is contained in:
parent
801fa74625
commit
8e920296b6
@ -1,9 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using DynamicData.Binding;
|
using DynamicData.Binding;
|
||||||
@ -16,23 +14,23 @@ namespace Wabbajack
|
|||||||
{
|
{
|
||||||
public class VortexCompilerVM : ViewModel, ISubCompilerVM
|
public class VortexCompilerVM : ViewModel, ISubCompilerVM
|
||||||
{
|
{
|
||||||
private readonly VortexCompilationSettings settings;
|
private readonly VortexCompilationSettings _settings;
|
||||||
|
|
||||||
public IReactiveCommand BeginCommand { get; }
|
public IReactiveCommand BeginCommand { get; }
|
||||||
|
|
||||||
private readonly ObservableAsPropertyHelper<bool> _Compiling;
|
private readonly ObservableAsPropertyHelper<bool> _compiling;
|
||||||
public bool Compiling => _Compiling.Value;
|
public bool Compiling => _compiling.Value;
|
||||||
|
|
||||||
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _ModlistSettings;
|
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _modListSettings;
|
||||||
public ModlistSettingsEditorVM ModlistSettings => _ModlistSettings.Value;
|
public ModlistSettingsEditorVM ModlistSettings => _modListSettings.Value;
|
||||||
|
|
||||||
private static ObservableCollectionExtended<GameVM> gameOptions = new ObservableCollectionExtended<GameVM>(
|
private static readonly ObservableCollectionExtended<GameVM> _gameOptions = new ObservableCollectionExtended<GameVM>(
|
||||||
EnumExt.GetValues<Game>()
|
EnumExt.GetValues<Game>()
|
||||||
.Where(g => GameRegistry.Games[g].SupportedModManager == ModManager.Vortex)
|
.Where(g => GameRegistry.Games[g].SupportedModManager == ModManager.Vortex)
|
||||||
.Select(g => new GameVM(g))
|
.Select(g => new GameVM(g))
|
||||||
.OrderBy(g => g.DisplayName));
|
.OrderBy(g => g.DisplayName));
|
||||||
|
|
||||||
public ObservableCollectionExtended<GameVM> GameOptions => gameOptions;
|
public ObservableCollectionExtended<GameVM> GameOptions => _gameOptions;
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public GameVM SelectedGame { get; set; }
|
public GameVM SelectedGame { get; set; }
|
||||||
@ -80,7 +78,7 @@ namespace Wabbajack
|
|||||||
this.WhenAny(x => x.GameLocation.InError),
|
this.WhenAny(x => x.GameLocation.InError),
|
||||||
this.WhenAny(x => x.DownloadsLocation.InError),
|
this.WhenAny(x => x.DownloadsLocation.InError),
|
||||||
this.WhenAny(x => x.StagingLocation.InError),
|
this.WhenAny(x => x.StagingLocation.InError),
|
||||||
resultSelector: (g, d, s) => !g && !d && !s)
|
(g, d, s) => !g && !d && !s)
|
||||||
.ObserveOnGuiThread(),
|
.ObserveOnGuiThread(),
|
||||||
execute: async () =>
|
execute: async () =>
|
||||||
{
|
{
|
||||||
@ -88,11 +86,11 @@ namespace Wabbajack
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
compiler = new VortexCompiler(
|
compiler = new VortexCompiler(
|
||||||
game: this.SelectedGame.Game,
|
SelectedGame.Game,
|
||||||
gamePath: this.GameLocation.TargetPath,
|
GameLocation.TargetPath,
|
||||||
vortexFolder: VortexCompiler.TypicalVortexFolder(),
|
VortexCompiler.TypicalVortexFolder(),
|
||||||
downloadsFolder: this.DownloadsLocation.TargetPath,
|
DownloadsLocation.TargetPath,
|
||||||
stagingFolder: this.StagingLocation.TargetPath);
|
StagingLocation.TargetPath);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -118,105 +116,99 @@ namespace Wabbajack
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
_Compiling = this.BeginCommand.IsExecuting
|
_compiling = BeginCommand.IsExecuting
|
||||||
.ToProperty(this, nameof(this.Compiling));
|
.ToProperty(this, nameof(Compiling));
|
||||||
|
|
||||||
// Load settings
|
// Load settings
|
||||||
settings = parent.MWVM.Settings.Compiler.VortexCompilation;
|
_settings = parent.MWVM.Settings.Compiler.VortexCompilation;
|
||||||
SelectedGame = gameOptions.FirstOrDefault(x => x.Game == settings.LastCompiledGame) ?? gameOptions[0];
|
SelectedGame = _gameOptions.FirstOrDefault(x => x.Game == _settings.LastCompiledGame) ?? _gameOptions[0];
|
||||||
parent.MWVM.Settings.SaveSignal
|
parent.MWVM.Settings.SaveSignal
|
||||||
.Subscribe(_ => Unload())
|
.Subscribe(_ => Unload())
|
||||||
.DisposeWith(this.CompositeDisposable);
|
.DisposeWith(CompositeDisposable);
|
||||||
|
|
||||||
// Load custom game settings when game type changes
|
// Load custom game settings when game type changes
|
||||||
this.WhenAny(x => x.SelectedGame)
|
this.WhenAny(x => x.SelectedGame)
|
||||||
.Select(game => settings.ModlistSettings.TryCreate(game.Game))
|
.Select(game => _settings.ModlistSettings.TryCreate(game.Game))
|
||||||
.Pairwise()
|
.Pairwise()
|
||||||
.Subscribe(pair =>
|
.Subscribe(pair =>
|
||||||
{
|
{
|
||||||
// Save old
|
// Save old
|
||||||
if (pair.Previous != null)
|
var (previous, current) = pair;
|
||||||
|
if (previous != null)
|
||||||
{
|
{
|
||||||
pair.Previous.GameLocation = this.GameLocation.TargetPath;
|
previous.GameLocation = GameLocation.TargetPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load new
|
// Load new
|
||||||
this.GameLocation.TargetPath = pair.Current?.GameLocation ?? null;
|
GameLocation.TargetPath = current?.GameLocation;
|
||||||
if (string.IsNullOrWhiteSpace(this.GameLocation.TargetPath))
|
if (string.IsNullOrWhiteSpace(GameLocation.TargetPath))
|
||||||
{
|
{
|
||||||
this.SetGameToSteamLocation();
|
SetGameToSteamLocation();
|
||||||
}
|
}
|
||||||
if (string.IsNullOrWhiteSpace(this.GameLocation.TargetPath))
|
if (string.IsNullOrWhiteSpace(GameLocation.TargetPath))
|
||||||
{
|
{
|
||||||
this.SetGameToGogLocation();
|
SetGameToGogLocation();
|
||||||
}
|
}
|
||||||
this.DownloadsLocation.TargetPath = pair.Current?.DownloadLocation ?? null;
|
DownloadsLocation.TargetPath = current?.DownloadLocation;
|
||||||
if (string.IsNullOrWhiteSpace(this.DownloadsLocation.TargetPath))
|
if (string.IsNullOrWhiteSpace(DownloadsLocation.TargetPath))
|
||||||
{
|
{
|
||||||
this.DownloadsLocation.TargetPath = VortexCompiler.RetrieveDownloadLocation(this.SelectedGame.Game);
|
DownloadsLocation.TargetPath = VortexCompiler.RetrieveDownloadLocation(SelectedGame.Game);
|
||||||
}
|
}
|
||||||
this.StagingLocation.TargetPath = pair.Current?.StagingLocation ?? null;
|
StagingLocation.TargetPath = current?.StagingLocation;
|
||||||
if (string.IsNullOrWhiteSpace(this.StagingLocation.TargetPath))
|
if (string.IsNullOrWhiteSpace(StagingLocation.TargetPath))
|
||||||
{
|
{
|
||||||
this.StagingLocation.TargetPath = VortexCompiler.RetrieveStagingLocation(this.SelectedGame.Game);
|
StagingLocation.TargetPath = VortexCompiler.RetrieveStagingLocation(SelectedGame.Game);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.DisposeWith(this.CompositeDisposable);
|
.DisposeWith(CompositeDisposable);
|
||||||
|
|
||||||
// Load custom modlist settings when game type changes
|
// Load custom ModList settings when game type changes
|
||||||
this._ModlistSettings = this.WhenAny(x => x.SelectedGame)
|
this._modListSettings = this.WhenAny(x => x.SelectedGame)
|
||||||
.Select(game =>
|
.Select(game =>
|
||||||
{
|
{
|
||||||
var gameSettings = settings.ModlistSettings.TryCreate(game.Game);
|
var gameSettings = _settings.ModlistSettings.TryCreate(game.Game);
|
||||||
return new ModlistSettingsEditorVM(gameSettings.ModlistSettings);
|
return new ModlistSettingsEditorVM(gameSettings.ModlistSettings);
|
||||||
})
|
})
|
||||||
// Interject and save old while loading new
|
// Interject and save old while loading new
|
||||||
.Pairwise()
|
.Pairwise()
|
||||||
.Do(pair =>
|
.Do(pair =>
|
||||||
{
|
{
|
||||||
pair.Previous?.Save();
|
var (previous, current) = pair;
|
||||||
pair.Current?.Init();
|
previous?.Save();
|
||||||
|
current?.Init();
|
||||||
})
|
})
|
||||||
.Select(x => x.Current)
|
.Select(x => x.Current)
|
||||||
// Save to property
|
// Save to property
|
||||||
.ObserveOnGuiThread()
|
.ObserveOnGuiThread()
|
||||||
.ToProperty(this, nameof(this.ModlistSettings));
|
.ToProperty(this, nameof(ModlistSettings));
|
||||||
|
|
||||||
// Find game commands
|
// Find game commands
|
||||||
this.FindGameInSteamCommand = ReactiveCommand.Create(SetGameToSteamLocation);
|
FindGameInSteamCommand = ReactiveCommand.Create(SetGameToSteamLocation);
|
||||||
this.FindGameInGogCommand = ReactiveCommand.Create(SetGameToGogLocation);
|
FindGameInGogCommand = ReactiveCommand.Create(SetGameToGogLocation);
|
||||||
|
|
||||||
// Add additional criteria to download/staging folders
|
// Add additional criteria to download/staging folders
|
||||||
this.DownloadsLocation.AdditionalError = this.WhenAny(x => x.DownloadsLocation.TargetPath)
|
DownloadsLocation.AdditionalError = this.WhenAny(x => x.DownloadsLocation.TargetPath)
|
||||||
.Select(path =>
|
.Select(path => path == null ? ErrorResponse.Success : VortexCompiler.IsValidDownloadsFolder(path));
|
||||||
{
|
StagingLocation.AdditionalError = this.WhenAny(x => x.StagingLocation.TargetPath)
|
||||||
if (path == null) return ErrorResponse.Success;
|
.Select(path => path == null ? ErrorResponse.Success : VortexCompiler.IsValidBaseStagingFolder(path));
|
||||||
return VortexCompiler.IsValidDownloadsFolder(path);
|
|
||||||
});
|
|
||||||
this.StagingLocation.AdditionalError = this.WhenAny(x => x.StagingLocation.TargetPath)
|
|
||||||
.Select(path =>
|
|
||||||
{
|
|
||||||
if (path == null) return ErrorResponse.Success;
|
|
||||||
return VortexCompiler.IsValidBaseStagingFolder(path);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unload()
|
public void Unload()
|
||||||
{
|
{
|
||||||
settings.LastCompiledGame = this.SelectedGame.Game;
|
_settings.LastCompiledGame = SelectedGame.Game;
|
||||||
this.ModlistSettings?.Save();
|
ModlistSettings?.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetGameToSteamLocation()
|
private void SetGameToSteamLocation()
|
||||||
{
|
{
|
||||||
var steamGame = SteamHandler.Instance.Games.FirstOrDefault(g => g.Game.HasValue && g.Game == this.SelectedGame.Game);
|
var steamGame = SteamHandler.Instance.Games.FirstOrDefault(g => g.Game.HasValue && g.Game == SelectedGame.Game);
|
||||||
this.GameLocation.TargetPath = steamGame?.InstallDir;
|
GameLocation.TargetPath = steamGame?.InstallDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetGameToGogLocation()
|
private void SetGameToGogLocation()
|
||||||
{
|
{
|
||||||
var gogGame = GOGHandler.Instance.Games.FirstOrDefault(g => g.Game.HasValue && g.Game == this.SelectedGame.Game);
|
var gogGame = GOGHandler.Instance.Games.FirstOrDefault(g => g.Game.HasValue && g.Game == SelectedGame.Game);
|
||||||
this.GameLocation.TargetPath = gogGame?.Path;
|
GameLocation.TargetPath = gogGame?.Path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user