diff --git a/Cargo.lock b/Cargo.lock index 4eda5cc..e53a162 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -253,7 +253,7 @@ dependencies = [ [[package]] name = "eu4save" version = "0.8.2" -source = "git+https://github.com/rakaly/eu4save.git#480250eedc8351d0c91c8822dd8756f45e6f3143" +source = "git+https://github.com/rakaly/eu4save.git#d124fa13876777d330fea1a9c5b55a9afcd44c13" dependencies = [ "flate2", "jomini", @@ -370,8 +370,9 @@ dependencies = [ [[package]] name = "imperator-save" version = "0.4.2" -source = "git+https://github.com/rakaly/imperator-save.git#70e66caade56820832e1b27f0d40faaf15926376" +source = "git+https://github.com/rakaly/imperator-save.git#6b9758be506ecef2e90f40f58a967cc2bd81f6ee" dependencies = [ + "flate2", "jomini", "libdeflater", "serde", diff --git a/src/json.rs b/src/json.rs index 4445c2d..0c35028 100644 --- a/src/json.rs +++ b/src/json.rs @@ -9,10 +9,7 @@ use hoi4save::{ file::{Hoi4ParsedFileKind, Hoi4Text}, Hoi4File, }; -use imperator_save::{ - file::{ImperatorParsedFileKind, ImperatorText}, - ImperatorFile, -}; +use imperator_save::{file::ImperatorText, ImperatorFile}; use jomini::{ json::{DuplicateKeyMode, JsonOptions}, TextTape, @@ -124,28 +121,21 @@ impl JsonCommand { } Some(x) if x == "rome" => { let file = ImperatorFile::from_slice(&data)?; - let mut zip_sink = Vec::new(); - let parsed_file = file.parse(&mut zip_sink)?; - match parsed_file.kind() { - ImperatorParsedFileKind::Text(text) => text - .reader() - .json() - .with_options(options) - .to_writer(std::io::stdout()), - ImperatorParsedFileKind::Binary(binary) => { - let melted = binary - .melter() - .verbatim(verbatim) - .on_failed_resolve(strategy) - .melt(&imperator_save::EnvTokens)?; - ImperatorText::from_slice(melted.data()) - .context("unable to parse melted imperator output")? - .reader() - .json() - .with_options(options) - .to_writer(std::io::stdout()) - } - } + let mut out = Cursor::new(Vec::new()); + let text = if !matches!(file.encoding(), imperator_save::Encoding::Text) { + file.melter() + .on_failed_resolve(strategy) + .verbatim(verbatim) + .melt(&mut out, &imperator_save::EnvTokens)?; + ImperatorText::from_slice(out.get_ref().as_slice())? + } else { + ImperatorText::from_slice(&data)? + }; + + text.reader() + .json() + .with_options(options) + .to_writer(std::io::stdout()) } Some(x) if x == "hoi4" => { let file = Hoi4File::from_slice(&data)?; diff --git a/src/melt.rs b/src/melt.rs index 2899c9e..953b115 100644 --- a/src/melt.rs +++ b/src/melt.rs @@ -130,15 +130,11 @@ impl Melter { } MelterKind::Imperator => { let file = imperator_save::ImperatorFile::from_slice(data)?; - let mut zip_sink = Vec::new(); - let parsed_file = file.parse(&mut zip_sink)?; - let binary = parsed_file.as_binary().context("not imperator binary")?; - let out = binary + let out = file .melter() .on_failed_resolve(self.options.resolve) .verbatim(self.options.retain) - .melt(&imperator_save::EnvTokens)?; - writer.write_all(out.data())?; + .melt(writer, &imperator_save::EnvTokens)?; Ok(MeltedDocument::Imperator(out)) } MelterKind::Vic3 => {