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();
await using var stream = _configuration.ModlistArchive.Open(FileMode.Open, FileAccess.Read, FileShare.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)
{
var path = entry.FullName.ToRelativePath().RelativeTo(ExtractedModlistFolder);
@ -182,7 +182,7 @@ public abstract class AInstaller<T>
/// </summary>
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),
HashedArchives);
await _vfs.BackfillMissing();
@ -190,7 +190,7 @@ public abstract class AInstaller<T>
public async Task BuildFolderStructure()
{
NextStep("Preparing", "Building Folder Structure", 0);
NextStep(Consts.StepPreparing, "Building Folder Structure", 0);
_logger.LogInformation("Building Folder Structure");
ModList.Directives
.Where(d => d.To.Depth > 1)
@ -201,7 +201,7 @@ public abstract class AInstaller<T>
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
.OfType<FromArchive>()
.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);
NextStep("Downloading", "Downloading files", missing.Count);
_logger.LogInformation("Downloading {Count} archives", missing.Count.ToString());
NextStep(Consts.StepDownloading, "Downloading files", missing.Count);
await missing
.OrderBy(a => a.Size)
.Where(a => a.State is not Manual)
.PDoAll(async archive =>
{
_logger.LogInformation("Downloading {archive}", archive.Name);
_logger.LogInformation("Downloading {Archive}", archive.Name);
var outputPath = _configuration.Downloads.Combine(archive.Name);
if (download)
@ -364,7 +364,7 @@ public abstract class AInstaller<T>
public async Task HashArchives(CancellationToken token)
{
NextStep("Hashing", "Hashing Archives", 0);
NextStep(Consts.StepHashing, "Hashing Archives", 0);
_logger.LogInformation("Looking for files to hash");
var allFiles = _configuration.Downloads.EnumerateFiles()
@ -415,7 +415,7 @@ public abstract class AInstaller<T>
var savePath = (RelativePath) "saves";
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
.PDoAll(async f =>
{
@ -434,7 +434,7 @@ public abstract class AInstaller<T>
});
_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
.Select(f => f.RelativeTo(_configuration.Install))
// 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();
NextStep("Preparing", "Removing redundant directives", indexed.Count);
NextStep(Consts.StepPreparing, "Removing redundant directives", indexed.Count);
await indexed.Values.PMapAll<Directive, Directive?>(async d =>
{
// 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,
indexed.Count);
NextStep("Preparing", "Finalizing modlist optimization", 0);
NextStep(Consts.StepPreparing, "Finalizing modlist optimization", 0);
var requiredArchives = indexed.Values.OfType<FromArchive>()
.GroupBy(d => d.ArchiveHashPath.Hash)
.Select(d => d.Key)

View File

@ -2,7 +2,7 @@ using Wabbajack.Paths;
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_DOUBLE_BACK = "{--||GAME_PATH_MAGIC_DOUBLE_BACK||--}";
@ -20,4 +20,10 @@ public class Consts
public static RelativePath MO2ModFolderName = "mods".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;
await _wjClient.SendMetric(MetricNames.BeginInstall, ModList.Name);
NextStep("Preparing", "Configuring Installer", 0);
NextStep(Consts.StepPreparing, "Configuring Installer", 0);
_logger.LogInformation("Configuring Processor");
if (_configuration.GameFolder == default)
@ -145,7 +145,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
await ExtractedModlistFolder!.DisposeAsync();
await _wjClient.SendMetric(MetricNames.FinishInstall, ModList.Name);
NextStep("Finished", "Finished", 1);
NextStep(Consts.StepFinished, "Finished", 1);
_logger.LogInformation("Finished Installation");
return true;
}
@ -275,7 +275,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
private async Task InstallIncludedFiles(CancellationToken token)
{
_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
.OfType<InlineFile>()
.PDoAll(async directive =>