mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
WorkQueue concepts migrated to MainWindowVM
Since WorkQueue is static itself, just put it in the main vm. If it ever gets made into a non-singleton, might refactor installer and compiler VMs to each have work queue systems
This commit is contained in:
parent
4f6c8b4aae
commit
1eafafcbec
15
Wabbajack/Util/CPUStatus.cs
Normal file
15
Wabbajack/Util/CPUStatus.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class CPUStatus
|
||||
{
|
||||
public int Progress { get; internal set; }
|
||||
public string Msg { get; internal set; }
|
||||
public int ID { get; internal set; }
|
||||
}
|
||||
}
|
@ -32,14 +32,12 @@ namespace Wabbajack
|
||||
public class AppState : ViewModel, IDataErrorInfo
|
||||
{
|
||||
public SlideShow Slideshow { get; }
|
||||
public MainWindowVM MWVM { get; }
|
||||
|
||||
private string _mo2Folder;
|
||||
|
||||
public readonly BitmapImage _noneImage = UIUtils.BitmapImageFromResource("Wabbajack.Resources.none.jpg");
|
||||
|
||||
private readonly Subject<CPUStatus> _statusSubject = new Subject<CPUStatus>();
|
||||
public ObservableCollectionExtended<CPUStatus> Status { get; } = new ObservableCollectionExtended<CPUStatus>();
|
||||
|
||||
private ModList _ModList;
|
||||
public ModList ModList { get => _ModList; private set => this.RaiseAndSetIfChanged(ref _ModList, value); }
|
||||
|
||||
@ -69,7 +67,7 @@ namespace Wabbajack
|
||||
public IReactiveCommand OpenReadmeCommand { get; }
|
||||
public IReactiveCommand OpenModListPropertiesCommand { get; }
|
||||
|
||||
public AppState(RunMode mode)
|
||||
public AppState(MainWindowVM mainWindowVM, RunMode mode)
|
||||
{
|
||||
if (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.ToLower()) == KnownFolders.Downloads.Path.ToLower())
|
||||
{
|
||||
@ -82,6 +80,7 @@ namespace Wabbajack
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
this.MWVM = mainWindowVM;
|
||||
Mode = mode;
|
||||
|
||||
// Define commands
|
||||
@ -103,22 +102,6 @@ namespace Wabbajack
|
||||
.ObserveOnGuiThread());
|
||||
|
||||
this.Slideshow = new SlideShow(this);
|
||||
|
||||
// Initialize work queue
|
||||
WorkQueue.Init(
|
||||
report_function: (id, msg, progress) => this._statusSubject.OnNext(new CPUStatus() { ID = id, Msg = msg, Progress = progress }),
|
||||
report_queue_size: (max, current) => this.SetQueueSize(max, current));
|
||||
// Compile progress updates and populate ObservableCollection
|
||||
this._statusSubject
|
||||
.ObserveOn(RxApp.TaskpoolScheduler)
|
||||
.ToObservableChangeSet(x => x.ID)
|
||||
.Batch(TimeSpan.FromMilliseconds(250))
|
||||
.EnsureUniqueChanges()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Sort(SortExpressionComparer<CPUStatus>.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly)
|
||||
.Bind(this.Status)
|
||||
.Subscribe()
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
}
|
||||
|
||||
public ObservableCollection<string> Log { get; } = new ObservableCollection<string>();
|
||||
@ -132,9 +115,6 @@ namespace Wabbajack
|
||||
private string _DownloadLocation;
|
||||
public string DownloadLocation { get => _DownloadLocation; set => this.RaiseAndSetIfChanged(ref _DownloadLocation, value); }
|
||||
|
||||
private int _queueProgress;
|
||||
public int QueueProgress { get => _queueProgress; set => this.RaiseAndSetIfChanged(ref _queueProgress, value); }
|
||||
|
||||
public string LogFile { get; }
|
||||
|
||||
private void ExecuteChangePath()
|
||||
@ -258,14 +238,6 @@ namespace Wabbajack
|
||||
Application.Current.Dispatcher.Invoke(() => Log.Add(msg));
|
||||
}
|
||||
|
||||
public void SetQueueSize(int max, int current)
|
||||
{
|
||||
if (max == 0)
|
||||
max = 1;
|
||||
var total = current * 100 / max;
|
||||
QueueProgress = total;
|
||||
}
|
||||
|
||||
private void ConfigureForBuild()
|
||||
{
|
||||
var profile_folder = Path.GetDirectoryName(Location);
|
||||
@ -384,11 +356,4 @@ namespace Wabbajack
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CPUStatus
|
||||
{
|
||||
public int Progress { get; internal set; }
|
||||
public string Msg { get; internal set; }
|
||||
public int ID { get; internal set; }
|
||||
}
|
||||
}
|
@ -1,9 +1,15 @@
|
||||
using ReactiveUI;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib;
|
||||
|
||||
namespace Wabbajack
|
||||
@ -15,9 +21,40 @@ namespace Wabbajack
|
||||
private ViewModel _ActivePane;
|
||||
public ViewModel ActivePane { get => _ActivePane; set => this.RaiseAndSetIfChanged(ref _ActivePane, value); }
|
||||
|
||||
private int _QueueProgress;
|
||||
public int QueueProgress { get => _QueueProgress; set => this.RaiseAndSetIfChanged(ref _QueueProgress, value); }
|
||||
|
||||
private readonly Subject<CPUStatus> _statusSubject = new Subject<CPUStatus>();
|
||||
public IObservable<CPUStatus> StatusObservable => _statusSubject;
|
||||
public ObservableCollectionExtended<CPUStatus> StatusList { get; } = new ObservableCollectionExtended<CPUStatus>();
|
||||
|
||||
public MainWindowVM(RunMode mode)
|
||||
{
|
||||
this.AppState = new AppState(mode);
|
||||
this.AppState = new AppState(this, mode);
|
||||
|
||||
// Initialize work queue
|
||||
WorkQueue.Init(
|
||||
report_function: (id, msg, progress) => this._statusSubject.OnNext(new CPUStatus() { ID = id, Msg = msg, Progress = progress }),
|
||||
report_queue_size: (max, current) => this.SetQueueSize(max, current));
|
||||
|
||||
// Compile progress updates and populate ObservableCollection
|
||||
this._statusSubject
|
||||
.ObserveOn(RxApp.TaskpoolScheduler)
|
||||
.ToObservableChangeSet(x => x.ID)
|
||||
.Batch(TimeSpan.FromMilliseconds(250))
|
||||
.EnsureUniqueChanges()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Sort(SortExpressionComparer<CPUStatus>.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly)
|
||||
.Bind(this.StatusList)
|
||||
.Subscribe()
|
||||
.DisposeWith(this.CompositeDisposable);
|
||||
}
|
||||
|
||||
private void SetQueueSize(int max, int current)
|
||||
{
|
||||
if (max == 0)
|
||||
max = 1;
|
||||
QueueProgress = current * 100 / max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@
|
||||
Background="#444444"
|
||||
Maximum="100"
|
||||
Minimum="0"
|
||||
Value="{Binding QueueProgress}" />
|
||||
Value="{Binding MWVM.QueueProgress}" />
|
||||
|
||||
<!-- Log -->
|
||||
<TextBlock
|
||||
@ -143,7 +143,7 @@
|
||||
Width="Auto"
|
||||
Margin="2,0,0,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding Status}">
|
||||
ItemsSource="{Binding MWVM.StatusList}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid HorizontalAlignment="Stretch">
|
||||
|
@ -227,6 +227,7 @@
|
||||
<Compile Include="Converters\IsNotNullVisibilityConverter.cs" />
|
||||
<Compile Include="Enums\RunMode.cs" />
|
||||
<Compile Include="Extensions\ReactiveUIExt.cs" />
|
||||
<Compile Include="Util\CPUStatus.cs" />
|
||||
<Compile Include="View Models\MainWindowVM.cs" />
|
||||
<Compile Include="Views\SlideshowView.xaml.cs">
|
||||
<DependentUpon>SlideshowView.xaml</DependentUpon>
|
||||
|
Loading…
Reference in New Issue
Block a user