From 138842318a89467bd7c930f0c8d74adedfe8d15d Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 2 Sep 2025 22:04:02 -0400 Subject: [PATCH] Let's try to be fancy --- BinaryObjectScanner/ProtectionProgress.cs | 14 ++++++++++++++ BinaryObjectScanner/Scanner.cs | 20 ++++++++++++++------ ProtectionScan/Program.cs | 8 +++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/BinaryObjectScanner/ProtectionProgress.cs b/BinaryObjectScanner/ProtectionProgress.cs index b38f60ca..2bb1a718 100644 --- a/BinaryObjectScanner/ProtectionProgress.cs +++ b/BinaryObjectScanner/ProtectionProgress.cs @@ -14,6 +14,11 @@ /// public string? Filename { get; } + /// + /// Number of levels deep the file is + /// + public int Depth { get; } + /// /// Value between 0 and 1 representign the percentage completed /// @@ -27,6 +32,15 @@ public ProtectionProgress(string? filename, float percentage, string? protection) { Filename = filename; + Depth = 0; + Percentage = percentage; + Protection = protection; + } + + public ProtectionProgress(string? filename, int depth, float percentage, string? protection) + { + Filename = filename; + Depth = depth; Percentage = percentage; Protection = protection; } diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs index 9fc66192..fd89f0e3 100644 --- a/BinaryObjectScanner/Scanner.cs +++ b/BinaryObjectScanner/Scanner.cs @@ -114,11 +114,15 @@ namespace BinaryObjectScanner // Get the reportable file name string reportableFileName = file; + int depth = 0; if (reportableFileName.StartsWith(tempFilePath)) - reportableFileName = $"--> {reportableFileName.Substring(tempFilePathWithGuid.Length)}"; + { + depth = 1; + reportableFileName = reportableFileName.Substring(tempFilePathWithGuid.Length); + } // Checkpoint - _fileProgress?.Report(new ProtectionProgress(reportableFileName, i / (float)files.Count, "Checking file" + (file != reportableFileName ? " from archive" : string.Empty))); + _fileProgress?.Report(new ProtectionProgress(reportableFileName, depth, i / (float)files.Count, "Checking file" + (file != reportableFileName ? " from archive" : string.Empty))); // Scan for path-detectable protections if (_options.ScanPaths) @@ -138,7 +142,7 @@ namespace BinaryObjectScanner var fullProtection = fullProtectionList != null && fullProtectionList.Count > 0 ? string.Join(", ", [.. fullProtectionList]) : null; - _fileProgress?.Report(new ProtectionProgress(reportableFileName, (i + 1) / (float)files.Count, fullProtection ?? string.Empty)); + _fileProgress?.Report(new ProtectionProgress(reportableFileName, depth, (i + 1) / (float)files.Count, fullProtection ?? string.Empty)); } } @@ -147,11 +151,15 @@ namespace BinaryObjectScanner { // Get the reportable file name string reportableFileName = path; + int depth = 0; if (reportableFileName.StartsWith(tempFilePath)) - reportableFileName = $"--> {reportableFileName.Substring(tempFilePathWithGuid.Length)}"; + { + depth = 1; + reportableFileName = reportableFileName.Substring(tempFilePathWithGuid.Length); + } // Checkpoint - _fileProgress?.Report(new ProtectionProgress(reportableFileName, 0, "Checking file" + (path != reportableFileName ? " from archive" : string.Empty))); + _fileProgress?.Report(new ProtectionProgress(reportableFileName, depth, 0, "Checking file" + (path != reportableFileName ? " from archive" : string.Empty))); // Scan for path-detectable protections if (_options.ScanPaths) @@ -171,7 +179,7 @@ namespace BinaryObjectScanner var fullProtection = fullProtectionList != null && fullProtectionList.Count > 0 ? string.Join(", ", [.. fullProtectionList]) : null; - _fileProgress?.Report(new ProtectionProgress(reportableFileName, 1, fullProtection ?? string.Empty)); + _fileProgress?.Report(new ProtectionProgress(reportableFileName, depth, 1, fullProtection ?? string.Empty)); } // Throw on an invalid path diff --git a/ProtectionScan/Program.cs b/ProtectionScan/Program.cs index bd6c7225..4d6ba1a3 100644 --- a/ProtectionScan/Program.cs +++ b/ProtectionScan/Program.cs @@ -134,7 +134,13 @@ namespace ProtectionScan /// private static void Changed(object? source, ProtectionProgress value) { - Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}"); + string prefix = string.Empty; + for (int i = 0; i < value.Depth; i++) + { + prefix += "--> "; + } + + Console.WriteLine($"{prefix}{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}"); } } }