diff --git a/Aaru.Archives/Aaru.Archives.csproj b/Aaru.Archives/Aaru.Archives.csproj index a88c0518c..5f8e1dece 100644 --- a/Aaru.Archives/Aaru.Archives.csproj +++ b/Aaru.Archives/Aaru.Archives.csproj @@ -63,4 +63,9 @@ Localization.resx + + + ..\..\..\..\.nuget\packages\spectre.console\0.50.0\lib\net9.0\Spectre.Console.dll + + diff --git a/Aaru.Archives/Zoo/Info.cs b/Aaru.Archives/Zoo/Info.cs index f50e53616..e2da15ce6 100644 --- a/Aaru.Archives/Zoo/Info.cs +++ b/Aaru.Archives/Zoo/Info.cs @@ -27,8 +27,11 @@ // ****************************************************************************/ using System.IO; +using System.Text; using Aaru.CommonTypes.Interfaces; using Aaru.Helpers; +using Aaru.Logging; +using Spectre.Console; namespace Aaru.Archives; @@ -53,5 +56,66 @@ public sealed partial class Zoo return header.zoo_tag == ZOO_TAG && header.zoo_start + header.zoo_minus == 0; } + /// + public void GetInformation(IFilter filter, Encoding encoding, out string information) + { + information = string.Empty; + + if(filter.DataForkLength < Marshal.SizeOf()) return; + + Stream stream = filter.GetDataForkStream(); + stream.Position = 0; + + byte[] hdr = new byte[Marshal.SizeOf()]; + + stream.ReadExactly(hdr, 0, hdr.Length); + + ZooHeader header = Marshal.ByteArrayToStructureLittleEndian(hdr); + + AaruLogging.Debug(MODULE_NAME, + "[blue]header.text[/] = [green]\"{0}\"[/]", + Markup.Escape(Encoding.UTF8.GetString(header.text).TrimEnd('\0'))); + + AaruLogging.Debug(MODULE_NAME, "[blue]header.zoo_tag[/] = [teal]0x{0:X8}[/]", header.zoo_tag); + AaruLogging.Debug(MODULE_NAME, "[blue]header.zoo_start[/] = [teal]{0}[/]", header.zoo_start); + AaruLogging.Debug(MODULE_NAME, "[blue]header.zoo_minus[/] = [teal]{0}[/]", header.zoo_minus); + AaruLogging.Debug(MODULE_NAME, "[blue]header.major_ver[/] = [teal]{0}[/]", header.major_ver); + AaruLogging.Debug(MODULE_NAME, "[blue]header.minor_ver[/] = [teal]{0}[/]", header.minor_ver); + AaruLogging.Debug(MODULE_NAME, "[blue]header.type[/] = [teal]{0}[/]", header.type); + AaruLogging.Debug(MODULE_NAME, "[blue]header.acmt_pos[/] = [teal]{0}[/]", header.acmt_pos); + AaruLogging.Debug(MODULE_NAME, "[blue]header.acmt_len[/] = [teal]{0}[/]", header.acmt_len); + AaruLogging.Debug(MODULE_NAME, "[blue]header.vdata[/] = [teal]0x{0:X4}[/]", header.vdata); + + var sb = new StringBuilder(); + sb.AppendLine("[bold][blue]Zoo archive:[/][/]"); + + sb.AppendFormat("[slateblue1]Header text:[/] [green]\"{0}\"[/]", + Markup.Escape(Encoding.UTF8.GetString(header.text).TrimEnd('\0'))) + .AppendLine(); + + sb.AppendFormat("[slateblue1]Start of archive:[/] [teal]{0}[/]", header.zoo_start).AppendLine(); + + sb.AppendFormat("[slateblue1]Version required to extract all files:[/] [teal]{0}.{1}[/]", + header.major_ver, + header.minor_ver) + .AppendLine(); + + sb.AppendFormat("[slateblue1]Archive type:[/] [teal]{0}[/]", header.type).AppendLine(); + + if(header.acmt_len > 0) + { + byte[] buffer = new byte[header.acmt_len]; + stream.Position = 0; + encoding ??= Encoding.UTF8; + stream.ReadExactly(buffer, 0, buffer.Length); + sb.AppendLine("[slateblue1]Archive comment:[/]"); + + sb.AppendFormat("[rosybrown]{0}[/]", Markup.Escape(StringHandlers.CToString(buffer, encoding))) + .AppendLine(); + } + + information = sb.ToString(); + } + #endregion } \ No newline at end of file diff --git a/Aaru.Archives/Zoo/Unimplemented.cs b/Aaru.Archives/Zoo/Unimplemented.cs index e9329b6f3..8c0604a1f 100644 --- a/Aaru.Archives/Zoo/Unimplemented.cs +++ b/Aaru.Archives/Zoo/Unimplemented.cs @@ -79,11 +79,5 @@ public sealed partial class Zoo /// public ErrorNumber GetEntry(int entryNumber, out IFilter filter) => throw new NotImplementedException(); - /// - public void GetInformation(IFilter filter, Encoding encoding, out string information) - { - throw new NotImplementedException(); - } - #endregion } \ No newline at end of file diff --git a/Aaru.Core/ArchiveInfo.cs b/Aaru.Core/ArchiveInfo.cs index cb713d30b..6c0508802 100644 --- a/Aaru.Core/ArchiveInfo.cs +++ b/Aaru.Core/ArchiveInfo.cs @@ -33,7 +33,6 @@ using System.Text; using Aaru.CommonTypes.Interfaces; using Aaru.Logging; -using Spectre.Console; namespace Aaru.Core; @@ -48,7 +47,7 @@ public static class ArchiveInfo imageFormat.GetInformation(filter, encoding, out string information); - AaruLogging.WriteLine(MarkupHelper.HighlightNumbers(Markup.Escape(information), "teal")); + AaruLogging.WriteLine(information); AaruLogging.WriteLine(); }