feat(formats): name font/image inner formats instead of hex
inner_format_label mapped only IDXD/xml/printable-tag magics; fonts and images fell through to a bare hex label (00010000, 89504E47, …). Recognize the known binary signatures and return friendly short tags so the pak browser's format column reads them: sfnt/true/typ1 → "ttf", OTTO → "otf", ttcf → "ttc", PNG → "png", plus RIFF/DDS. Still-unidentified magics keep the hex fallback. Shared by the CLI `pak list` and the GUI browser. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -263,19 +263,34 @@ fn be32(b: &[u8], o: usize) -> u32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Best-effort human label for a decompressed entry's inner format, from its
|
/// Best-effort human label for a decompressed entry's inner format, from its
|
||||||
/// first bytes: `IDXD`, `xml`, a printable 4-char tag (RATC, IXUD, LSTA, …), or
|
/// first bytes: a known signature (`IDXD`, fonts, `png`, …), a printable 4-char
|
||||||
/// a hex fallback. Shared by the CLI `pak list` and the GUI pack browser.
|
/// tag (RATC, IXUD, LSTA, …), or a hex fallback for still-unidentified magics.
|
||||||
|
/// Shared by the CLI `pak list` and the GUI pack browser.
|
||||||
pub fn inner_format_label(payload: &[u8]) -> String {
|
pub fn inner_format_label(payload: &[u8]) -> String {
|
||||||
if payload.len() < 4 {
|
if payload.len() < 4 {
|
||||||
return "empty".into();
|
return "empty".into();
|
||||||
}
|
}
|
||||||
let m = &payload[0..4];
|
let m = &payload[0..4];
|
||||||
if m == b"IDXD" {
|
|
||||||
"IDXD".into()
|
// Known binary/text signatures → friendly short tags (so fonts/images don't
|
||||||
} else if payload.starts_with(b"<?xml") {
|
// show as bare hex like `00010000` / `89504E47`).
|
||||||
"xml".into()
|
let known = match m {
|
||||||
} else if m.iter().all(|&b| b.is_ascii_graphic()) {
|
b"IDXD" => Some("IDXD"),
|
||||||
// Many inner formats are 4-char tags (RATC, T8aD, IXUD, LSTA, ttcf, …).
|
b"\x89PNG" => Some("png"),
|
||||||
|
b"\x00\x01\x00\x00" | b"true" | b"typ1" => Some("ttf"), // sfnt TrueType
|
||||||
|
b"OTTO" => Some("otf"), // OpenType (CFF)
|
||||||
|
b"ttcf" => Some("ttc"), // TrueType Collection
|
||||||
|
b"RIFF" => Some("riff"),
|
||||||
|
b"DDS " => Some("dds"),
|
||||||
|
_ if payload.starts_with(b"<?xml") => Some("xml"),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
if let Some(tag) = known {
|
||||||
|
return tag.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.iter().all(|&b| b.is_ascii_graphic()) {
|
||||||
|
// Many inner formats are 4-char tags (RATC, T8aD, IXUD, LSTA, …).
|
||||||
String::from_utf8_lossy(m).into_owned()
|
String::from_utf8_lossy(m).into_owned()
|
||||||
} else {
|
} else {
|
||||||
format!("{:02X}{:02X}{:02X}{:02X}", m[0], m[1], m[2], m[3])
|
format!("{:02X}{:02X}{:02X}{:02X}", m[0], m[1], m[2], m[3])
|
||||||
|
|||||||
Reference in New Issue
Block a user