the great refactor
This commit is contained in:
@@ -6,14 +6,13 @@ use std::{
|
||||
|
||||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||
use log::warn;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::{
|
||||
basic_types::{InstalledMod, ModConfig, ModFile, ModdedInstance, RootConfig},
|
||||
file_conflict_solver::ConflictSolver,
|
||||
fomod, install_prompt,
|
||||
mod_config_installer::run_fomod_installer,
|
||||
utils::resolve_case_insensitive,
|
||||
types::{InstalledMod, ModConfig, ModFile, ModdedInstance, RootConfig},
|
||||
utils::{resolve_case_insensitive, walk_all_files},
|
||||
};
|
||||
|
||||
pub fn insert_mod_to_instance(
|
||||
@@ -25,9 +24,9 @@ pub fn insert_mod_to_instance(
|
||||
let mut solver = ConflictSolver::new();
|
||||
|
||||
let mut installed_files: Vec<(ModFile, &InstalledMod)> = Vec::new();
|
||||
for installed_mod in &instance.mods {
|
||||
for installed_mod in instance.mods() {
|
||||
for link in installed_mod.files() {
|
||||
let recreated_mod_file = ModFile::new(&link.src, &link.dst, 0);
|
||||
let recreated_mod_file = ModFile::new(link.src(), link.dst(), 0);
|
||||
installed_files.push((recreated_mod_file, installed_mod));
|
||||
}
|
||||
}
|
||||
@@ -38,7 +37,7 @@ pub fn insert_mod_to_instance(
|
||||
}
|
||||
}
|
||||
|
||||
let new_mod = InstalledMod::new(&from_mod.id, priority);
|
||||
let new_mod = InstalledMod::new(from_mod.id(), priority);
|
||||
for file in files {
|
||||
if let Some(conflict) = solver.add_file(file, &new_mod) {
|
||||
// TODO: Return conflict
|
||||
@@ -50,14 +49,14 @@ pub fn insert_mod_to_instance(
|
||||
let mut map: HashMap<String, InstalledMod> = HashMap::new();
|
||||
|
||||
for (file, from_mod) in new_link_tree {
|
||||
match map.get_mut(&from_mod.mod_id()) {
|
||||
match map.get_mut(from_mod.mod_id()) {
|
||||
Some(existing) => {
|
||||
existing.add_file(file);
|
||||
}
|
||||
None => {
|
||||
let mut new_mod = InstalledMod::new(&from_mod.mod_id(), from_mod.priority());
|
||||
let mut new_mod = InstalledMod::new(from_mod.mod_id(), from_mod.priority());
|
||||
new_mod.add_file(file);
|
||||
map.insert(new_mod.mod_id(), new_mod);
|
||||
map.insert(new_mod.mod_id().to_owned(), new_mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +71,7 @@ pub fn files_to_install_mod(
|
||||
instance: &ModdedInstance,
|
||||
mod_to_install: &ModConfig,
|
||||
) -> anyhow::Result<Vec<ModFile>> {
|
||||
let mod_location = root_config.get_mod_location(mod_to_install);
|
||||
let mod_location = root_config.mod_location().join(mod_to_install.path());
|
||||
|
||||
let files = match determain_mod_kind(mod_to_install, &mod_location)? {
|
||||
ModKind::Fomod(xml_path) => install_fomod(instance, xml_path, &mod_location)?,
|
||||
@@ -127,25 +126,15 @@ fn install_fomod(
|
||||
|
||||
fn install_from_dir(
|
||||
mod_config: &ModConfig,
|
||||
path: impl AsRef<Path>,
|
||||
mod_location: impl AsRef<Path>,
|
||||
) -> anyhow::Result<Vec<ModFile>> {
|
||||
let glob_filter = create_glob_filter(mod_config.ignore())?;
|
||||
let files: Vec<_> = WalkDir::new(path)
|
||||
.into_iter()
|
||||
.map(|entry| {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
let rel_path = path.strip_prefix(&path).unwrap();
|
||||
|
||||
if !glob_filter.is_match(rel_path) {
|
||||
Ok(Some(ModFile::new(&rel_path, &rel_path, 0)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
})
|
||||
.filter_map(|r| r.transpose())
|
||||
.collect::<Result<_, io::Error>>()?;
|
||||
let files: Vec<_> = walk_all_files(&mod_location)?
|
||||
.map(|entry| entry.path().strip_prefix(&mod_location).unwrap().to_owned())
|
||||
.filter(|rel_path| !glob_filter.is_match(rel_path))
|
||||
.map(|rel_path| ModFile::new(&rel_path, &rel_path, 0))
|
||||
.collect();
|
||||
|
||||
Ok(files)
|
||||
}
|
||||
@@ -156,25 +145,12 @@ fn install_from_dir_to_data(
|
||||
) -> anyhow::Result<Vec<ModFile>> {
|
||||
let glob_filter = create_glob_filter(mod_config.ignore())?;
|
||||
let data = PathBuf::from("Data");
|
||||
let files: Vec<_> = WalkDir::new(&path)
|
||||
.into_iter()
|
||||
.map(|entry| {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
let rel_path = path.strip_prefix(&path).unwrap();
|
||||
if !should_be_included(rel_path) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
if glob_filter.is_match(rel_path) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
Ok(Some(ModFile::new(rel_path, data.join(rel_path), 0)))
|
||||
})
|
||||
.filter_map(|r| r.transpose())
|
||||
.collect::<Result<_, io::Error>>()?;
|
||||
let files: Vec<ModFile> = walk_all_files(&path)?
|
||||
.map(|entry| entry.path().strip_prefix(&path).unwrap().to_owned())
|
||||
.filter(|rel_path| !glob_filter.is_match(rel_path))
|
||||
.filter(|rel_path| should_be_included(rel_path))
|
||||
.map(|rel_path| ModFile::new(&rel_path, data.join(&rel_path), 0))
|
||||
.collect();
|
||||
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user