public static void Main(string[] args) { DicConsole.WriteLineEvent += System.Console.WriteLine; DicConsole.WriteEvent += System.Console.Write; DicConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine; Settings.Settings.LoadSettings(); if (Settings.Settings.Current.GdprCompliance < DicSettings.GdprLevel) { Configure.DoConfigure(true); } Statistics.LoadStats(); if (Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.ShareStats) { Statistics.SubmitStats(); } Parser.Default.ParseArguments(args, typeof(AnalyzeOptions), typeof(BenchmarkOptions), typeof(ChecksumOptions), typeof(CompareOptions), typeof(ConfigureOptions), typeof(ConvertImageOptions), typeof(CreateSidecarOptions), typeof(DecodeOptions), typeof(DeviceInfoOptions), typeof(DeviceReportOptions), typeof(DumpMediaOptions), typeof(EntropyOptions), typeof(ExtractFilesOptions), typeof(FormatsOptions), typeof(ImageInfoOptions), typeof(ListDevicesOptions), typeof(ListEncodingsOptions), typeof(ListOptionsOptions), typeof(LsOptions), typeof(MediaInfoOptions), typeof(MediaScanOptions), typeof(PrintHexOptions), typeof(StatsOptions), typeof(VerifyOptions), typeof(GuiOptions)) .WithParsed <AnalyzeOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Analyze.DoAnalyze(opts); }).WithParsed <CompareOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Compare.DoCompare(opts); }).WithParsed <ChecksumOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Checksum.DoChecksum(opts); }).WithParsed <EntropyOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Entropy.DoEntropy(opts); }).WithParsed <VerifyOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Verify.DoVerify(opts); }).WithParsed <PrintHexOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Commands.PrintHex.DoPrintHex(opts); }).WithParsed <DecodeOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Decode.DoDecode(opts); }).WithParsed <DeviceInfoOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); DeviceInfo.DoDeviceInfo(opts); }).WithParsed <MediaInfoOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); MediaInfo.DoMediaInfo(opts); }).WithParsed <MediaScanOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); MediaScan.DoMediaScan(opts); }).WithParsed <FormatsOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Formats.ListFormats(opts); }).WithParsed <BenchmarkOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Benchmark.DoBenchmark(opts); }).WithParsed <CreateSidecarOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); CreateSidecar.DoSidecar(opts); }).WithParsed <DumpMediaOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); DumpMedia.DoDumpMedia(opts); }).WithParsed <DeviceReportOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); DeviceReport.DoDeviceReport(opts); }).WithParsed <LsOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); Ls.DoLs(opts); }).WithParsed <ExtractFilesOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); ExtractFiles.DoExtractFiles(opts); }).WithParsed <ListDevicesOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); ListDevices.DoListDevices(opts); }).WithParsed <ListEncodingsOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); ListEncodings.DoList(); }).WithParsed <ListOptionsOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); ListOptions.DoList(); }).WithParsed <ConvertImageOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); ConvertImage.DoConvert(opts); }).WithParsed <ImageInfoOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } PrintCopyright(); ImageInfo.GetImageInfo(opts); }).WithParsed <ConfigureOptions>(opts => { PrintCopyright(); Configure.DoConfigure(false); }).WithParsed <StatsOptions>(opts => { PrintCopyright(); Commands.Statistics.ShowStats(); }).WithParsed <GuiOptions>(opts => { if (opts.Debug) { DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (opts.Verbose) { DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; } new Application(Platform.Detect).Run(new frmMain(opts.Debug, opts.Verbose)); }).WithNotParsed(errs => Environment.Exit(1)); Statistics.SaveStats(); }
// TODO: Allow to save MHDD and ImgBurn log files void DoWork() { if (devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0])) { devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':'; } var dev = new Device(devicePath); if (dev.IsRemote) { Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem, dev.RemoteOperatingSystemVersion, dev.RemoteArchitecture); } if (dev.Error) { MessageBox.Show($"Error {dev.LastError} opening device.", MessageBoxType.Error); btnStop.Visible = false; btnScan.Visible = true; btnCancel.Visible = true; stkProgress.Visible = false; return; } Statistics.AddDevice(dev); localResults = new ScanResults(); scanner = new MediaScan(null, null, devicePath, dev); scanner.ScanTime += OnScanTime; scanner.ScanUnreadable += OnScanUnreadable; scanner.UpdateStatus += UpdateStatus; scanner.StoppingErrorMessage += StoppingErrorMessage; scanner.PulseProgress += PulseProgress; scanner.InitProgress += InitProgress; scanner.UpdateProgress += UpdateProgress; scanner.EndProgress += EndProgress; scanner.InitBlockMap += InitBlockMap; scanner.ScanSpeed += ScanSpeed; ScanResults results = scanner.Scan(); Application.Instance.Invoke(() => { lblTotalTime.Text = lblTotalTime.Text = $"Took a total of {results.TotalTime} seconds ({results.ProcessingTime} processing commands)."; lblAvgSpeed.Text = $"Average speed: {results.AvgSpeed:F3} MiB/sec."; lblMaxSpeed.Text = $"Fastest speed burst: {results.MaxSpeed:F3} MiB/sec."; lblMinSpeed.Text = $"Slowest speed burst: {results.MinSpeed:F3} MiB/sec."; lblA.Text = $"{results.A} sectors took less than 3 ms."; lblB.Text = $"{results.B} sectors took less than 10 ms but more than 3 ms."; lblC.Text = $"{results.C} sectors took less than 50 ms but more than 10 ms."; lblD.Text = $"{results.D} sectors took less than 150 ms but more than 50 ms."; lblE.Text = $"{results.E} sectors took less than 500 ms but more than 150 ms."; lblF.Text = $"{results.F} sectors took more than 500 ms."; lblUnreadableSectors.Text = $"{results.UnreadableSectors.Count} sectors could not be read."; }); // TODO: Show list of unreadable sectors /* * if(results.UnreadableSectors.Count > 0) * foreach(ulong bad in results.UnreadableSectors) * string.Format("Sector {0} could not be read", bad); */ // TODO: Show results /* #pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator * if(results.SeekTotal != 0 || results.SeekMin != double.MaxValue || results.SeekMax != double.MinValue) #pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator * string.Format("Testing {0} seeks, longest seek took {1:F3} ms, fastest one took {2:F3} ms. ({3:F3} ms average)", * results.SeekTimes, results.SeekMax, results.SeekMin, results.SeekTotal / 1000); */ Statistics.AddCommand("media-scan"); dev.Close(); WorkFinished(); }
public static int Invoke(bool debug, bool verbose, string devicePath, string ibgLog, string mhddLog) { MainClass.PrintCopyright(); if (debug) { AaruConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; } if (verbose) { AaruConsole.VerboseWriteLineEvent += System.Console.WriteLine; } Statistics.AddCommand("media-scan"); AaruConsole.DebugWriteLine("Media-Scan command", "--debug={0}", debug); AaruConsole.DebugWriteLine("Media-Scan command", "--device={0}", devicePath); AaruConsole.DebugWriteLine("Media-Scan command", "--ibg-log={0}", ibgLog); AaruConsole.DebugWriteLine("Media-Scan command", "--mhdd-log={0}", mhddLog); AaruConsole.DebugWriteLine("Media-Scan command", "--verbose={0}", verbose); if (devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0])) { devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':'; } Devices.Device dev; try { dev = new Devices.Device(devicePath); if (dev.IsRemote) { Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem, dev.RemoteOperatingSystemVersion, dev.RemoteArchitecture); } if (dev.Error) { AaruConsole.ErrorWriteLine(Error.Print(dev.LastError)); return((int)ErrorNumber.CannotOpenDevice); } } catch (DeviceException e) { AaruConsole.ErrorWriteLine(e.Message); return((int)ErrorNumber.CannotOpenDevice); } Statistics.AddDevice(dev); var scanner = new MediaScan(mhddLog, ibgLog, devicePath, dev); scanner.UpdateStatus += Progress.UpdateStatus; scanner.StoppingErrorMessage += Progress.ErrorMessage; scanner.UpdateProgress += Progress.UpdateProgress; scanner.PulseProgress += Progress.PulseProgress; scanner.InitProgress += Progress.InitProgress; scanner.EndProgress += Progress.EndProgress; System.Console.CancelKeyPress += (sender, e) => { e.Cancel = true; scanner.Abort(); }; ScanResults results = scanner.Scan(); AaruConsole.WriteLine("Took a total of {0} seconds ({1} processing commands).", results.TotalTime, results.ProcessingTime); AaruConsole.WriteLine("Average speed: {0:F3} MiB/sec.", results.AvgSpeed); AaruConsole.WriteLine("Fastest speed burst: {0:F3} MiB/sec.", results.MaxSpeed); AaruConsole.WriteLine("Slowest speed burst: {0:F3} MiB/sec.", results.MinSpeed); AaruConsole.WriteLine("Summary:"); AaruConsole.WriteLine("{0} sectors took less than 3 ms.", results.A); AaruConsole.WriteLine("{0} sectors took less than 10 ms but more than 3 ms.", results.B); AaruConsole.WriteLine("{0} sectors took less than 50 ms but more than 10 ms.", results.C); AaruConsole.WriteLine("{0} sectors took less than 150 ms but more than 50 ms.", results.D); AaruConsole.WriteLine("{0} sectors took less than 500 ms but more than 150 ms.", results.E); AaruConsole.WriteLine("{0} sectors took more than 500 ms.", results.F); AaruConsole.WriteLine("{0} sectors could not be read.", results.UnreadableSectors.Count); if (results.UnreadableSectors.Count > 0) { foreach (ulong bad in results.UnreadableSectors) { AaruConsole.WriteLine("Sector {0} could not be read", bad); } } AaruConsole.WriteLine(); if (results.SeekTotal > 0 || results.SeekMin < double.MaxValue || results.SeekMax > double.MinValue) { AaruConsole. WriteLine("Testing {0} seeks, longest seek took {1:F3} ms, fastest one took {2:F3} ms. ({3:F3} ms average)", results.SeekTimes, results.SeekMax, results.SeekMin, results.SeekTotal / 1000); } dev.Close(); return((int)ErrorNumber.NoError); }