From 5fa1a0b5ea52b7591b388f2c3b70d4177dc52690 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 16 Aug 2025 21:11:52 +0100 Subject: [PATCH] Add serilog for handling verbose and debug outputs. --- Aaru.Console/AaruConsole.cs | 39 +------ Aaru.Images/Nero/Read.cs | 112 +++++++++---------- Aaru/Aaru.csproj | 2 + Aaru/Commands/Archive/Extract.cs | 29 ----- Aaru/Commands/Archive/Info.cs | 29 ----- Aaru/Commands/Archive/List.cs | 29 ----- Aaru/Commands/Configure.cs | 29 ----- Aaru/Commands/Database/Statistics.cs | 29 ----- Aaru/Commands/Database/Update.cs | 30 ------ Aaru/Commands/Device/DeviceReport.cs | 29 ----- Aaru/Commands/Device/Info.cs | 29 ----- Aaru/Commands/Device/List.cs | 29 ----- Aaru/Commands/Filesystem/ExtractFiles.cs | 29 ----- Aaru/Commands/Filesystem/Info.cs | 29 ----- Aaru/Commands/Filesystem/Ls.cs | 29 ----- Aaru/Commands/Filesystem/Options.cs | 29 ----- Aaru/Commands/Formats.cs | 29 ----- Aaru/Commands/Image/Checksum.cs | 29 ----- Aaru/Commands/Image/Compare.cs | 29 ----- Aaru/Commands/Image/Convert.cs | 29 ----- Aaru/Commands/Image/CreateSidecar.cs | 29 ----- Aaru/Commands/Image/Decode.cs | 29 ----- Aaru/Commands/Image/Entropy.cs | 29 ----- Aaru/Commands/Image/Info.cs | 29 ----- Aaru/Commands/Image/Options.cs | 29 ----- Aaru/Commands/Image/Print.cs | 31 +----- Aaru/Commands/Image/Verify.cs | 41 ++----- Aaru/Commands/ListEncodings.cs | 29 ----- Aaru/Commands/ListNamespaces.cs | 29 ----- Aaru/Commands/Media/Dump.cs | 30 ------ Aaru/Commands/Media/Info.cs | 29 ----- Aaru/Commands/Media/Scan.cs | 29 ----- Aaru/Commands/Remote.cs | 29 ----- Aaru/LogLevelInterceptor.cs | 31 ++++++ Aaru/Main.cs | 24 ++++- Directory.Packages.props | 132 ++++++++++++----------- 36 files changed, 188 insertions(+), 1038 deletions(-) create mode 100644 Aaru/LogLevelInterceptor.cs diff --git a/Aaru.Console/AaruConsole.cs b/Aaru.Console/AaruConsole.cs index 6a58e57d2..d47f41940 100644 --- a/Aaru.Console/AaruConsole.cs +++ b/Aaru.Console/AaruConsole.cs @@ -139,15 +139,6 @@ public static class AaruConsole /// Event to receive writings to the standard output console. public static event WriteHandler WriteEvent; - /// Event to receive writings to the error output console. - public static event ErrorWriteHandler ErrorWriteEvent; - - /// Event to receive writings to the verbose output console. - public static event VerboseWriteHandler VerboseWriteEvent; - - /// Event to receive writings to the debug output console. - public static event DebugWriteHandler DebugWriteEvent; - /// Event to receive exceptions to write to the debug output console. public static event WriteExceptionHandler WriteExceptionEvent; @@ -185,7 +176,7 @@ public static class AaruConsole /// An array of objects to write using . public static void DebugWriteLine(string module, string format, params object[] arg) { - DebugWriteLineEvent?.Invoke("DEBUG (" + module + "): " + format, arg); + DebugWriteLineEvent?.Invoke($"[blue]({module}):[/] {format}", arg); DebugWithModuleWriteLineEvent?.Invoke(module, format, arg); } @@ -209,32 +200,6 @@ public static class AaruConsole /// An array of objects to write using . public static void Write(string format, params object[] arg) => WriteEvent?.Invoke(format, arg); - /// - /// Writes the text representation of the specified array of objects to the error output console using the - /// specified format information. - /// - /// A composite format string. - /// An array of objects to write using . - public static void ErrorWrite(string format, params object[] arg) => ErrorWriteEvent?.Invoke(format, arg); - - /// - /// Writes the text representation of the specified array of objects to the verbose output console using the - /// specified format information. - /// - /// A composite format string. - /// An array of objects to write using . - public static void VerboseWrite(string format, params object[] arg) => VerboseWriteEvent?.Invoke(format, arg); - - /// - /// Writes the text representation of the specified array of objects to the debug output console using the - /// specified format information. - /// - /// Description of the module writing to the debug console - /// A composite format string. - /// An array of objects to write using . - public static void DebugWrite(string module, string format, params object[] arg) => - DebugWriteEvent?.Invoke("DEBUG (" + module + "): " + format, arg); - /// Writes the specified string value, followed by the current line terminator, to the standard output console. /// The value to write. public static void WriteLine(string value) => WriteLineEvent?.Invoke("{0}", value); @@ -251,7 +216,7 @@ public static class AaruConsole /// Description of the module writing to the debug console /// The value to write. public static void DebugWriteLine(string module, string value) => - DebugWriteLineEvent?.Invoke("{0}", "DEBUG (" + module + "): " + value); + DebugWriteLineEvent?.Invoke("[blue]({0}):[/] {1}", module, value); /// /// Writes the exception to the debug output console. diff --git a/Aaru.Images/Nero/Read.cs b/Aaru.Images/Nero/Read.cs index 73503a249..8f37de378 100644 --- a/Aaru.Images/Nero/Read.cs +++ b/Aaru.Images/Nero/Read.cs @@ -60,7 +60,7 @@ public sealed partial class Nero var footerV2 = new FooterV2(); _imageStream.Seek(-8, SeekOrigin.End); - var buffer = new byte[8]; + byte[] buffer = new byte[8]; _imageStream.EnsureRead(buffer, 0, 8); footerV1.ChunkId = BigEndianBitConverter.ToUInt32(buffer, 0); footerV1.FirstChunkOffset = BigEndianBitConverter.ToUInt32(buffer, 4); @@ -94,7 +94,7 @@ public sealed partial class Nero _imageNewFormat = true; else { - AaruConsole.DebugWrite(MODULE_NAME, Localization.Nero_version_not_recognized); + AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Nero_version_not_recognized); return ErrorNumber.NotSupported; } @@ -105,7 +105,7 @@ public sealed partial class Nero else _imageStream.Seek(footerV1.FirstChunkOffset, SeekOrigin.Begin); - var parsing = true; + bool parsing = true; ushort currentSession = 1; uint currentTrack = 1; @@ -115,18 +115,18 @@ public sealed partial class Nero _imageInfo.MediaType = CommonTypes.MediaType.CD; _imageInfo.Sectors = 0; _imageInfo.SectorSize = 0; - var oldFormat = false; - int currentLba = -150; - var corruptedTrackMode = false; + bool oldFormat = false; + int currentLba = -150; + bool corruptedTrackMode = false; // Parse chunks while(parsing) { - var chunkHeaderBuffer = new byte[8]; + byte[] chunkHeaderBuffer = new byte[8]; _imageStream.EnsureRead(chunkHeaderBuffer, 0, 8); - var chunkId = BigEndianBitConverter.ToUInt32(chunkHeaderBuffer, 0); - var chunkLength = BigEndianBitConverter.ToUInt32(chunkHeaderBuffer, 4); + uint chunkId = BigEndianBitConverter.ToUInt32(chunkHeaderBuffer, 0); + uint chunkLength = BigEndianBitConverter.ToUInt32(chunkHeaderBuffer, 4); AaruConsole.DebugWriteLine(MODULE_NAME, "ChunkID = 0x{0:X8} (\"{1}\")", @@ -150,9 +150,9 @@ public sealed partial class Nero Entries = [] }; - var tmpBuffer = new byte[8]; + byte[] tmpBuffer = new byte[8]; - for(var i = 0; i < newCuesheetV1.ChunkSize; i += 8) + for(int i = 0; i < newCuesheetV1.ChunkSize; i += 8) { var entry = new CueEntryV1(); _imageStream.EnsureRead(tmpBuffer, 0, 8); @@ -226,9 +226,9 @@ public sealed partial class Nero Entries = [] }; - var tmpBuffer = new byte[8]; + byte[] tmpBuffer = new byte[8]; - for(var i = 0; i < newCuesheetV2.ChunkSize; i += 8) + for(int i = 0; i < newCuesheetV2.ChunkSize; i += 8) { var entry = new CueEntryV2(); _imageStream.EnsureRead(tmpBuffer, 0, 8); @@ -288,7 +288,7 @@ public sealed partial class Nero ChunkSizeBe = chunkLength }; - var tmpBuffer = new byte[22]; + byte[] tmpBuffer = new byte[22]; _imageStream.EnsureRead(tmpBuffer, 0, 22); _neroDaov1.ChunkSizeLe = BigEndianBitConverter.ToUInt32(tmpBuffer, 0); _neroDaov1.Upc = new byte[14]; @@ -316,7 +316,7 @@ public sealed partial class Nero tmpBuffer = new byte[30]; - for(var i = 0; i < _neroDaov1.ChunkSizeBe - 22; i += 30) + for(int i = 0; i < _neroDaov1.ChunkSizeBe - 22; i += 30) { var entry = new DaoEntryV1(); _imageStream.EnsureRead(tmpBuffer, 0, 30); @@ -423,7 +423,7 @@ public sealed partial class Nero ChunkSizeBe = chunkLength }; - var tmpBuffer = new byte[22]; + byte[] tmpBuffer = new byte[22]; _imageStream.EnsureRead(tmpBuffer, 0, 22); _neroDaov2.ChunkSizeLe = BigEndianBitConverter.ToUInt32(tmpBuffer, 0); _neroDaov2.Upc = new byte[14]; @@ -451,7 +451,7 @@ public sealed partial class Nero tmpBuffer = new byte[42]; - for(var i = 0; i < _neroDaov2.ChunkSizeBe - 22; i += 42) + for(int i = 0; i < _neroDaov2.ChunkSizeBe - 22; i += 42) { var entry = new DaoEntryV2(); _imageStream.EnsureRead(tmpBuffer, 0, 42); @@ -560,9 +560,9 @@ public sealed partial class Nero Packs = [] }; - var tmpBuffer = new byte[18]; + byte[] tmpBuffer = new byte[18]; - for(var i = 0; i < _cdtxt.ChunkSize; i += 18) + for(int i = 0; i < _cdtxt.ChunkSize; i += 18) { var entry = new CdTextPack(); _imageStream.EnsureRead(tmpBuffer, 0, 18); @@ -628,9 +628,9 @@ public sealed partial class Nero Tracks = [] }; - var tmpBuffer = new byte[12]; + byte[] tmpBuffer = new byte[12]; - for(var i = 0; i < _taoV0.ChunkSize; i += 12) + for(int i = 0; i < _taoV0.ChunkSize; i += 12) { var entry = new TaoEntryV0(); _imageStream.EnsureRead(tmpBuffer, 0, 12); @@ -699,9 +699,9 @@ public sealed partial class Nero Tracks = [] }; - var tmpBuffer = new byte[20]; + byte[] tmpBuffer = new byte[20]; - for(var i = 0; i < _taoV1.ChunkSize; i += 20) + for(int i = 0; i < _taoV1.ChunkSize; i += 20) { var entry = new TaoEntryV1(); _imageStream.EnsureRead(tmpBuffer, 0, 20); @@ -781,9 +781,9 @@ public sealed partial class Nero Tracks = [] }; - var tmpBuffer = new byte[32]; + byte[] tmpBuffer = new byte[32]; - for(var i = 0; i < _taoV2.ChunkSize; i += 32) + for(int i = 0; i < _taoV2.ChunkSize; i += 32) { var entry = new TaoEntryV2(); _imageStream.EnsureRead(tmpBuffer, 0, 32); @@ -871,9 +871,9 @@ public sealed partial class Nero Localization.Found_SINF_chunk_parsing_0_bytes, chunkLength); - var tmpBuffer = new byte[4]; + byte[] tmpBuffer = new byte[4]; _imageStream.EnsureRead(tmpBuffer, 0, 4); - var sessionTracks = BigEndianBitConverter.ToUInt32(tmpBuffer, 0); + uint sessionTracks = BigEndianBitConverter.ToUInt32(tmpBuffer, 0); _neroSessions.Add(currentSession, sessionTracks); AaruConsole.DebugWriteLine(MODULE_NAME, @@ -898,7 +898,7 @@ public sealed partial class Nero ChunkSize = chunkLength }; - var tmpBuffer = new byte[4]; + byte[] tmpBuffer = new byte[4]; _imageStream.EnsureRead(tmpBuffer, 0, 4); _mediaType.Type = BigEndianBitConverter.ToUInt32(tmpBuffer, 0); @@ -924,7 +924,7 @@ public sealed partial class Nero ChunkSize = chunkLength }; - var tmpBuffer = new byte[4]; + byte[] tmpBuffer = new byte[4]; _imageStream.EnsureRead(tmpBuffer, 0, 4); _discInfo.Unknown = BigEndianBitConverter.ToUInt32(tmpBuffer, 0); @@ -947,7 +947,7 @@ public sealed partial class Nero ChunkSize = chunkLength }; - var tmpBuffer = new byte[4]; + byte[] tmpBuffer = new byte[4]; _imageStream.EnsureRead(tmpBuffer, 0, 4); _relo.Unknown = BigEndianBitConverter.ToUInt32(tmpBuffer, 0); @@ -968,7 +968,7 @@ public sealed partial class Nero ChunkSize = chunkLength }; - var tmpBuffer = new byte[2]; + byte[] tmpBuffer = new byte[2]; _imageStream.EnsureRead(tmpBuffer, 0, 2); _toc.Unknown = BigEndianBitConverter.ToUInt16(tmpBuffer, 0); @@ -1060,7 +1060,7 @@ public sealed partial class Nero var currentSessionStruct = new CommonTypes.Structs.Session(); ulong partitionSequence = 0; ulong partitionStartByte = 0; - var trackCounter = 1; + int trackCounter = 1; _trackFlags = new Dictionary(); if(currentSessionMaxTrack == 0) currentSessionMaxTrack = 1; @@ -1200,8 +1200,8 @@ public sealed partial class Nero _imageInfo.ReadableSectorTags.Add(SectorTagType.CdTrackIsrc); } - var rawMode1 = false; - var rawMode2 = false; + bool rawMode1 = false; + bool rawMode2 = false; switch((DaoMode)neroTrack.Mode) { @@ -1387,9 +1387,9 @@ public sealed partial class Nero } }; - var rawMode1 = false; - var rawMode2 = false; - var subSize = 0; + bool rawMode1 = false; + bool rawMode2 = false; + int subSize = 0; switch((DaoMode)_neroTracks[1].Mode) { @@ -1549,13 +1549,13 @@ public sealed partial class Nero if(_imageInfo.MediaType is CommonTypes.MediaType.Unknown or CommonTypes.MediaType.CD) { - var data = false; - var mode2 = false; - var firstAudio = false; - var firstData = false; - var audio = false; + bool data = false; + bool mode2 = false; + bool firstAudio = false; + bool firstData = false; + bool audio = false; - for(var i = 0; i < _neroTracks.Count; i++) + for(int i = 0; i < _neroTracks.Count; i++) { // First track is audio firstAudio |= i == 0 && @@ -1665,7 +1665,7 @@ public sealed partial class Nero } catch { - AaruConsole.DebugWrite(MODULE_NAME, Localization.Exception_occurred_opening_file); + AaruConsole.DebugWriteLine(MODULE_NAME, Localization.Exception_occurred_opening_file); return ErrorNumber.UnexpectedException; } @@ -1749,7 +1749,7 @@ public sealed partial class Nero uint sectorOffset; uint sectorSize; uint sectorSkip; - var mode2 = false; + bool mode2 = false; switch((DaoMode)aaruTrack.Mode) { @@ -1848,9 +1848,9 @@ public sealed partial class Nero buffer = br.ReadBytes((int)((sectorSize + sectorSkip) * length)); - for(var i = 0; i < length; i++) + for(int i = 0; i < length; i++) { - var sector = new byte[sectorSize]; + byte[] sector = new byte[sectorSize]; Array.Copy(buffer, (sectorSize + sectorSkip) * i, sector, 0, sectorSize); sector = Sector.GetUserData(sector); mode2Ms.Write(sector, 0, sector.Length); @@ -1862,7 +1862,7 @@ public sealed partial class Nero buffer = br.ReadBytes((int)(sectorSize * length)); else { - for(var i = 0; i < length; i++) + for(int i = 0; i < length; i++) { br.BaseStream.Seek(sectorOffset, SeekOrigin.Current); byte[] sector = br.ReadBytes((int)sectorSize); @@ -2176,7 +2176,7 @@ public sealed partial class Nero buffer = br.ReadBytes((int)(sectorSize * length)); else { - for(var i = 0; i < length; i++) + for(int i = 0; i < length; i++) { br.BaseStream.Seek(sectorOffset, SeekOrigin.Current); byte[] sector = br.ReadBytes((int)sectorSize); @@ -2287,7 +2287,7 @@ public sealed partial class Nero buffer = br.ReadBytes((int)(sectorSize * length)); else { - for(var i = 0; i < length; i++) + for(int i = 0; i < length; i++) { br.BaseStream.Seek(sectorOffset, SeekOrigin.Current); byte[] sector = br.ReadBytes((int)sectorSize); @@ -2301,8 +2301,8 @@ public sealed partial class Nero { case DaoMode.Data: { - var fullSector = new byte[2352]; - var fullBuffer = new byte[2352 * length]; + byte[] fullSector = new byte[2352]; + byte[] fullBuffer = new byte[2352 * length]; for(uint i = 0; i < length; i++) { @@ -2318,8 +2318,8 @@ public sealed partial class Nero } case DaoMode.DataM2F1: { - var fullSector = new byte[2352]; - var fullBuffer = new byte[2352 * length]; + byte[] fullSector = new byte[2352]; + byte[] fullBuffer = new byte[2352 * length]; for(uint i = 0; i < length; i++) { @@ -2337,8 +2337,8 @@ public sealed partial class Nero } case DaoMode.DataM2F2: { - var fullSector = new byte[2352]; - var fullBuffer = new byte[2352 * length]; + byte[] fullSector = new byte[2352]; + byte[] fullBuffer = new byte[2352 * length]; for(uint i = 0; i < length; i++) { diff --git a/Aaru/Aaru.csproj b/Aaru/Aaru.csproj index 4e2157a42..c1e969afa 100644 --- a/Aaru/Aaru.csproj +++ b/Aaru/Aaru.csproj @@ -75,6 +75,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Aaru/Commands/Archive/Extract.cs b/Aaru/Commands/Archive/Extract.cs index 6d236468d..b0150ce47 100644 --- a/Aaru/Commands/Archive/Extract.cs +++ b/Aaru/Commands/Archive/Extract.cs @@ -58,35 +58,6 @@ sealed class ArchiveExtractCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("archive-extract"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Archive/Info.cs b/Aaru/Commands/Archive/Info.cs index efa8dc5ba..231f878f8 100644 --- a/Aaru/Commands/Archive/Info.cs +++ b/Aaru/Commands/Archive/Info.cs @@ -53,35 +53,6 @@ sealed class ArchiveInfoCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("archive-info"); AaruConsole.DebugWriteLine(MODULE_NAME, "debug={0}", settings.Debug); diff --git a/Aaru/Commands/Archive/List.cs b/Aaru/Commands/Archive/List.cs index aab5c608f..d6107ffde 100644 --- a/Aaru/Commands/Archive/List.cs +++ b/Aaru/Commands/Archive/List.cs @@ -53,35 +53,6 @@ sealed class ArchiveListCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(Markup.Escape(format)); - else - stderrConsole.MarkupLine(Markup.Escape(format), objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); AaruConsole.DebugWriteLine(MODULE_NAME, "--encoding={0}", Markup.Escape(settings.Encoding ?? "")); AaruConsole.DebugWriteLine(MODULE_NAME, "--long-format={0}", settings.LongFormat); diff --git a/Aaru/Commands/Configure.cs b/Aaru/Commands/Configure.cs index 2eba2e14d..acda0dcbe 100644 --- a/Aaru/Commands/Configure.cs +++ b/Aaru/Commands/Configure.cs @@ -45,35 +45,6 @@ sealed class ConfigureCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - return DoConfigure(false); } diff --git a/Aaru/Commands/Database/Statistics.cs b/Aaru/Commands/Database/Statistics.cs index b7607a3ed..88b8e30e3 100644 --- a/Aaru/Commands/Database/Statistics.cs +++ b/Aaru/Commands/Database/Statistics.cs @@ -49,35 +49,6 @@ sealed class StatisticsCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - var ctx = AaruContext.Create(Aaru.Settings.Settings.LocalDbPath); if(!ctx.Commands.Any() && diff --git a/Aaru/Commands/Database/Update.cs b/Aaru/Commands/Database/Update.cs index bd443e199..9799bf882 100644 --- a/Aaru/Commands/Database/Update.cs +++ b/Aaru/Commands/Database/Update.cs @@ -41,7 +41,6 @@ using Aaru.Core; using Aaru.Database; using Aaru.Localization; using Microsoft.EntityFrameworkCore; -using Spectre.Console; using Spectre.Console.Cli; namespace Aaru.Commands.Database; @@ -55,35 +54,6 @@ sealed class UpdateCommand : AsyncCommand { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => stderrConsole.WriteException(ex); - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); AaruConsole.DebugWriteLine(MODULE_NAME, "--verbose={0}", settings.Verbose); diff --git a/Aaru/Commands/Device/DeviceReport.cs b/Aaru/Commands/Device/DeviceReport.cs index d85863031..eeac7b47f 100644 --- a/Aaru/Commands/Device/DeviceReport.cs +++ b/Aaru/Commands/Device/DeviceReport.cs @@ -64,35 +64,6 @@ sealed class DeviceReportCommand : AsyncCommand { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("device-report"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Device/Info.cs b/Aaru/Commands/Device/Info.cs index 7845146c5..ea229d030 100644 --- a/Aaru/Commands/Device/Info.cs +++ b/Aaru/Commands/Device/Info.cs @@ -70,35 +70,6 @@ sealed class DeviceInfoCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("device-info"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Device/List.cs b/Aaru/Commands/Device/List.cs index db1d7112e..e426ecf9f 100644 --- a/Aaru/Commands/Device/List.cs +++ b/Aaru/Commands/Device/List.cs @@ -52,35 +52,6 @@ sealed class ListDevicesCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("list-devices"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Filesystem/ExtractFiles.cs b/Aaru/Commands/Filesystem/ExtractFiles.cs index 9ffada654..6745b30b2 100644 --- a/Aaru/Commands/Filesystem/ExtractFiles.cs +++ b/Aaru/Commands/Filesystem/ExtractFiles.cs @@ -59,35 +59,6 @@ sealed class ExtractFilesCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("extract-files"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Filesystem/Info.cs b/Aaru/Commands/Filesystem/Info.cs index ccd61130a..78a6a1bc6 100644 --- a/Aaru/Commands/Filesystem/Info.cs +++ b/Aaru/Commands/Filesystem/Info.cs @@ -55,35 +55,6 @@ sealed class FilesystemInfoCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("fs-info"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Filesystem/Ls.cs b/Aaru/Commands/Filesystem/Ls.cs index 823d2170c..7782f1f3d 100644 --- a/Aaru/Commands/Filesystem/Ls.cs +++ b/Aaru/Commands/Filesystem/Ls.cs @@ -56,35 +56,6 @@ sealed class LsCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(Markup.Escape(format)); - else - stderrConsole.MarkupLine(Markup.Escape(format), objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); AaruConsole.DebugWriteLine(MODULE_NAME, "--encoding={0}", Markup.Escape(settings.Encoding ?? "")); AaruConsole.DebugWriteLine(MODULE_NAME, "--input={0}", Markup.Escape(settings.ImagePath ?? "")); diff --git a/Aaru/Commands/Filesystem/Options.cs b/Aaru/Commands/Filesystem/Options.cs index 112dc95f4..1b18a6368 100644 --- a/Aaru/Commands/Filesystem/Options.cs +++ b/Aaru/Commands/Filesystem/Options.cs @@ -53,35 +53,6 @@ sealed class ListOptionsCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); AaruConsole.DebugWriteLine(MODULE_NAME, "--verbose={0}", settings.Verbose); Statistics.AddCommand("list-options"); diff --git a/Aaru/Commands/Formats.cs b/Aaru/Commands/Formats.cs index 48426841b..4a325833d 100644 --- a/Aaru/Commands/Formats.cs +++ b/Aaru/Commands/Formats.cs @@ -51,35 +51,6 @@ sealed class FormatsCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("formats"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Image/Checksum.cs b/Aaru/Commands/Image/Checksum.cs index 4379dd04c..4bcc9a3b6 100644 --- a/Aaru/Commands/Image/Checksum.cs +++ b/Aaru/Commands/Image/Checksum.cs @@ -58,35 +58,6 @@ sealed class ChecksumCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("checksum"); AaruConsole.DebugWriteLine(MODULE_NAME, "--adler32={0}", settings.Adler32); diff --git a/Aaru/Commands/Image/Compare.cs b/Aaru/Commands/Image/Compare.cs index 5bd99f5f2..83bcaf1cb 100644 --- a/Aaru/Commands/Image/Compare.cs +++ b/Aaru/Commands/Image/Compare.cs @@ -57,35 +57,6 @@ sealed class CompareCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("compare"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Image/Convert.cs b/Aaru/Commands/Image/Convert.cs index 7e3ea2be1..7ecc59809 100644 --- a/Aaru/Commands/Image/Convert.cs +++ b/Aaru/Commands/Image/Convert.cs @@ -71,35 +71,6 @@ sealed class ConvertImageCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - bool fixSubchannel = settings.FixSubchannel; bool fixSubchannelCrc = settings.FixSubchannelCrc; bool fixSubchannelPosition = settings.FixSubchannelPosition; diff --git a/Aaru/Commands/Image/CreateSidecar.cs b/Aaru/Commands/Image/CreateSidecar.cs index f39da6672..3f8ab005c 100644 --- a/Aaru/Commands/Image/CreateSidecar.cs +++ b/Aaru/Commands/Image/CreateSidecar.cs @@ -60,35 +60,6 @@ sealed class CreateSidecarCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("create-sidecar"); AaruConsole.DebugWriteLine(MODULE_NAME, "--block-size={0}", settings.BlockSize); diff --git a/Aaru/Commands/Image/Decode.cs b/Aaru/Commands/Image/Decode.cs index 4a418f16a..37ee17900 100644 --- a/Aaru/Commands/Image/Decode.cs +++ b/Aaru/Commands/Image/Decode.cs @@ -54,35 +54,6 @@ sealed class DecodeCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("decode"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Image/Entropy.cs b/Aaru/Commands/Image/Entropy.cs index cb87319cc..58da4e40b 100644 --- a/Aaru/Commands/Image/Entropy.cs +++ b/Aaru/Commands/Image/Entropy.cs @@ -52,35 +52,6 @@ sealed class EntropyCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("entropy"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Image/Info.cs b/Aaru/Commands/Image/Info.cs index fbf1f240e..3005d446f 100644 --- a/Aaru/Commands/Image/Info.cs +++ b/Aaru/Commands/Image/Info.cs @@ -51,35 +51,6 @@ sealed class ImageInfoCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("image-info"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Image/Options.cs b/Aaru/Commands/Image/Options.cs index ee8d17c47..37f7abbd2 100644 --- a/Aaru/Commands/Image/Options.cs +++ b/Aaru/Commands/Image/Options.cs @@ -53,35 +53,6 @@ sealed class ListOptionsCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); AaruConsole.DebugWriteLine(MODULE_NAME, "--verbose={0}", settings.Verbose); Statistics.AddCommand("list-options"); diff --git a/Aaru/Commands/Image/Print.cs b/Aaru/Commands/Image/Print.cs index f0faa424f..d273bcd2d 100644 --- a/Aaru/Commands/Image/Print.cs +++ b/Aaru/Commands/Image/Print.cs @@ -53,35 +53,6 @@ sealed class PrintHexCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("print-hex"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); @@ -219,9 +190,11 @@ sealed class PrintHexCommand : Command }); if(errno == ErrorNumber.NoError) + { AaruConsole.WriteLine(Markup.Escape(PrintHex.ByteArrayToHexArrayString(sector, settings.Width, true))); + } else AaruConsole.ErrorWriteLine(string.Format(UI.Error_0_reading_sector_1, errno, settings.Start + i)); } diff --git a/Aaru/Commands/Image/Verify.cs b/Aaru/Commands/Image/Verify.cs index e4ae14d44..a6a6566cc 100644 --- a/Aaru/Commands/Image/Verify.cs +++ b/Aaru/Commands/Image/Verify.cs @@ -57,35 +57,6 @@ sealed class VerifyCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("verify"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); @@ -226,9 +197,11 @@ sealed class VerifyCommand : Command opticalMediaImage.Info.Sectors); } else if(settings.CreateGraph) + { mediaGraph = new BlockMap((int)settings.Dimensions, (int)settings.Dimensions, opticalMediaImage.Info.Sectors); + } List inputTracks = opticalMediaImage.Tracks; ulong currentSectorAll = 0; @@ -427,18 +400,16 @@ sealed class VerifyCommand : Command if(failingLbas.Count == (int)inputFormat.Info.Sectors) AaruConsole.VerboseWriteLine($"\t[red]{UI.all_sectors}[/]"); else - { - foreach(ulong t in failingLbas) AaruConsole.VerboseWriteLine("\t{0}", t); - } + foreach(ulong t in failingLbas) + AaruConsole.VerboseWriteLine("\t{0}", t); AaruConsole.WriteLine($"[yellow3_1]{UI.LBAs_without_checksum}[/]"); if(unknownLbas.Count == (int)inputFormat.Info.Sectors) AaruConsole.VerboseWriteLine($"\t[yellow3_1]{UI.all_sectors}[/]"); else - { - foreach(ulong t in unknownLbas) AaruConsole.VerboseWriteLine("\t{0}", t); - } + foreach(ulong t in unknownLbas) + AaruConsole.VerboseWriteLine("\t{0}", t); } // TODO: Convert to table diff --git a/Aaru/Commands/ListEncodings.cs b/Aaru/Commands/ListEncodings.cs index 3a357e0de..560fff0cb 100644 --- a/Aaru/Commands/ListEncodings.cs +++ b/Aaru/Commands/ListEncodings.cs @@ -50,35 +50,6 @@ sealed class ListEncodingsCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("list-encodings"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/ListNamespaces.cs b/Aaru/Commands/ListNamespaces.cs index 640ef1d81..a8d363f6c 100644 --- a/Aaru/Commands/ListNamespaces.cs +++ b/Aaru/Commands/ListNamespaces.cs @@ -51,35 +51,6 @@ sealed class ListNamespacesCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); AaruConsole.DebugWriteLine(MODULE_NAME, "--verbose={0}", settings.Verbose); Statistics.AddCommand("list-namespaces"); diff --git a/Aaru/Commands/Media/Dump.cs b/Aaru/Commands/Media/Dump.cs index 560f9eaf6..177322940 100644 --- a/Aaru/Commands/Media/Dump.cs +++ b/Aaru/Commands/Media/Dump.cs @@ -72,36 +72,6 @@ sealed class DumpMediaCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - - bool fixSubchannel = settings.FixSubchannel; bool fixSubchannelCrc = settings.FixSubchannelCrc; bool fixSubchannelPosition = settings.FixSubchannelPosition; diff --git a/Aaru/Commands/Media/Info.cs b/Aaru/Commands/Media/Info.cs index 0e35cdc27..d97d91660 100644 --- a/Aaru/Commands/Media/Info.cs +++ b/Aaru/Commands/Media/Info.cs @@ -71,35 +71,6 @@ sealed class MediaInfoCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("media-info"); AaruConsole.DebugWriteLine(MODULE_NAME, "debug={0}", settings.Debug); diff --git a/Aaru/Commands/Media/Scan.cs b/Aaru/Commands/Media/Scan.cs index dd6772705..316fa3b9f 100644 --- a/Aaru/Commands/Media/Scan.cs +++ b/Aaru/Commands/Media/Scan.cs @@ -53,35 +53,6 @@ sealed class MediaScanCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("media-scan"); AaruConsole.DebugWriteLine(MODULE_NAME, "--debug={0}", settings.Debug); diff --git a/Aaru/Commands/Remote.cs b/Aaru/Commands/Remote.cs index 75b59889e..10c0b8a51 100644 --- a/Aaru/Commands/Remote.cs +++ b/Aaru/Commands/Remote.cs @@ -51,35 +51,6 @@ sealed class RemoteCommand : Command { MainClass.PrintCopyright(); - if(settings.Debug) - { - IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings - { - Out = new AnsiConsoleOutput(System.Console.Error) - }); - - AaruConsole.DebugWriteLineEvent += (format, objects) => - { - if(objects is null) - stderrConsole.MarkupLine(format); - else - stderrConsole.MarkupLine(format, objects); - }; - - AaruConsole.WriteExceptionEvent += ex => { stderrConsole.WriteException(ex); }; - } - - if(settings.Verbose) - { - AaruConsole.WriteEvent += (format, objects) => - { - if(objects is null) - AnsiConsole.Markup(format); - else - AnsiConsole.Markup(format, objects); - }; - } - Statistics.AddCommand("remote"); AaruConsole.DebugWriteLine(MODULE_NAME, "debug={0}", settings.Debug); diff --git a/Aaru/LogLevelInterceptor.cs b/Aaru/LogLevelInterceptor.cs new file mode 100644 index 000000000..5ad99c073 --- /dev/null +++ b/Aaru/LogLevelInterceptor.cs @@ -0,0 +1,31 @@ +using Aaru.Commands; +using Serilog; +using Serilog.Core; +using Serilog.Events; +using Spectre.Console.Cli; + +public class LogLevelInterceptor : ICommandInterceptor +{ + private readonly LoggingLevelSwitch _levelSwitch; + + public LogLevelInterceptor(LoggingLevelSwitch levelSwitch) => _levelSwitch = levelSwitch; + +#region ICommandInterceptor Members + + public void Intercept(CommandContext context, CommandSettings settings) + { + if(settings is BaseSettings global) + { + if(global.Debug) + _levelSwitch.MinimumLevel = LogEventLevel.Debug; + else if(global.Verbose) + _levelSwitch.MinimumLevel = LogEventLevel.Verbose; + else + _levelSwitch.MinimumLevel = LogEventLevel.Information; + + Log.Information("Log level set to {Level}", _levelSwitch.MinimumLevel); + } + } + +#endregion +} \ No newline at end of file diff --git a/Aaru/Main.cs b/Aaru/Main.cs index 672dacbe3..853d71c8c 100644 --- a/Aaru/Main.cs +++ b/Aaru/Main.cs @@ -52,6 +52,9 @@ using Aaru.Localization; using Aaru.Settings; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; +using Serilog; +using Serilog.Core; +using Serilog.Sinks.Spectre; using Spectre.Console; using Spectre.Console.Cli; using ListOptionsCommand = Aaru.Commands.Filesystem.ListOptionsCommand; @@ -71,6 +74,15 @@ class MainClass Out = new AnsiConsoleOutput(System.Console.Error) }); + var levelSwitch = new LoggingLevelSwitch(); + + Log.Logger = new LoggerConfiguration().MinimumLevel.ControlledBy(levelSwitch) + .WriteTo + .Spectre("[{Timestamp:HH:mm:ss} {Level:u3}{Module}] {Message:lj}{NewLine}{Exception}", + levelSwitch: levelSwitch, + renderTextAsMarkup: true) + .CreateLogger(); + object[] attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false); _assemblyTitle = ((AssemblyTitleAttribute)attributes[0]).Title; attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); @@ -106,8 +118,16 @@ class MainClass stderrConsole.MarkupLine(format); else stderrConsole.MarkupLine(format, objects); + + Log.Error(format, objects); }; + AaruConsole.VerboseWriteLineEvent += Log.Verbose; + + AaruConsole.DebugWriteLineEvent += Log.Debug; + + AaruConsole.WriteExceptionEvent += ex => Log.Error(ex, "Unhandled exception"); + Settings.Settings.LoadSettings(); AaruContext ctx = null; @@ -385,9 +405,9 @@ class MainClass .WithDescription(UI.List_Namespaces_Command_Description); config.AddCommand("remote").WithAlias("rem").WithDescription(UI.Remote_Command_Description); - }); - PrintCopyright(); + config.SetInterceptor(new LogLevelInterceptor(levelSwitch)); + }); int ret = await app.RunAsync(args); diff --git a/Directory.Packages.props b/Directory.Packages.props index 090ff8950..6b5b42e75 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,69 +1,71 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file