add name and nexusid to mod

This commit is contained in:
2026-03-18 21:11:36 +01:00
parent 281327d69c
commit 3949723303
5 changed files with 26 additions and 16 deletions

View File

@@ -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(())
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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<String>,
name: Option<String>,
nexus_id: Option<String>,
}
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<Path>, 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

View File

@@ -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<Path>,
) -> anyhow::Result<ModConfig> {
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)? {
@@ -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<Path>, to: impl AsRef<Path>) -> anyhow::Result<()> {