ABatchProcessor nullable. ConfigureProcessor removed

This commit is contained in:
Justin Swanson 2020-04-04 13:26:14 -05:00
parent 5377cd0cce
commit 6572f14f49
9 changed files with 26 additions and 28 deletions

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack.Common.StatusFeed; using Wabbajack.Common.StatusFeed;
using Wabbajack.VirtualFileSystem; using Wabbajack.VirtualFileSystem;
#nullable enable
namespace Wabbajack.Lib namespace Wabbajack.Lib
{ {
@ -15,9 +16,9 @@ namespace Wabbajack.Lib
{ {
public WorkQueue Queue { get; } = new WorkQueue(); public WorkQueue Queue { get; } = new WorkQueue();
public Context VFS { get; private set; } public Context VFS { get; }
protected StatusUpdateTracker UpdateTracker { get; private set; } protected StatusUpdateTracker UpdateTracker { get; }
private Subject<Percent> _percentCompleted { get; } = new Subject<Percent>(); private Subject<Percent> _percentCompleted { get; } = new Subject<Percent>();
@ -42,7 +43,6 @@ namespace Wabbajack.Lib
private Subject<bool> _isRunning { get; } = new Subject<bool>(); private Subject<bool> _isRunning { get; } = new Subject<bool>();
public IObservable<bool> IsRunning => _isRunning; public IObservable<bool> IsRunning => _isRunning;
private int _configured;
private int _started; private int _started;
private readonly CancellationTokenSource _cancel = new CancellationTokenSource(); private readonly CancellationTokenSource _cancel = new CancellationTokenSource();
@ -53,21 +53,16 @@ namespace Wabbajack.Lib
public BehaviorSubject<byte> MaxCores = new BehaviorSubject<byte>(byte.MaxValue); public BehaviorSubject<byte> MaxCores = new BehaviorSubject<byte>(byte.MaxValue);
public BehaviorSubject<Percent> TargetUsagePercent = new BehaviorSubject<Percent>(Percent.One); public BehaviorSubject<Percent> TargetUsagePercent = new BehaviorSubject<Percent>(Percent.One);
protected void ConfigureProcessor(int steps, IObservable<int> numThreads = null) public ABatchProcessor(int steps)
{ {
if (1 == Interlocked.CompareExchange(ref _configured, 1, 1))
{
throw new InvalidDataException("Can't configure a processor twice");
}
Queue.SetActiveThreadsObservable(numThreads);
UpdateTracker = new StatusUpdateTracker(steps); UpdateTracker = new StatusUpdateTracker(steps);
VFS = new Context(Queue) { UpdateTracker = UpdateTracker };
Queue.Status.Subscribe(_queueStatus) Queue.Status.Subscribe(_queueStatus)
.DisposeWith(_subs); .DisposeWith(_subs);
Queue.LogMessages.Subscribe(_logMessages) Queue.LogMessages.Subscribe(_logMessages)
.DisposeWith(_subs); .DisposeWith(_subs);
UpdateTracker.Progress.Subscribe(_percentCompleted); UpdateTracker.Progress.Subscribe(_percentCompleted);
UpdateTracker.StepName.Subscribe(_textStatus); UpdateTracker.StepName.Subscribe(_textStatus);
VFS = new Context(Queue) { UpdateTracker = UpdateTracker };
} }
/// <summary> /// <summary>

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
@ -50,6 +50,11 @@ namespace Wabbajack.Lib
public List<IndexedArchive> IndexedArchives = new List<IndexedArchive>(); public List<IndexedArchive> IndexedArchives = new List<IndexedArchive>();
public Dictionary<Hash, IEnumerable<VirtualFile>> IndexedFiles = new Dictionary<Hash, IEnumerable<VirtualFile>>(); public Dictionary<Hash, IEnumerable<VirtualFile>> IndexedFiles = new Dictionary<Hash, IEnumerable<VirtualFile>>();
public ACompiler(int steps)
: base(steps)
{
}
public static void Info(string msg) public static void Info(string msg)
{ {
Utils.Log(msg); Utils.Log(msg);

View File

@ -31,7 +31,8 @@ namespace Wabbajack.Lib
public SystemParameters SystemParameters { get; set; } public SystemParameters SystemParameters { get; set; }
public AInstaller(AbsolutePath archive, ModList modList, AbsolutePath outputFolder, AbsolutePath downloadFolder, SystemParameters parameters) public AInstaller(AbsolutePath archive, ModList modList, AbsolutePath outputFolder, AbsolutePath downloadFolder, SystemParameters parameters, int steps)
: base(steps)
{ {
ModList = modList; ModList = modList;
ModListArchive = archive; ModListArchive = archive;

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Wabbajack.Common; using Wabbajack.Common;
#nullable enable
namespace Wabbajack.Lib namespace Wabbajack.Lib
{ {

View File

@ -49,6 +49,7 @@ namespace Wabbajack.Lib
$"vfs_compile_cache-{Path.Combine((string)MO2Folder ?? "Unknown", "ModOrganizer.exe").StringSha256Hex()}.bin"); $"vfs_compile_cache-{Path.Combine((string)MO2Folder ?? "Unknown", "ModOrganizer.exe").StringSha256Hex()}.bin");
public MO2Compiler(AbsolutePath mo2Folder, string mo2Profile, AbsolutePath outputFile) public MO2Compiler(AbsolutePath mo2Folder, string mo2Profile, AbsolutePath outputFile)
: base(steps: 20)
{ {
MO2Folder = mo2Folder; MO2Folder = mo2Folder;
MO2Profile = mo2Profile; MO2Profile = mo2Profile;
@ -88,7 +89,7 @@ namespace Wabbajack.Lib
protected override async Task<bool> _Begin(CancellationToken cancel) protected override async Task<bool> _Begin(CancellationToken cancel)
{ {
if (cancel.IsCancellationRequested) return false; if (cancel.IsCancellationRequested) return false;
ConfigureProcessor(20, ConstructDynamicNumThreads(await RecommendQueueSize())); Queue.SetActiveThreadsObservable(ConstructDynamicNumThreads(await RecommendQueueSize()));
UpdateTracker.Reset(); UpdateTracker.Reset();
UpdateTracker.NextStep("Gathering information"); UpdateTracker.NextStep("Gathering information");
Info("Looking for other profiles"); Info("Looking for other profiles");

View File

@ -38,7 +38,8 @@ namespace Wabbajack.Lib
modList: modList, modList: modList,
outputFolder: outputFolder, outputFolder: outputFolder,
downloadFolder: downloadFolder, downloadFolder: downloadFolder,
parameters: parameters) parameters: parameters,
steps: 20)
{ {
} }
@ -48,7 +49,7 @@ namespace Wabbajack.Lib
var metric = Metrics.Send(Metrics.BeginInstall, ModList.Name); var metric = Metrics.Send(Metrics.BeginInstall, ModList.Name);
Utils.Log("Configuring Processor"); Utils.Log("Configuring Processor");
ConfigureProcessor(20, ConstructDynamicNumThreads(await RecommendQueueSize())); Queue.SetActiveThreadsObservable(ConstructDynamicNumThreads(await RecommendQueueSize()));
var game = ModList.GameType.MetaData(); var game = ModList.GameType.MetaData();
if (GameFolder == null) if (GameFolder == null)

View File

@ -26,7 +26,8 @@ namespace Wabbajack.Lib
modList: modList, modList: modList,
outputFolder: outputFolder, outputFolder: outputFolder,
downloadFolder: downloadFolder, downloadFolder: downloadFolder,
parameters: parameters) parameters: parameters,
steps: 10)
{ {
#if DEBUG #if DEBUG
// TODO: only for testing // TODO: only for testing
@ -51,7 +52,7 @@ namespace Wabbajack.Lib
} }
if (cancel.IsCancellationRequested) return false; if (cancel.IsCancellationRequested) return false;
ConfigureProcessor(10, ConstructDynamicNumThreads(await RecommendQueueSize())); Queue.SetActiveThreadsObservable(ConstructDynamicNumThreads(await RecommendQueueSize()));
DownloadFolder.CreateDirectory(); DownloadFolder.CreateDirectory();
if (cancel.IsCancellationRequested) return false; if (cancel.IsCancellationRequested) return false;

View File

@ -532,7 +532,6 @@ namespace Wabbajack.Test
return state.ToJson().FromJsonString<T>(); return state.ToJson().FromJsonString<T>();
} }
[Fact] [Fact]
public async Task TestUpgrading() public async Task TestUpgrading()
{ {
@ -553,13 +552,12 @@ namespace Wabbajack.Test
Assert.Equal(Hash.FromBase64("gCRVrvzDNH0="), await dest.FileHashCachedAsync()); Assert.Equal(Hash.FromBase64("gCRVrvzDNH0="), await dest.FileHashCachedAsync());
} }
class TestInstaller : AInstaller class TestInstaller : AInstaller
{ {
public TestInstaller(AbsolutePath archive, ModList modList, AbsolutePath outputFolder, AbsolutePath downloadFolder, SystemParameters parameters) : base(archive, modList, outputFolder, downloadFolder, parameters) public TestInstaller(AbsolutePath archive, ModList modList, AbsolutePath outputFolder, AbsolutePath downloadFolder, SystemParameters parameters)
: base(archive, modList, outputFolder, downloadFolder, parameters, steps: 1)
{ {
ConfigureProcessor(1, new Subject<int>().StartWith(1)); Queue.SetActiveThreadsObservable(Observable.Return(1));
} }
protected override Task<bool> _Begin(CancellationToken cancel) protected override Task<bool> _Begin(CancellationToken cancel)
@ -569,10 +567,5 @@ namespace Wabbajack.Test
public override ModManager ModManager { get => ModManager.MO2; } public override ModManager ModManager { get => ModManager.MO2; }
} }
} }
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Windows; using System.Windows;
using System.Windows.Data; using System.Windows.Data;