1use hadris_iso::boot::options::BootOptions;
4use hadris_iso::joliet::JolietLevel;
5use hadris_iso::rrip::RripOptions;
6use hadris_iso::write::options::{BaseIsoLevel, HybridBootOptions};
7use hadris_udf::UdfRevision;
8
9#[derive(Debug, Clone)]
11pub struct CdOptions {
12 pub volume_id: String,
14 pub sector_size: usize,
16 pub iso: IsoOptions,
18 pub udf: UdfOptions,
20 pub boot: Option<BootOptions>,
22 pub hybrid_boot: Option<HybridBootOptions>,
24}
25
26impl Default for CdOptions {
27 fn default() -> Self {
28 Self {
29 volume_id: String::from("CDROM"),
30 sector_size: 2048,
31 iso: IsoOptions::default(),
32 udf: UdfOptions::default(),
33 boot: None,
34 hybrid_boot: None,
35 }
36 }
37}
38
39impl CdOptions {
40 pub fn with_volume_id(volume_id: impl Into<String>) -> Self {
42 Self {
43 volume_id: volume_id.into(),
44 ..Default::default()
45 }
46 }
47
48 pub fn volume_id(mut self, id: impl Into<String>) -> Self {
50 self.volume_id = id.into();
51 self
52 }
53
54 pub fn with_joliet(mut self) -> Self {
56 self.iso.joliet = Some(JolietLevel::Level3);
57 self
58 }
59
60 pub fn with_rock_ridge(mut self) -> Self {
62 self.iso.rock_ridge = Some(RripOptions::default());
63 self
64 }
65
66 pub fn with_boot(mut self, boot: BootOptions) -> Self {
68 self.boot = Some(boot);
69 self
70 }
71
72 pub fn with_hybrid_boot(mut self, hybrid: HybridBootOptions) -> Self {
74 self.hybrid_boot = Some(hybrid);
75 self
76 }
77
78 pub fn iso_only(mut self) -> Self {
80 self.udf.enabled = false;
81 self
82 }
83
84 pub fn udf_only(mut self) -> Self {
86 self.iso.enabled = false;
87 self
88 }
89}
90
91#[derive(Debug, Clone)]
93pub struct IsoOptions {
94 pub enabled: bool,
96 pub level: BaseIsoLevel,
98 pub long_filenames: bool,
100 pub joliet: Option<JolietLevel>,
102 pub rock_ridge: Option<RripOptions>,
104}
105
106impl Default for IsoOptions {
107 fn default() -> Self {
108 Self {
109 enabled: true,
110 level: BaseIsoLevel::Level2 {
111 supports_lowercase: false,
112 supports_rrip: false,
113 },
114 long_filenames: true,
115 joliet: Some(JolietLevel::Level3),
116 rock_ridge: None,
117 }
118 }
119}
120
121#[derive(Debug, Clone)]
123pub struct UdfOptions {
124 pub enabled: bool,
126 pub revision: UdfRevision,
128}
129
130impl Default for UdfOptions {
131 fn default() -> Self {
132 Self {
133 enabled: true,
134 revision: UdfRevision::V1_02,
135 }
136 }
137}
138
139#[cfg(test)]
140mod tests {
141 use super::*;
142
143 #[test]
144 fn test_default_options() {
145 let opts = CdOptions::default();
146 assert_eq!(opts.volume_id, "CDROM");
147 assert_eq!(opts.sector_size, 2048);
148 assert!(opts.iso.enabled);
149 assert!(opts.udf.enabled);
150 }
151
152 #[test]
153 fn test_builder_pattern() {
154 let opts = CdOptions::with_volume_id("MY_DISC")
155 .with_joliet()
156 .with_rock_ridge();
157
158 assert_eq!(opts.volume_id, "MY_DISC");
159 assert!(opts.iso.joliet.is_some());
160 assert!(opts.iso.rock_ridge.is_some());
161 }
162}