From 0933e15c9e6f4775ad613eb9f2497bcbc850674e Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Sat, 30 May 2020 15:05:26 -0600 Subject: [PATCH] Several small tweaks for auto healing --- Wabbajack.Common.Test/MiscTests.cs | 11 +++++++++++ Wabbajack.Common/Hash.cs | 9 +++++---- Wabbajack.Lib/Downloaders/DownloadDispatcher.cs | 2 +- Wabbajack.Server/DataLayer/Patches.cs | 4 ++-- Wabbajack.Server/Services/ListValidator.cs | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Wabbajack.Common.Test/MiscTests.cs b/Wabbajack.Common.Test/MiscTests.cs index 251fcd71..47d73577 100644 --- a/Wabbajack.Common.Test/MiscTests.cs +++ b/Wabbajack.Common.Test/MiscTests.cs @@ -26,5 +26,16 @@ namespace Wabbajack.Common.Test Assert.True(Utils.TryGetHashCache(testFile, out var fileHash)); Assert.Equal(Hash.FromBase64("eSIyd+KOG3s="), fileHash); } + + [Fact] + public void TestHashHex() + { + + var hash = Hash.FromULong((ulong)Utils.NextRandom(0, int.MaxValue)); + Assert.Equal(hash, Hash.FromHex(hash.ToHex())); + + hash = Hash.FromLong(4085310893299329733); + Assert.Equal(hash, Hash.FromHex(hash.ToHex())); + } } } diff --git a/Wabbajack.Common/Hash.cs b/Wabbajack.Common/Hash.cs index 88b32ae0..943a81d5 100644 --- a/Wabbajack.Common/Hash.cs +++ b/Wabbajack.Common/Hash.cs @@ -66,10 +66,7 @@ namespace Wabbajack.Common return BitConverter.ToInt64(BitConverter.GetBytes(a._code)); } - public string ToHex() - { - return BitConverter.GetBytes(_code).ToHex(); - } + public string ToBase64() { @@ -97,6 +94,10 @@ namespace Wabbajack.Common { return new Hash(BitConverter.ToUInt64(xxHashAsHex.FromHex())); } + public string ToHex() + { + return BitConverter.GetBytes(_code).ToHex(); + } public byte[] ToArray() { diff --git a/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs b/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs index 4080772e..a5d6dc99 100644 --- a/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs +++ b/Wabbajack.Lib/Downloaders/DownloadDispatcher.cs @@ -118,7 +118,7 @@ namespace Wabbajack.Lib.Downloaders } - Utils.Log($"Looking for patch for {archive.Name}"); + Utils.Log($"Looking for patch for {archive.Name} ({(long)archive.Hash} {archive.Hash.ToHex()} -> {(long)result.Archive!.Hash} {result.Archive!.Hash.ToHex()})"); var patchResult = await ClientAPI.GetModUpgrade(archive, result.Archive!); Utils.Log($"Downloading patch for {archive.Name}"); diff --git a/Wabbajack.Server/DataLayer/Patches.cs b/Wabbajack.Server/DataLayer/Patches.cs index 60c2d969..e654dbd3 100644 --- a/Wabbajack.Server/DataLayer/Patches.cs +++ b/Wabbajack.Server/DataLayer/Patches.cs @@ -131,14 +131,14 @@ namespace Wabbajack.Server.DataLayer "SELECT SrcId, DestId, PatchSize, Finished, IsFailed, FailMessage FROM dbo.Patches WHERE SrcId = @SrcId", new {SrcId = sourceDownload}); List results = new List(); - foreach (var (srcId, destId, patchSize, finished, isFinished, failMessage) in patches) + foreach (var (srcId, destId, patchSize, finished, isFailed, failMessage) in patches) { results.Add( new Patch { Src = await GetArchiveDownload(srcId), Dest = await GetArchiveDownload(destId), PatchSize = patchSize, Finished = finished, - IsFailed = isFinished, + IsFailed = isFailed, FailMessage = failMessage }); } diff --git a/Wabbajack.Server/Services/ListValidator.cs b/Wabbajack.Server/Services/ListValidator.cs index 0285b708..840e92a3 100644 --- a/Wabbajack.Server/Services/ListValidator.cs +++ b/Wabbajack.Server/Services/ListValidator.cs @@ -158,7 +158,7 @@ namespace Wabbajack.Server.Services return (archive, ArchiveStatus.Updating); if (patch.IsFailed == true) - continue; + return (archive, ArchiveStatus.InValid); var (_, status) = await ValidateArchive(data, patch.Dest.Archive); if (status == ArchiveStatus.Valid)