From 1a7dec86c1487bfbb8e1a680d3eeabb458322071 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Fri, 13 Sep 2019 21:44:07 -0600 Subject: [PATCH] few fixes and improvements --- CHANGELOG.md | 1 + VirtualFileSystem/VirtualFileSystem.cs | 53 ++++++++++-------------- Wabbajack.Common/Wabbajack.Common.csproj | 1 - Wabbajack/Compiler.cs | 1 + Wabbajack/Data.cs | 1 + Wabbajack/Installer.cs | 5 +++ 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 501c1809..a4500f2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Ignore some files Wabbajack creates * Improve compilation times by reworking file indexing algorithm * Store patch files in byte format instead of base64 strings +* Verify SHA of patched files after install #### Version 0.9.1 - 9/5/2019 * Fixed a bug where having only one profile selected would result in no profiles being selected diff --git a/VirtualFileSystem/VirtualFileSystem.cs b/VirtualFileSystem/VirtualFileSystem.cs index 7c14d6c0..8540be1e 100644 --- a/VirtualFileSystem/VirtualFileSystem.cs +++ b/VirtualFileSystem/VirtualFileSystem.cs @@ -45,41 +45,34 @@ namespace VFS Directory.CreateDirectory(_stagedRoot); } - private static void DeleteDirectory(string path) + private static void DeleteDirectory(string path, bool recursive = true) { - Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) - .DoProgress("Cleaning VFS Files", file => + if (recursive) + { + var subfolders = Directory.GetDirectories(path); + foreach (var s in subfolders) { - try + DeleteDirectory(s, recursive); + } + } + var files = Directory.GetFiles(path); + foreach (var f in files) + { + try + { + var attr = File.GetAttributes(f); + if ((attr & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { - var fi = new FileInfo(file); - fi.Attributes &= ~FileAttributes.ReadOnly; - File.Delete(file); + File.SetAttributes(f, attr ^ FileAttributes.ReadOnly); } - catch (Exception ex) - { - Utils.Log(ex.ToString()); - } - }); + File.Delete(f); + } + catch (IOException) + { + } + } + Directory.Delete(path, true); - Directory.EnumerateDirectories(path, DirectoryEnumerationOptions.Recursive) - .OrderByDescending(d => d.Length) - .DoProgress("Cleaning VFS Folders", folder => - { - try - { - if (!Directory.Exists(folder)) - return; - var di = new DirectoryInfo(folder); - di.Attributes &= ~FileAttributes.ReadOnly; - Directory.Delete(path, true); - } - catch (Exception ex) - { - Utils.Log(ex.ToString()); - } - }); - } diff --git a/Wabbajack.Common/Wabbajack.Common.csproj b/Wabbajack.Common/Wabbajack.Common.csproj index 896e3a3b..849b94c7 100644 --- a/Wabbajack.Common/Wabbajack.Common.csproj +++ b/Wabbajack.Common/Wabbajack.Common.csproj @@ -91,7 +91,6 @@ - diff --git a/Wabbajack/Compiler.cs b/Wabbajack/Compiler.cs index caae657f..7398ac75 100644 --- a/Wabbajack/Compiler.cs +++ b/Wabbajack/Compiler.cs @@ -903,6 +903,7 @@ namespace Wabbajack var e = source.EvolveTo(); e.ArchiveHashPath = found.MakeRelativePaths(); e.To = source.Path; + e.Hash = source.File.Hash; Utils.TryGetPatch(found.Hash, source.File.Hash, out e.Patch); return e; diff --git a/Wabbajack/Data.cs b/Wabbajack/Data.cs index 6621de09..f60e660a 100644 --- a/Wabbajack/Data.cs +++ b/Wabbajack/Data.cs @@ -157,6 +157,7 @@ namespace Wabbajack /// The file to apply to the source file to patch it /// public byte[] Patch; + public string Hash; } [Serializable] diff --git a/Wabbajack/Installer.cs b/Wabbajack/Installer.cs index 907d9fae..4b3ee9e3 100644 --- a/Wabbajack/Installer.cs +++ b/Wabbajack/Installer.cs @@ -411,6 +411,11 @@ namespace Wabbajack { BSDiff.Apply(old_data, () => new MemoryStream(patch_data), out_stream); } + + Status($"Verifying Patch {Path.GetFileName(to_patch.To)}"); + var result_sha = Utils.FileSHA256(to_file); + if (result_sha != to_patch.Hash) + throw new InvalidDataException($"Invalid Hash for {to_patch.To} after patching"); } }