From 3a59c2490ccd5c4bd523323685e00ceb441112f9 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Wed, 4 May 2022 21:49:25 +0100 Subject: [PATCH] Replaced static field with optional parameter to switch verbose debugging off. Signed-off-by: Konstantina Chremmou --- CommandLib/export.cs | 31 +++++++++++++++++++------------ xva_verify/verify_main.cs | 23 ++++++++++++++--------- xva_verify/xva_verify.csproj | 2 +- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/CommandLib/export.cs b/CommandLib/export.cs index c868a6645..9400002cf 100644 --- a/CommandLib/export.cs +++ b/CommandLib/export.cs @@ -73,12 +73,19 @@ namespace CommandLib private readonly XXHash64 _xxHash = new XXHash64(); - public static bool verbose_debugging = false; + private readonly bool _quiet; - private static void debug(string x) + public Export(bool quiet = false) { - if (verbose_debugging) - Console.WriteLine(x); + _quiet = quiet; + } + + private void Debug(string x) + { + if (_quiet) + return; + + Console.WriteLine(x); } private string checksum_sha1(byte[] data) @@ -108,7 +115,7 @@ namespace CommandLib return hex(_xxHash.ComputeHash(data)); } - private static Hashtable parse_checksum_table(string checksum_xml) + private Hashtable parse_checksum_table(string checksum_xml) { Hashtable table = new Hashtable(); @@ -130,14 +137,14 @@ namespace CommandLib value = v.Value; } - debug(String.Format("adding {0} = {1}", name, value)); + Debug(String.Format("adding {0} = {1}", name, value)); table.Add(name, value); } return table; } - private static void compare_tables(Hashtable recomputed, Hashtable original) + private void compare_tables(Hashtable recomputed, Hashtable original) { foreach (DictionaryEntry x in recomputed) { @@ -149,7 +156,7 @@ namespace CommandLib } else { - debug(String.Format("{0} hash OK", (string)x.Key)); + Debug(String.Format("{0} hash OK", (string)x.Key)); } } } @@ -209,13 +216,13 @@ namespace CommandLib while (!cancelling()) { Header header_data = nextHeader(input, output, callback); - debug(header_data.ToString()); + Debug(header_data.ToString()); byte[] bytes_data = nextData(input, output, callback, header_data.file_size); if (header_data.file_name.Equals("ova.xml")) { - debug("Skipping ova.xml"); + Debug("Skipping ova.xml"); } else if (header_data.file_name.EndsWith("checksum.xml")) { @@ -234,7 +241,7 @@ namespace CommandLib if (!csum.Equals(csum_compare)) throw new BlockChecksumFailed(header_data.file_name, csum, csum_compare); - debug(String.Format(" has checksum: {0}", csum)); + Debug(String.Format(" has checksum: {0}", csum)); recomputed_checksums.Add(header_data.file_name, csum); nextData(input, output, callback, header_checksum.paddingLength()); // Eat the padding for the checksum file @@ -245,7 +252,7 @@ namespace CommandLib } catch (EndOfArchive) { - debug("EOF"); + Debug("EOF"); if (original_checksums != null) compare_tables(recomputed_checksums, original_checksums); } diff --git a/xva_verify/verify_main.cs b/xva_verify/verify_main.cs index 93c68b346..5513ffbd6 100644 --- a/xva_verify/verify_main.cs +++ b/xva_verify/verify_main.cs @@ -32,6 +32,7 @@ using System; using System.IO; using System.IO.Compression; +using System.Linq; using System.Text; using CommandLib; @@ -41,30 +42,34 @@ namespace xva_verify { public static void Main(string[] args) { - Export.verbose_debugging = true; - if (args.Length < 1 || args.Length > 2) + if (args.Length < 1 || args.Length > 3) { var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("Usage").AppendLine(); - sb.AppendLine(" xva_verify []").AppendLine(); + sb.AppendLine(" xva_verify [ -q]").AppendLine(); sb.AppendLine("where").AppendLine(); sb.AppendLine(" The name of the archive file to verify. Use '-' to read from stdin."); - sb.AppendLine(" If specified, a copy of the archive file is created with this name.").AppendLine(); + sb.AppendLine(" If specified, a copy of the archive file is created with this name."); + sb.AppendLine(" -q If specified, it switches off verbose debugging."); + sb.AppendLine(); Console.WriteLine(sb.ToString()); Environment.Exit(1); } + bool quiet = args.Contains("-q"); + var fileArgs = args.Where(a => a != "-q").ToArray(); + try { - string filename = args[0]; + string filename = fileArgs[0]; Stream g = null; - if (args.Length == 2) - g = new FileStream(args[1], FileMode.Create); + if (fileArgs.Length > 1) + g = new FileStream(fileArgs[1], FileMode.Create); - Stream f = args[0].Equals("-") + Stream f = fileArgs[0].Equals("-") ? Console.OpenStandardInput() : new FileStream(filename, FileMode.Open, FileAccess.Read); @@ -88,7 +93,7 @@ namespace xva_verify } } - new Export().verify(f, g, () => false); + new Export(quiet).verify(f, g, () => false); } catch(UnauthorizedAccessException) { diff --git a/xva_verify/xva_verify.csproj b/xva_verify/xva_verify.csproj index 91f4f9793..b43b1c32e 100755 --- a/xva_verify/xva_verify.csproj +++ b/xva_verify/xva_verify.csproj @@ -62,7 +62,7 @@ - +