repak/examples/subcommands/unpack.rs

18 lines
628 B
Rust
Raw Normal View History

2023-01-17 05:27:36 +00:00
pub fn unpack(path: String, key: Option<String>) -> Result<(), unpak::Error> {
2023-01-14 18:32:06 +00:00
let folder = std::path::Path::new(
std::path::Path::new(&path)
.file_stem()
.and_then(|name| name.to_str())
.unwrap_or_default(),
);
let mut pak = super::load_pak(path.clone(), key)?;
2023-01-15 16:26:23 +00:00
for file in pak.files() {
std::fs::create_dir_all(folder.join(&file).parent().expect("will be a file"))?;
match pak.read(&file, &mut std::fs::File::create(folder.join(&file))?) {
Ok(_) => println!("{file}"),
Err(e) => eprintln!("{e}"),
2023-01-14 18:32:06 +00:00
}
2023-01-15 16:26:23 +00:00
}
Ok(())
2023-01-14 18:32:06 +00:00
}