Rework the InstallVMs

This commit is contained in:
Timothy Baldridge 2021-12-30 16:55:41 -07:00
parent 2215acf0e9
commit 7faa65ca77
18 changed files with 276 additions and 781 deletions

View File

@ -11,6 +11,7 @@ using ReactiveUI;
using Splat; using Splat;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack; using Wabbajack;
using Wabbajack.Models;
using Wabbajack.Services.OSIntegrated; using Wabbajack.Services.OSIntegrated;
using Wabbajack.Util; using Wabbajack.Util;
@ -48,12 +49,14 @@ namespace Wabbajack
services.AddTransient<MainWindowVM>(); services.AddTransient<MainWindowVM>();
services.AddSingleton<SystemParametersConstructor>(); services.AddSingleton<SystemParametersConstructor>();
services.AddSingleton<LauncherUpdater>(); services.AddSingleton<LauncherUpdater>();
services.AddSingleton<ResourceMonitor>();
services.AddSingleton<MainSettings>(); services.AddSingleton<MainSettings>();
services.AddTransient<CompilerVM>(); services.AddTransient<CompilerVM>();
services.AddTransient<InstallerVM>(); services.AddTransient<InstallerVM>();
services.AddTransient<ModeSelectionVM>(); services.AddTransient<ModeSelectionVM>();
services.AddTransient<ModListGalleryVM>(); services.AddTransient<ModListGalleryVM>();
services.AddTransient<InstallerVM>();
return services; return services;
} }

View File

