1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//! Disc image format and filesystem type definitions.
use std::path::Path;
/// Supported disc image container formats.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiscFormat {
/// Plain ISO 9660 image (`.iso`, `.toast`) — 2048-byte cooked sectors.
Iso,
/// Raw binary with CUE sheet (`.bin` + `.cue`) — 2352-byte raw sectors.
BinCue,
/// MAME Compressed Hunks of Data, optical variant (`.chd`).
Chd,
/// Media Descriptor Sidecar (`.mds` + `.mdf`) — not yet implemented.
MdsMdf,
/// Dreamcast GD-ROM track descriptor (`.gdi`) with sidecar track files.
Gdi,
/// Nintendo GameCube / Wii disc image (`.gcm`, `.rvz`, `.wbfs`, `.ciso`,
/// `.gcz`, `.wia`, `.tgc`, `.nfs`) — read via the `nod` crate. A raw GameCube
/// or Wii dump may also carry a plain `.iso` extension; those are detected by
/// magic and browsed through the same path.
Nintendo,
}
impl DiscFormat {
/// Detect format from file extension (case-insensitive).
pub fn from_path(path: impl AsRef<Path>) -> Option<Self> {
let ext = path.as_ref().extension()?.to_str()?.to_lowercase();
match ext.as_str() {
"iso" | "toast" => Some(Self::Iso),
"bin" | "cue" => Some(Self::BinCue),
"chd" => Some(Self::Chd),
"mds" | "mdf" => Some(Self::MdsMdf),
"gdi" => Some(Self::Gdi),
"gcm" | "rvz" | "wbfs" | "ciso" | "gcz" | "wia" | "tgc" | "nfs" => Some(Self::Nintendo),
_ => None,
}
}
/// Human-readable name for this format.
pub fn display_name(self) -> &'static str {
match self {
Self::Iso => "ISO image",
Self::BinCue => "BIN/CUE",
Self::Chd => "CHD (Compressed Hunks of Data)",
Self::MdsMdf => "MDS/MDF",
Self::Gdi => "GDI (Dreamcast GD-ROM)",
Self::Nintendo => "Nintendo GameCube/Wii",
}
}
/// File extensions associated with this format.
pub fn extensions(self) -> &'static [&'static str] {
match self {
Self::Iso => &["iso", "toast"],
Self::BinCue => &["bin", "cue"],
Self::Chd => &["chd"],
Self::MdsMdf => &["mds", "mdf"],
Self::Gdi => &["gdi"],
Self::Nintendo => &["gcm", "rvz", "wbfs", "ciso", "gcz", "wia", "tgc", "nfs"],
}
}
}
/// All file extensions recognised by the library, for use in file-open dialogs.
pub fn supported_extensions() -> &'static [&'static str] {
&[
"iso", "toast", "bin", "cue", "chd", "mds", "mdf", "gdi", "gcm", "rvz", "wbfs", "ciso",
"gcz", "wia", "tgc", "nfs",
]
}
/// Filesystem type found on the data track of a disc.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FilesystemType {
/// ISO 9660 standard filesystem (data CDs, DVDs).
Iso9660,
/// High Sierra Format — the pre-ISO 9660 CD-ROM filesystem (1986 standard,
/// `CDROM` identifier). Early Microsoft/IBM titles (Bookshelf, Programmer's
/// Library). Browsed by the ISO 9660 reader with High-Sierra field offsets.
HighSierra,
/// Joliet extensions (Unicode long filenames on top of ISO 9660).
Joliet,
/// Universal Disk Format (DVDs, Blu-ray).
Udf,
/// Classic HFS (Macintosh CDs, pre-Mac OS X).
Hfs,
/// HFS+ / Mac OS Extended (Mac OS X CDs and DVDs).
HfsPlus,
/// SGI EFS (Extent File System) — IRIX install/distribution CDs.
Efs,
/// UFS / FFS (BSD Fast File System) — Digital UNIX / Tru64, SunOS/Solaris CDs.
Ufs,
/// VMS ODS-2 / Files-11 — OpenVMS (VAX / Alpha) discs.
Ods2,
/// Nintendo GameCube filesystem (GCM/FST), browsed via the `nod` crate.
GameCube,
/// Nintendo Wii filesystem (encrypted partitions + FST), via the `nod` crate.
Wii,
/// Philips CD-i (Green Book) — ISO 9660-derived, big-endian records.
Cdi,
/// 3DO Opera filesystem (big-endian, block-based directory tree).
Opera,
/// Could not be determined.
Unknown,
}
impl FilesystemType {
/// Human-readable name.
pub fn display_name(self) -> &'static str {
match self {
Self::Iso9660 => "ISO 9660",
Self::HighSierra => "High Sierra",
Self::Joliet => "Joliet",
Self::Udf => "UDF",
Self::Hfs => "HFS",
Self::HfsPlus => "HFS+",
Self::Efs => "EFS",
Self::Ufs => "UFS",
Self::Ods2 => "ODS-2",
Self::GameCube => "GameCube",
Self::Wii => "Wii",
Self::Cdi => "CD-i",
Self::Opera => "3DO Opera",
Self::Unknown => "Unknown",
}
}
/// Returns true if this filesystem can be browsed by the library.
pub fn is_browsable(self) -> bool {
matches!(
self,
Self::Iso9660
| Self::HighSierra
| Self::Hfs
| Self::HfsPlus
| Self::Efs
| Self::Ufs
| Self::Ods2
| Self::Udf
| Self::GameCube
| Self::Wii
| Self::Cdi
| Self::Opera
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn format_from_extension() {
assert_eq!(DiscFormat::from_path("game.iso"), Some(DiscFormat::Iso));
assert_eq!(DiscFormat::from_path("game.ISO"), Some(DiscFormat::Iso));
assert_eq!(DiscFormat::from_path("game.toast"), Some(DiscFormat::Iso));
assert_eq!(DiscFormat::from_path("game.bin"), Some(DiscFormat::BinCue));
assert_eq!(DiscFormat::from_path("game.cue"), Some(DiscFormat::BinCue));
assert_eq!(DiscFormat::from_path("game.chd"), Some(DiscFormat::Chd));
assert_eq!(DiscFormat::from_path("game.txt"), None);
}
}