diff --git a/Wabbajack.CLI/OptionsDefinition.cs b/Wabbajack.CLI/OptionsDefinition.cs index 30aab2dc..e39f729d 100644 --- a/Wabbajack.CLI/OptionsDefinition.cs +++ b/Wabbajack.CLI/OptionsDefinition.cs @@ -1,4 +1,5 @@ using System; +using Markdig.Syntax.Inlines; using Wabbajack.CLI.Verbs; namespace Wabbajack.CLI @@ -21,7 +22,8 @@ namespace Wabbajack.CLI typeof(FindSimilar), typeof(BSADump), typeof(MigrateGameFolderFiles), - typeof(HashFile) + typeof(HashFile), + typeof(InlinedFileReport) }; } } diff --git a/Wabbajack.CLI/Program.cs b/Wabbajack.CLI/Program.cs index 65b18926..b5f90cad 100644 --- a/Wabbajack.CLI/Program.cs +++ b/Wabbajack.CLI/Program.cs @@ -29,6 +29,7 @@ namespace Wabbajack.CLI (BSADump opts) => opts.Execute(), (MigrateGameFolderFiles opts) => opts.Execute(), (HashFile opts) => opts.Execute(), + (InlinedFileReport opts) => opts.Execute(), errs => 1); } } diff --git a/Wabbajack.CLI/Verbs/InlinedFileReport.cs b/Wabbajack.CLI/Verbs/InlinedFileReport.cs new file mode 100644 index 00000000..d67bea6e --- /dev/null +++ b/Wabbajack.CLI/Verbs/InlinedFileReport.cs @@ -0,0 +1,68 @@ +using System; +using System.IO.Compression; +using System.Linq; +using System.Threading.Tasks; +using CommandLine; +using Wabbajack.Common; +using Wabbajack.Lib; + +namespace Wabbajack.CLI.Verbs +{ + [Verb("inlined-file-report", HelpText = "Reports on what could be causing .wabbajack bloat")] + public class InlinedFileReport : AVerb + { + [Option('i', "input", Required = true, HelpText = "Input modlist to report on")] + public string Input { get; set; } = ""; + protected override async Task Run() + { + var file = (AbsolutePath)Input; + + var modlist = AInstaller.LoadFromFile(file); + using var arch = new ZipArchive(await file.OpenRead(), ZipArchiveMode.Read); + + var reported = modlist.Directives + .Select(d => + { + switch (d) + { + case CleanedESM esm: + { + var entry = arch.GetEntry(esm.SourceDataID.ToString()); + return (entry.Length, d); + } + case InlineFile inlined: + return (inlined.Size, d); + case PatchedFromArchive pfa: + { + var entry = arch.GetEntry(pfa.PatchID.ToString()); + return (entry.Length, d); + } + default: + return (0, d); + } + }) + .Where(f => f.Item1 != 0) + .OrderBy(f => f.Item1); + + foreach (var entry in reported) + { + switch (entry.d) + { + case CleanedESM esm: + Console.WriteLine($"{entry.Item1.ToFileSizeString()} for a cleaned ESM patch on {entry.d.To}"); + break; + case InlineFile ilined: + Console.WriteLine($"{entry.Item1.ToFileSizeString()} for a inlined file {entry.d.To}"); + break; + case PatchedFromArchive archive: + Console.WriteLine($"{entry.Item1.ToFileSizeString()} for a patch on {entry.d.To}"); + break; + default: + break; + } + } + Console.WriteLine($"{reported.Count()} entries {reported.Sum(e => e.Item1).ToFileSizeString()} in total"); + return 0; + } + } +}