one-rust/one-rust/examples/onear.rs

28 lines
778 B
Rust

extern crate one_rust;
extern crate binread;
use std::env;
use std::fs::File;
use std::io::prelude::*;
use binread::prelude::*;
use one_rust::JodOne;
use std::path::PathBuf;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().collect();
for arg in &args[1..] {
let mut infile = File::open(arg)?;
let archive: JodOne = infile.read_le()?;
let entries = archive.unpack();
let dir = PathBuf::from(format!("{}.d", arg));
for (name, data) in entries {
let full_path = dir.join(name);
if let Some(path) = full_path.parent() {
std::fs::create_dir_all(path)?;
}
File::create(full_path)?.write_all(&data)?;
}
}
Ok(())
}