From 131f7de823d18995a52ec46c6676265ef49e48c0 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sat, 9 Jan 2021 20:04:11 +0100 Subject: [PATCH] Fix Wabbajack.Lib --- Wabbajack.Lib/ACompiler.cs | 11 +++++++++-- Wabbajack.Lib/AInstaller.cs | 5 +++-- Wabbajack.Lib/AuthorApi/Client.cs | 2 +- Wabbajack.Lib/ClientAPI.cs | 6 +++++- Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs | 5 +++-- Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs | 3 ++- Wabbajack.Lib/Downloaders/HTTPDownloader.cs | 4 +++- Wabbajack.Lib/Downloaders/NexusDownloader.cs | 8 ++++++-- Wabbajack.Lib/MO2Compiler.cs | 6 +++++- Wabbajack.Lib/MO2Installer.cs | 2 +- Wabbajack.Lib/ModListRegistry/ModListMetadata.cs | 2 +- 11 files changed, 39 insertions(+), 15 deletions(-) diff --git a/Wabbajack.Lib/ACompiler.cs b/Wabbajack.Lib/ACompiler.cs index 445ab884..70756702 100644 --- a/Wabbajack.Lib/ACompiler.cs +++ b/Wabbajack.Lib/ACompiler.cs @@ -338,11 +338,18 @@ namespace Wabbajack.Lib } } - Utils.Log("Exporting ModList metadata"); + Utils.Log("Exporting Modlist metadata"); + var outputFileHash = await ModListOutputFile.FileHashAsync(); + if (outputFileHash == null) + { + Utils.Error("Unable to hash Modlist Output File"); + return; + } + var metadata = new DownloadMetadata { Size = ModListOutputFile.Size, - Hash = await ModListOutputFile.FileHashAsync(), + Hash = outputFileHash.Value, NumberOfArchives = ModList.Archives.Count, SizeOfArchives = ModList.Archives.Sum(a => a.Size), NumberOfInstalledFiles = ModList.Directives.Count, diff --git a/Wabbajack.Lib/AInstaller.cs b/Wabbajack.Lib/AInstaller.cs index 6f1c5c13..7fa918b5 100644 --- a/Wabbajack.Lib/AInstaller.cs +++ b/Wabbajack.Lib/AInstaller.cs @@ -145,7 +145,7 @@ namespace Wabbajack.Lib await ClientAPI.GetVirusScanResult(toFile) == VirusScanner.Result.Malware) { await toFile.DeleteAsync(); - Utils.ErrorThrow(new Exception($"Virus scan of patched executable reported possible malware: {toFile.ToString()} ({(long)await toFile.FileHashCachedAsync()})")); + Utils.ErrorThrow(new Exception($"Virus scan of patched executable reported possible malware: {toFile.ToString()} ({(long)(await toFile.FileHashCachedAsync())!.Value})")); } } break; @@ -298,7 +298,8 @@ namespace Wabbajack.Lib .OrderByDescending(e => e.Item2.LastModified) .GroupBy(e => e.Item1) .Select(e => e.First()) - .Select(e => new KeyValuePair(e.Item1, e.Item2))); + .Where(x => x.Item1 != null) + .Select(e => new KeyValuePair(e.Item1!.Value, e.Item2))); } /// diff --git a/Wabbajack.Lib/AuthorApi/Client.cs b/Wabbajack.Lib/AuthorApi/Client.cs index bf2da6a0..68705af5 100644 --- a/Wabbajack.Lib/AuthorApi/Client.cs +++ b/Wabbajack.Lib/AuthorApi/Client.cs @@ -58,7 +58,7 @@ namespace Wabbajack.Lib.AuthorApi { OriginalFileName = path.FileName, Size = path.Size, - Hash = await path.FileHashCachedAsync(), + Hash = await path.FileHashCachedAsync() ?? Hash.Empty, Parts = await parts.PMap(queue, async part => { progressFn("Hashing file parts", Percent.FactoryPutInRange(part.Index, parts.Length)); diff --git a/Wabbajack.Lib/ClientAPI.cs b/Wabbajack.Lib/ClientAPI.cs index f866f53b..cfc56de2 100644 --- a/Wabbajack.Lib/ClientAPI.cs +++ b/Wabbajack.Lib/ClientAPI.cs @@ -242,8 +242,12 @@ using Wabbajack.Lib.Downloaders; Utils.Log($"Checking virus result for {path}"); var hash = await path.FileHashAsync(); + if (hash == null) + { + throw new Exception("Hash is null!"); + } - using var result = await client.GetAsync($"{Consts.WabbajackBuildServerUri}virus_scan/{hash.ToHex()}", errorsAsExceptions: false); + using var result = await client.GetAsync($"{Consts.WabbajackBuildServerUri}virus_scan/{hash.Value.ToHex()}", errorsAsExceptions: false); if (result.StatusCode == HttpStatusCode.OK) { var data = await result.Content.ReadAsStringAsync(); diff --git a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs index 495d2d53..a8c3117f 100644 --- a/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs +++ b/Wabbajack.Lib/Downloaders/AbstractIPS4Downloader.cs @@ -334,14 +334,15 @@ namespace Wabbajack.Lib.Downloaders if (await newFile.State.Download(newFile, tmp.Path)) { newFile.Size = tmp.Path.Size; - newFile.Hash = await tmp.Path.FileHashAsync(); + var tmpHash = await tmp.Path.FileHashAsync(); + if (tmpHash == null) return default; + newFile.Hash = tmpHash.Value; return (newFile, tmp); } await tmp.DisposeAsync(); } return default; - } public override async Task ValidateUpgrade(Hash srcHash, AbstractDownloadState newArchiveState) diff --git a/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs b/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs index 0753e010..3483f18d 100644 --- a/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs +++ b/Wabbajack.Lib/Downloaders/GameFileSourceDownloader.cs @@ -28,12 +28,13 @@ namespace Wabbajack.Lib.Downloaders var fp = filePath.Value; var hash = await fp.FileHashCachedAsync(); + if (hash == null) return null; return new State(game.InstalledVersion) { Game = game.Game, GameFile = (RelativePath)gameFile, - Hash = hash + Hash = hash.Value }; } diff --git a/Wabbajack.Lib/Downloaders/HTTPDownloader.cs b/Wabbajack.Lib/Downloaders/HTTPDownloader.cs index 78dbd700..4f4ce189 100644 --- a/Wabbajack.Lib/Downloaders/HTTPDownloader.cs +++ b/Wabbajack.Lib/Downloaders/HTTPDownloader.cs @@ -234,7 +234,9 @@ TOP: return default; } - newArchive.Hash = await tmpFile.Path.FileHashAsync(); + var hash = await tmpFile.Path.FileHashAsync(); + if (hash == null) return default; + newArchive.Hash = hash.Value; newArchive.Size = tmpFile.Path.Size; if (newArchive.Hash == a.Hash || a.Size > 2_500_000_000 || newArchive.Size > 2_500_000_000) diff --git a/Wabbajack.Lib/Downloaders/NexusDownloader.cs b/Wabbajack.Lib/Downloaders/NexusDownloader.cs index a52840d8..38a1639f 100644 --- a/Wabbajack.Lib/Downloaders/NexusDownloader.cs +++ b/Wabbajack.Lib/Downloaders/NexusDownloader.cs @@ -290,7 +290,9 @@ namespace Wabbajack.Lib.Downloaders if (fastPath != default) { newArchive.Size = fastPath.Size; - newArchive.Hash = await fastPath.FileHashAsync(); + var hash = await fastPath.FileHashAsync(); + if (hash == null) return default; + newArchive.Hash = hash.Value; return (newArchive, new TempFile()); } @@ -300,7 +302,9 @@ namespace Wabbajack.Lib.Downloaders await newArchive.State.Download(newArchive, tempFile.Path); newArchive.Size = tempFile.Path.Size; - newArchive.Hash = await tempFile.Path.FileHashAsync(); + var newArchiveHash = await tempFile.Path.FileHashAsync(); + if (newArchiveHash == null) return default; + newArchive.Hash = newArchiveHash.Value; Utils.Log($"Possible upgrade {newArchive.State.PrimaryKeyString} downloaded"); diff --git a/Wabbajack.Lib/MO2Compiler.cs b/Wabbajack.Lib/MO2Compiler.cs index e8be9553..6632fe86 100644 --- a/Wabbajack.Lib/MO2Compiler.cs +++ b/Wabbajack.Lib/MO2Compiler.cs @@ -382,11 +382,15 @@ namespace Wabbajack.Lib var source = DownloadsPath.Combine(a.Name + Consts.MetaFileExtension); var ini = a.State.GetMetaIniString(); var (id, fullPath) = await IncludeString(ini); + var hash = await fullPath.FileHashAsync(); + + if (hash == null) return; + InstallDirectives.Add(new ArchiveMeta { SourceDataID = id, Size = fullPath.Size, - Hash = await fullPath.FileHashAsync(), + Hash = hash.Value, To = source.FileName }); }); diff --git a/Wabbajack.Lib/MO2Installer.cs b/Wabbajack.Lib/MO2Installer.cs index f1bf7a82..668d89d8 100644 --- a/Wabbajack.Lib/MO2Installer.cs +++ b/Wabbajack.Lib/MO2Installer.cs @@ -294,7 +294,7 @@ namespace Wabbajack.Lib var hash = await gameFile.FileHashAsync(); if (hash != esm.SourceESMHash) { - Utils.ErrorThrow(new InvalidGameESMError(esm, hash, gameFile)); + Utils.ErrorThrow(new InvalidGameESMError(esm, hash ?? Hash.Empty, gameFile)); } } } diff --git a/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs b/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs index acbe7ef0..7504a877 100644 --- a/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs +++ b/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs @@ -128,7 +128,7 @@ namespace Wabbajack.Lib.ModListRegistry { return true; } - return DownloadMetadata.Hash != await modlistPath.FileHashCachedAsync(true); + return DownloadMetadata.Hash != await modlistPath.FileHashCachedAsync(); } }