diff --git a/README.md b/README.md index 6811ae7..00df9e7 100644 --- a/README.md +++ b/README.md @@ -267,5 +267,5 @@ msg-tool create -t | Script Type | Feature Name | Name | Export | Import | Export Multiple | Import Multiple | Custom Export | Custom Import | Create | Remarks | |---|---|---|---|---|---|---|---|---|---|---| | `yuris-yscm` | `yuris` | Yu-Ris YSCM(opcodes metadata) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | | -| `yuris-yser` | `yuris` | Yu-Ris YSER(error message) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | | -| `yuris-yscfg` | `yuris` | Yu-Ris YSCFG(config) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | | +| `yuris-yser` | `yuris` | Yu-Ris YSER(error message) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | ✔️ | | +| `yuris-yscfg` | `yuris` | Yu-Ris YSCFG(config) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | ✔️ | | diff --git a/src/scripts/yuris/yscfg.rs b/src/scripts/yuris/yscfg.rs index ecb3eda..ab55811 100644 --- a/src/scripts/yuris/yscfg.rs +++ b/src/scripts/yuris/yscfg.rs @@ -50,6 +50,27 @@ impl ScriptBuilder for YSCFGBuilder { fn script_type(&self) -> &'static ScriptType { &ScriptType::YurisYSCFG } + + fn can_create_file(&self) -> bool { + true + } + + fn create_file<'a>( + &'a self, + filename: &'a str, + writer: Box, + encoding: Encoding, + file_encoding: Encoding, + config: &ExtraConfig, + ) -> Result<()> { + create_file( + filename, + writer, + encoding, + file_encoding, + config.custom_yaml, + ) + } } #[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)] @@ -141,4 +162,39 @@ impl Script for YSCFG { writer.flush()?; Ok(()) } + + fn custom_import<'a>( + &'a self, + custom_filename: &'a str, + file: Box, + encoding: Encoding, + output_encoding: Encoding, + ) -> Result<()> { + create_file( + custom_filename, + file, + encoding, + output_encoding, + self.custom_yaml, + ) + } +} + +fn create_file<'a>( + custom_filename: &'a str, + mut writer: Box, + encoding: Encoding, + output_encoding: Encoding, + yaml: bool, +) -> Result<()> { + let input = crate::utils::files::read_file(custom_filename)?; + let s = decode_to_string(output_encoding, &input, true)?; + let data: YSCFGData = if yaml { + serde_yaml_ng::from_str(&s).map_err(|e| anyhow::anyhow!("Failed to parse YAML: {}", e))? + } else { + serde_json::from_str(&s).map_err(|e| anyhow::anyhow!("Failed to parse JSON: {}", e))? + }; + writer.write_all(b"YSCF")?; + data.pack(&mut writer, false, encoding, &None)?; + Ok(()) } diff --git a/src/scripts/yuris/yser.rs b/src/scripts/yuris/yser.rs index a0487f0..4b92d35 100644 --- a/src/scripts/yuris/yser.rs +++ b/src/scripts/yuris/yser.rs @@ -50,6 +50,27 @@ impl ScriptBuilder for YSERBuilder { fn script_type(&self) -> &'static ScriptType { &ScriptType::YurisYSER } + + fn can_create_file(&self) -> bool { + true + } + + fn create_file<'a>( + &'a self, + filename: &'a str, + writer: Box, + encoding: Encoding, + file_encoding: Encoding, + config: &ExtraConfig, + ) -> Result<()> { + create_file( + filename, + writer, + encoding, + file_encoding, + config.custom_yaml, + ) + } } #[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)] @@ -122,4 +143,39 @@ impl Script for YSER { writer.flush()?; Ok(()) } + + fn custom_import<'a>( + &'a self, + custom_filename: &'a str, + file: Box, + encoding: Encoding, + output_encoding: Encoding, + ) -> Result<()> { + create_file( + custom_filename, + file, + encoding, + output_encoding, + self.custom_yaml, + ) + } +} + +fn create_file<'a>( + custom_filename: &'a str, + mut writer: Box, + encoding: Encoding, + output_encoding: Encoding, + yaml: bool, +) -> Result<()> { + let input = crate::utils::files::read_file(custom_filename)?; + let s = decode_to_string(output_encoding, &input, true)?; + let data: YSERData = if yaml { + serde_yaml_ng::from_str(&s).map_err(|e| anyhow::anyhow!("Failed to parse YAML: {}", e))? + } else { + serde_json::from_str(&s).map_err(|e| anyhow::anyhow!("Failed to parse JSON: {}", e))? + }; + writer.write_all(b"YSER")?; + data.pack(&mut writer, false, encoding, &None)?; + Ok(()) }