added basic unpacker
This commit is contained in:
28
src/unpacker.rs
Normal file
28
src/unpacker.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use anyhow::anyhow;
|
||||
|
||||
use crate::types::{ModConfig, RootConfig};
|
||||
|
||||
pub fn unpack(
|
||||
root_config: &RootConfig,
|
||||
id: &str,
|
||||
path: impl AsRef<Path>,
|
||||
) -> anyhow::Result<ModConfig> {
|
||||
let extract_to = root_config.mod_location().join(id);
|
||||
|
||||
if fs::exists(&extract_to)? {
|
||||
return Err(anyhow!("File already exists"));
|
||||
}
|
||||
|
||||
unpack_7z_file(path, &extract_to)?;
|
||||
|
||||
let new_mod = ModConfig::new(id, id);
|
||||
|
||||
Ok(new_mod)
|
||||
}
|
||||
|
||||
fn unpack_7z_file(path: impl AsRef<Path>, to: impl AsRef<Path>) -> anyhow::Result<()> {
|
||||
sevenz_rust::decompress_file(path, to)?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user