diff --git a/Wabbajack.App.Wpf/View Models/CPUDisplayVM.cs b/Wabbajack.App.Wpf/View Models/CPUDisplayVM.cs index 559d95c3..0af57155 100644 --- a/Wabbajack.App.Wpf/View Models/CPUDisplayVM.cs +++ b/Wabbajack.App.Wpf/View Models/CPUDisplayVM.cs @@ -1,11 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using ReactiveUI.Fody.Helpers; -using Wabbajack.Common; using Wabbajack.Lib; +using Wabbajack.RateLimiter; namespace Wabbajack { @@ -26,12 +22,12 @@ namespace Wabbajack { } - public CPUDisplayVM(CPUStatus cpu) + public CPUDisplayVM(IJob cpu) { AbsorbStatus(cpu); } - public void AbsorbStatus(CPUStatus cpu) + public void AbsorbStatus(IJob cpu) { bool starting = cpu.IsWorking && !IsWorking; if (starting) @@ -39,7 +35,7 @@ namespace Wabbajack StartTime = DateTime.Now; } - ID = cpu.ID; + ID = cpu.; Msg = cpu.Msg; ProgressPercent = cpu.ProgressPercent; IsWorking = cpu.IsWorking; diff --git a/Wabbajack.App.Wpf/View Models/SlideShow.cs b/Wabbajack.App.Wpf/View Models/SlideShow.cs index 48d8565e..0b4cd6a5 100644 --- a/Wabbajack.App.Wpf/View Models/SlideShow.cs +++ b/Wabbajack.App.Wpf/View Models/SlideShow.cs @@ -1,10 +1,14 @@ 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.Lib; using Wabbajack.Lib.Extensions; @@ -34,7 +38,7 @@ namespace Wabbajack.View_Models public const int PreloadAmount = 4; - public SlideShow(InstallerVM appState) + public SlideShow(InstallerVM appState, ServiceProvider provider) { Installer = appState; @@ -85,15 +89,15 @@ namespace Wabbajack.View_Models return modList.SourceModList.Archives .Select(m => m.State) .OfType() - .Where(x => x.URL != default && x.ImageURL != default) - .DistinctBy(x => x.URL) + .Where(x => x.LinkUrl != default && x.ImageURL != default) + .DistinctBy(x => x.LinkUrl) // Shuffle it .Shuffle(_random) - .AsObservableChangeSet(x => x.URL); + .AsObservableChangeSet(x => x.LinkUrl); }) // Switch to the new list after every ModList change .Switch() - .Transform(mod => new ModVM(mod)) + .Transform(mod => new ModVM(provider.GetService>(), mod)) .DisposeMany() // Filter out any NSFW slides if we don't want them .AutoRefreshOnObservable(slide => this.WhenAny(x => x.ShowNSFW)) @@ -122,10 +126,10 @@ namespace Wabbajack.View_Models VisitURLCommand = ReactiveCommand.Create( execute: () => { - UIUtils.OpenWebsite(TargetMod.State.URL); + UIUtils.OpenWebsite(TargetMod.State.LinkUrl); return Unit.Default; }, - canExecute: this.WhenAny(x => x.TargetMod.State.URL) + canExecute: this.WhenAny(x => x.TargetMod.State.LinkUrl) .Select(x => { //var regex = new Regex("^(http|https):\\/\\/"); diff --git a/Wabbajack.Common/IEnumerableExtensions.cs b/Wabbajack.Common/IEnumerableExtensions.cs index 0ac36ba3..26922597 100644 --- a/Wabbajack.Common/IEnumerableExtensions.cs +++ b/Wabbajack.Common/IEnumerableExtensions.cs @@ -11,6 +11,28 @@ public static class IEnumerableExtensions { foreach (var i in coll) f(i); } + + #region Shuffle + /// https://stackoverflow.com/questions/5807128/an-extension-method-on-ienumerable-needed-for-shuffling + + public static IEnumerable Shuffle(this IEnumerable source, Random rng) + { + return source.ShuffleIterator(rng); + } + + private static IEnumerable ShuffleIterator( + this IEnumerable source, Random rng) + { + var buffer = source.ToList(); + for (int i = 0; i < buffer.Count; i++) + { + int j = rng.Next(i, buffer.Count); + yield return buffer[j]; + + buffer[j] = buffer[i]; + } + } + #endregion public static IEnumerable TryKeep(this IEnumerable coll, Func fn)