Compare commits
4 Commits
74df0d1cc1
...
eae0207b0f
| Author | SHA1 | Date | |
|---|---|---|---|
|
eae0207b0f
|
|||
|
52e48be57f
|
|||
|
defc4a5721
|
|||
|
55f9e3f6d6
|
@@ -1,4 +1,4 @@
|
|||||||
use std::ffi::OsStr;
|
use std::{collections::HashSet, ffi::OsStr};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ use crate::{
|
|||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
pub struct InstalledMod {
|
pub struct InstalledMod {
|
||||||
id: String,
|
id: String,
|
||||||
files: Vec<Link>,
|
files: HashSet<Link>,
|
||||||
priority: isize,
|
priority: isize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,13 +18,13 @@ impl InstalledMod {
|
|||||||
pub fn new(root_mod_id: &str, priority: isize) -> Self {
|
pub fn new(root_mod_id: &str, priority: isize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: root_mod_id.to_owned(),
|
id: root_mod_id.to_owned(),
|
||||||
files: Vec::new(),
|
files: HashSet::new(),
|
||||||
priority,
|
priority,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_file(&mut self, file: &ModFile) {
|
pub fn add_file(&mut self, file: &ModFile) {
|
||||||
self.files.push(Link::from_mod_file(file));
|
self.files.insert(Link::from_mod_file(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the id of the mod
|
/// Get the id of the mod
|
||||||
@@ -38,7 +38,7 @@ impl InstalledMod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The selected files
|
/// The selected files
|
||||||
pub fn files(&self) -> &[Link] {
|
pub fn files(&self) -> &HashSet<Link> {
|
||||||
&self.files
|
&self.files
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use crate::types::mod_file::ModFile;
|
use crate::types::mod_file::ModFile;
|
||||||
|
|
||||||
/// A link between a file from a mod and a destination in a ModdedInstance
|
/// A link between a file from a mod and a destination in a ModdedInstance
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
|
||||||
#[serde(from = "(PathBuf, PathBuf)", into = "(PathBuf,PathBuf)")]
|
#[serde(from = "(PathBuf, PathBuf)", into = "(PathBuf,PathBuf)")]
|
||||||
pub struct Link {
|
pub struct Link {
|
||||||
src: PathBuf,
|
src: PathBuf,
|
||||||
|
|||||||
45
tests/add_mod_test.rs
Normal file
45
tests/add_mod_test.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
use std::{collections::HashSet, error::Error, path::PathBuf};
|
||||||
|
|
||||||
|
use fomod_manager::{
|
||||||
|
instance::{files_to_install_mod, insert_mod_to_instance},
|
||||||
|
types::{Link, RootConfig},
|
||||||
|
};
|
||||||
|
|
||||||
|
fn get_parent() -> PathBuf {
|
||||||
|
PathBuf::from(file!()).parent().unwrap().to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_root() -> RootConfig {
|
||||||
|
RootConfig::load_from_file(get_parent().join("data/root_config_complex.toml")).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_simple_mod() -> Result<(), Box<dyn Error>> {
|
||||||
|
let root_config = load_root();
|
||||||
|
let mut instance = root_config.load_instance_by_id("instance_minimal")?;
|
||||||
|
let mod_to_install = root_config.mod_by_id("add_test_1").expect("Mod not found");
|
||||||
|
let files_to_add = files_to_install_mod(&root_config, &instance, &mod_to_install)?;
|
||||||
|
|
||||||
|
insert_mod_to_instance(&mut instance, &mod_to_install, &files_to_add, 0)?;
|
||||||
|
|
||||||
|
let installed_mods = instance.mods();
|
||||||
|
|
||||||
|
assert_eq!(installed_mods.len(), 1);
|
||||||
|
|
||||||
|
let the_mod = installed_mods.first().expect("Asserted before");
|
||||||
|
|
||||||
|
assert_eq!(the_mod.mod_id(), "add_test_1");
|
||||||
|
assert_eq!(the_mod.priority(), 0);
|
||||||
|
|
||||||
|
let expected_files: HashSet<_> = [Link::new("plugin.esp", "Data/plugin.esp")]
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
*the_mod.files(),
|
||||||
|
expected_files,
|
||||||
|
"Installed files missmatch"
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
1
tests/data/games/sse/Data/Skyrim.esm
Normal file
1
tests/data/games/sse/Data/Skyrim.esm
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Skyrim.esm
|
||||||
1
tests/data/games/sse/Data/Update.esm
Normal file
1
tests/data/games/sse/Data/Update.esm
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Update.esm
|
||||||
1
tests/data/games/sse/SkyrimSE.exe
Normal file
1
tests/data/games/sse/SkyrimSE.exe
Normal file
@@ -0,0 +1 @@
|
|||||||
|
SkyrimSE.exe
|
||||||
1
tests/data/games/sse/SkyrimSELauncher.exe
Normal file
1
tests/data/games/sse/SkyrimSELauncher.exe
Normal file
@@ -0,0 +1 @@
|
|||||||
|
SkyrimSELauncher.exe
|
||||||
1
tests/data/mods/add_test_1/plugin.esp
Normal file
1
tests/data/mods/add_test_1/plugin.esp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
plugin.esl-add_test_1
|
||||||
@@ -2,13 +2,15 @@ mod_location = "mods"
|
|||||||
download_location = "downloads"
|
download_location = "downloads"
|
||||||
nexus_api_key = "1234"
|
nexus_api_key = "1234"
|
||||||
|
|
||||||
[games.sse]
|
[games.example_game]
|
||||||
path = "/home/user/games/sse"
|
path = "/home/user/games/sse"
|
||||||
|
|
||||||
|
[games.sse]
|
||||||
|
path = "games/sse"
|
||||||
|
|
||||||
[instances.example1]
|
[instances.example1]
|
||||||
path = "example1.toml"
|
path = "example1.toml"
|
||||||
|
|
||||||
|
|
||||||
[instances.example2]
|
[instances.example2]
|
||||||
path = "/home/user/example2.toml"
|
path = "/home/user/example2.toml"
|
||||||
|
|
||||||
@@ -26,3 +28,6 @@ path = "mod2"
|
|||||||
|
|
||||||
[mods.mod3]
|
[mods.mod3]
|
||||||
path = "mod3"
|
path = "mod3"
|
||||||
|
|
||||||
|
[mods.add_test_1]
|
||||||
|
path = "add_test_1"
|
||||||
|
|||||||
@@ -34,11 +34,18 @@ fn parse_complex() {
|
|||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
config
|
config
|
||||||
.game_by_id("sse")
|
.game_by_id("example_game")
|
||||||
.is_some_and(|e| e.install_location() == "/home/user/games/sse"),
|
.is_some_and(|e| e.install_location() == "/home/user/games/sse"),
|
||||||
"Installed game wrong path"
|
"Installed game wrong path"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
config
|
||||||
|
.game_by_id("sse")
|
||||||
|
.is_some_and(|e| e.install_location().ends_with("games/sse")),
|
||||||
|
"Installed game wrong path"
|
||||||
|
);
|
||||||
|
|
||||||
assert!(config.game_by_id("starfield").is_none());
|
assert!(config.game_by_id("starfield").is_none());
|
||||||
|
|
||||||
assert!(config.mod_by_id("mod1").is_some());
|
assert!(config.mod_by_id("mod1").is_some());
|
||||||
|
|||||||
Reference in New Issue
Block a user