2019-11-24 03:17:22 +00:00
|
|
|
|
using DynamicData;
|
2019-10-22 03:03:01 +00:00
|
|
|
|
using DynamicData.Binding;
|
|
|
|
|
using ReactiveUI;
|
2019-11-02 23:23:11 +00:00
|
|
|
|
using ReactiveUI.Fody.Helpers;
|
2019-10-22 02:12:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2019-10-22 03:03:01 +00:00
|
|
|
|
using System.Reactive.Disposables;
|
|
|
|
|
using System.Reactive.Linq;
|
2019-12-04 04:12:08 +00:00
|
|
|
|
using System.Windows;
|
2019-10-22 03:03:01 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-12-04 04:12:08 +00:00
|
|
|
|
using Wabbajack.Common.StatusFeed;
|
2019-10-22 02:12:55 +00:00
|
|
|
|
using Wabbajack.Lib;
|
2019-12-04 04:12:08 +00:00
|
|
|
|
using Wabbajack.Lib.StatusMessages;
|
2019-10-22 02:12:55 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
2019-10-23 04:15:42 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Main View Model for the application.
|
|
|
|
|
/// Keeps track of which sub view is being shown in the window, and has some singleton wiring like WorkQueue and Logging.
|
|
|
|
|
/// </summary>
|
2019-10-22 02:12:55 +00:00
|
|
|
|
public class MainWindowVM : ViewModel
|
|
|
|
|
{
|
2019-10-25 04:26:29 +00:00
|
|
|
|
public MainWindow MainWindow { get; }
|
2019-10-22 02:12:55 +00:00
|
|
|
|
|
2019-11-06 03:22:38 +00:00
|
|
|
|
public MainSettings Settings { get; }
|
|
|
|
|
|
2019-11-24 08:12:28 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public ViewModel ActivePane { get; set; }
|
2019-10-22 02:12:55 +00:00
|
|
|
|
|
2019-12-04 04:12:08 +00:00
|
|
|
|
public ObservableCollectionExtended<IStatusMessage> Log { get; } = new ObservableCollectionExtended<IStatusMessage>();
|
2019-10-23 04:15:42 +00:00
|
|
|
|
|
2019-11-24 08:12:28 +00:00
|
|
|
|
public readonly Lazy<CompilerVM> Compiler;
|
|
|
|
|
public readonly Lazy<InstallerVM> Installer;
|
2019-11-30 09:08:04 +00:00
|
|
|
|
public readonly Lazy<ModListGalleryVM> Gallery;
|
2019-11-24 08:12:28 +00:00
|
|
|
|
public readonly ModeSelectionVM ModeSelectionVM;
|
2019-11-02 22:21:05 +00:00
|
|
|
|
|
2019-11-24 08:12:28 +00:00
|
|
|
|
public MainWindowVM(MainWindow mainWindow, MainSettings settings)
|
2019-10-22 02:12:55 +00:00
|
|
|
|
{
|
2019-11-21 15:04:33 +00:00
|
|
|
|
MainWindow = mainWindow;
|
|
|
|
|
Settings = settings;
|
2019-11-24 08:12:28 +00:00
|
|
|
|
Installer = new Lazy<InstallerVM>(() => new InstallerVM(this));
|
|
|
|
|
Compiler = new Lazy<CompilerVM>(() => new CompilerVM(this));
|
2019-11-30 09:08:04 +00:00
|
|
|
|
Gallery = new Lazy<ModListGalleryVM>(() => new ModListGalleryVM(this));
|
2019-11-24 08:12:28 +00:00
|
|
|
|
ModeSelectionVM = new ModeSelectionVM(this);
|
2019-10-25 04:26:29 +00:00
|
|
|
|
|
2019-10-23 04:15:42 +00:00
|
|
|
|
// Set up logging
|
2019-11-05 04:14:31 +00:00
|
|
|
|
Utils.LogMessages
|
2019-11-10 23:43:27 +00:00
|
|
|
|
.ObserveOn(RxApp.TaskpoolScheduler)
|
2019-10-23 04:15:42 +00:00
|
|
|
|
.ToObservableChangeSet()
|
2019-11-10 23:43:27 +00:00
|
|
|
|
.Buffer(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
|
2019-10-23 04:15:42 +00:00
|
|
|
|
.Where(l => l.Count > 0)
|
2019-11-24 03:17:22 +00:00
|
|
|
|
.ObserveOn(RxApp.MainThreadScheduler)
|
2019-10-23 04:15:42 +00:00
|
|
|
|
.FlattenBufferResult()
|
2019-11-21 15:04:33 +00:00
|
|
|
|
.Bind(Log)
|
2019-10-23 04:15:42 +00:00
|
|
|
|
.Subscribe()
|
2019-11-21 15:04:33 +00:00
|
|
|
|
.DisposeWith(CompositeDisposable);
|
2019-11-17 04:16:42 +00:00
|
|
|
|
|
2019-12-04 04:12:08 +00:00
|
|
|
|
Utils.LogMessages
|
|
|
|
|
.OfType<ConfirmUpdateOfExistingInstall>()
|
|
|
|
|
.Subscribe(msg => ConfirmUpdate(msg));
|
|
|
|
|
|
2019-11-24 23:48:39 +00:00
|
|
|
|
if (IsStartingFromModlist(out var path))
|
|
|
|
|
{
|
2019-12-03 05:40:59 +00:00
|
|
|
|
Installer.Value.ModListLocation.TargetPath = path;
|
2019-11-24 23:48:39 +00:00
|
|
|
|
ActivePane = Installer.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Start on mode selection
|
|
|
|
|
ActivePane = ModeSelectionVM;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 04:12:08 +00:00
|
|
|
|
private void ConfirmUpdate(ConfirmUpdateOfExistingInstall msg)
|
|
|
|
|
{
|
|
|
|
|
var result = MessageBox.Show(msg.ExtendedDescription, msg.ShortDescription, MessageBoxButton.OKCancel);
|
|
|
|
|
if (result == MessageBoxResult.OK)
|
2019-12-05 05:14:40 +00:00
|
|
|
|
msg.Confirm();
|
2019-12-04 04:12:08 +00:00
|
|
|
|
else
|
|
|
|
|
msg.Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-24 23:48:39 +00:00
|
|
|
|
private static bool IsStartingFromModlist(out string modlistPath)
|
|
|
|
|
{
|
|
|
|
|
string[] args = Environment.GetCommandLineArgs();
|
|
|
|
|
if (args.Length != 3 || !args[1].Contains("-i"))
|
|
|
|
|
{
|
|
|
|
|
modlistPath = default;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modlistPath = args[2];
|
|
|
|
|
return true;
|
2019-10-23 04:15:42 +00:00
|
|
|
|
}
|
2019-11-30 09:08:04 +00:00
|
|
|
|
|
|
|
|
|
public void OpenInstaller(string path)
|
|
|
|
|
{
|
|
|
|
|
if (path == null) return;
|
|
|
|
|
var installer = Installer.Value;
|
|
|
|
|
Settings.Installer.LastInstalledListLocation = path;
|
|
|
|
|
ActivePane = installer;
|
2019-12-03 05:40:59 +00:00
|
|
|
|
installer.ModListLocation.TargetPath = path;
|
2019-11-30 09:08:04 +00:00
|
|
|
|
}
|
2019-10-22 02:12:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|