@ -18,11 +18,20 @@ public class LoadingLock : ReactiveObject, IDisposable
this.WhenAnyValue(vm => vm.LoadLevel) this.WhenAnyValue(vm => vm.LoadLevel)
.Subscribe(v => IsLoading = v > 0) .Subscribe(v => IsLoading = v > 0)
.DisposeWith(_disposable); .DisposeWith(_disposable);
this.WhenAnyValue(vm => vm.LoadLevel)
.Subscribe(v => IsNotLoading = v == 0)
.DisposeWith(_disposable);
} }
[Reactive] public int LoadLevel { get; private set; } [Reactive] public int LoadLevel { get; private set; }
[Reactive] public bool IsLoading { get; private set; } [Reactive] public bool IsLoading { get; private set; }
[Reactive] public bool IsNotLoading { get; private set; }
public IObservable<bool> IsLoadingObservable => this.WhenAnyValue(ll => ll.IsLoading);
public IObservable<bool> IsNotLoadingObservable => this.WhenAnyValue(ll => ll.IsNotLoading);
public void Dispose() public void Dispose()
{ {

View File

@ -0,0 +1,19 @@
using ReactiveUI;
using Wabbajack.Paths;
namespace Wabbajack.Messages;
public class LoadModlistForInstalling
{
public AbsolutePath Path { get; }
public LoadModlistForInstalling(AbsolutePath path)
{
Path = path;
}
public static void Send(AbsolutePath path)
{
MessageBus.Current.SendMessage(new LoadModlistForInstalling(path));
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Subjects;
using System.Timers;
using Wabbajack.RateLimiter;
namespace Wabbajack.Models;
public class ResourceMonitor : IDisposable
{
private readonly IResource[] _resources;
private readonly Timer _timer;
private readonly Subject<(string Name, long Througput)[]> _updates = new ();
private (string Name, long Throughput)[] _prev;
public IObservable<(string Name, long Throughput)[]> Updates => _updates;
public ResourceMonitor(IEnumerable<IResource> resources)
{
_resources = resources.ToArray();
_timer = new Timer();
_timer.Interval = 1000;
_timer.Elapsed += Elapsed;
_timer.Enabled = true;
_prev = _resources.Select(x => (x.Name, (long)0)).ToArray();
}
private void Elapsed(object? sender, ElapsedEventArgs e)
{
var current = _resources.Select(x => (x.Name, x.StatusReport.Transferred)).ToArray();
var diff = _prev.Zip(current)
.Select(t => (t.First.Name, (long)((t.Second.Transferred - t.First.Throughput) / (_timer.Interval / 1000.0))))
.ToArray();
_prev = current;
_updates.OnNext(diff);
}
public void Dispose()
{
_timer?.Dispose();
}
}

View File

@ -142,59 +142,19 @@ namespace Wabbajack
IsLoadingIdle.OnNext(true); IsLoadingIdle.OnNext(true);
} }
}, IsLoadingIdle.StartWith(true)); }, IsLoadingIdle.StartWith(true));
ExecuteCommand = ReactiveCommand.CreateFromObservable<Unit, Unit>(
canExecute: this.WhenAny(x => x.IsBroken).Select(x => !x), ExecuteCommand = ReactiveCommand.CreateFromTask(async () =>
execute: (unit) => {
Observable.Return(unit) if (await _maintainer.HaveModList(Metadata))
.WithLatestFrom(
this.WhenAny(x => x.Exists),
(_, e) => e)
// Do any download work on background thread
.ObserveOn(RxApp.TaskpoolScheduler)
.SelectTask(async (exists) =>
{ {
if (!exists) LoadModlistForInstalling.Send(_maintainer.ModListPath(Metadata));
{ NavigateToGlobal.Send(NavigateToGlobal.ScreenType.Installer);
try }
{ else
await Download();
}
catch (Exception ex)
{
Error = ErrorResponse.Fail(ex);
return false;
}
// Return an updated check on exists
return Location.FileExists();
}
return exists;
})
.Where(exists => exists)
// Do any install page swap over on GUI thread
.ObserveOnGuiThread()
.Select(_ =>
{ {
// TODO await Download();
//_parent.MWVM.OpenInstaller(Location); }
}, LoadingLock.WhenAnyValue(ll => ll.IsLoading).Select(v => !v));
// Wait for modlist member to be filled, then open its readme
return _parent.MWVM.Installer.Value.WhenAny(x => x.ModList)
.NotNull()
.Take(1)
.Do(modList =>
{
try
{
modList.OpenReadme();
}
catch (Exception ex)
{
_logger.LogError(ex, "While opening modlist README");
}
});
})
.Switch()
.Unit());
_Exists = Observable.Interval(TimeSpan.FromSeconds(0.5)) _Exists = Observable.Interval(TimeSpan.FromSeconds(0.5))
.Unit() .Unit()

View File

@ -8,14 +8,19 @@ using System.Windows.Media;
using DynamicData; using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using System.Reactive; using System.Reactive;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.WindowsAPICodePack.Dialogs; using Microsoft.WindowsAPICodePack.Dialogs;
using Microsoft.WindowsAPICodePack.Shell; using Microsoft.WindowsAPICodePack.Shell;
using Wabbajack.Common;
using Wabbajack.DTOs;
using Wabbajack.DTOs.JsonConverters; using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Extensions; using Wabbajack.Extensions;
using Wabbajack.Installer;
using Wabbajack.Interventions; using Wabbajack.Interventions;
using Wabbajack.Messages; using Wabbajack.Messages;
using Wabbajack.Paths;
using Wabbajack.RateLimiter; using Wabbajack.RateLimiter;
using Wabbajack.View_Models; using Wabbajack.View_Models;
using Wabbajack.Paths.IO; using Wabbajack.Paths.IO;
@ -29,66 +34,49 @@ public enum ModManager
Standard Standard
} }
public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM public class InstallerVM : BackNavigatingVM, IBackNavigatingVM
{ {
public SlideShow Slideshow { get; }
public MainWindowVM MWVM { get; }
private readonly ObservableAsPropertyHelper<ModListVM> _modList;
public ModListVM ModList => _modList.Value;
public FilePickerVM ModListLocation { get; }
private readonly ObservableAsPropertyHelper<ISubInstallerVM> _installer;
public ISubInstallerVM Installer => _installer.Value;
private readonly ObservableAsPropertyHelper<bool> _installing;
public bool Installing => _installing.Value;
[Reactive] [Reactive]
public bool StartedInstallation { get; set; } public ModList ModList { get; set; }
[Reactive] [Reactive]
public ErrorResponse? Completed { get; set; } public ErrorResponse? Completed { get; set; }
private readonly ObservableAsPropertyHelper<ImageSource> _image; [Reactive]
public ImageSource Image => _image.Value; public FilePickerVM ModListLocation { get; set; }
[Reactive]
public MO2InstallerVM Installer { get; set; }
[Reactive]
public BitmapFrame ModListImage { get; set; }
[Reactive]
public BitmapFrame SlideShowImage { get; set; }
/// <summary>
/// Slideshow Data
/// </summary>
[Reactive]
public string SlideShowTitle { get; set; }
[Reactive]
public string SlideShowAuthor { get; set; }
[Reactive]
public string SlideShowDescription { get; set; }
private readonly ObservableAsPropertyHelper<string> _titleText;
public string TitleText => _titleText.Value;
private readonly ObservableAsPropertyHelper<string> _authorText; private readonly ObservableAsPropertyHelper<bool> _installing;
public string AuthorText => _authorText.Value; private readonly DTOSerializer _dtos;
private readonly ObservableAsPropertyHelper<string> _description;
public string Description => _description.Value;
private readonly ObservableAsPropertyHelper<string> _progressTitle;
public string ProgressTitle => _progressTitle.Value;
private readonly ObservableAsPropertyHelper<string> _modListName;
public string ModListName => _modListName.Value;
private readonly ObservableAsPropertyHelper<Percent> _percentCompleted;
public Percent PercentCompleted => _percentCompleted.Value;
public ObservableCollectionExtended<CPUDisplayVM> StatusList { get; } = new ObservableCollectionExtended<CPUDisplayVM>();
public ObservableCollectionExtended<IStatusMessage> Log => MWVM.Log;
private readonly ObservableAsPropertyHelper<ModManager?> _TargetManager;
public ModManager? TargetManager => _TargetManager.Value;
private readonly ObservableAsPropertyHelper<IUserIntervention> _ActiveGlobalUserIntervention;
public IUserIntervention ActiveGlobalUserIntervention => _ActiveGlobalUserIntervention.Value;
private readonly ObservableAsPropertyHelper<(int CurrentCPUs, int DesiredCPUs)> _CurrentCpuCount;
public (int CurrentCPUs, int DesiredCPUs) CurrentCpuCount => _CurrentCpuCount.Value;
private readonly ObservableAsPropertyHelper<bool> _LoadingModlist;
private readonly ILogger<InstallerVM> _logger; private readonly ILogger<InstallerVM> _logger;
public bool LoadingModlist => _LoadingModlist.Value;
[Reactive]
public bool Installing { get; set; }
// Command properties // Command properties
public ReactiveCommand<Unit, Unit> ShowManifestCommand { get; } public ReactiveCommand<Unit, Unit> ShowManifestCommand { get; }
public ReactiveCommand<Unit, Unit> OpenReadmeCommand { get; } public ReactiveCommand<Unit, Unit> OpenReadmeCommand { get; }
@ -98,33 +86,27 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
public ReactiveCommand<Unit, Unit> OpenLogsCommand { get; } public ReactiveCommand<Unit, Unit> OpenLogsCommand { get; }
public ReactiveCommand<Unit, Unit> GoToInstallCommand { get; } public ReactiveCommand<Unit, Unit> GoToInstallCommand { get; }
public ReactiveCommand<Unit, Unit> BeginCommand { get; } public ReactiveCommand<Unit, Unit> BeginCommand { get; }
public ReactiveCommand<Unit, Unit> BackCommand { get; }
public InstallerVM(ILogger<InstallerVM> logger, MainWindowVM mainWindowVM, IServiceProvider serviceProvider) : base(logger) public InstallerVM(ILogger<InstallerVM> logger, DTOSerializer dtos) : base(logger)
{ {
_logger = logger; _logger = logger;
_dtos = dtos;
/* TODO Installer = new MO2InstallerVM(this);
var downloadsPath = KnownFolders.Downloads.Path;
var skyDrivePath = KnownFolders.SkyDrive.Path; BackCommand = ReactiveCommand.Create(() => NavigateToGlobal.Send(NavigateToGlobal.ScreenType.ModeSelectionView));
if (downloadsPath != null && AbsolutePath.EntryPoint.IsChildOf(new AbsolutePath(downloadsPath))) OpenReadmeCommand = ReactiveCommand.Create(() =>
{ {
logger.LogError(Error(new CriticalFailureIntervention( UIUtils.OpenWebsite(new Uri(ModList!.Readme));
"Wabbajack is running inside your Downloads folder. This folder is often highly monitored by antivirus software and these can often " + }, LoadingLock.IsNotLoadingObservable);
"conflict with the operations Wabbajack needs to perform. Please move Wabbajack outside of your Downloads folder and then restart the app.",
"Cannot run inside Downloads", true)); VisitModListWebsiteCommand = ReactiveCommand.Create(() =>
}
if (skyDrivePath != null && AbsolutePath.EntryPoint.IsChildOf(new AbsolutePath(skyDrivePath)))
{ {
Utils.Error(new CriticalFailureIntervention( UIUtils.OpenWebsite(ModList!.Website);
$"Wabbajack is running inside a OneDrive folder \"{skyDrivePath}\". This folder is known to cause issues with Wabbajack. " + }, LoadingLock.IsNotLoadingObservable);
"Please move Wabbajack outside of your OneDrive folder and then restart the app.",
"Cannot run inside OneDrive", true));
}*/
MWVM = mainWindowVM;
ModListLocation = new FilePickerVM ModListLocation = new FilePickerVM
{ {
ExistCheckOption = FilePickerVM.CheckOptions.On, ExistCheckOption = FilePickerVM.CheckOptions.On,
@ -132,350 +114,47 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM
PromptTitle = "Select a ModList to install" PromptTitle = "Select a ModList to install"
}; };
ModListLocation.Filters.Add(new CommonFileDialogFilter("Wabbajack Modlist", "*.wabbajack")); ModListLocation.Filters.Add(new CommonFileDialogFilter("Wabbajack Modlist", "*.wabbajack"));
// Swap to proper sub VM based on selected type MessageBus.Current.Listen<LoadModlistForInstalling>()
_installer = this.WhenAny(x => x.TargetManager) .Subscribe(msg => LoadModlist(msg.Path).FireAndForget())
// Delay so the initial VM swap comes in immediately, subVM comes right after
.DelayInitial(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
.Select<ModManager?, ISubInstallerVM>(type =>
{
switch (type)
{
case ModManager.Standard:
return new MO2InstallerVM(this);
default:
return null;
}
})
// Unload old VM
.Pairwise()
.Do(pair =>
{
pair.Previous?.Unload();
})
.Select(p => p.Current)
.ToGuiProperty(this, nameof(Installer));
// Load settings
MWVM.Settings.SaveSignal
.Subscribe(_ =>
{
MWVM.Settings.Installer.LastInstalledListLocation = ModListLocation.TargetPath;
})
.DisposeWith(CompositeDisposable); .DisposeWith(CompositeDisposable);
// Active path represents the path to currently have loaded
// If we're not actively showing, then "unload" the active path
var activePath = Observable.CombineLatest(
this.WhenAny(x => x.ModListLocation.TargetPath),
this.WhenAny(x => x.IsActive),
resultSelector: (path, active) => (path, active))
.Select(x =>
{
if (!x.active) return default;
return x.path;
})
// Throttle slightly so changes happen more atomically
.Throttle(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
.Replay(1)
.RefCount();
this.WhenActivated(disposables =>
_modList = activePath
.ObserveOn(RxApp.TaskpoolScheduler)
// Convert from active path to modlist VM
.Select(modListPath =>
{
if (modListPath == default) return default;
if (!modListPath.FileExists()) return default;
return new ModListVM(serviceProvider.GetRequiredService<ILogger<ModListVM>>()!, modListPath, serviceProvider.GetRequiredService<DTOSerializer>());
})
.DisposeOld()
.ObserveOnGuiThread()
.StartWith(default(ModListVM))
.ToGuiProperty(this, nameof(ModList));
// Force GC collect when modlist changes, just to make sure we clean up any loose large items immediately
this.WhenAny(x => x.ModList)
.Delay(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler)
.Subscribe(x =>
{
GC.Collect();
});
_LoadingModlist = Observable.Merge(
// When active path changes, mark as loading
activePath
.Select(_ => true),
// When the resulting modlist comes in, mark it as done
this.WhenAny(x => x.ModList)
.Select(_ => false))
.ToGuiProperty(this, nameof(LoadingModlist));
_installing = this.WhenAny(x => x.Installer.ActiveInstallation)
.Select(i => i != null)
.ToGuiProperty(this, nameof(Installing));
/*TODO
_TargetManager = this.WhenAny(x => x.ModList)
.Select(modList => ModManager.Standard)
.ToGuiProperty(this, nameof(TargetManager));
*/
// Add additional error check on ModList
ModListLocation.AdditionalError = this.WhenAny(x => x.ModList)
.Select<ModListVM, IErrorResponse>(modList =>
{
if (modList == null) return ErrorResponse.Fail("Modlist path resulted in a null object.");
if (modList.Error != null) return ErrorResponse.Fail("Modlist is corrupt", modList.Error);
if (modList.WabbajackVersion != null && modList.WabbajackVersion > Consts.CurrentMinimumWabbajackVersion)
return ErrorResponse.Fail("The Modlist you are trying to install was made using a newer Version of Wabbajack. Please update Wabbajack before installing!");
return ErrorResponse.Success;
});
BackCommand = ReactiveCommand.Create(
execute: () =>
{
StartedInstallation = false;
Completed = null;
NavigateToGlobal.Send(NavigateToGlobal.ScreenType.ModeSelectionView);
},
canExecute: Observable.CombineLatest(
this.WhenAny(x => x.Installing)
.Select(x => !x),
this.ConstructCanNavigateBack(),
resultSelector: (i, b) => i && b)
.ObserveOnGuiThread());
/* TODO
_percentCompleted = this.WhenAny(x => x.Installer.ActiveInstallation)
.StartWith(default(IInstaller))
.CombineLatest(
this.WhenAny(x => x.Completed),
(installer, completed) =>
{
if (installer == null)
{
return Observable.Return<Percent>(completed != null ? Percent.One : Percent.Zero);
}
return installer.PercentCompleted.StartWith(Percent.Zero);
})
.Switch()
.Debounce(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler)
.ToGuiProperty(this, nameof(PercentCompleted));
*/
Slideshow = new SlideShow( this, serviceProvider);
// Set display items to ModList if configuring or complete,
// or to the current slideshow data if installing
_image = Observable.CombineLatest(
this.WhenAny(x => x.ModList.Error),
this.WhenAny(x => x.ModList)
.Select(x => x?.ImageObservable ?? Observable.Return(default(BitmapImage)))
.Switch()
.StartWith(default(BitmapImage)),
this.WhenAny(x => x.Slideshow.Image)
.StartWith(default(BitmapImage)),
this.WhenAny(x => x.Installing),
this.WhenAny(x => x.LoadingModlist),
resultSelector: (err, modList, slideshow, installing, loading) =>
{
if (err != null)
{
return ResourceLinks.WabbajackErrLogo.Value;
}
if (loading) return default;
return installing ? slideshow : modList;
})
.Select<BitmapImage, ImageSource>(x => x)
.ToGuiProperty(this, nameof(Image));
_titleText = Observable.CombineLatest(
this.WhenAny(x => x.ModList)
.Select(modList => modList?.Name ?? string.Empty),
this.WhenAny(x => x.Slideshow.TargetMod.State.Name)
.StartWith(default(string)),
this.WhenAny(x => x.Installing),
resultSelector: (modList, mod, installing) => installing ? mod : modList)
.ToGuiProperty(this, nameof(TitleText));
_authorText = Observable.CombineLatest(
this.WhenAny(x => x.ModList)
.Select(modList => modList?.Author ?? string.Empty),
this.WhenAny(x => x.Slideshow.TargetMod.State.Author)
.StartWith(default(string)),
this.WhenAny(x => x.Installing),
resultSelector: (modList, mod, installing) => installing ? mod : modList)
.ToGuiProperty(this, nameof(AuthorText));
_description = Observable.CombineLatest(
this.WhenAny(x => x.ModList)
.Select(modList => modList?.Description ?? string.Empty),
this.WhenAny(x => x.Slideshow.TargetMod.State.Description)
.StartWith(default(string)),
this.WhenAny(x => x.Installing),
resultSelector: (modList, mod, installing) => installing ? mod : modList)
.ToGuiProperty(this, nameof(Description));
/* TODO
_modListName = Observable.CombineLatest(
this.WhenAny(x => x.ModList.Error)
.Select(x => x != null),
this.WhenAny(x => x.ModList)
.Select(x => x?.Name),
resultSelector: (err, name) =>
{
if (err) return "Corrupted Modlist";
return name;
})
.Merge(this.WhenAny(x => x.Installer.ActiveInstallation)
.Where(c => c != null)
.SelectMany(c => c.TextStatus))
.ToGuiProperty(this, nameof(ModListName));
*/
ShowManifestCommand = ReactiveCommand.Create(() =>
{ {
UIUtils.OpenWebsite(new Uri("https://www.wabbajack.org/#/modlists/manifest")); ModListLocation.WhenAnyValue(l => l.TargetPath)
}, this.WhenAny(x => x.ModList) .Subscribe(p => LoadModlist(p).FireAndForget())
.Select(x => x?.SourceModList != null) .DisposeWith(disposables);
.ObserveOnGuiThread());
OpenReadmeCommand = ReactiveCommand.Create(
execute: () => this.ModList?.OpenReadme(),
canExecute: this.WhenAny(x => x.ModList)
.Select(modList => !string.IsNullOrEmpty(modList?.Readme))
.ObserveOnGuiThread());
/*TODO
OpenLogsCommand = ReactiveCommand.Create(
execute: () => UIUtils.OpenFolder(Consts.LogsFolder));
*/
VisitModListWebsiteCommand = ReactiveCommand.Create(
execute: () =>
{
UIUtils.OpenWebsite(ModList.Website);
return Unit.Default;
},
canExecute: this.WhenAny(x => x.ModList.Website)
.Select(x => x != null)
.ObserveOnGuiThread());
_progressTitle = this.WhenAnyValue( });
x => x.Installing,
x => x.StartedInstallation,
x => x.Completed,
selector: (installing, started, completed) =>
{
if (installing)
{
return "Installing";
}
else if (started)
{
if (completed == null) return "Installing";
return completed.Value.Succeeded ? "Installed" : "Failed";
}
else
{
return "Awaiting Input";
}
})
.ToGuiProperty(this, nameof(ProgressTitle));
/*
UIUtils.BindCpuStatus(
this.WhenAny(x => x.Installer.ActiveInstallation)
.SelectMany(c => c?.QueueStatus ?? Observable.Empty<CPUStatus>()),
StatusList)
.DisposeWith(CompositeDisposable);
*/
BeginCommand = ReactiveCommand.CreateFromTask(
canExecute: this.WhenAny(x => x.Installer.CanInstall)
.Select(err => err.Succeeded),
execute: async () =>
{
try
{
_logger.LogInformation("Starting to install {Name}", ModList.Name);
IsBackEnabledSubject.OnNext(false);
var success = await this.Installer.Install();
Completed = ErrorResponse.Create(success);
try
{
this.ModList?.OpenReadme();
}
catch (Exception ex)
{
_logger.LogError(ex, "During installation");
}
}
catch (Exception ex)
{
_logger.LogError(ex, $"Encountered error, can't continue");
while (ex.InnerException != null) ex = ex.InnerException;
Completed = ErrorResponse.Fail(ex);
}
finally
{
IsBackEnabledSubject.OnNext(true);
}
});
// When sub installer begins an install, mark state variable
BeginCommand.StartingExecution()
.Subscribe(_ =>
{
StartedInstallation = true;
})
.DisposeWith(CompositeDisposable);
/*
// Listen for user interventions, and compile a dynamic list of all unhandled ones
var activeInterventions = this.WhenAny(x => x.Installer.ActiveInstallation)
.WithLatestFrom(
this.WhenAny(x => x.Installer),
(activeInstall, installer) =>
{
if (activeInstall == null) return Observable.Empty<IChangeSet<IUserIntervention>>();
return activeInstall.LogMessages
.WhereCastable<IStatusMessage, IUserIntervention>()
.ToObservableChangeSet()
.AutoRefresh(i => i.Handled)
.Filter(i => !i.Handled)
.Transform(x => installer.InterventionConverter(x));
})
.Switch()
.AsObservableList();
// Find the top intervention /w no CPU ID to be marked as "global"
_ActiveGlobalUserIntervention = activeInterventions.Connect()
.Filter(x => x.CpuID == WorkQueue.UnassignedCpuId)
.QueryWhenChanged(query => query.FirstOrDefault())
.ToGuiProperty(this, nameof(ActiveGlobalUserIntervention));
*/
CloseWhenCompleteCommand = ReactiveCommand.CreateFromTask(
canExecute: this.WhenAny(x => x.Completed)
.Select(x => x != null),
execute: async () =>
{
await MWVM.ShutdownApplication();
});
GoToInstallCommand = ReactiveCommand.Create(
canExecute: Observable.CombineLatest(
this.WhenAny(x => x.Completed)
.Select(x => x != null),
this.WhenAny(x => x.Installer.SupportsAfterInstallNavigation),
resultSelector: (complete, supports) => complete && supports),
execute: () =>
{
Installer.AfterInstallNavigation();
});
/*
_CurrentCpuCount = this.WhenAny(x => x.Installer.ActiveInstallation.Queue.CurrentCpuCount)
.Switch()
.ToGuiProperty(this, nameof(CurrentCpuCount));
*/
} }
private async Task LoadModlist(AbsolutePath path)
{
using var ll = LoadingLock.WithLoading();
ModListLocation.TargetPath = path;
try
{
ModList = await StandardInstaller.LoadFromFile(_dtos, path);
ModListImage = BitmapFrame.Create(await StandardInstaller.ModListImageStream(path));
PopulateSlideShow(ModList);
ll.Succeed();
}
catch (Exception ex)
{
_logger.LogError(ex, "While loading modlist");
ll.Fail();
}
}
private void PopulateSlideShow(ModList modList)
{
SlideShowTitle = modList.Name;
SlideShowAuthor = modList.Author;
SlideShowDescription = modList.Description;
SlideShowImage = ModListImage;
}
} }

View File

@ -12,6 +12,7 @@ using ReactiveUI.Fody.Helpers;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack.Installer; using Wabbajack.Installer;
using Wabbajack; using Wabbajack;
using Wabbajack.DTOs;
using Wabbajack.Interventions; using Wabbajack.Interventions;
using Wabbajack.Util; using Wabbajack.Util;
@ -20,15 +21,15 @@ namespace Wabbajack
public class MO2InstallerVM : ViewModel, ISubInstallerVM public class MO2InstallerVM : ViewModel, ISubInstallerVM
{ {
public InstallerVM Parent { get; } public InstallerVM Parent { get; }
private readonly ObservableAsPropertyHelper<ErrorResponse> _CanInstall; [Reactive]
public ErrorResponse CanInstall => _CanInstall.Value; public ErrorResponse CanInstall { get; set; }
[Reactive] [Reactive]
public IInstaller ActiveInstallation { get; private set; } public IInstaller ActiveInstallation { get; private set; }
private readonly ObservableAsPropertyHelper<Mo2ModlistInstallationSettings> _CurrentSettings;
public Mo2ModlistInstallationSettings CurrentSettings => _CurrentSettings.Value; [Reactive] public Mo2ModlistInstallationSettings CurrentSettings { get; set; }
public FilePickerVM Location { get; } public FilePickerVM Location { get; }
@ -150,7 +151,7 @@ namespace Wabbajack
private void SaveSettings(Mo2ModlistInstallationSettings settings) private void SaveSettings(Mo2ModlistInstallationSettings settings)
{ {
Parent.MWVM.Settings.Installer.LastInstalledListLocation = Parent.ModListLocation.TargetPath; //Parent.MWVM.Settings.Installer.LastInstalledListLocation = Parent.ModListLocation.TargetPath;
if (settings == null) return; if (settings == null) return;
settings.InstallationLocation = Location.TargetPath; settings.InstallationLocation = Location.TargetPath;
settings.DownloadLocation = DownloadLocation.TargetPath; settings.DownloadLocation = DownloadLocation.TargetPath;

View File

@ -3,6 +3,7 @@ using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Reflection; using System.Reflection;
@ -16,6 +17,7 @@ using Wabbajack.Downloaders.GameFile;
using Wabbajack; using Wabbajack;
using Wabbajack.Interventions; using Wabbajack.Interventions;
using Wabbajack.Messages; using Wabbajack.Messages;
using Wabbajack.Models;
using Wabbajack.Networking.WabbajackClientApi; using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Paths; using Wabbajack.Paths;
using Wabbajack.View_Models; using Wabbajack.View_Models;
@ -38,7 +40,7 @@ namespace Wabbajack
public ObservableCollectionExtended<IStatusMessage> Log { get; } = new ObservableCollectionExtended<IStatusMessage>(); public ObservableCollectionExtended<IStatusMessage> Log { get; } = new ObservableCollectionExtended<IStatusMessage>();
public readonly Lazy<CompilerVM> Compiler; public readonly Lazy<CompilerVM> Compiler;
public readonly Lazy<InstallerVM> Installer; public readonly InstallerVM Installer;
public readonly Lazy<SettingsVM> SettingsPane; public readonly Lazy<SettingsVM> SettingsPane;
public readonly ModListGalleryVM Gallery; public readonly ModListGalleryVM Gallery;
public readonly ModeSelectionVM ModeSelectionVM; public readonly ModeSelectionVM ModeSelectionVM;
@ -46,24 +48,30 @@ namespace Wabbajack
public readonly UserInterventionHandlers UserInterventionHandlers; public readonly UserInterventionHandlers UserInterventionHandlers;
private readonly Client _wjClient; private readonly Client _wjClient;
private readonly ILogger<MainWindowVM> _logger; private readonly ILogger<MainWindowVM> _logger;
private readonly ResourceMonitor _resourceMonitor;
public ICommand CopyVersionCommand { get; } public ICommand CopyVersionCommand { get; }
public ICommand ShowLoginManagerVM { get; } public ICommand ShowLoginManagerVM { get; }
public ICommand OpenSettingsCommand { get; } public ICommand OpenSettingsCommand { get; }
public string VersionDisplay { get; } public string VersionDisplay { get; }
[Reactive]
public string ResourceStatus { get; set; }
[Reactive] [Reactive]
public bool UpdateAvailable { get; private set; } public bool UpdateAvailable { get; private set; }
public MainWindowVM(ILogger<MainWindowVM> logger, MainSettings settings, Client wjClient, public MainWindowVM(ILogger<MainWindowVM> logger, MainSettings settings, Client wjClient,
IServiceProvider serviceProvider, ModeSelectionVM modeSelectionVM, ModListGalleryVM modListGalleryVM) IServiceProvider serviceProvider, ModeSelectionVM modeSelectionVM, ModListGalleryVM modListGalleryVM, ResourceMonitor resourceMonitor,
InstallerVM installer)
{ {
_logger = logger; _logger = logger;
_wjClient = wjClient; _wjClient = wjClient;
_resourceMonitor = resourceMonitor;
ConverterRegistration.Register(); ConverterRegistration.Register();
Settings = settings; Settings = settings;
Installer = new Lazy<InstallerVM>(() => new InstallerVM(serviceProvider.GetRequiredService<ILogger<InstallerVM>>(), this, serviceProvider)); Installer = installer;
Compiler = new Lazy<CompilerVM>(() => new CompilerVM(serviceProvider.GetRequiredService<ILogger<CompilerVM>>(), this)); Compiler = new Lazy<CompilerVM>(() => new CompilerVM(serviceProvider.GetRequiredService<ILogger<CompilerVM>>(), this));
SettingsPane = new Lazy<SettingsVM>(() => new SettingsVM(serviceProvider.GetRequiredService<ILogger<SettingsVM>>(), this, serviceProvider)); SettingsPane = new Lazy<SettingsVM>(() => new SettingsVM(serviceProvider.GetRequiredService<ILogger<SettingsVM>>(), this, serviceProvider));
Gallery = modListGalleryVM; Gallery = modListGalleryVM;
@ -74,6 +82,12 @@ namespace Wabbajack
MessageBus.Current.Listen<NavigateToGlobal>() MessageBus.Current.Listen<NavigateToGlobal>()
.Subscribe(m => HandleNavigateTo(m.Screen)) .Subscribe(m => HandleNavigateTo(m.Screen))
.DisposeWith(CompositeDisposable); .DisposeWith(CompositeDisposable);
_resourceMonitor.Updates
.Select(r => string.Join(", ", r.Where(r => r.Throughput > 0)
.Select(s => $"{s.Name} - {s.Throughput.ToFileSizeString()}/sec")))
.BindToStrict(this, view => view.ResourceStatus);
// Set up logging // Set up logging
/* TODO /* TODO
@ -120,7 +134,7 @@ namespace Wabbajack
if (IsStartingFromModlist(out var path)) if (IsStartingFromModlist(out var path))
{ {
Installer.Value.ModListLocation.TargetPath = path; LoadModlistForInstalling.Send(path);
NavigateToGlobal.Send(NavigateToGlobal.ScreenType.Installer); NavigateToGlobal.Send(NavigateToGlobal.ScreenType.Installer);
} }
else else
@ -161,7 +175,7 @@ namespace Wabbajack
{ {
NavigateToGlobal.ScreenType.ModeSelectionView => ModeSelectionVM, NavigateToGlobal.ScreenType.ModeSelectionView => ModeSelectionVM,
NavigateToGlobal.ScreenType.ModListGallery => Gallery, NavigateToGlobal.ScreenType.ModListGallery => Gallery,
NavigateToGlobal.ScreenType.Installer => Installer.Value, NavigateToGlobal.ScreenType.Installer => Installer,
NavigateToGlobal.ScreenType.Settings => SettingsPane.Value, NavigateToGlobal.ScreenType.Settings => SettingsPane.Value,
_ => ActivePane _ => ActivePane
}; };
@ -183,15 +197,6 @@ namespace Wabbajack
return false; return false;
} }
public void OpenInstaller(AbsolutePath path)
{
if (path == default) return;
var installer = Installer.Value;
Settings.Installer.LastInstalledListLocation = path;
NavigateToGlobal.Send(NavigateToGlobal.ScreenType.Installer);
installer.ModListLocation.TargetPath = path;
}
/* /*
public void NavigateTo(ViewModel vm) public void NavigateTo(ViewModel vm)
{ {

View File

@ -23,19 +23,7 @@ namespace Wabbajack
public ModeSelectionVM() public ModeSelectionVM()
{ {
InstallCommand = ReactiveCommand.Create( InstallCommand = ReactiveCommand.Create(() => NavigateToGlobal.Send(NavigateToGlobal.ScreenType.Installer));
execute: () =>
{
/* TODO
var path = mainVM.Settings.Installer.LastInstalledListLocation;
if (path == default || !path.FileExists())
{
path = UIUtils.OpenFileDialog($"*{Ext.Wabbajack}|*{Ext.Wabbajack}");
}
_mainVM.OpenInstaller(path);
*/
});
CompileCommand = ReactiveCommand.Create(() => NavigateToGlobal.Send(NavigateToGlobal.ScreenType.Compiler)); CompileCommand = ReactiveCommand.Create(() => NavigateToGlobal.Send(NavigateToGlobal.ScreenType.Compiler));
BrowseCommand = ReactiveCommand.Create(() => NavigateToGlobal.Send(NavigateToGlobal.ScreenType.ModListGallery)); BrowseCommand = ReactiveCommand.Create(() => NavigateToGlobal.Send(NavigateToGlobal.ScreenType.ModListGallery));
} }

View File

@ -1,161 +0,0 @@
using System;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Windows.Media.Imaging;
using DynamicData;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Common;
using Wabbajack.DTOs.DownloadStates;
using Wabbajack;
using Wabbajack.Extensions;
namespace Wabbajack.View_Models
{
public class SlideShow : ViewModel
{
private readonly Random _random = new Random();
public InstallerVM Installer { get; }
[Reactive]
public bool ShowNSFW { get; set; }
[Reactive]
public bool Enable { get; set; } = true;
private readonly ObservableAsPropertyHelper<BitmapImage> _image;
public BitmapImage Image => _image.Value;
private readonly ObservableAsPropertyHelper<ModVM> _targetMod;
public ModVM TargetMod => _targetMod.Value;
public ReactiveCommand<Unit, Unit> SlideShowNextItemCommand { get; } = ReactiveCommand.Create(() => { });
public ReactiveCommand<Unit, Unit> VisitURLCommand { get; }
public const int PreloadAmount = 4;
public SlideShow(InstallerVM appState, IServiceProvider provider)
{
Installer = appState;
// Wire target slideshow index
var intervalSeconds = 10;
// Compile all the sources that trigger a slideshow update, any of which trigger a counter update
var selectedIndex = Observable.Merge(
// If user requests one manually
SlideShowNextItemCommand.StartingExecution(),
// If the natural timer fires
Observable.Merge(
// Start with an initial timer
Observable.Return(Observable.Interval(TimeSpan.FromSeconds(intervalSeconds))),
// but reset timer if user requests one
SlideShowNextItemCommand.StartingExecution()
.Select(_ => Observable.Interval(TimeSpan.FromSeconds(intervalSeconds))))
// When a new timer comes in, swap to it
.Switch()
.Unit()
// Only subscribe to timer if enabled and installing
.FlowSwitch(
Observable.CombineLatest(
this.WhenAny(x => x.Enable),
this.WhenAny(x => x.Installer.Installing),
resultSelector: (enabled, installing) => enabled && installing)))
// When filter switch enabled, fire an initial signal
.StartWith(Unit.Default)
// Only subscribe to slideshow triggers if started
.FlowSwitch(this.WhenAny(x => x.Installer.StartedInstallation))
// Block spam
.Debounce(TimeSpan.FromMilliseconds(250), RxApp.MainThreadScheduler)
.Scan(
seed: 0,
accumulator: (i, _) => i + 1)
.Publish()
.RefCount();
// Dynamic list changeset of mod VMs to display
var modVMs = this.WhenAny(x => x.Installer.ModList)
// Whenever modlist changes, grab the list of its slides
.Select(modList =>
{
if (modList?.SourceModList?.Archives == null)
{
return Observable.Empty<IMetaState>()
.ToObservableChangeSet(x => x.LinkUrl);
}
return modList.SourceModList.Archives
.Select(m => m.State)
.OfType<IMetaState>()
.Where(x => x.LinkUrl != default && x.ImageURL != default)
.DistinctBy(x => x.LinkUrl)
// Shuffle it
.Shuffle(_random)
.AsObservableChangeSet(x => x.LinkUrl);
})
// Switch to the new list after every ModList change
.Switch()
.Transform(mod => new ModVM(provider.GetRequiredService<ILogger<ModVM>>(), mod))
.DisposeMany()
// Filter out any NSFW slides if we don't want them
.AutoRefreshOnObservable(slide => this.WhenAny(x => x.ShowNSFW))
.Filter(slide => !slide.State.IsNSFW || ShowNSFW)
.RefCount();
// Find target mod to display by combining dynamic list with currently desired index
_targetMod = Observable.CombineLatest(
modVMs.QueryWhenChanged(),
selectedIndex,
resultSelector: (query, selected) =>
{
var index = selected % (query.Count == 0 ? 1 : query.Count);
return query.Items.ElementAtOrDefault(index);
})
.StartWith(default(ModVM))
.ToGuiProperty(this, nameof(TargetMod));
// Mark interest and materialize image of target mod
_image = this.WhenAny(x => x.TargetMod)
// We want to Switch here, not SelectMany, as we want to hotswap to newest target without waiting on old ones
.Select(x => x?.ImageObservable ?? Observable.Return(default(BitmapImage)))
.Switch()
.ToGuiProperty(this, nameof(Image));
VisitURLCommand = ReactiveCommand.Create(
execute: () =>
{
UIUtils.OpenWebsite(TargetMod.State.LinkUrl);
return Unit.Default;
},
canExecute: this.WhenAny(x => x.TargetMod.State.LinkUrl)
.Select(x =>
{
//var regex = new Regex("^(http|https):\\/\\/");
var scheme = x?.Scheme;
return scheme != null &&
(scheme.Equals("https", StringComparison.OrdinalIgnoreCase) ||
scheme.Equals("http", StringComparison.OrdinalIgnoreCase));
})
.ObserveOnGuiThread());
// Preload upcoming images
var list = Observable.CombineLatest(
modVMs.QueryWhenChanged(),
selectedIndex,
resultSelector: (query, selected) =>
{
// Retrieve the mods that should be preloaded
var index = selected % (query.Count == 0 ? 1 : query.Count);
var amountToTake = Math.Min(query.Count - index, PreloadAmount);
return query.Items.Skip(index).Take(amountToTake).ToObservable();
})
.Select(i => i.ToObservableChangeSet())
.Switch()
.Transform(mod => mod.ImageObservable.Subscribe())
.DisposeMany()
.AsObservableList();
}
}
}

View File

@ -119,6 +119,7 @@ namespace Wabbajack
.BindToStrict(this, x => x.BadgeImage.Source) .BindToStrict(this, x => x.BadgeImage.Source)
.DisposeWith(dispose); .DisposeWith(dispose);
this.WhenAny(x => x.Image) this.WhenAny(x => x.Image)
.Select(f => f)
.BindToStrict(this, x => x.ModlistImage.Source) .BindToStrict(this, x => x.ModlistImage.Source)
.DisposeWith(dispose); .DisposeWith(dispose);
this.WhenAny(x => x.Image) this.WhenAny(x => x.Image)

View File

@ -301,6 +301,7 @@
<local:CpuView Grid.Column="2" <local:CpuView Grid.Column="2"
x:Name="CpuView" x:Name="CpuView"
ViewModel="{Binding}" /> ViewModel="{Binding}" />
<!--
<local:AttentionBorder Grid.Column="2" <local:AttentionBorder Grid.Column="2"
x:Name="UserInterventionsControl" x:Name="UserInterventionsControl"
Content="{Binding ActiveGlobalUserIntervention}"> Content="{Binding ActiveGlobalUserIntervention}">
@ -313,6 +314,7 @@
</DataTemplate> </DataTemplate>
</local:AttentionBorder.Resources> </local:AttentionBorder.Resources>
</local:AttentionBorder> </local:AttentionBorder>
-->
<local:InstallationCompleteView Grid.Column="2" <local:InstallationCompleteView Grid.Column="2"
x:Name="InstallComplete" x:Name="InstallComplete"
ViewModel="{Binding}" /> ViewModel="{Binding}" />

View File

@ -14,130 +14,48 @@ namespace Wabbajack
public InstallationView() public InstallationView()
{ {
InitializeComponent(); InitializeComponent();
this.WhenActivated(dispose => this.WhenActivated(disposables =>
{ {
this.MarkAsNeeded<InstallationView, InstallerVM, bool>(this.ViewModel, x => x.Installing); MidInstallDisplayGrid.Visibility = Visibility.Collapsed;
this.MarkAsNeeded<InstallationView, InstallerVM, bool>(this.ViewModel, x => x.Slideshow.Enable); LogView.Visibility = Visibility.Collapsed;
CpuView.Visibility = Visibility.Collapsed;
// General progress indicators //ViewModel.WhenAnyValue(vm => vm.ModList.Name)
this.WhenAny(x => x.ViewModel.PercentCompleted) // .BindToStrict(this, view => view.Name)
.Select(x => (double)x)
.BindToStrict(this, x => x.HeatedBackground.PercentCompleted)
.DisposeWith(dispose);
// Top Progress Bar ViewModel.WhenAnyValue(vm => vm.BackCommand)
this.WhenAny(x => x.ViewModel.ModListName) .BindToStrict(this, view => view.BackButton.Command)
.BindToStrict(this, x => x.TopProgressBar.Title) .DisposeWith(disposables);
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.ProgressTitle)
.BindToStrict(this, x => x.TopProgressBar.StatePrefixTitle)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.PercentCompleted)
.Select(x => (double)x)
.BindToStrict(this, x => x.TopProgressBar.ProgressPercent)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.BackCommand)
.BindToStrict(this, x => x.BackButton.Command)
.DisposeWith(dispose);
// Detail Image ViewModel.WhenAnyValue(vm => vm.OpenReadmeCommand)
this.WhenAny(x => x.ViewModel.TitleText) .BindToStrict(this, view => view.OpenReadmePreInstallButton.Command)
.BindToStrict(this, x => x.DetailImage.Title) .DisposeWith(disposables);
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.AuthorText)
.BindToStrict(this, x => x.DetailImage.Author)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.Description)
.BindToStrict(this, x => x.DetailImage.Description)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.Image)
.BindToStrict(this, x => x.DetailImage.Image)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.LoadingModlist)
.Select(x => x ? Visibility.Visible : Visibility.Collapsed)
.BindToStrict(this, x => x.ModlistLoadingRing.Visibility)
.DisposeWith(dispose);
// Slideshow controls ViewModel.WhenAnyValue(vm => vm.VisitModListWebsiteCommand)
this.WhenAny(x => x.ViewModel.Slideshow.SlideShowNextItemCommand) .BindToStrict(this, view => view.OpenWebsite.Command)
.BindToStrict(this, x => x.SkipSlideButton.Command) .DisposeWith(disposables);
.DisposeWith(dispose);
this.BindStrict(this.ViewModel, x => x.Slideshow.Enable, x => x.PlayPauseButton.IsChecked,
vmToViewConverter: x => x,
viewToVmConverter: x => x ?? true)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.Slideshow.Enable)
.Select(enabled =>
{
return $"{(enabled ? "Pause" : "Play")} slideshow";
})
.BindToStrict(this, x => x.PlayPauseButton.ToolTip)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.Slideshow.VisitURLCommand)
.BindToStrict(this, x => x.OpenWebsite.Command)
.DisposeWith(dispose);
this.BindStrict(this.ViewModel, x => x.Slideshow.ShowNSFW, x => x.ShowNSFWButton.IsChecked,
vmToViewConverter: x => x,
viewToVmConverter: x => x ?? true)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.Slideshow.ShowNSFW)
.Select(show =>
{
return $"{(show ? "Hide" : "Show")} NSFW mods";
})
.BindToStrict(this, x => x.ShowNSFWButton.ToolTip)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.Slideshow.ShowNSFW)
.Select(show => show ? Visibility.Collapsed : Visibility.Visible)
.BindToStrict(this, x => x.NSFWSlashIcon.Visibility)
.DisposeWith(dispose);
// Bottom Input Customization ViewModel.WhenAnyValue(vm => vm.LoadingLock.IsLoading)
this.WhenAny(x => x.ViewModel.StartedInstallation) .Select(loading => loading ? Visibility.Visible : Visibility.Collapsed)
.Select(started => started ? Visibility.Hidden : Visibility.Visible) .BindToStrict(this, view => view.ModlistLoadingRing.Visibility)
.BindToStrict(this, x => x.BottomButtonInputGrid.Visibility) .DisposeWith(disposables);
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.OpenReadmeCommand) // Slideshow
.BindToStrict(this, x => x.OpenReadmePreInstallButton.Command) ViewModel.WhenAnyValue(vm => vm.SlideShowTitle)
.DisposeWith(dispose); .Select(f => f)
this.WhenAny(x => x.ViewModel.VisitModListWebsiteCommand) .BindToStrict(this, view => view.DetailImage.Title)
.BindToStrict(this, x => x.VisitWebsitePreInstallButton.Command) .DisposeWith(disposables);
.DisposeWith(dispose); ViewModel.WhenAnyValue(vm => vm.SlideShowAuthor)
this.WhenAny(x => x.ViewModel.ShowManifestCommand) .BindToStrict(this, view => view.DetailImage.Author)
.BindToStrict(this, x => x.ShowManifestPreInstallButton.Command) .DisposeWith(disposables);
.DisposeWith(dispose); ViewModel.WhenAnyValue(vm => vm.SlideShowDescription)
this.WhenAny(x => x.ViewModel.StartedInstallation) .BindToStrict(this, view => view.DetailImage.Description)
.Select(started => started ? Visibility.Collapsed : Visibility.Visible) .DisposeWith(disposables);
.BindToStrict(this, x => x.InstallationConfigurationView.Visibility)
.DisposeWith(dispose); ViewModel.WhenAnyValue(vm => vm.SlideShowImage)
.BindToStrict(this, view => view.DetailImage.Image)
.DisposeWith(disposables);
// Bottom mid-install display
this.WhenAny(x => x.ViewModel.StartedInstallation)
.Select(started => started ? Visibility.Visible : Visibility.Hidden)
.BindToStrict(this, x => x.MidInstallDisplayGrid.Visibility)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.PercentCompleted)
.Select(x => (double)x)
.BindToStrict(this, x => x.LogView.ProgressPercent)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.PercentCompleted)
.BindToStrict(this, x => x.CpuView.ProgressPercent)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.MWVM.Settings)
.BindToStrict(this, x => x.CpuView.SettingsHook)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.ActiveGlobalUserIntervention)
.Select(x => x == null ? Visibility.Visible : Visibility.Collapsed)
.BindToStrict(this, x => x.CpuView.Visibility)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.ActiveGlobalUserIntervention)
.Select(x => x != null ? Visibility.Visible : Visibility.Collapsed)
.BindToStrict(this, x => x.UserInterventionsControl.Visibility)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.Completed)
.Select(completed => completed != null ? Visibility.Visible : Visibility.Collapsed)
.BindToStrict(this, x => x.InstallComplete.Visibility)
.DisposeWith(dispose);
}); });
} }
} }

