# HG changeset patch # User Emmanuel Gil Peyrot # Date 1609817310 -3600 # Node ID abcb586566e6e8005adf4c2953be5254ebc2f428 # Parent daa23a4ff24d93b259a93cb452f14f870567f8aa formats: Add a dump_dat binary. diff --git a/formats/src/bin/dump_dat.rs b/formats/src/bin/dump_dat.rs new file mode 100644 --- /dev/null +++ b/formats/src/bin/dump_dat.rs @@ -0,0 +1,31 @@ +use touhou_formats::th06::pbg3::PBG3; +use std::env; +use std::path::Path; +use std::fs::{File, create_dir_all}; +use std::io::{self, BufReader, Write}; + +fn main() -> io::Result<()> { + // Parse arguments. + let args: Vec<_> = env::args().collect(); + if args.len() != 3 { + eprintln!("Usage: {} ", args[0]); + std::process::exit(1); + } + + let filename = Path::new(&args[1]); + let output_filename = Path::new(&args[2]); + + let file = File::open(filename)?; + let file = BufReader::new(file); + let mut pbg3 = PBG3::from_file(file)?; + let list = pbg3.list_files().cloned().collect::>(); + + create_dir_all(output_filename)?; + for filename in list { + let data = pbg3.get_file(&filename, true)?; + let mut output = File::create(output_filename.join(filename))?; + output.write(&data)?; + } + + Ok(()) +}