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")); 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 file_id: u64 = nxm_url.file.parse()?;
let new_mod = ModConfig::from_mod_info(&mod_id, &mod_id, &mod_info, file_id); 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 }, LoadOrder { instance: String },
ApiCheck, ApiCheck,
Download { url: String }, Download { url: String },
Unpack { id: String, path: String },
} }

View File

@@ -10,8 +10,7 @@ use fomod_manager::{
}, },
cli::{self, Args}, cli::{self, Args},
nexus::NexusAPI, nexus::NexusAPI,
types::{ModConfig, RootConfig}, types::RootConfig,
unpacker::unpack,
}; };
fn command_activate( fn command_activate(
@@ -70,27 +69,6 @@ fn command_download(root_config: &mut RootConfig, raw_url: &str) -> anyhow::Resu
Ok(()) 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() { fn setup_logger() {
env_logger::builder() env_logger::builder()
.filter_level(log::LevelFilter::max()) .filter_level(log::LevelFilter::max())
@@ -124,9 +102,6 @@ fn main() -> Result<(), Box<dyn Error>> {
cli::Commands::Download { url } => { cli::Commands::Download { url } => {
command_download(&mut root_config, &url)?; command_download(&mut root_config, &url)?;
} }
cli::Commands::Unpack { id, path } => {
command_unpack(&mut root_config, &id, path)?;
}
} }
Ok(()) Ok(())

View File

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