mirror of
https://github.com/ow-mods/ow-mod-man.git
synced 2025-12-11 20:15:50 +01:00
[CORE/CLI] Add error checking for duplicate mods
This commit is contained in:
parent
8134d5c8e6
commit
689660c83c
@ -163,6 +163,12 @@ pub fn log_mod_validation_errors(local_mod: &UnsafeLocalMod, local_db: &LocalDat
|
||||
ModValidationError::InvalidManifest(why) => {
|
||||
error!("Could not load manifest for {}: {}", name, why);
|
||||
}
|
||||
ModValidationError::DuplicateMod(other_path) => {
|
||||
error!(
|
||||
"Mod at {} was already loaded from {}, this may indicate duplicate mods",
|
||||
name, other_path
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,15 +264,30 @@ impl LocalDatabase {
|
||||
let glob_matches = glob(mods_path.join("*").join("manifest.json").to_str().unwrap())?;
|
||||
for entry in glob_matches {
|
||||
let entry = entry?;
|
||||
let path = entry
|
||||
.parent()
|
||||
.ok_or_else(|| anyhow!("Invalid Manifest!"))?
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let local_mod = Self::read_local_mod(&entry);
|
||||
if let Ok(local_mod) = local_mod {
|
||||
mods.insert(
|
||||
local_mod.manifest.unique_name.to_owned(),
|
||||
UnsafeLocalMod::Valid(local_mod),
|
||||
);
|
||||
} else if let Some(parent) = entry.parent() {
|
||||
if let Some(UnsafeLocalMod::Valid(other)) =
|
||||
mods.get(&local_mod.manifest.unique_name)
|
||||
{
|
||||
let failed_mod = FailedMod {
|
||||
mod_path: path.to_string(),
|
||||
error: ModValidationError::DuplicateMod(other.mod_path.to_string()),
|
||||
};
|
||||
mods.insert(path.to_string(), UnsafeLocalMod::Invalid(failed_mod));
|
||||
} else {
|
||||
mods.insert(
|
||||
local_mod.manifest.unique_name.to_owned(),
|
||||
UnsafeLocalMod::Valid(local_mod),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
let err = format!("{:?}", local_mod.err().unwrap());
|
||||
let path = parent.to_str().unwrap().to_string();
|
||||
warn!("Failed to load mod at {}: {:?}", path, err);
|
||||
let failed_mod = FailedMod {
|
||||
mod_path: path.to_string(),
|
||||
@ -290,6 +305,8 @@ impl LocalDatabase {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// TODO: Tests for invalid/duplicate mods
|
||||
|
||||
use crate::constants::DEFAULT_DB_URL;
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -28,6 +28,8 @@ pub enum ModValidationError {
|
||||
ConflictingMod(String),
|
||||
/// The DLL the mod specifies in its `manifest.json` doesn't exist, contains the path (if even present) to the DLL specified by the mod
|
||||
MissingDLL(Option<String>),
|
||||
/// There's another mod already in the DB with this mod's unique name, contains the path of the other mod that has the same unique name
|
||||
DuplicateMod(String),
|
||||
}
|
||||
|
||||
fn check_mod_dll(local_mod: &LocalMod) -> Option<ModValidationError> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user