ZArchive support (#75)

* ZArchive support

* Fix offset record format

* Simplfiy Extensions

* Delete unused writers and test data

* Rework reader

* Fix build
This commit is contained in:
Deterous
2026-04-02 15:18:47 +09:00
committed by GitHub
parent 4035d9db86
commit 5bb8557555
23 changed files with 1292 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
using System;
using System.Text;
using SabreTools.Data.Models.ZArchive;
using SabreTools.Numerics;
namespace SabreTools.Data.Extensions
{
public static class ZArchiveExtensions
{
/// <summary>
/// Retrieves the name of the specified node from the NameTable
/// </summary>
/// <param name="node">Node in the file tree</param>
/// <param name="nameTable">ZArchive NameTable</param>
/// <returns>UTF-8 string representing node's name</returns>
public static string? GetName(this FileDirectoryEntry node, NameTable nameTable)
{
// Check for a valid offset into the NameTable
uint nameOffset = node.NameOffsetAndTypeFlag & Constants.RootNode;
if (nameOffset == Constants.RootNode)
return null;
// Get the index into the name table
var index = Array.IndexOf(nameTable.NameTableOffsets, nameOffset);
if (index < 0)
return null;
// Get the name entry for the requested index
var nameEntry = nameTable.NameEntries[index];
if (nameEntry is null)
return null;
// Decode name to UTF-8
return Encoding.UTF8.GetString(nameEntry.NodeName);
}
}
}