Rename Compiler/Installer to MO2Compiler/MO2Installer, other code cleanup as well

This commit is contained in:
Timothy Baldridge 2019-11-17 17:17:06 -07:00
parent 0c78680c09
commit 8d5843ecc6
20 changed files with 79 additions and 80 deletions

View File

@ -26,40 +26,35 @@ namespace Wabbajack.Lib
protected StatusUpdateTracker UpdateTracker { get; private set; }
private Subject<float> _percentCompleted { get; set; } = new Subject<float>();
private Subject<float> _percentCompleted { get; } = new Subject<float>();
/// <summary>
/// The current progress of the entire processing system on a scale of 0.0 to 1.0
/// </summary>
public IObservable<float> PercentCompleted { get; }
public IObservable<float> PercentCompleted => _percentCompleted;
private Subject<string> _textStatus { get; set; } = new Subject<string>();
private Subject<string> _textStatus { get; } = new Subject<string>();
/// <summary>
/// The current status of the processor as a text string
/// </summary>
public IObservable<string> TextStatus { get; }
public IObservable<string> TextStatus => _textStatus;
private Subject<CPUStatus> _QueueStatus { get; set; } = new Subject<CPUStatus>();
public IObservable<CPUStatus> QueueStatus { get; }
private Subject<CPUStatus> _queueStatus { get; } = new Subject<CPUStatus>();
public IObservable<CPUStatus> QueueStatus => _queueStatus;
private Subject<bool> _IsRunning { get; set; } = new Subject<bool>();
public IObservable<bool> IsRunning { get; }
private Subject<bool> _isRunning { get; } = new Subject<bool>();
public IObservable<bool> IsRunning => _isRunning;
private Thread _processorThread { get; set; }
protected ABatchProcessor()
{
QueueStatus = _QueueStatus;
}
protected void ConfigureProcessor(int steps, int threads = 0)
{
if (_configured)
throw new InvalidDataException("Can't configure a processor twice");
Queue = new WorkQueue(threads);
UpdateTracker = new StatusUpdateTracker(steps);
Queue.Status.Subscribe(_QueueStatus);
Queue.Status.Subscribe(_queueStatus);
UpdateTracker.Progress.Subscribe(_percentCompleted);
UpdateTracker.StepName.Subscribe(_textStatus);
VFS = new Context(Queue) { UpdateTracker = UpdateTracker };
@ -69,7 +64,7 @@ namespace Wabbajack.Lib
protected abstract bool _Begin();
public Task<bool> Begin()
{
_IsRunning.OnNext(true);
_isRunning.OnNext(true);
var _tcs = new TaskCompletionSource<bool>();
if (_processorThread != null)
{
@ -88,7 +83,7 @@ namespace Wabbajack.Lib
}
finally
{
_IsRunning.OnNext(false);
_isRunning.OnNext(false);
}
});
_processorThread.Priority = ThreadPriority.BelowNormal;
@ -100,7 +95,7 @@ namespace Wabbajack.Lib
{
Queue?.Shutdown();
_processorThread?.Abort();
_IsRunning.OnNext(false);
_isRunning.OnNext(false);
}
}
}

View File

