Fix Wabbajack.Lib

This commit is contained in:
erri120 2021-01-09 20:04:11 +01:00
parent 03a68da0d1
commit 131f7de823
11 changed files with 39 additions and 15 deletions

View File

@ -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,

View File

@ -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<Hash, AbsolutePath>(e.Item1, e.Item2)));
.Where(x => x.Item1 != null)
.Select(e => new KeyValuePair<Hash, AbsolutePath>(e.Item1!.Value, e.Item2)));
}
/// <summary>

View File

@ -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));

View File

@ -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();

View File

@ -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<bool> ValidateUpgrade(Hash srcHash, AbstractDownloadState newArchiveState)

View File

@ -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
};
}

View File

@ -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)

View File

@ -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");

View File

@ -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
});
});

View File

@ -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));
}
}
}

View File

@ -128,7 +128,7 @@ namespace Wabbajack.Lib.ModListRegistry
{
return true;
}
return DownloadMetadata.Hash != await modlistPath.FileHashCachedAsync(true);
return DownloadMetadata.Hash != await modlistPath.FileHashCachedAsync();
}
}