diff --git a/src/actions/download.rs b/src/actions/download.rs index a3449c0..27266a7 100644 --- a/src/actions/download.rs +++ b/src/actions/download.rs @@ -3,7 +3,7 @@ use log::error; use crate::{ nexus::{NXMUrl, download_nxm}, - types::RootConfig, + types::{ModConfig, RootConfig}, unpacker::unpack, }; @@ -32,11 +32,11 @@ pub fn handle_nxm(root_config: &mut RootConfig, raw_url: &str) -> anyhow::Result return Err(anyhow!("Mod with generated id already exists")); } - let new_mod = unpack(root_config, &mod_id, dl_file)?; + unpack(root_config, &mod_id, dl_file)?; + + let new_mod = ModConfig::from_mod_info(&mod_id, &mod_id, &mod_info); root_config.add_mod(&new_mod); - root_config.save_to_file()?; - Ok(()) } diff --git a/src/main.rs b/src/main.rs index 7e222e7..5a81478 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use fomod_manager::{ }, cli::{self, Args}, nexus::NexusAPI, - types::RootConfig, + types::{ModConfig, RootConfig}, unpacker::unpack, }; @@ -76,7 +76,9 @@ fn command_unpack( return Err(anyhow!("Mod already exists")); } - let new_mod = unpack(root_config, id, file)?; + unpack(root_config, id, file)?; + + let new_mod = ModConfig::new(id, id); root_config.add_mod(&new_mod); diff --git a/src/nexus.rs b/src/nexus.rs index 575e835..abc72af 100644 --- a/src/nexus.rs +++ b/src/nexus.rs @@ -2,6 +2,6 @@ mod api; mod downloader; mod url; -pub use api::NexusAPI; +pub use api::{ModInfo, NexusAPI}; pub use downloader::download_nxm; pub use url::NXMUrl; diff --git a/src/types/mod_config.rs b/src/types/mod_config.rs index 32cb73f..056b164 100644 --- a/src/types/mod_config.rs +++ b/src/types/mod_config.rs @@ -2,6 +2,8 @@ use std::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; +use crate::nexus::ModInfo; + /// Config for an available mod #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(deny_unknown_fields)] @@ -22,6 +24,9 @@ pub struct ModConfig { #[serde(default)] #[serde(skip_serializing_if = "Vec::is_empty")] ignore: Vec, + + name: Option, + nexus_id: Option, } impl ModConfig { @@ -31,9 +36,18 @@ impl ModConfig { path: source.as_ref().to_owned(), root_mod: false, ignore: Vec::new(), + name: None, + nexus_id: None, } } + pub fn from_mod_info(id: &str, source: impl AsRef, mod_info: &ModInfo) -> Self { + let mut normal = Self::new(id, source); + normal.name = Some(mod_info.name.clone()); + + normal + } + pub fn add_id(mut self, id: &str) -> Self { self.id = id.to_owned(); self diff --git a/src/unpacker.rs b/src/unpacker.rs index c3f79aa..f7d3cf9 100644 --- a/src/unpacker.rs +++ b/src/unpacker.rs @@ -4,13 +4,9 @@ use anyhow::anyhow; use log::error; use zip::ZipArchive; -use crate::types::{ModConfig, RootConfig}; +use crate::types::RootConfig; -pub fn unpack( - root_config: &RootConfig, - id: &str, - path: impl AsRef, -) -> anyhow::Result { +pub fn unpack(root_config: &RootConfig, id: &str, path: impl AsRef) -> anyhow::Result<()> { let extract_to = root_config.mod_location().join(id); if fs::exists(&extract_to)? { @@ -37,9 +33,7 @@ pub fn unpack( } }?; - let new_mod = ModConfig::new(id, id); - - Ok(new_mod) + Ok(()) } fn unpack_7z_file(path: impl AsRef, to: impl AsRef) -> anyhow::Result<()> {