diff --git a/crates/sylpheed-formats/src/pak.rs b/crates/sylpheed-formats/src/pak.rs index 6548389..439b4df 100644 --- a/crates/sylpheed-formats/src/pak.rs +++ b/crates/sylpheed-formats/src/pak.rs @@ -263,19 +263,34 @@ fn be32(b: &[u8], o: usize) -> u32 { } /// 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 -/// a hex fallback. Shared by the CLI `pak list` and the GUI pack browser. +/// first bytes: a known signature (`IDXD`, fonts, `png`, …), a printable 4-char +/// 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 { if payload.len() < 4 { return "empty".into(); } let m = &payload[0..4]; - if m == b"IDXD" { - "IDXD".into() - } else if payload.starts_with(b" Some("IDXD"), + 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" 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() } else { format!("{:02X}{:02X}{:02X}{:02X}", m[0], m[1], m[2], m[3])