@ -13,11 +13,11 @@ namespace Wabbajack.Lib.CompilationSteps
private readonly IEnumerable<string> _include_directly;
private readonly List<ICompilationStep> _microstack;
private readonly List<ICompilationStep> _microstackWithInclude;
private readonly Compiler _mo2Compiler;
private readonly MO2Compiler _mo2Compiler;
public DeconstructBSAs(ACompiler compiler) : base(compiler)
{
_mo2Compiler = (Compiler) compiler;
_mo2Compiler = (MO2Compiler) compiler;
_include_directly = _mo2Compiler.ModInis.Where(kv =>
{
var general = kv.Value.General;

View File

@ -9,11 +9,11 @@ namespace Wabbajack.Lib.CompilationSteps
public class IgnoreDisabledMods : ACompilationStep
{
private readonly IEnumerable<string> _allEnabledMods;
private readonly Compiler _mo2Compiler;
private readonly MO2Compiler _mo2Compiler;
public IgnoreDisabledMods(ACompiler compiler) : base(compiler)
{
_mo2Compiler = (Compiler) compiler;
_mo2Compiler = (MO2Compiler) compiler;
var alwaysEnabled = _mo2Compiler.ModInis.Where(f => IsAlwaysEnabled(f.Value)).Select(f => f.Key).ToHashSet();
_allEnabledMods = _mo2Compiler.SelectedProfiles

View File

@ -8,11 +8,11 @@ namespace Wabbajack.Lib.CompilationSteps
public class IgnoreOtherProfiles : ACompilationStep
{
private readonly IEnumerable<string> _profiles;
private readonly Compiler _mo2Compiler;
private readonly MO2Compiler _mo2Compiler;
public IgnoreOtherProfiles(ACompiler compiler) : base(compiler)
{
_mo2Compiler = (Compiler) compiler;
_mo2Compiler = (MO2Compiler) compiler;
_profiles = _mo2Compiler.SelectedProfiles
.Select(p => Path.Combine("profiles", p) + "\\")

View File

@ -7,11 +7,11 @@ namespace Wabbajack.Lib.CompilationSteps
{
public class IncludeStubbedConfigFiles : ACompilationStep
{
private readonly Compiler _mo2Compiler;
private readonly MO2Compiler _mo2Compiler;
public IncludeStubbedConfigFiles(ACompiler compiler) : base(compiler)
{
_mo2Compiler = (Compiler) compiler;
_mo2Compiler = (MO2Compiler) compiler;
}
public override Directive Run(RawSourceFile source)

View File

@ -9,11 +9,11 @@ namespace Wabbajack.Lib.CompilationSteps
{
private readonly IEnumerable<string> _includeDirectly;
private readonly string _tag;
private readonly Compiler _mo2Compiler;
private readonly MO2Compiler _mo2Compiler;
public IncludeTaggedMods(ACompiler compiler, string tag) : base(compiler)
{
_mo2Compiler = (Compiler) compiler;
_mo2Compiler = (MO2Compiler) compiler;
_tag = tag;
_includeDirectly = _mo2Compiler.ModInis.Where(kv =>
{

View File

@ -9,11 +9,11 @@ namespace Wabbajack.Lib.CompilationSteps
public class IncludeThisProfile : ACompilationStep
{
private readonly IEnumerable<string> _correctProfiles;
private readonly Compiler _mo2Compiler;
private readonly MO2Compiler _mo2Compiler;
public IncludeThisProfile(ACompiler compiler) : base(compiler)
{
_mo2Compiler = (Compiler) compiler;
_mo2Compiler = (MO2Compiler) compiler;
_correctProfiles = _mo2Compiler.SelectedProfiles.Select(p => Path.Combine("profiles", p) + "\\").ToList();
}

View File

@ -8,11 +8,11 @@ namespace Wabbajack.Lib.CompilationSteps
{
public class PatchStockESMs : ACompilationStep
{
private readonly Compiler _mo2Compiler;
private readonly MO2Compiler _mo2Compiler;
public PatchStockESMs(ACompiler compiler) : base(compiler)
{
_mo2Compiler = (Compiler) compiler;
_mo2Compiler = (MO2Compiler) compiler;
}
public override Directive Run(RawSourceFile source)

View File

@ -16,18 +16,16 @@ using Path = Alphaleonis.Win32.Filesystem.Path;
namespace Wabbajack.Lib
{
public class Compiler : ACompiler
public class MO2Compiler : ACompiler
{
private string _mo2DownloadsFolder;
public Dictionary<string, IEnumerable<IndexedFileMatch>> DirectMatchIndex;
public string MO2Folder;
public string MO2Profile;
public Compiler(string mo2_folder)
public MO2Compiler(string mo2_folder)
{
ModManager = ModManager.MO2;

View File

@ -15,9 +15,9 @@ using Path = Alphaleonis.Win32.Filesystem.Path;
namespace Wabbajack.Lib
{
public class Installer : AInstaller
public class MO2Installer : AInstaller
{
public Installer(string archive, ModList mod_list, string output_folder)
public MO2Installer(string archive, ModList mod_list, string output_folder)
{
ModManager = ModManager.MO2;
ModListArchive = archive;

View File

@ -46,9 +46,9 @@ namespace Wabbajack.Lib
public void Build(ACompiler c, ModList lst)
{
Compiler compiler = null;
MO2Compiler compiler = null;
if (lst.ModManager == ModManager.MO2)
compiler = (Compiler) c;
compiler = (MO2Compiler) c;
Text($"### {lst.Name} by {lst.Author} - Installation Summary");
Text($"Build with Wabbajack Version {lst.WabbajackVersion}");

View File

@ -111,7 +111,7 @@
<Compile Include="CompilationSteps\IStackStep.cs" />
<Compile Include="CompilationSteps\PatchStockESMs.cs" />
<Compile Include="CompilationSteps\Serialization.cs" />
<Compile Include="Compiler.cs" />
<Compile Include="MO2Compiler.cs" />
<Compile Include="Data.cs" />
<Compile Include="Downloaders\AbstractDownloadState.cs" />
<Compile Include="Downloaders\DownloadDispatcher.cs" />
@ -127,7 +127,7 @@
<Compile Include="Downloaders\ModDBDownloader.cs" />
<Compile Include="Downloaders\NexusDownloader.cs" />
<Compile Include="IBatchProcessor.cs" />
<Compile Include="Installer.cs" />
<Compile Include="MO2Installer.cs" />
<Compile Include="ModListRegistry\ModListMetadata.cs" />
<Compile Include="NexusApi\Dtos.cs" />
<Compile Include="NexusApi\NexusApi.cs" />

View File

@ -14,11 +14,11 @@ namespace Wabbajack.Lib
{
public class zEditIntegration
{
private static Compiler _mo2Compiler;
private static MO2Compiler _mo2Compiler;
public static string FindzEditPath(ACompiler compiler)
{
_mo2Compiler = (Compiler) compiler;
_mo2Compiler = (MO2Compiler) compiler;
var executables = _mo2Compiler.MO2Ini.customExecutables;
if (executables.size == null) return null;
@ -141,7 +141,7 @@ namespace Wabbajack.Lib
public string dataFolder;
}
public static void VerifyMerges(Compiler compiler)
public static void VerifyMerges(MO2Compiler compiler)
{
var by_name = compiler.InstallDirectives.ToDictionary(f => f.To);
@ -160,7 +160,7 @@ namespace Wabbajack.Lib
}
}
public static void GenerateMerges(Installer installer)
public static void GenerateMerges(MO2Installer installer)
{
installer.ModList
.Directives

View File

@ -64,7 +64,7 @@ namespace Wabbajack.Test.ListValidation
Log($"Loading {modlist_path}");
var installer = Installer.LoadFromFile(modlist_path);
var installer = MO2Installer.LoadFromFile(modlist_path);
Log($"{installer.Archives.Count} archives to validate");

View File

@ -32,7 +32,7 @@ namespace Wabbajack.Test
utils.Dispose();
}
protected Compiler ConfigureAndRunCompiler(string profile)
protected MO2Compiler ConfigureAndRunCompiler(string profile)
{
var compiler = MakeCompiler();
compiler.MO2Profile = profile;
@ -41,9 +41,9 @@ namespace Wabbajack.Test
return compiler;
}
protected Compiler MakeCompiler()
protected MO2Compiler MakeCompiler()
{
var compiler = new Compiler(utils.MO2Folder);
var compiler = new MO2Compiler(utils.MO2Folder);
return compiler;
}
protected ModList CompileAndInstall(string profile)
@ -53,10 +53,10 @@ namespace Wabbajack.Test
return compiler.ModList;
}
protected void Install(Compiler compiler)
protected void Install(MO2Compiler compiler)
{
var modlist = Installer.LoadFromFile(compiler.ModListOutputFile);
var installer = new Installer(compiler.ModListOutputFile, modlist, utils.InstallFolder);
var modlist = MO2Installer.LoadFromFile(compiler.ModListOutputFile);
var installer = new MO2Installer(compiler.ModListOutputFile, modlist, utils.InstallFolder);
installer.DownloadFolder = utils.DownloadsFolder;
installer.GameFolder = utils.GameFolder;
installer.Begin().Wait();

View File

@ -60,8 +60,8 @@ namespace Wabbajack.Test
protected void Install(VortexCompiler vortexCompiler)
{
var modList = Installer.LoadFromFile(vortexCompiler.ModListOutputFile);
var installer = new Installer(vortexCompiler.ModListOutputFile, modList, utils.InstallFolder)
var modList = MO2Installer.LoadFromFile(vortexCompiler.ModListOutputFile);
var installer = new MO2Installer(vortexCompiler.ModListOutputFile, modList, utils.InstallFolder)
{
DownloadFolder = utils.DownloadsFolder,
GameFolder = utils.GameFolder,

View File

@ -73,7 +73,7 @@ namespace Wabbajack.Test
if (Directory.Exists(loot_folder))
Directory.Delete(loot_folder, true);
var compiler = new Compiler(utils.InstallFolder);
var compiler = new MO2Compiler(utils.InstallFolder);
compiler.MO2DownloadsFolder = Path.Combine(utils.DownloadsFolder);
compiler.MO2Profile = profile;
compiler.ShowReportWhenFinished = false;
@ -144,18 +144,18 @@ namespace Wabbajack.Test
return compiler.ModList;
}
private void Install(Compiler compiler)
private void Install(MO2Compiler compiler)
{
var modlist = Installer.LoadFromFile(compiler.ModListOutputFile);
var installer = new Installer(compiler.ModListOutputFile, modlist, utils.InstallFolder);
var modlist = MO2Installer.LoadFromFile(compiler.ModListOutputFile);
var installer = new MO2Installer(compiler.ModListOutputFile, modlist, utils.InstallFolder);
installer.DownloadFolder = utils.DownloadsFolder;
installer.GameFolder = utils.GameFolder;
installer.Begin().Wait();
}
private Compiler ConfigureAndRunCompiler(string profile)
private MO2Compiler ConfigureAndRunCompiler(string profile)
{
var compiler = new Compiler(utils.MO2Folder);
var compiler = new MO2Compiler(utils.MO2Folder);
compiler.MO2Profile = profile;
compiler.ShowReportWhenFinished = false;
Assert.IsTrue(compiler.Begin().Result);

View File

@ -13,6 +13,7 @@ namespace Wabbajack
{
IReactiveCommand BeginCommand { get; }
bool Compiling { get; }
ModlistSettingsEditorVM ModlistSettings { get; }
StatusUpdateTracker StatusTracker { get;}
void Unload();

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;
using Wabbajack.Common;
@ -100,10 +101,10 @@ namespace Wabbajack
.ObserveOnGuiThread(),
execute: async () =>
{
Compiler compiler;
MO2Compiler compiler;
try
{
compiler = new Compiler(this.Mo2Folder)
compiler = new MO2Compiler(this.Mo2Folder)
{
MO2Profile = this.MOProfile,
ModListName = this.ModlistSettings.ModListName,
@ -113,6 +114,10 @@ namespace Wabbajack
ModListWebsite = this.ModlistSettings.Website,
ModListReadme = this.ModlistSettings.ReadMeText.TargetPath,
};
// TODO: USE RX HERE
compiler.TextStatus.Subscribe(Utils.Log);
// TODO: Where do we bind this?
//compiler.QueueStatus.Subscribe(_cpuStatus);
}
catch (Exception ex)
{
@ -120,22 +125,22 @@ namespace Wabbajack
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
return;
}
await Task.Run(async () =>
try
{
try
{
await compiler.Begin();
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
}
finally
{
this.StatusTracker = null;
}
});
await compiler.Begin();
}
catch (Exception ex)
{
while (ex.InnerException != null) ex = ex.InnerException;
Utils.Log($"Compiler error: {ex.ExceptionToString()}");
}
finally
{
this.StatusTracker = null;
compiler.Dispose();
}
});
this._Compiling = this.BeginCommand.IsExecuting
.ToProperty(this, nameof(this.Compiling));
@ -190,7 +195,7 @@ namespace Wabbajack
{
try
{
var tmp_compiler = new Compiler(this.Mo2Folder);
var tmp_compiler = new MO2Compiler(this.Mo2Folder);
this.DownloadLocation.TargetPath = tmp_compiler.MO2DownloadsFolder;
}
catch (Exception ex)

View File

@ -132,7 +132,7 @@ namespace Wabbajack
.Select(modListPath =>
{
if (modListPath == null) return default(ModListVM);
var modList = Installer.LoadFromFile(modListPath);
var modList = MO2Installer.LoadFromFile(modListPath);
if (modList == null)
{
MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK,
@ -292,7 +292,7 @@ namespace Wabbajack
{
this.Installing = true;
this.InstallingMode = true;
var installer = new Installer(this.ModListPath, this.ModList.SourceModList, Location.TargetPath)
var installer = new MO2Installer(this.ModListPath, this.ModList.SourceModList, Location.TargetPath)
{
DownloadFolder = DownloadLocation.TargetPath
};