[AMG] Implement Identify and GetInformation.

This commit is contained in:
2025-09-04 20:36:33 +01:00
parent fd34b79bfa
commit 8f8bdf3c8e
8 changed files with 159 additions and 10 deletions

View File

@@ -0,0 +1,6 @@
namespace Aaru.Archives;
public sealed partial class Amg
{
const ushort ARC_MAGIC = 0x36AD;
}

71
Aaru.Archives/Amg/Info.cs Normal file
View File

@@ -0,0 +1,71 @@
using System.IO;
using System.Text;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
using Spectre.Console;
namespace Aaru.Archives;
public sealed partial class Amg
{
#region IArchive Members
/// <inheritdoc />
public bool Identify(IFilter filter)
{
if(filter.DataForkLength < Marshal.SizeOf<ArcHeader>()) return false;
Stream stream = filter.GetDataForkStream();
stream.Position = 0;
byte[] hdr = new byte[Marshal.SizeOf<ArcHeader>()];
stream.ReadExactly(hdr, 0, hdr.Length);
ArcHeader header = Marshal.ByteArrayToStructureLittleEndian<ArcHeader>(hdr);
// Not a valid magic
return header.magic == ARC_MAGIC;
}
/// <inheritdoc />
public void GetInformation(IFilter filter, Encoding encoding, out string information)
{
encoding ??= Encoding.ASCII;
information = "";
if(filter.DataForkLength < Marshal.SizeOf<ArcHeader>()) return;
Stream stream = filter.GetDataForkStream();
stream.Position = 0;
byte[] hdr = new byte[Marshal.SizeOf<ArcHeader>()];
stream.ReadExactly(hdr, 0, hdr.Length);
ArcHeader header = Marshal.ByteArrayToStructureLittleEndian<ArcHeader>(hdr);
// Not a valid magic
if(header.magic != ARC_MAGIC) return;
var sb = new StringBuilder();
sb.AppendLine(Localization.AMG_archive);
sb.AppendFormat(Localization.AMG_version_0_1, header.version >> 4, header.version & 0xF).AppendLine();
if(header.files > 0)
sb.AppendFormat(Localization.Archive_contains_0_files_for_1_bytes, header.files, header.size).AppendLine();
if(header.commentLength > 0)
{
byte[] buffer = new byte[header.commentLength];
stream.ReadExactly(buffer, 0, buffer.Length);
sb.AppendLine(Localization.Archive_comment);
sb.AppendLine(Markup.Escape(StringHandlers.CToString(buffer, encoding)));
}
information = sb.ToString();
}
#endregion
}

View File

@@ -0,0 +1,21 @@
using System.Runtime.InteropServices;
namespace Aaru.Archives;
public sealed partial class Amg
{
#region Nested type: ArcHeader
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
readonly struct ArcHeader
{
public readonly ushort magic;
public readonly byte version;
public readonly byte padding;
public readonly ushort files;
public readonly uint size;
public readonly ushort commentLength;
}
#endregion
}

View File

@@ -12,9 +12,6 @@ public sealed partial class Amg
{
#region IArchive Members
/// <inheritdoc />
public bool Identify(IFilter filter) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber Open(IFilter filter, Encoding encoding) => throw new NotImplementedException();
@@ -54,11 +51,5 @@ public sealed partial class Amg
/// <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

@@ -92,7 +92,7 @@ public sealed partial class Arc
// Hope for the best
var sb = new StringBuilder();
sb.AppendLine("[bold][blue]ARC archive[/][/]");
sb.AppendLine(Localization.ARC_archive);
information = sb.ToString();
}

View File

@@ -650,5 +650,35 @@ namespace Aaru.Archives {
return ResourceManager.GetString("Profile_ID_0", resourceCulture);
}
}
internal static string ARC_archive {
get {
return ResourceManager.GetString("ARC_archive", resourceCulture);
}
}
internal static string AMG_archive {
get {
return ResourceManager.GetString("AMG_archive", resourceCulture);
}
}
internal static string AMG_version_0_1 {
get {
return ResourceManager.GetString("AMG_version_0_1", resourceCulture);
}
}
internal static string Archive_contains_0_files_for_1_bytes {
get {
return ResourceManager.GetString("Archive_contains_0_files_for_1_bytes", resourceCulture);
}
}
internal static string Archive_comment {
get {
return ResourceManager.GetString("Archive_comment", resourceCulture);
}
}
}
}

View File

@@ -318,4 +318,19 @@
<data name="Version_0" xml:space="preserve">
<value>[bold][slateblue1]Versión:[/][/] [teal]{0}[/]</value>
</data>
<data name="AMG_archive" xml:space="preserve">
<value>[bold][blue]Archivo AMG[/][/]</value>
</data>
<data name="AMG_version_0_1" xml:space="preserve">
<value>[slateblue1]Creado con AMG versión [green]{0}.{1}[/][/]</value>
</data>
<data name="Archive_comment" xml:space="preserve">
<value>[bold][slateblue1]Comentario del archivo:[/][/]</value>
</data>
<data name="Archive_contains_0_files_for_1_bytes" xml:space="preserve">
<value>[slateblue1]El archivo contiene [green]{0}[/] ficheros por [lime]{1}[/] bytes[/]</value>
</data>
<data name="ARC_archive" xml:space="preserve">
<value>[bold][blue]Archivo ARC[/][/]</value>
</data>
</root>

View File

@@ -326,4 +326,19 @@
<data name="Profile_ID_0" xml:space="preserve">
<value>[bold][slateblue1]Profile ID:[/][/] [teal]{0}[/]</value>
</data>
<data name="ARC_archive" xml:space="preserve">
<value>[bold][blue]ARC archive[/][/]</value>
</data>
<data name="AMG_archive" xml:space="preserve">
<value>[bold][blue]AMG archive[/][/]</value>
</data>
<data name="AMG_version_0_1" xml:space="preserve">
<value>[slateblue1]Created with AMG version [green]{0}.{1}[/][/]</value>
</data>
<data name="Archive_contains_0_files_for_1_bytes" xml:space="preserve">
<value>[slateblue1]Archive contains [green]{0}[/] files for [lime]{1}[/] bytes[/]</value>
</data>
<data name="Archive_comment" xml:space="preserve">
<value>[bold][slateblue1]Archive comment:[/][/]</value>
</data>
</root>