2019-11-14 05:28:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-11-16 23:10:17 +00:00
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Reactive.Linq;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-11-17 00:41:59 +00:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using DynamicData.Binding;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
using ReactiveUI;
|
2019-11-16 23:10:17 +00:00
|
|
|
|
using ReactiveUI.Fody.Helpers;
|
|
|
|
|
using Wabbajack.Common;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
|
|
|
|
public class VortexCompilerVM : ViewModel, ISubCompilerVM
|
|
|
|
|
{
|
2019-11-16 23:10:17 +00:00
|
|
|
|
private readonly VortexCompilationSettings settings;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
|
2019-11-16 23:10:17 +00:00
|
|
|
|
public IReactiveCommand BeginCommand { get; }
|
2019-11-14 05:28:27 +00:00
|
|
|
|
|
2019-11-16 23:10:17 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<bool> _Compiling;
|
|
|
|
|
public bool Compiling => _Compiling.Value;
|
2019-11-16 23:09:13 +00:00
|
|
|
|
|
2019-11-16 23:10:17 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _ModlistSettings;
|
|
|
|
|
public ModlistSettingsEditorVM ModlistSettings => _ModlistSettings.Value;
|
|
|
|
|
|
2019-11-17 00:41:59 +00:00
|
|
|
|
private static ObservableCollectionExtended<GameVM> gameOptions = new ObservableCollectionExtended<GameVM>(
|
|
|
|
|
EnumExt.GetValues<Game>()
|
|
|
|
|
.Select(g => new GameVM(g))
|
|
|
|
|
.OrderBy(g => g.DisplayName));
|
|
|
|
|
|
|
|
|
|
public ObservableCollectionExtended<GameVM> GameOptions => gameOptions;
|
|
|
|
|
|
2019-11-16 23:10:17 +00:00
|
|
|
|
[Reactive]
|
2019-11-17 00:41:59 +00:00
|
|
|
|
public GameVM SelectedGame { get; set; } = gameOptions.First(x => x.Game == Game.SkyrimSpecialEdition);
|
2019-11-16 23:10:17 +00:00
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public FilePickerVM GameLocation { get; set; }
|
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public FilePickerVM DownloadsLocation { get; set; }
|
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public FilePickerVM StagingLocation { get; set; }
|
|
|
|
|
|
2019-11-17 01:42:42 +00:00
|
|
|
|
public ICommand FindGameInSteamCommand { get; }
|
|
|
|
|
|
|
|
|
|
public ICommand FindGameInGogCommand { get; }
|
|
|
|
|
|
2019-11-16 23:10:17 +00:00
|
|
|
|
public VortexCompilerVM(CompilerVM parent)
|
|
|
|
|
{
|
|
|
|
|
this.GameLocation = new FilePickerVM()
|
|
|
|
|
{
|
|
|
|
|
DoExistsCheck = true,
|
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.Folder,
|
|
|
|
|
PromptTitle = "Select Game Folder Location"
|
|
|
|
|
};
|
|
|
|
|
this.DownloadsLocation = new FilePickerVM()
|
|
|
|
|
{
|
2019-11-17 03:09:46 +00:00
|
|
|
|
DoExistsCheck = true,
|
2019-11-16 23:10:17 +00:00
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.Folder,
|
|
|
|
|
PromptTitle = "Select Downloads Folder"
|
|
|
|
|
};
|
|
|
|
|
this.StagingLocation = new FilePickerVM()
|
|
|
|
|
{
|
2019-11-17 03:09:46 +00:00
|
|
|
|
DoExistsCheck = true,
|
2019-11-16 23:10:17 +00:00
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.Folder,
|
|
|
|
|
PromptTitle = "Select Staging Folder"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Wire start command
|
|
|
|
|
this.BeginCommand = ReactiveCommand.CreateFromTask(
|
|
|
|
|
canExecute: Observable.CombineLatest(
|
|
|
|
|
this.WhenAny(x => x.GameLocation.InError),
|
|
|
|
|
this.WhenAny(x => x.DownloadsLocation.InError),
|
|
|
|
|
this.WhenAny(x => x.StagingLocation.InError),
|
2019-11-16 23:54:20 +00:00
|
|
|
|
resultSelector: (g, d, s) => !g && !d && !s)
|
2019-11-16 23:10:17 +00:00
|
|
|
|
.ObserveOnGuiThread(),
|
|
|
|
|
execute: async () =>
|
|
|
|
|
{
|
|
|
|
|
VortexCompiler compiler;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
compiler = new VortexCompiler(
|
2019-11-17 00:41:59 +00:00
|
|
|
|
game: this.SelectedGame.Game,
|
2019-11-16 23:10:17 +00:00
|
|
|
|
gamePath: this.GameLocation.TargetPath,
|
2019-11-16 23:54:20 +00:00
|
|
|
|
vortexFolder: VortexCompiler.TypicalVortexFolder(),
|
2019-11-16 23:10:17 +00:00
|
|
|
|
downloadsFolder: this.DownloadsLocation.TargetPath,
|
|
|
|
|
stagingFolder: this.StagingLocation.TargetPath);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
while (ex.InnerException != null) ex = ex.InnerException;
|
|
|
|
|
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
compiler.Compile();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
while (ex.InnerException != null) ex = ex.InnerException;
|
|
|
|
|
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
this._Compiling = this.BeginCommand.IsExecuting
|
|
|
|
|
.ToProperty(this, nameof(this.Compiling));
|
|
|
|
|
|
|
|
|
|
// Load settings
|
|
|
|
|
this.settings = parent.MWVM.Settings.Compiler.VortexCompilation;
|
2019-11-17 00:41:59 +00:00
|
|
|
|
this.SelectedGame = gameOptions.First(x => x.Game == settings.LastCompiledGame);
|
2019-11-16 23:10:17 +00:00
|
|
|
|
parent.MWVM.Settings.SaveSignal
|
|
|
|
|
.Subscribe(_ => Unload())
|
|
|
|
|
.DisposeWith(this.CompositeDisposable);
|
|
|
|
|
|
|
|
|
|
// Load custom game settings when game type changes
|
|
|
|
|
this.WhenAny(x => x.SelectedGame)
|
2019-11-17 00:41:59 +00:00
|
|
|
|
.Select(game => settings.ModlistSettings.TryCreate(game.Game))
|
2019-11-16 23:10:17 +00:00
|
|
|
|
.Pairwise()
|
|
|
|
|
.Subscribe(pair =>
|
|
|
|
|
{
|
2019-11-17 01:42:42 +00:00
|
|
|
|
// Save old
|
2019-11-16 23:10:17 +00:00
|
|
|
|
if (pair.Previous != null)
|
|
|
|
|
{
|
|
|
|
|
pair.Previous.GameLocation = this.GameLocation.TargetPath;
|
|
|
|
|
}
|
2019-11-17 01:42:42 +00:00
|
|
|
|
|
|
|
|
|
// Load new
|
2019-11-16 23:10:17 +00:00
|
|
|
|
this.GameLocation.TargetPath = pair.Current?.GameLocation ?? null;
|
2019-11-17 01:42:42 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(this.GameLocation.TargetPath))
|
|
|
|
|
{
|
|
|
|
|
this.SetGameToSteamLocation();
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrWhiteSpace(this.GameLocation.TargetPath))
|
|
|
|
|
{
|
|
|
|
|
this.SetGameToGogLocation();
|
|
|
|
|
}
|
2019-11-17 03:09:46 +00:00
|
|
|
|
this.DownloadsLocation.TargetPath = pair.Current?.DownloadLocation ?? null;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(this.DownloadsLocation.TargetPath))
|
|
|
|
|
{
|
|
|
|
|
this.DownloadsLocation.TargetPath = VortexCompiler.RetrieveDownloadLocation(this.SelectedGame.Game);
|
|
|
|
|
}
|
|
|
|
|
this.StagingLocation.TargetPath = pair.Current?.StagingLocation ?? null;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(this.StagingLocation.TargetPath))
|
|
|
|
|
{
|
|
|
|
|
this.StagingLocation.TargetPath = VortexCompiler.RetrieveStagingLocation(this.SelectedGame.Game);
|
|
|
|
|
}
|
2019-11-16 23:10:17 +00:00
|
|
|
|
})
|
|
|
|
|
.DisposeWith(this.CompositeDisposable);
|
|
|
|
|
|
|
|
|
|
// Load custom modlist settings when game type changes
|
|
|
|
|
this._ModlistSettings = this.WhenAny(x => x.SelectedGame)
|
|
|
|
|
.Select(game =>
|
|
|
|
|
{
|
2019-11-17 00:41:59 +00:00
|
|
|
|
var gameSettings = settings.ModlistSettings.TryCreate(game.Game);
|
2019-11-16 23:10:17 +00:00
|
|
|
|
return new ModlistSettingsEditorVM(gameSettings.ModlistSettings);
|
|
|
|
|
})
|
|
|
|
|
// Interject and save old while loading new
|
|
|
|
|
.Pairwise()
|
|
|
|
|
.Do(pair =>
|
|
|
|
|
{
|
|
|
|
|
pair.Previous?.Save();
|
|
|
|
|
pair.Current?.Init();
|
|
|
|
|
})
|
|
|
|
|
.Select(x => x.Current)
|
|
|
|
|
// Save to property
|
|
|
|
|
.ObserveOnGuiThread()
|
|
|
|
|
.ToProperty(this, nameof(this.ModlistSettings));
|
2019-11-17 01:42:42 +00:00
|
|
|
|
|
|
|
|
|
// Find game commands
|
|
|
|
|
this.FindGameInSteamCommand = ReactiveCommand.Create(SetGameToSteamLocation);
|
|
|
|
|
this.FindGameInGogCommand = ReactiveCommand.Create(SetGameToGogLocation);
|
2019-11-17 03:09:46 +00:00
|
|
|
|
|
|
|
|
|
// Add additional criteria to download/staging folders
|
|
|
|
|
this.DownloadsLocation.AdditionalError = this.WhenAny(x => x.DownloadsLocation.TargetPath)
|
|
|
|
|
.Select(path =>
|
|
|
|
|
{
|
|
|
|
|
if (path == null) return ErrorResponse.Success;
|
|
|
|
|
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);
|
|
|
|
|
});
|
2019-11-16 23:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unload()
|
|
|
|
|
{
|
2019-11-17 00:41:59 +00:00
|
|
|
|
settings.LastCompiledGame = this.SelectedGame.Game;
|
2019-11-16 23:10:17 +00:00
|
|
|
|
this.ModlistSettings?.Save();
|
|
|
|
|
}
|
2019-11-17 01:42:42 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
2019-11-16 23:10:17 +00:00
|
|
|
|
}
|