PatchSet only serializes patches to the file.

This commit is contained in:
Lyle Mantooth 2022-06-04 14:35:44 -04:00
parent 4cbc70eeca
commit 975d6fd420
Signed by: IslandUsurper
GPG key ID: 6DB52EAE123A5789
2 changed files with 17 additions and 3 deletions

View file

@ -49,8 +49,7 @@ fn main() -> Result<(), anyhow::Error> {
patches.add_patches(rom_patches);
println!("Writing output file {}", output_path);
let out_file = File::create(&output_path)?;
serde_json::to_writer(out_file, &patches)?;
patches.save_to_file(Path::new(&output_path))?;
Ok(())
}

View file

@ -24,7 +24,6 @@ pub struct Patch {
pub patch_data: Vec<u8>,
}
#[derive(Deserialize, Serialize)]
pub struct PatchSet {
filename: PathBuf,
patches: Vec<Patch>,
@ -43,6 +42,22 @@ impl PatchSet {
})
}
pub fn save(&self) -> anyhow::Result<()> {
let file = File::create(&self.filename)?;
let buffer = std::io::BufWriter::new(file);
serde_json::to_writer(buffer, &self.patches)?;
Ok(())
}
pub fn save_to_file(&self, filename: &Path) -> anyhow::Result<()> {
let file = File::create(filename)?;
let buffer = std::io::BufWriter::new(file);
serde_json::to_writer(buffer, &self.patches)?;
Ok(())
}
pub fn add_patch(&mut self, patch: Patch) {
self.patches.push(patch);
}