From ebc548ee04713ba590324287c5ac8735427e81eb Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 10 Sep 2019 07:02:25 -0600 Subject: [PATCH] bit of code cleanup and additions to the report --- CHANGELOG.md | 1 + Wabbajack.Common/Utils.cs | 11 +++++++++++ Wabbajack/Compiler.cs | 1 + Wabbajack/Data.cs | 2 ++ Wabbajack/ReportBuilder.cs | 10 ++++------ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bd163db..1d77f1a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Log when the executable is being generated * Fixed a integer overflow resulting in a crash in very large BSA reading * Fix a bug in BSA string encoding +* Add human friendly filesizes to the download header and file info sections in the Install Report #### 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/Wabbajack.Common/Utils.cs b/Wabbajack.Common/Utils.cs index 26ae877f..818f74e3 100644 --- a/Wabbajack.Common/Utils.cs +++ b/Wabbajack.Common/Utils.cs @@ -406,5 +406,16 @@ namespace Wabbajack.Common return default(V); } + private static string[] Suffix = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB + public static string ToFileSizeString(this long byteCount) + { + if (byteCount == 0) + return "0" + Suffix[0]; + long bytes = Math.Abs(byteCount); + int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024))); + double num = Math.Round(bytes / Math.Pow(1024, place), 1); + return (Math.Sign(byteCount) * num).ToString() + Suffix[place]; + } + } } diff --git a/Wabbajack/Compiler.cs b/Wabbajack/Compiler.cs index c478c876..c265a46f 100644 --- a/Wabbajack/Compiler.cs +++ b/Wabbajack/Compiler.cs @@ -506,6 +506,7 @@ namespace Wabbajack result.Name = found.Name; result.Hash = found.File.Hash; result.Meta = found.Meta; + result.Size = found.File.Size; Info($"Checking link for {found.Name}"); diff --git a/Wabbajack/Data.cs b/Wabbajack/Data.cs index c4349350..a5ce39c0 100644 --- a/Wabbajack/Data.cs +++ b/Wabbajack/Data.cs @@ -172,6 +172,8 @@ namespace Wabbajack /// Meta INI for the downloaded archive /// public string Meta; + + public long Size; } public class NexusMod : Archive diff --git a/Wabbajack/ReportBuilder.cs b/Wabbajack/ReportBuilder.cs index 635ccd62..4b5b9d4f 100644 --- a/Wabbajack/ReportBuilder.cs +++ b/Wabbajack/ReportBuilder.cs @@ -41,7 +41,7 @@ namespace Wabbajack public void Build(ModList lst) { Text($"### {lst.Name} - Installation Summary"); - Text($"#### Download Summary ({lst.Archives.Count} archives)"); + Text($"#### Download Summary ({lst.Archives.Count} archives - {lst.Archives.Sum(a => a.Size).ToFileSizeString()})"); foreach (var archive in SortArchives(lst.Archives)) { var hash = archive.Hash.FromBase64().ToHEX(); @@ -52,25 +52,23 @@ namespace Wabbajack NoWrapText($"* [{m.Name}](http://nexusmods.com/{NexusAPI.ConvertGameName(m.GameName)}/mods/{m.ModID})"); NoWrapText($" * Author : [{m.UploadedBy}]({profile})"); NoWrapText($" * Version : {m.Version}"); - NoWrapText($" * SHA256 : [{hash}](https://www.virustotal.com/gui/file/{hash})"); break; case MODDBArchive m: NoWrapText($"* MODDB - [{m.Name}]({m.URL})"); - NoWrapText($" * SHA256 : [{hash}](https://www.virustotal.com/gui/file/{hash})"); break; case MEGAArchive m: NoWrapText($"* MEGA - [{m.Name}]({m.URL})"); - NoWrapText($" * SHA256 : [{hash}](https://www.virustotal.com/gui/file/{hash})"); break; case GoogleDriveMod m: NoWrapText($"* GoogleDrive - [{m.Name}](https://drive.google.com/uc?id={m.Id}&export=download)"); - NoWrapText($" * SHA256 : [{hash}](https://www.virustotal.com/gui/file/{hash})"); break; case DirectURLArchive m: NoWrapText($"* URL - [{m.Name} - {m.URL}]({m.URL})"); - NoWrapText($" * SHA256 : [{hash}](https://www.virustotal.com/gui/file/{hash})"); break; } + NoWrapText($" * Size : {archive.Size.ToFileSizeString()}"); + NoWrapText($" * SHA256 : [{hash}](https://www.virustotal.com/gui/file/{hash})"); + } Text($"\n\n"); var patched = lst.Directives.OfType().OrderBy(p => p.To).ToList();