[ZOO] Implement showing archive information.

This commit is contained in:
2025-08-23 05:54:02 +01:00
parent 9f927a8ed2
commit 10ec902999
4 changed files with 70 additions and 8 deletions

View File

@@ -63,4 +63,9 @@
<DependentUpon>Localization.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="Spectre.Console">
<HintPath>..\..\..\..\.nuget\packages\spectre.console\0.50.0\lib\net9.0\Spectre.Console.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -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;
}
/// <inheritdoc />
public void GetInformation(IFilter filter, Encoding encoding, out string information)
{
information = string.Empty;
if(filter.DataForkLength < Marshal.SizeOf<ZooHeader>()) return;
Stream stream = filter.GetDataForkStream();
stream.Position = 0;
byte[] hdr = new byte[Marshal.SizeOf<ZooHeader>()];
stream.ReadExactly(hdr, 0, hdr.Length);
ZooHeader header = Marshal.ByteArrayToStructureLittleEndian<ZooHeader>(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
}

View File

@@ -79,11 +79,5 @@ public sealed partial class Zoo
/// <inheritdoc />
public ErrorNumber GetEntry(int entryNumber, out IFilter filter) => throw new NotImplementedException();
/// <inheritdoc />
public void GetInformation(IFilter filter, Encoding encoding, out string information)
{
throw new NotImplementedException();
}
#endregion
}

View File

@@ -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();
}