comparison formats/src/bin/dump_dat.rs @ 759:abcb586566e6

formats: Add a dump_dat binary.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 05 Jan 2021 04:28:30 +0100
parents
children ccb04468c5fa
comparison
equal deleted inserted replaced
758:daa23a4ff24d 759:abcb586566e6
1 use touhou_formats::th06::pbg3::PBG3;
2 use std::env;
3 use std::path::Path;
4 use std::fs::{File, create_dir_all};
5 use std::io::{self, BufReader, Write};
6
7 fn main() -> io::Result<()> {
8 // Parse arguments.
9 let args: Vec<_> = env::args().collect();
10 if args.len() != 3 {
11 eprintln!("Usage: {} <DAT file> <output dir>", args[0]);
12 std::process::exit(1);
13 }
14
15 let filename = Path::new(&args[1]);
16 let output_filename = Path::new(&args[2]);
17
18 let file = File::open(filename)?;
19 let file = BufReader::new(file);
20 let mut pbg3 = PBG3::from_file(file)?;
21 let list = pbg3.list_files().cloned().collect::<Vec<_>>();
22
23 create_dir_all(output_filename)?;
24 for filename in list {
25 let data = pbg3.get_file(&filename, true)?;
26 let mut output = File::create(output_filename.join(filename))?;
27 output.write(&data)?;
28 }
29
30 Ok(())
31 }