View File

@ -21,7 +21,12 @@
UseLayoutRounding="True" UseLayoutRounding="True"
WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}" WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}"
mc:Ignorable="d"> mc:Ignorable="d">
<ContentPresenter Content="{Binding ActivePane}"> <Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="0" Content="{Binding ActivePane}">
<ContentPresenter.Resources> <ContentPresenter.Resources>
<DataTemplate DataType="{x:Type local:CompilerVM}"> <DataTemplate DataType="{x:Type local:CompilerVM}">
<local:CompilerView ViewModel="{Binding}" /> <local:CompilerView ViewModel="{Binding}" />
@ -46,12 +51,15 @@
</DataTemplate> </DataTemplate>
</ContentPresenter.Resources> </ContentPresenter.Resources>
</ContentPresenter> </ContentPresenter>
<TextBlock Grid.Row="1" Margin="5, 0" Name="ResourceUsage" HorizontalAlignment="Right"></TextBlock>
</Grid>
<mahapps:MetroWindow.RightWindowCommands> <mahapps:MetroWindow.RightWindowCommands>
<mahapps:WindowCommands> <mahapps:WindowCommands>
<mahapps:WindowCommands.Resources> <mahapps:WindowCommands.Resources>
<Style BasedOn="{StaticResource IconBareButtonStyle}" TargetType="Button" /> <Style BasedOn="{StaticResource IconBareButtonStyle}" TargetType="Button" />
</mahapps:WindowCommands.Resources> </mahapps:WindowCommands.Resources>
<Button <Button
Margin="5,0" Margin="5,0"
Command="{Binding CopyVersionCommand}" Command="{Binding CopyVersionCommand}"

