Fix VFS FullPath errors

This commit is contained in:
Timothy Baldridge 2020-04-24 07:56:03 -06:00
parent 8efdfcd5f0
commit fee49cca12
2 changed files with 42 additions and 21 deletions

View File

@ -250,7 +250,14 @@ namespace Wabbajack.VirtualFileSystem
public async Task BackfillMissing()
{
var newFiles = _knownArchives.ToDictionary(kv => kv.Key,
kv => new VirtualFile {Name = kv.Value, Size = kv.Value.Size, Hash = kv.Key});
kv => new VirtualFile
{
Name = kv.Value,
Size = kv.Value.Size,
Hash = kv.Key,
});
newFiles.Values.Do(f => f.FillFullPath(0));
var parentchild = new Dictionary<(VirtualFile, RelativePath), VirtualFile>();
@ -266,6 +273,7 @@ namespace Wabbajack.VirtualFileSystem
}
var nf = new VirtualFile {Name = path, Parent = parent};
nf.FillFullPath();
parent.Children = parent.Children.Add(nf);
parentchild.Add((parent, path), nf);
parent = nf;

View File

@ -153,6 +153,8 @@ namespace Wabbajack.VirtualFileSystem
LastAnalyzed = DateTime.Now.AsUnixTime(),
Hash = file.Hash
};
vself.FillFullPath();
vself.Children = file.Children.Select(f => Convert(f, f.Name, vself)).ToImmutableList();
@ -192,11 +194,24 @@ namespace Wabbajack.VirtualFileSystem
return self;
}
private void FillFullPath(in int depth)
internal void FillFullPath()
{
int depth = 0;
var self = this;
while (self.Parent != null)
{
depth += 1;
self = self.Parent;
}
FillFullPath(depth);
}
internal void FillFullPath(int depth)
{
if (depth == 0)
{
FullPath = new FullPath((AbsolutePath)Name, new RelativePath[0]);
FullPath = new FullPath((AbsolutePath)Name);
}
else
{
@ -333,27 +348,25 @@ namespace Wabbajack.VirtualFileSystem
public static ExtendedHashes FromFile(IExtractedFile file)
{
var hashes = new ExtendedHashes();
using (var stream = file.OpenRead())
using var stream = file.OpenRead();
hashes.SHA256 = System.Security.Cryptography.SHA256.Create().ComputeHash(stream).ToHex();
stream.Position = 0;
hashes.SHA1 = System.Security.Cryptography.SHA1.Create().ComputeHash(stream).ToHex();
stream.Position = 0;
hashes.MD5 = System.Security.Cryptography.MD5.Create().ComputeHash(stream).ToHex();
stream.Position = 0;
var bytes = new byte[1024 * 8];
var crc = new Crc32();
while (true)
{
hashes.SHA256 = System.Security.Cryptography.SHA256.Create().ComputeHash(stream).ToHex();
stream.Position = 0;
hashes.SHA1 = System.Security.Cryptography.SHA1.Create().ComputeHash(stream).ToHex();
stream.Position = 0;
hashes.MD5 = System.Security.Cryptography.MD5.Create().ComputeHash(stream).ToHex();
stream.Position = 0;
var bytes = new byte[1024 * 8];
var crc = new Crc32();
while (true)
{
var read = stream.Read(bytes, 0, bytes.Length);
if (read == 0) break;
crc.Update(bytes, 0, read);
}
hashes.CRC = crc.DigestBytes().ToHex();
var read = stream.Read(bytes, 0, bytes.Length);
if (read == 0) break;
crc.Update(bytes, 0, read);
}
hashes.CRC = crc.DigestBytes().ToHex();
return hashes;
}
}