diff --git a/src/args.rs b/src/args.rs index b5c0b49..30994ea 100644 --- a/src/args.rs +++ b/src/args.rs @@ -635,6 +635,10 @@ pub struct Arg { #[arg(long, global = true, action = ArgAction::SetTrue)] /// Disable part labels in Entis GLS csx script when exporting. pub entis_gls_csx_no_part_label: bool, + #[cfg(feature = "qlie-img")] + #[arg(long, global = true, action = ArgAction::SetTrue)] + /// Disable process ABMP10 images in ABMP10 images. + pub qlie_abmp10_no_process_abmp10: bool, #[command(subcommand)] /// Command pub command: Command, diff --git a/src/main.rs b/src/main.rs index 16af5a8..4cb8654 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3321,6 +3321,8 @@ fn main() { entis_gls_csx_v2_ver: arg.entis_gls_csx_v2_ver, #[cfg(feature = "entis-gls")] entis_gls_csx_no_part_label: arg.entis_gls_csx_no_part_label, + #[cfg(feature = "qlie-img")] + qlie_abmp10_process_abmp10: !arg.qlie_abmp10_no_process_abmp10, }); match &arg.command { args::Command::Export { input, output } => { diff --git a/src/scripts/qlie/image/abmp10.rs b/src/scripts/qlie/image/abmp10.rs index f763c9e..c14c08b 100644 --- a/src/scripts/qlie/image/abmp10.rs +++ b/src/scripts/qlie/image/abmp10.rs @@ -512,9 +512,15 @@ struct AbmpImage { resource_filenames: Vec, } +fn is_false(b: &bool) -> bool { + !*b +} + #[derive(Clone, Debug, Serialize, Deserialize)] struct Resource { path: String, + #[serde(skip_serializing_if = "is_false", default)] + ambp10: bool, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -566,7 +572,8 @@ impl AbmpImage { #[derive(Debug)] pub struct Abmp10Image { img: AbmpImage, - custom_yaml: bool, + encoding: Encoding, + config: ExtraConfig, } impl Abmp10Image { @@ -578,7 +585,8 @@ impl Abmp10Image { let img = AbmpImage::new_from(&mut data, encoding)?; Ok(Abmp10Image { img, - custom_yaml: config.custom_yaml, + encoding, + config: config.clone(), }) } @@ -587,11 +595,31 @@ impl Abmp10Image { folder_path: &std::path::PathBuf, path: String, data: &[u8], + encoding: Encoding, ) -> Result { - let res = Resource { path }; - let path = folder_path.join(&res.path); - make_sure_dir_exists(&path)?; - std::fs::write(&path, data)?; + let mut res = Resource { + path, + ambp10: false, + }; + if self.config.qlie_abmp10_process_abmp10 + && data.len() > 6 + && data.starts_with(b"abmp1") + && data[5] >= b'0' + && data[5] <= b'2' + { + res.ambp10 = true; + let another = Abmp10Image::new(MemReaderRef::new(data), self.encoding, &self.config)?; + let mut np = std::path::PathBuf::from(&res.path); + np.set_extension(another.custom_output_extension()); + res.path = np.to_string_lossy().to_string(); + let path = folder_path.join(&res.path); + make_sure_dir_exists(&path)?; + another.custom_export(&path, encoding)?; + } else { + let path = folder_path.join(&res.path); + make_sure_dir_exists(&path)?; + std::fs::write(&path, data)?; + } Ok(res) } } @@ -610,7 +638,11 @@ impl Script for Abmp10Image { } fn custom_output_extension<'a>(&'a self) -> &'a str { - if self.custom_yaml { "yaml" } else { "json" } + if self.config.custom_yaml { + "yaml" + } else { + "json" + } } fn custom_export(&self, filename: &std::path::Path, encoding: Encoding) -> Result<()> { @@ -626,10 +658,10 @@ impl Script for Abmp10Image { .zip(self.img.resource_filenames.iter()) { let res_name = sanitize_path(res_name); - let res = self.output_resource(&base_path, res_name, res)?; + let res = self.output_resource(&base_path, res_name, res, encoding)?; img.resources.push(res); } - let s = if self.custom_yaml { + let s = if self.config.custom_yaml { serde_yaml_ng::to_string(&img)? } else { serde_json::to_string_pretty(&img)? diff --git a/src/types.rs b/src/types.rs index 87db9d6..ed58f8a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -592,6 +592,10 @@ pub struct ExtraConfig { #[cfg(feature = "entis-gls")] /// Disable part labels in Entis GLS csx script when exporting. pub entis_gls_csx_no_part_label: bool, + #[cfg(feature = "qlie-img")] + #[default(true)] + /// Whether to process ABMP10 images in ABMP10 images. + pub qlie_abmp10_process_abmp10: bool, } #[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]