Using const strings instead of magic strings

This commit is contained in:
erri120 2022-01-28 13:01:49 +01:00
parent c4c80b7fe0
commit 74badacf08
No known key found for this signature in database
GPG Key ID: 7FA9556C936B847C
3 changed files with 22 additions and 16 deletions

View File

@ -120,7 +120,7 @@ public abstract class AInstaller<T>
ExtractedModlistFolder = _manager.CreateFolder(); ExtractedModlistFolder = _manager.CreateFolder();
await using var stream = _configuration.ModlistArchive.Open(FileMode.Open, FileAccess.Read, FileShare.Read); await using var stream = _configuration.ModlistArchive.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
using var archive = new ZipArchive(stream, ZipArchiveMode.Read); using var archive = new ZipArchive(stream, ZipArchiveMode.Read);
NextStep("Preparing","Extracting Modlist", archive.Entries.Count); NextStep(Consts.StepPreparing,"Extracting Modlist", archive.Entries.Count);
foreach (var entry in archive.Entries) foreach (var entry in archive.Entries)
{ {
var path = entry.FullName.ToRelativePath().RelativeTo(ExtractedModlistFolder); var path = entry.FullName.ToRelativePath().RelativeTo(ExtractedModlistFolder);
@ -182,7 +182,7 @@ public abstract class AInstaller<T>
/// </summary> /// </summary>
protected async Task PrimeVFS() protected async Task PrimeVFS()
{ {
NextStep("Preparing","Priming VFS", 0); NextStep(Consts.StepPreparing,"Priming VFS", 0);
_vfs.AddKnown(_configuration.ModList.Directives.OfType<FromArchive>().Select(d => d.ArchiveHashPath), _vfs.AddKnown(_configuration.ModList.Directives.OfType<FromArchive>().Select(d => d.ArchiveHashPath),
HashedArchives); HashedArchives);
await _vfs.BackfillMissing(); await _vfs.BackfillMissing();
@ -190,7 +190,7 @@ public abstract class AInstaller<T>
public async Task BuildFolderStructure() public async Task BuildFolderStructure()
{ {
NextStep("Preparing", "Building Folder Structure", 0); NextStep(Consts.StepPreparing, "Building Folder Structure", 0);
_logger.LogInformation("Building Folder Structure"); _logger.LogInformation("Building Folder Structure");
ModList.Directives ModList.Directives
.Where(d => d.To.Depth > 1) .Where(d => d.To.Depth > 1)
@ -201,7 +201,7 @@ public abstract class AInstaller<T>
public async Task InstallArchives(CancellationToken token) public async Task InstallArchives(CancellationToken token)
{ {
NextStep("Installing", "Installing files", ModList.Directives.Sum(d => d.Size)); NextStep(Consts.StepInstalling, "Installing files", ModList.Directives.Sum(d => d.Size));
var grouped = ModList.Directives var grouped = ModList.Directives
.OfType<FromArchive>() .OfType<FromArchive>()
.Select(a => new {VF = _vfs.Index.FileForArchiveHashPath(a.ArchiveHashPath), Directive = a}) .Select(a => new {VF = _vfs.Index.FileForArchiveHashPath(a.ArchiveHashPath), Directive = a})
@ -302,15 +302,15 @@ public abstract class AInstaller<T>
} }
} }
_logger.LogInformation("Downloading {count} archives", missing.Count); _logger.LogInformation("Downloading {Count} archives", missing.Count.ToString());
NextStep("Downloading", "Downloading files", missing.Count); NextStep(Consts.StepDownloading, "Downloading files", missing.Count);
await missing await missing
.OrderBy(a => a.Size) .OrderBy(a => a.Size)
.Where(a => a.State is not Manual) .Where(a => a.State is not Manual)
.PDoAll(async archive => .PDoAll(async archive =>
{ {
_logger.LogInformation("Downloading {archive}", archive.Name); _logger.LogInformation("Downloading {Archive}", archive.Name);
var outputPath = _configuration.Downloads.Combine(archive.Name); var outputPath = _configuration.Downloads.Combine(archive.Name);
if (download) if (download)
@ -364,7 +364,7 @@ public abstract class AInstaller<T>
public async Task HashArchives(CancellationToken token) public async Task HashArchives(CancellationToken token)
{ {
NextStep("Hashing", "Hashing Archives", 0); NextStep(Consts.StepHashing, "Hashing Archives", 0);
_logger.LogInformation("Looking for files to hash"); _logger.LogInformation("Looking for files to hash");
var allFiles = _configuration.Downloads.EnumerateFiles() var allFiles = _configuration.Downloads.EnumerateFiles()
@ -415,7 +415,7 @@ public abstract class AInstaller<T>
var savePath = (RelativePath) "saves"; var savePath = (RelativePath) "saves";
var existingFiles = _configuration.Install.EnumerateFiles().ToList(); var existingFiles = _configuration.Install.EnumerateFiles().ToList();
NextStep("Preparing", "Looking for files to delete", existingFiles.Count); NextStep(Consts.StepPreparing, "Looking for files to delete", existingFiles.Count);
await existingFiles await existingFiles
.PDoAll(async f => .PDoAll(async f =>
{ {
@ -434,7 +434,7 @@ public abstract class AInstaller<T>
}); });
_logger.LogInformation("Cleaning empty folders"); _logger.LogInformation("Cleaning empty folders");
NextStep("Preparing", "Cleaning empty folders", indexed.Keys.Count); NextStep(Consts.StepPreparing, "Cleaning empty folders", indexed.Keys.Count);
var expectedFolders = (indexed.Keys var expectedFolders = (indexed.Keys
.Select(f => f.RelativeTo(_configuration.Install)) .Select(f => f.RelativeTo(_configuration.Install))
// We ignore the last part of the path, so we need a dummy file name // We ignore the last part of the path, so we need a dummy file name
@ -469,7 +469,7 @@ public abstract class AInstaller<T>
var existingfiles = _configuration.Install.EnumerateFiles().ToHashSet(); var existingfiles = _configuration.Install.EnumerateFiles().ToHashSet();
NextStep("Preparing", "Removing redundant directives", indexed.Count); NextStep(Consts.StepPreparing, "Removing redundant directives", indexed.Count);
await indexed.Values.PMapAll<Directive, Directive?>(async d => await indexed.Values.PMapAll<Directive, Directive?>(async d =>
{ {
// Bit backwards, but we want to return null for // Bit backwards, but we want to return null for
@ -488,7 +488,7 @@ public abstract class AInstaller<T>
_logger.LogInformation("Optimized {optimized} directives to {indexed} required", ModList.Directives.Length, _logger.LogInformation("Optimized {optimized} directives to {indexed} required", ModList.Directives.Length,
indexed.Count); indexed.Count);
NextStep("Preparing", "Finalizing modlist optimization", 0); NextStep(Consts.StepPreparing, "Finalizing modlist optimization", 0);
var requiredArchives = indexed.Values.OfType<FromArchive>() var requiredArchives = indexed.Values.OfType<FromArchive>()
.GroupBy(d => d.ArchiveHashPath.Hash) .GroupBy(d => d.ArchiveHashPath.Hash)
.Select(d => d.Key) .Select(d => d.Key)

View File

@ -2,7 +2,7 @@ using Wabbajack.Paths;
namespace Wabbajack.Installer; namespace Wabbajack.Installer;
public class Consts public static class Consts
{ {
public static string GAME_PATH_MAGIC_BACK = "{--||GAME_PATH_MAGIC_BACK||--}"; public static string GAME_PATH_MAGIC_BACK = "{--||GAME_PATH_MAGIC_BACK||--}";
public static string GAME_PATH_MAGIC_DOUBLE_BACK = "{--||GAME_PATH_MAGIC_DOUBLE_BACK||--}"; public static string GAME_PATH_MAGIC_DOUBLE_BACK = "{--||GAME_PATH_MAGIC_DOUBLE_BACK||--}";
@ -20,4 +20,10 @@ public class Consts
public static RelativePath MO2ModFolderName = "mods".ToRelativePath(); public static RelativePath MO2ModFolderName = "mods".ToRelativePath();
public static RelativePath MO2ProfilesFolderName = "profiles".ToRelativePath(); public static RelativePath MO2ProfilesFolderName = "profiles".ToRelativePath();
public const string StepPreparing = "Preparing";
public const string StepInstalling = "Installing";
public const string StepDownloading = "Downloading";
public const string StepHashing = "Hashing";
public const string StepFinished = "Finished";
} }

View File

@ -61,7 +61,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
{ {
if (token.IsCancellationRequested) return false; if (token.IsCancellationRequested) return false;
await _wjClient.SendMetric(MetricNames.BeginInstall, ModList.Name); await _wjClient.SendMetric(MetricNames.BeginInstall, ModList.Name);
NextStep("Preparing", "Configuring Installer", 0); NextStep(Consts.StepPreparing, "Configuring Installer", 0);
_logger.LogInformation("Configuring Processor"); _logger.LogInformation("Configuring Processor");
if (_configuration.GameFolder == default) if (_configuration.GameFolder == default)
@ -145,7 +145,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
await ExtractedModlistFolder!.DisposeAsync(); await ExtractedModlistFolder!.DisposeAsync();
await _wjClient.SendMetric(MetricNames.FinishInstall, ModList.Name); await _wjClient.SendMetric(MetricNames.FinishInstall, ModList.Name);
NextStep("Finished", "Finished", 1); NextStep(Consts.StepFinished, "Finished", 1);
_logger.LogInformation("Finished Installation"); _logger.LogInformation("Finished Installation");
return true; return true;
} }
@ -275,7 +275,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
private async Task InstallIncludedFiles(CancellationToken token) private async Task InstallIncludedFiles(CancellationToken token)
{ {
_logger.LogInformation("Writing inline files"); _logger.LogInformation("Writing inline files");
NextStep("Installing", "Installing Included Files", ModList.Directives.OfType<InlineFile>().Count()); NextStep(Consts.StepInstalling, "Installing Included Files", ModList.Directives.OfType<InlineFile>().Count());
await ModList.Directives await ModList.Directives
.OfType<InlineFile>() .OfType<InlineFile>()
.PDoAll(async directive => .PDoAll(async directive =>