mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-07-08 01:31:53 +08:00
Allow to create yscfg/yser file
This commit is contained in:
@@ -267,5 +267,5 @@ msg-tool create -t <script-type> <input> <output>
|
|||||||
| Script Type | Feature Name | Name | Export | Import | Export Multiple | Import Multiple | Custom Export | Custom Import | Create | Remarks |
|
| 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-yscm` | `yuris` | Yu-Ris YSCM(opcodes metadata) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | |
|
||||||
| `yuris-yser` | `yuris` | Yu-Ris YSER(error message) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | |
|
| `yuris-yser` | `yuris` | Yu-Ris YSER(error message) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | ✔️ | |
|
||||||
| `yuris-yscfg` | `yuris` | Yu-Ris YSCFG(config) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | |
|
| `yuris-yscfg` | `yuris` | Yu-Ris YSCFG(config) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | ✔️ | |
|
||||||
|
|||||||
@@ -50,6 +50,27 @@ impl ScriptBuilder for YSCFGBuilder {
|
|||||||
fn script_type(&self) -> &'static ScriptType {
|
fn script_type(&self) -> &'static ScriptType {
|
||||||
&ScriptType::YurisYSCFG
|
&ScriptType::YurisYSCFG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn can_create_file(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_file<'a>(
|
||||||
|
&'a self,
|
||||||
|
filename: &'a str,
|
||||||
|
writer: Box<dyn WriteSeek + 'a>,
|
||||||
|
encoding: Encoding,
|
||||||
|
file_encoding: Encoding,
|
||||||
|
config: &ExtraConfig,
|
||||||
|
) -> Result<()> {
|
||||||
|
create_file(
|
||||||
|
filename,
|
||||||
|
writer,
|
||||||
|
encoding,
|
||||||
|
file_encoding,
|
||||||
|
config.custom_yaml,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)]
|
#[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)]
|
||||||
@@ -141,4 +162,39 @@ impl Script for YSCFG {
|
|||||||
writer.flush()?;
|
writer.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn custom_import<'a>(
|
||||||
|
&'a self,
|
||||||
|
custom_filename: &'a str,
|
||||||
|
file: Box<dyn WriteSeek + 'a>,
|
||||||
|
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<dyn WriteSeek + 'a>,
|
||||||
|
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(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,27 @@ impl ScriptBuilder for YSERBuilder {
|
|||||||
fn script_type(&self) -> &'static ScriptType {
|
fn script_type(&self) -> &'static ScriptType {
|
||||||
&ScriptType::YurisYSER
|
&ScriptType::YurisYSER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn can_create_file(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_file<'a>(
|
||||||
|
&'a self,
|
||||||
|
filename: &'a str,
|
||||||
|
writer: Box<dyn WriteSeek + 'a>,
|
||||||
|
encoding: Encoding,
|
||||||
|
file_encoding: Encoding,
|
||||||
|
config: &ExtraConfig,
|
||||||
|
) -> Result<()> {
|
||||||
|
create_file(
|
||||||
|
filename,
|
||||||
|
writer,
|
||||||
|
encoding,
|
||||||
|
file_encoding,
|
||||||
|
config.custom_yaml,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)]
|
#[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)]
|
||||||
@@ -122,4 +143,39 @@ impl Script for YSER {
|
|||||||
writer.flush()?;
|
writer.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn custom_import<'a>(
|
||||||
|
&'a self,
|
||||||
|
custom_filename: &'a str,
|
||||||
|
file: Box<dyn WriteSeek + 'a>,
|
||||||
|
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<dyn WriteSeek + 'a>,
|
||||||
|
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(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user