using System.Xml.Linq;
namespace GsaEditor.Core.IO;
///
/// Represents a single entry parsed from a .idx NML index file.
///
public class GsaIndexEntry
{
///
/// The file alias (relative path) of the entry.
///
public string Id { get; set; } = string.Empty;
///
/// Compression method: 0 = raw, 1 = zlib.
///
public int Method { get; set; }
///
/// Original (decompressed) size in bytes.
///
public uint Length { get; set; }
///
/// Compressed size in bytes.
///
public uint CompressedLength { get; set; }
///
/// Byte offset of the data block within the archive.
///
public long Offset { get; set; }
}
///
/// Parses .idx NML index files (XML-compatible format) into a list of .
///
public static class GsaIndexReader
{
///
/// Reads index entries from the specified .idx file.
///
/// The path to the .idx file.
/// A list of parsed index entries.
public static List Read(string filePath)
{
var doc = XDocument.Load(filePath);
var entries = new List();
var root = doc.Root;
if (root == null || root.Name.LocalName != "Index")
return entries;
foreach (var entryEl in root.Elements("Entry"))
{
var entry = new GsaIndexEntry
{
Id = entryEl.Element("Id")?.Value ?? string.Empty,
Method = int.TryParse(entryEl.Element("Method")?.Value, out var m) ? m : 0,
Length = uint.TryParse(entryEl.Element("Len")?.Value, out var l) ? l : 0,
CompressedLength = uint.TryParse(entryEl.Element("CompLen")?.Value, out var cl) ? cl : 0,
Offset = long.TryParse(entryEl.Element("Offset")?.Value, out var o) ? o : 0
};
entries.Add(entry);
}
return entries;
}
}