public void Test_Ico_Misnamed() { var model = new Diags.Model(null); var fn = @"Targets\Singles\DutchIco.jpeg"; var file = new FileInfo(fn); bool isKnown; FileFormat actual; var fs = new FileStream(fn, FileMode.Open); var fmt = FormatBase.CreateModel(model.Data.FileFormats.Items, fs, fn, 0, 0, null, out isKnown, out actual); var fb = fmt.Data; Assert.IsNotNull(fmt); Assert.IsTrue(fb.Issues.MaxSeverity == Severity.Warning); Assert.AreEqual(1, fb.Issues.Items.Count); Assert.IsInstanceOfType(fmt, typeof(IcoFormat.Model)); Assert.AreEqual("ico", actual.PrimaryName); Assert.AreEqual(1, fb.Issues.RepairableCount); string errMsg = fmt.IssueModel.Repair(0); Assert.AreEqual(0, fb.Issues.RepairableCount); Assert.IsNull(errMsg); }
public void Test_FormatList() { var model = new Diags.Model(null); var formatsListText = model.Data.FormatListText; Assert.AreEqual("ape, asf/wmv/wma, avi/divx, cue, db (Thumbs), flac, flv, gif, ico, jpg/jpeg, log (EAC), log (XLD), m3u, m3u8, m4a, md5, mkv/mka, mov/qt, mp3, mp4, mpg/mpeg/vob, ogg, png, sha1, sha1x, sha256, wav", formatsListText); }
public void Test_LogEac_StrictWeb() { var dn = baseDir + @"\Targets\EacLogs\"; var model = new Diags.Model(dn); // Uncomment next line to test hash verification. Requires the interweb. // model.Bind.HashFlags |= Hashes.WebCheck; // log1 has self-hash var s1 = new FileStream(dn + "Nightmare.log", FileMode.Open); var h1 = new byte[0x2C]; s1.Read(h1, 0, h1.Length); var log1Model = LogEacFormat.CreateModel(s1, h1, dn); log1Model.CalcHashes(model.Data.HashFlags, 0); model.Data.ErrEscalator = IssueTags.ProveErr; log1Model.IssueModel.Escalate(model.Data.WarnEscalator, model.Data.ErrEscalator); var b1 = log1Model.Data; Assert.IsFalse(b1.Issues.HasError); if ((model.Data.HashFlags & Hashes.WebCheck) != 0) { Assert.IsTrue(b1.ShIssue.Success == true); } else { Assert.IsNull(b1.ShIssue); } // log2 has no self-hash var s2 = new FileStream(dn + "EAC1NoHashOrCT.log", FileMode.Open); var h2 = new byte[0x2C]; s2.Read(h2, 0, h1.Length); var log2Model = LogEacFormat.CreateModel(s2, h2, dn); log2Model.CalcHashes(model.Data.HashFlags, 0); model.Data.ErrEscalator = IssueTags.ProveErr | IssueTags.Fussy; log2Model.IssueModel.Escalate(model.Data.WarnEscalator, model.Data.ErrEscalator); var b2 = log2Model.Data; Assert.IsTrue(b2.Issues.HasError); if ((model.Data.HashFlags & Hashes.WebCheck) != 0) { Assert.IsTrue(b2.ShIssue.Success == false); } else { Assert.IsNull(b2.ShIssue); } }
public int Run() { model = new Diags.Model(null); int exitCode = ParseArgs(); if (exitCode == 0) { if (model.Data.Scope == Granularity.Detail) { NotifyEvery = 0; } if (mirrorName != null) { try { var mirrorWriter = new TextWriterTraceListener(mirrorName); mirrorWriter.WriteLine(String.Empty); mirrorWriter.WriteLine(Diags.MajorSeparator); mirrorWriter.WriteLine(DateTime.Now); Trace.Listeners.Add(mirrorWriter); } catch (Exception) { Console.Error.WriteLine("Ignoring malformed <mirror>"); } } if (model.Data.Scope <= Granularity.Verbose) { if (model.Data.IsDigestForm) { Trace.Write("; "); } Trace.WriteLine($"{ProductText} v{VersionText}"); Trace.WriteLine(String.Empty); } viewFactory.Create(this, model.Data); exitCode = (int)Severity.NoIssue; string err = null; #if !DEBUG try { #endif foreach (FormatBase.Model fmtModel in model.CheckRoot()) { } model.ReportSummary("checked"); exitCode = (int)model.Data.Result; #if !DEBUG } catch (Exception ex) when(ex is IOException || ex is ArgumentException) { err = ex.Message; } #endif if (err != null) { exitCode = (int)Severity.Fatal; Console.Error.WriteLine("* Error: " + err); } } if (waitForKeyPress) { Console.WriteLine(); Console.Write("Press the escape key to escape..."); while (Console.ReadKey().Key != ConsoleKey.Escape) { } } return(exitCode); }
public int Run() { int exitCode = ParseArgs(args); if (exitCode == 0) { NotifyEvery = notifyEvery ?? (scope < Granularity.Verbose? 0 : 1); if (mirrorName != null) { try { var mirrorWriter = new TextWriterTraceListener(mirrorName); mirrorWriter.WriteLine(String.Empty); mirrorWriter.WriteLine(SessionSeparator); mirrorWriter.WriteLine(DateTime.Now); Trace.Listeners.Add(mirrorWriter); } catch (Exception) { Console.Error.WriteLine("Ignoring malformed <mirror>"); } } if (scope <= Granularity.Verbose) { Trace.WriteLine(ProductText + " v" + VersionText); Trace.WriteLine(String.Empty); } model = new Diags.Model(args[args.Length - 1], filter, exclusion, action, scope, warnEscalator, errEscalator); viewFactory.Create(this, model.Data); model.Data.HashFlags = hashes; model.Data.ValidationFlags = validations; exitCode = (int)Severity.NoIssue; string err = null; #if !DEBUG try { #endif foreach (FormatBase.Model fmtModel in model.CheckRoot()) { } model.Data.OnReportClose(); exitCode = (int)model.Data.Result; #if !DEBUG } catch (IOException ex) { err = ex.Message; } catch (ArgumentException ex) { err = ex.Message; } #endif if (err != null) { exitCode = (int)Severity.Fatal; Console.Error.WriteLine("* Error: " + err); } } if (waitForKeyPress) { Console.WriteLine(); Console.Write("Press the escape key to exit..."); while (Console.ReadKey().Key != ConsoleKey.Escape) { } } return(exitCode); }
private static void ShowUsage() { string exe = Process.GetCurrentProcess().ProcessName; Console.WriteLine($"{ProductText} v{VersionText}"); Console.WriteLine(); Console.WriteLine("Usage:"); Console.WriteLine($"{exe} [/R] [/f:<wildcard>] [/g:<granularity>] [/h:<hashes>] [/v:<validations>] [/w:<escalators>] [/e:<escalators>] [/out:<mirror>] [/p:<counter>] [/x:<exclusion>] [/k] <fileOrDirectory>"); Console.WriteLine(); Console.WriteLine("Where <fileOrDirectory> is a file or directory name without wildcards."); Console.WriteLine(); Console.Write("Where <granularity> from"); foreach (var name in Enum.GetNames(typeof(Granularity))) { Console.Write(" " + name); } Console.WriteLine(); Console.WriteLine(); Console.Write("Where <hashes> is list of"); foreach (var name in Enum.GetNames(typeof(Hashes))) { Console.Write(" " + name); } Console.WriteLine(); Console.WriteLine(); Console.Write("Where <validations> is list of"); foreach (var name in Enum.GetNames(typeof(Validations))) { Console.Write(" " + name); } Console.WriteLine(); Console.WriteLine(); Console.Write("Where <escalators> is list of"); var groupNames = Enum.GetNames(typeof(IssueTags)); for (var di = 1; di < groupNames.Length; ++di) { Enum.TryParse <IssueTags> (groupNames[di], true, out IssueTags tag); if (((int)tag & 0x00FFFFFF) != 0) { Console.Write(" " + groupNames[di]); } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Example switches:"); Console.WriteLine(); Console.WriteLine("Use /e:substandard to error on lower quality encodings."); Console.WriteLine(); Console.WriteLine("Use /f:*.log to only diagnose files with the .log extension."); Console.WriteLine(); Console.WriteLine("Use /g:detail to display maximum diagnostics."); Console.WriteLine(); Console.WriteLine("Use /h:FileMD5,FileSHA1 to calculate file MD5 and SHA1 hashes."); Console.WriteLine(); Console.WriteLine("Use /k to wait for keypress before exiting."); Console.WriteLine(); Console.WriteLine("Use /out:results.txt to mirror output to results.txt."); Console.WriteLine(); Console.WriteLine("Use /p:0 to suppress the progress counter."); Console.WriteLine(); Console.WriteLine("Use /v:0 to only parse digests and perform no hash checks."); Console.WriteLine(); Console.WriteLine("Use /x:@ to ignore all paths that include the at sign."); Console.WriteLine(); Console.WriteLine("Description:"); Console.WriteLine(); foreach (var line in helpText) { Console.WriteLine(line); } // Create a dummy model just to get a format list. var model = new Diags.Model(null); Console.WriteLine(); Console.WriteLine("The following file extensions are supported:"); Console.WriteLine(model.Data.FormatListText); }