Fix nullable reference logic errors.

This commit is contained in:
Timothy Baldridge 2020-04-03 22:02:53 -06:00
parent 1b7cb772d2
commit 07c35f7a96
6 changed files with 36 additions and 31 deletions

View File

@ -171,10 +171,6 @@ namespace Wabbajack.BuildServer.Models.Jobs
try
{
var gameMeta = state.Game.MetaData();
if (gameMeta == null)
return false;
var game = gameMeta.Game;
var modFiles = (await db.NexusModFiles.AsQueryable().Where(g => g.Game == gameMeta.NexusName && g.ModId == state.ModID).FirstOrDefaultAsync())?.Data;
@ -182,7 +178,7 @@ namespace Wabbajack.BuildServer.Models.Jobs
{
Utils.Log($"No Cache for {state.PrimaryKeyString} falling back to HTTP");
var nexusApi = await NexusApiClient.Get();
modFiles = await nexusApi.GetModFiles(game, state.ModID);
modFiles = await nexusApi.GetModFiles(state.Game, state.ModID);
}
var found = modFiles.files

View File

@ -36,7 +36,7 @@ namespace Wabbajack.Common
return true;
}
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, [MaybeNullWhen(false)] out object result)
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, [MaybeNullWhen(false)] out object? result)
{
if (indexes.Length > 1)
{
@ -115,7 +115,7 @@ namespace Wabbajack.Common
return Encoding.UTF8.GetString(acc.ToArray());
}
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, [MaybeNullWhen(false)] out object result)
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, [MaybeNullWhen(false)] out object? result)
{
if (indexes.Length > 1)
{

View File

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net;
@ -690,10 +691,16 @@ namespace Wabbajack.Common
public override string ToString()
{
return string.Join("|", Paths.Select(t => t.ToString()).Cons(BaseHash.ToString()));
var paths = Paths == null ? EmptyPath : Paths;
return string.Join("|", paths.Select(t => t.ToString()).Cons(BaseHash.ToString()));
}
private static RelativePath[] EmptyPath = Array.Empty<RelativePath>();
public static bool operator ==(HashRelativePath a, HashRelativePath b)
{
if (a.Paths == null || b.Paths == null) return false;
if (a.BaseHash != b.BaseHash || a.Paths.Length != b.Paths.Length)
{
return false;
@ -739,6 +746,7 @@ namespace Wabbajack.Common
public struct FullPath : IEquatable<FullPath>, IPath
{
public AbsolutePath Base { get; }
public RelativePath[] Paths { get; }
private readonly int _hash;
@ -746,7 +754,7 @@ namespace Wabbajack.Common
public FullPath(AbsolutePath basePath, params RelativePath[] paths)
{
Base = basePath;
Paths = paths;
Paths = paths == null ? Array.Empty<RelativePath>() : paths;
_hash = Base.GetHashCode();
foreach (var itm in Paths)
{
@ -756,7 +764,8 @@ namespace Wabbajack.Common
public override string ToString()
{
return string.Join("|", Paths.Select(t => (string)t).Cons((string)Base));
var paths = Paths == null ? EmptyPath : Paths;
return string.Join("|", paths.Select(t => (string)t).Cons((string)Base));
}
public override int GetHashCode()
@ -764,8 +773,12 @@ namespace Wabbajack.Common
return _hash;
}
private static RelativePath[] EmptyPath = Array.Empty<RelativePath>();
public static bool operator ==(FullPath a, FullPath b)
{
if (a.Paths == null || b.Paths == null) return false;
if (a.Base != b.Base || a.Paths.Length != b.Paths.Length)
{
return false;

View File

@ -780,7 +780,7 @@ namespace Wabbajack.Common
return true;
}
ePatch = null;
ePatch = Array.Empty<byte>();
return false;
}

View File

@ -94,9 +94,7 @@ namespace Wabbajack.Lib.CompilationSteps
e.To = source.Path;
e.Hash = source.File.Hash;
Utils.TryGetPatch(found.Hash, source.File.Hash, out var data);
if (data != null)
if (Utils.TryGetPatch(found.Hash, source.File.Hash, out var data))
e.PatchID = await _compiler.IncludeFile(data);
return e;

View File

@ -450,24 +450,22 @@ namespace Wabbajack.Lib
private async Task BuildArchivePatches(Hash archiveSha, IEnumerable<PatchedFromArchive> group,
Dictionary<RelativePath, AbsolutePath> absolutePaths)
{
using (var files = await VFS.StageWith(group.Select(g => VFS.Index.FileForArchiveHashPath(g.ArchiveHashPath))))
using var files = await VFS.StageWith(@group.Select(g => VFS.Index.FileForArchiveHashPath(g.ArchiveHashPath)));
var byPath = files.GroupBy(f => string.Join("|", f.FilesInFullPath.Skip(1).Select(i => i.Name)))
.ToDictionary(f => f.Key, f => f.First());
// Now Create the patches
await @group.PMap(Queue, async entry =>
{
var byPath = files.GroupBy(f => string.Join("|", f.FilesInFullPath.Skip(1).Select(i => i.Name)))
.ToDictionary(f => f.Key, f => f.First());
// Now Create the patches
await group.PMap(Queue, async entry =>
{
Info($"Patching {entry.To}");
Status($"Patching {entry.To}");
var srcFile = byPath[string.Join("|", entry.ArchiveHashPath.Paths)];
await using var srcStream = srcFile.OpenRead();
await using var outputStream = IncludeFile(out var id);
entry.PatchID = id;
await using var destStream = LoadDataForTo(entry.To, absolutePaths);
await Utils.CreatePatch(srcStream, srcFile.Hash, destStream, entry.Hash, outputStream);
Info($"Patch size {outputStream.Length} for {entry.To}");
});
}
Info($"Patching {entry.To}");
Status($"Patching {entry.To}");
var srcFile = byPath[string.Join("|", entry.ArchiveHashPath.Paths)];
await using var srcStream = srcFile.OpenRead();
await using var outputStream = IncludeFile(out var id);
entry.PatchID = id;
await using var destStream = LoadDataForTo(entry.To, absolutePaths);
await Utils.CreatePatch(srcStream, srcFile.Hash, destStream, entry.Hash, outputStream);
Info($"Patch size {outputStream.Length} for {entry.To}");
});
}
private FileStream LoadDataForTo(RelativePath to, Dictionary<RelativePath, AbsolutePath> absolutePaths)