2019-11-14 05:28:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
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.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-17 12:42:31 +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-17 12:42:31 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<bool> _compiling;
|
|
|
|
|
public bool Compiling => _compiling.Value;
|
2019-11-16 23:09:13 +00:00
|
|
|
|
|
2019-11-17 12:42:31 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<ModlistSettingsEditorVM> _modListSettings;
|
|
|
|
|
public ModlistSettingsEditorVM ModlistSettings => _modListSettings.Value;
|
2019-11-16 23:10:17 +00:00
|
|
|
|
|
2019-11-17 12:42:31 +00:00
|
|
|
|
private static readonly ObservableCollectionExtended<GameVM> _gameOptions = new ObservableCollectionExtended<GameVM>(
|
2019-11-17 00:41:59 +00:00
|
|
|
|
EnumExt.GetValues<Game>()
|
2019-11-17 12:36:07 +00:00
|
|
|
|
.Where(g => GameRegistry.Games[g].SupportedModManager == ModManager.Vortex)
|
|
|
|
|
.Select(g => new GameVM(g))
|
|
|
|
|
.OrderBy(g => g.DisplayName));
|
2019-11-17 00:41:59 +00:00
|
|
|
|
|
2019-11-17 12:42:31 +00:00
|
|
|
|
public ObservableCollectionExtended<GameVM> GameOptions => _gameOptions;
|
2019-11-17 00:41:59 +00:00
|
|
|
|
|
2019-11-16 23:10:17 +00:00
|
|
|
|
[Reactive]
|
2019-11-17 12:36:07 +00:00
|
|
|
|
public GameVM SelectedGame { get; set; }
|
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-17 07:59:00 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public StatusUpdateTracker StatusTracker { get; private set; }
|
|
|
|
|
|
2019-11-16 23:10:17 +00:00
|
|
|
|
public VortexCompilerVM(CompilerVM parent)
|
|
|
|
|
{
|
2019-11-17 12:36:07 +00:00
|
|
|
|
GameLocation = new FilePickerVM()
|
2019-11-16 23:10:17 +00:00
|
|
|
|
{
|
2019-11-17 07:04:53 +00:00
|
|
|
|
ExistCheckOption = FilePickerVM.ExistCheckOptions.On,
|
2019-11-16 23:10:17 +00:00
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.Folder,
|
|
|
|
|
PromptTitle = "Select Game Folder Location"
|
|
|
|
|
};
|
2019-11-17 12:36:07 +00:00
|
|
|
|
DownloadsLocation = new FilePickerVM()
|
2019-11-16 23:10:17 +00:00
|
|
|
|
{
|
2019-11-17 07:04:53 +00:00
|
|
|
|
ExistCheckOption = FilePickerVM.ExistCheckOptions.On,
|
2019-11-16 23:10:17 +00:00
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.Folder,
|
|
|
|
|
PromptTitle = "Select Downloads Folder"
|
|
|
|
|
};
|
2019-11-17 12:36:07 +00:00
|
|
|
|
StagingLocation = new FilePickerVM()
|
2019-11-16 23:10:17 +00:00
|
|
|
|
{
|
2019-11-17 07:04:53 +00:00
|
|
|
|
ExistCheckOption = FilePickerVM.ExistCheckOptions.On,
|
2019-11-16 23:10:17 +00:00
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.Folder,
|
|
|
|
|
PromptTitle = "Select Staging Folder"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Wire start command
|
2019-11-17 12:36:07 +00:00
|
|
|
|
BeginCommand = ReactiveCommand.CreateFromTask(
|
2019-11-16 23:10:17 +00:00
|
|
|
|
canExecute: Observable.CombineLatest(
|
|
|
|
|
this.WhenAny(x => x.GameLocation.InError),
|
|
|
|
|
this.WhenAny(x => x.DownloadsLocation.InError),
|
|
|
|
|
this.WhenAny(x => x.StagingLocation.InError),
|
2019-11-17 12:42:31 +00:00
|
|
|
|
(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 12:42:31 +00:00
|
|
|
|
SelectedGame.Game,
|
|
|
|
|
GameLocation.TargetPath,
|
|
|
|
|
VortexCompiler.TypicalVortexFolder(),
|
|
|
|
|
DownloadsLocation.TargetPath,
|
2019-11-17 14:30:06 +00:00
|
|
|
|
StagingLocation.TargetPath)
|
|
|
|
|
{
|
|
|
|
|
ModListName = ModlistSettings.ModListName,
|
|
|
|
|
ModListAuthor = ModlistSettings.AuthorText,
|
|
|
|
|
ModListDescription = ModlistSettings.Description,
|
|
|
|
|
ModListImage = ModlistSettings.ImagePath.TargetPath,
|
|
|
|
|
ModListWebsite = ModlistSettings.Website,
|
|
|
|
|
ModListReadme = ModlistSettings.ReadMeText.TargetPath
|
|
|
|
|
};
|
2019-11-16 23:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
while (ex.InnerException != null) ex = ex.InnerException;
|
|
|
|
|
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-11-17 07:59:00 +00:00
|
|
|
|
this.StatusTracker = compiler.UpdateTracker;
|
2019-11-16 23:10:17 +00:00
|
|
|
|
compiler.Compile();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
while (ex.InnerException != null) ex = ex.InnerException;
|
|
|
|
|
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
|
|
|
|
|
}
|
2019-11-17 07:59:00 +00:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
this.StatusTracker = null;
|
|
|
|
|
}
|
2019-11-16 23:10:17 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2019-11-17 12:42:31 +00:00
|
|
|
|
_compiling = BeginCommand.IsExecuting
|
|
|
|
|
.ToProperty(this, nameof(Compiling));
|
2019-11-16 23:10:17 +00:00
|
|
|
|
|
|
|
|
|
// Load settings
|
2019-11-17 12:42:31 +00:00
|
|
|
|
_settings = parent.MWVM.Settings.Compiler.VortexCompilation;
|
|
|
|
|
SelectedGame = _gameOptions.FirstOrDefault(x => x.Game == _settings.LastCompiledGame) ?? _gameOptions[0];
|
2019-11-16 23:10:17 +00:00
|
|
|
|
parent.MWVM.Settings.SaveSignal
|
|
|
|
|
.Subscribe(_ => Unload())
|
2019-11-17 12:42:31 +00:00
|
|
|
|
.DisposeWith(CompositeDisposable);
|
2019-11-16 23:10:17 +00:00
|
|
|
|
|
|
|
|
|
// Load custom game settings when game type changes
|
|
|
|
|
this.WhenAny(x => x.SelectedGame)
|
2019-11-17 12:42:31 +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-17 12:42:31 +00:00
|
|
|
|
var (previous, current) = pair;
|
|
|
|
|
if (previous != null)
|
2019-11-16 23:10:17 +00:00
|
|
|
|
{
|
2019-11-17 12:42:31 +00:00
|
|
|
|
previous.GameLocation = GameLocation.TargetPath;
|
2019-11-16 23:10:17 +00:00
|
|
|
|
}
|
2019-11-17 01:42:42 +00:00
|
|
|
|
|
|
|
|
|
// Load new
|
2019-11-17 12:42:31 +00:00
|
|
|
|
GameLocation.TargetPath = current?.GameLocation;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(GameLocation.TargetPath))
|
2019-11-17 01:42:42 +00:00
|
|
|
|
{
|
2019-11-17 12:42:31 +00:00
|
|
|
|
SetGameToSteamLocation();
|
2019-11-17 01:42:42 +00:00
|
|
|
|
}
|
2019-11-17 12:42:31 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(GameLocation.TargetPath))
|
2019-11-17 01:42:42 +00:00
|
|
|
|
{
|
2019-11-17 12:42:31 +00:00
|
|
|
|
SetGameToGogLocation();
|
2019-11-17 01:42:42 +00:00
|
|
|
|
}
|
2019-11-17 12:42:31 +00:00
|
|
|
|
DownloadsLocation.TargetPath = current?.DownloadLocation;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(DownloadsLocation.TargetPath))
|
2019-11-17 03:09:46 +00:00
|
|
|
|
{
|
2019-11-17 12:42:31 +00:00
|
|
|
|
DownloadsLocation.TargetPath = VortexCompiler.RetrieveDownloadLocation(SelectedGame.Game);
|
2019-11-17 03:09:46 +00:00
|
|
|
|
}
|
2019-11-17 12:42:31 +00:00
|
|
|
|
StagingLocation.TargetPath = current?.StagingLocation;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(StagingLocation.TargetPath))
|
2019-11-17 03:09:46 +00:00
|
|
|
|
{
|
2019-11-17 12:42:31 +00:00
|
|
|
|
StagingLocation.TargetPath = VortexCompiler.RetrieveStagingLocation(SelectedGame.Game);
|
2019-11-17 03:09:46 +00:00
|
|
|
|
}
|
2019-11-16 23:10:17 +00:00
|
|
|
|
})
|
2019-11-17 12:42:31 +00:00
|
|
|
|
.DisposeWith(CompositeDisposable);
|
2019-11-16 23:10:17 +00:00
|
|
|
|
|
2019-11-17 12:42:31 +00:00
|
|
|
|
// Load custom ModList settings when game type changes
|
|
|
|
|
this._modListSettings = this.WhenAny(x => x.SelectedGame)
|
2019-11-16 23:10:17 +00:00
|
|
|
|
.Select(game =>
|
|
|
|
|
{
|
2019-11-17 12:42:31 +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 =>
|
|
|
|
|
{
|
2019-11-17 12:42:31 +00:00
|
|
|
|
var (previous, current) = pair;
|
|
|
|
|
previous?.Save();
|
|
|
|
|
current?.Init();
|
2019-11-16 23:10:17 +00:00
|
|
|
|
})
|
|
|
|
|
.Select(x => x.Current)
|
|
|
|
|
// Save to property
|
|
|
|
|
.ObserveOnGuiThread()
|
2019-11-17 12:42:31 +00:00
|
|
|
|
.ToProperty(this, nameof(ModlistSettings));
|
2019-11-17 01:42:42 +00:00
|
|
|
|
|
|
|
|
|
// Find game commands
|
2019-11-17 12:42:31 +00:00
|
|
|
|
FindGameInSteamCommand = ReactiveCommand.Create(SetGameToSteamLocation);
|
|
|
|
|
FindGameInGogCommand = ReactiveCommand.Create(SetGameToGogLocation);
|
2019-11-17 03:09:46 +00:00
|
|
|
|
|
|
|
|
|
// Add additional criteria to download/staging folders
|
2019-11-17 12:42:31 +00:00
|
|
|
|
DownloadsLocation.AdditionalError = this.WhenAny(x => x.DownloadsLocation.TargetPath)
|
|
|
|
|
.Select(path => path == null ? ErrorResponse.Success : VortexCompiler.IsValidDownloadsFolder(path));
|
|
|
|
|
StagingLocation.AdditionalError = this.WhenAny(x => x.StagingLocation.TargetPath)
|
|
|
|
|
.Select(path => path == null ? ErrorResponse.Success : VortexCompiler.IsValidBaseStagingFolder(path));
|
2019-11-16 23:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unload()
|
|
|
|
|
{
|
2019-11-17 12:42:31 +00:00
|
|
|
|
_settings.LastCompiledGame = SelectedGame.Game;
|
|
|
|
|
ModlistSettings?.Save();
|
2019-11-16 23:10:17 +00:00
|
|
|
|
}
|
2019-11-17 01:42:42 +00:00
|
|
|
|
|
|
|
|
|
private void SetGameToSteamLocation()
|
|
|
|
|
{
|
2019-11-17 12:42:31 +00:00
|
|
|
|
var steamGame = SteamHandler.Instance.Games.FirstOrDefault(g => g.Game.HasValue && g.Game == SelectedGame.Game);
|
|
|
|
|
GameLocation.TargetPath = steamGame?.InstallDir;
|
2019-11-17 01:42:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetGameToGogLocation()
|
|
|
|
|
{
|
2019-11-17 12:42:31 +00:00
|
|
|
|
var gogGame = GOGHandler.Instance.Games.FirstOrDefault(g => g.Game.HasValue && g.Game == SelectedGame.Game);
|
|
|
|
|
GameLocation.TargetPath = gogGame?.Path;
|
2019-11-17 01:42:42 +00:00
|
|
|
|
}
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
2019-11-16 23:10:17 +00:00
|
|
|
|
}
|