diff --git a/src/actions/download.rs b/src/actions/download.rs index 3ab2939..4c99dcb 100644 --- a/src/actions/download.rs +++ b/src/actions/download.rs @@ -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); diff --git a/src/cli.rs b/src/cli.rs index 3bb85e5..2b13fee 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -19,5 +19,4 @@ pub enum Commands { LoadOrder { instance: String }, ApiCheck, Download { url: String }, - Unpack { id: String, path: String }, } diff --git a/src/main.rs b/src/main.rs index ffb4c0c..99402cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, -) -> 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> { cli::Commands::Download { url } => { command_download(&mut root_config, &url)?; } - cli::Commands::Unpack { id, path } => { - command_unpack(&mut root_config, &id, path)?; - } } Ok(()) diff --git a/src/unpacker.rs b/src/unpacker.rs index f7d3cf9..55349c9 100644 --- a/src/unpacker.rs +++ b/src/unpacker.rs @@ -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) -> anyhow::Result<()> { - let extract_to = root_config.mod_location().join(id); - +pub fn unpack(archive_path: impl AsRef, extract_to: impl AsRef) -> 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) -> 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")) }