View File

@ -1,8 +1,11 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Reactive.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using MahApps.Metro.Controls; using MahApps.Metro.Controls;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ReactiveUI;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack; using Wabbajack;
using Wabbajack.LibCefHelpers; using Wabbajack.LibCefHelpers;
@ -92,6 +95,15 @@ namespace Wabbajack
_logger.LogError(ex, "During Main Window Startup"); _logger.LogError(ex, "During Main Window Startup");
Environment.Exit(-1); Environment.Exit(-1);
} }
vm.WhenAnyValue(vm => vm.ResourceStatus)
.BindToStrict(this, view => view.ResourceUsage.Text);
vm.WhenAnyValue(vm => vm.ResourceStatus)
.Select(x => string.IsNullOrWhiteSpace(x) ? Visibility.Collapsed : Visibility.Visible)
.BindToStrict(this, view => view.ResourceUsage.Visibility);
} }
public void Init(MainWindowVM vm, MainSettings settings) public void Init(MainWindowVM vm, MainSettings settings)

View File

@ -111,8 +111,4 @@
<SplashScreen Include="Resources\Wabba_Mouth_Small.png" /> <SplashScreen Include="Resources\Wabba_Mouth_Small.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Models" />
</ItemGroup>
</Project> </Project>

View File

@ -165,6 +165,16 @@ public abstract class AInstaller<T>
} }
} }
public static async Task<Stream> ModListImageStream(AbsolutePath path)
{
await using var fs = path.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
using var ar = new ZipArchive(fs, ZipArchiveMode.Read);
var entry = ar.GetEntry("modlist-image.png");
if (entry == null)
throw new InvalidDataException("No modlist image found");
return new MemoryStream(await entry.Open().ReadAllAsync());
}
/// <summary> /// <summary>
/// We don't want to make the installer index all the archives, that's just a waste of time, so instead /// We don't want to make the installer index all the archives, that's just a waste of time, so instead
/// we'll pass just enough information to VFS to let it know about the files we have. /// we'll pass just enough information to VFS to let it know about the files we have.

View File

@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Modlist/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Wabbajack/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> <s:Boolean x:Key="/Default/UserDictionary/Words/=Wabbajack/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>