added basic unpacker

This commit is contained in:
2026-03-11 23:50:00 +01:00
parent 1199d40b31
commit 1eb9341d93
5 changed files with 317 additions and 3 deletions

28
src/unpacker.rs Normal file
View 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(())
}