[HA] Implement Identify and GetInformation.

This commit is contained in:
2025-09-07 13:28:54 +01:00
parent fa12cc60b9
commit 296a7a88f8
9 changed files with 153 additions and 10 deletions

View File

@@ -4,6 +4,7 @@
xml:space="preserve">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=amg/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=arc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=ha/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=localization/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=stfs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=symbian/@EntryIndexedValue">True</s:Boolean>

View File

@@ -0,0 +1,6 @@
namespace Aaru.Archives;
public sealed partial class Ha
{
const ushort HA_MAGIC = 0x4148;
}

View File

@@ -10,7 +10,7 @@ public sealed partial class Ha : IArchive
/// <inheritdoc />
public string Name => "HA";
/// <inheritdoc />
public Guid Id { get; }
public Guid Id => new("2FB42964-82A0-4819-9C2D-CC2F24E35526");
/// <inheritdoc />
public string Author => Authors.NataliaPortillo;
/// <inheritdoc />

62
Aaru.Archives/Ha/Info.cs Normal file
View File

@@ -0,0 +1,62 @@
using System.IO;
using System.Text;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
namespace Aaru.Archives;
public sealed partial class Ha
{
#region IArchive Members
/// <inheritdoc />
public bool Identify(IFilter filter)
{
if(filter.DataForkLength < Marshal.SizeOf<HaHeader>()) return false;
Stream stream = filter.GetDataForkStream();
stream.Position = 0;
byte[] hdr = new byte[Marshal.SizeOf<HaHeader>()];
stream.ReadExactly(hdr, 0, hdr.Length);
HaHeader header = Marshal.ByteArrayToStructureLittleEndian<HaHeader>(hdr);
// Not a valid magic
return header.magic == HA_MAGIC;
}
/// <inheritdoc />
public void GetInformation(IFilter filter, Encoding encoding, out string information)
{
information = "";
if(filter.DataForkLength < Marshal.SizeOf<HaHeader>()) return;
Stream stream = filter.GetDataForkStream();
stream.Position = 0;
byte[] hdr = new byte[Marshal.SizeOf<HaHeader>()];
stream.ReadExactly(hdr, 0, hdr.Length);
HaHeader header = Marshal.ByteArrayToStructureLittleEndian<HaHeader>(hdr);
// Not a valid magic
if(header.magic != HA_MAGIC) return;
var sb = new StringBuilder();
sb.AppendLine(Localization.HA_archive);
int vertype = stream.ReadByte();
sb.AppendFormat(Localization.Created_with_HA_version_0, vertype >> 4).AppendLine();
sb.AppendFormat(Localization.Archive_contains_0_files, header.count).AppendLine();
information = sb.ToString();
}
#endregion
}

View File

@@ -0,0 +1,47 @@
using System.Runtime.InteropServices;
namespace Aaru.Archives;
public sealed partial class Ha
{
#region Nested type: FHeader
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
readonly struct FHeader
{
// First nibble is archive version, second nibble is compression type
public readonly byte VerType;
// Compressed length
public readonly ushort clen;
// Original length
public readonly ushort olen;
// Unclear if DOS packed date or what
public readonly ushort date;
public readonly ushort time;
// CRC32
public readonly uint crc;
// Follows null-terminated path
// Follows null-terminated filename
// Follows 1-byte machine dependent information length
// Follows machine dependent information
// Follows compressed data
}
#endregion
#region Nested type: HaHeader
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
readonly struct HaHeader
{
public readonly ushort magic;
public readonly ushort count;
}
#endregion
}

View File

@@ -12,9 +12,6 @@ public sealed partial class Ha
{
#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 Ha
/// <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

@@ -680,5 +680,23 @@ namespace Aaru.Archives {
return ResourceManager.GetString("Archive_comment", resourceCulture);
}
}
internal static string HA_archive {
get {
return ResourceManager.GetString("HA_archive", resourceCulture);
}
}
internal static string Created_with_HA_version_0 {
get {
return ResourceManager.GetString("Created_with_HA_version_0", resourceCulture);
}
}
internal static string Archive_contains_0_files {
get {
return ResourceManager.GetString("Archive_contains_0_files", resourceCulture);
}
}
}
}

View File

@@ -333,4 +333,13 @@
<data name="ARC_archive" xml:space="preserve">
<value>[bold][blue]Archivo ARC[/][/]</value>
</data>
<data name="HA_archive" xml:space="preserve">
<value>[bold][blue]Archivo HA[/][/]</value>
</data>
<data name="Created_with_HA_version_0" xml:space="preserve">
<value>[slateblue1]Creado con HA versión [green]{0}[/][/]</value>
</data>
<data name="Archive_contains_0_files" xml:space="preserve">
<value>[slateblue1]El archivo contiene [green]{0}[/] ficheros[/]</value>
</data>
</root>

View File

@@ -341,4 +341,13 @@
<data name="Archive_comment" xml:space="preserve">
<value>[bold][slateblue1]Archive comment:[/][/]</value>
</data>
<data name="HA_archive" xml:space="preserve">
<value>[bold][blue]HA archive[/][/]</value>
</data>
<data name="Created_with_HA_version_0" xml:space="preserve">
<value>[slateblue1]Created with HA version [green]{0}[/][/]</value>
</data>
<data name="Archive_contains_0_files" xml:space="preserve">
<value>[slateblue1]Archive contains [green]{0}[/] files[/]</value>
</data>
</root>