improved unpack unterface & removed unpack command

This commit is contained in:
2026-03-20 13:14:22 +01:00
parent ddf76602be
commit bdd5d849eb
4 changed files with 10 additions and 39 deletions

View File

@@ -32,7 +32,8 @@ pub fn handle_nxm(root_config: &mut RootConfig, raw_url: &str) -> anyhow::Result
return Err(anyhow!("Mod with generated id already exists"));
}
unpack(root_config, &mod_id, dl_file)?;
let extract_to = root_config.mod_location().join(&mod_id);
unpack(dl_file, extract_to)?;
let file_id: u64 = nxm_url.file.parse()?;
let new_mod = ModConfig::from_mod_info(&mod_id, &mod_id, &mod_info, file_id);

View File

@@ -19,5 +19,4 @@ pub enum Commands {
LoadOrder { instance: String },
ApiCheck,
Download { url: String },
Unpack { id: String, path: String },
}

View File

@@ -10,8 +10,7 @@ use fomod_manager::{
},
cli::{self, Args},
nexus::NexusAPI,
types::{ModConfig, RootConfig},
unpacker::unpack,
types::RootConfig,
};
fn command_activate(
@@ -70,27 +69,6 @@ fn command_download(root_config: &mut RootConfig, raw_url: &str) -> anyhow::Resu
Ok(())
}
fn command_unpack(
root_config: &mut RootConfig,
id: &str,
file: impl AsRef<Path>,
) -> anyhow::Result<()> {
if root_config.game_by_id(id).is_some() {
error!("Mod already present");
return Err(anyhow!("Mod already exists"));
}
unpack(root_config, id, file)?;
let new_mod = ModConfig::new(id, id);
root_config.add_mod(&new_mod);
root_config.save_to_file()?;
Ok(())
}
fn setup_logger() {
env_logger::builder()
.filter_level(log::LevelFilter::max())
@@ -124,9 +102,6 @@ fn main() -> Result<(), Box<dyn Error>> {
cli::Commands::Download { url } => {
command_download(&mut root_config, &url)?;
}
cli::Commands::Unpack { id, path } => {
command_unpack(&mut root_config, &id, path)?;
}
}
Ok(())

View File

@@ -4,22 +4,18 @@ use anyhow::anyhow;
use log::error;
use zip::ZipArchive;
use crate::types::RootConfig;
pub fn unpack(root_config: &RootConfig, id: &str, path: impl AsRef<Path>) -> anyhow::Result<()> {
let extract_to = root_config.mod_location().join(id);
pub fn unpack(archive_path: impl AsRef<Path>, extract_to: impl AsRef<Path>) -> anyhow::Result<()> {
if fs::exists(&extract_to)? {
return Err(anyhow!(
"File already exists: {}",
extract_to.to_string_lossy()
extract_to.as_ref().to_string_lossy()
));
}
match path.as_ref().extension().and_then(|e| e.to_str()) {
Some("7z") => unpack_7z_file(path, &extract_to),
Some("zip") => unpack_zip_file(path, &extract_to),
Some("rar") => unpack_rar(path, &extract_to),
match archive_path.as_ref().extension().and_then(|e| e.to_str()) {
Some("7z") => unpack_7z_file(archive_path, &extract_to),
Some("zip") => unpack_zip_file(archive_path, &extract_to),
Some("rar") => unpack_rar(archive_path, &extract_to),
Some(ext) => {
error!("Unsupported archive format: {}", ext);
Err(anyhow!("Unsupported archive format: {}", ext))
@@ -27,7 +23,7 @@ pub fn unpack(root_config: &RootConfig, id: &str, path: impl AsRef<Path>) -> any
None => {
error!(
"Failed to determine the file extension for {}",
&path.as_ref().to_string_lossy()
&archive_path.as_ref().to_string_lossy()
);
Err(anyhow!("Failed to determine file extension"))
}