diff --git a/src/basic_types.rs b/src/basic_types.rs index 8f401a9..7ca4f30 100644 --- a/src/basic_types.rs +++ b/src/basic_types.rs @@ -1,3 +1,4 @@ +use log::trace; use serde::{Deserialize, Serialize}; use std::{ error::Error, @@ -30,6 +31,11 @@ pub struct RootConfig { impl RootConfig { pub fn load_from_file(path: impl AsRef) -> Result> { + trace!( + "Loading RootConfig from file: {}", + path.as_ref().to_string_lossy() + ); + let data = read_to_string(path)?; let config = toml::from_str(&data)?; @@ -111,6 +117,11 @@ impl ModdedInstance { } pub fn load_from_file(path: impl AsRef) -> Result> { + trace!( + "Loading ModdedInstance from file: {}", + path.as_ref().to_string_lossy() + ); + let data = read_to_string(path)?; let config = toml::from_str(&data)?; @@ -118,6 +129,11 @@ impl ModdedInstance { } pub fn save_to_file(&self, path: impl AsRef) -> Result<(), Box> { + trace!( + "Saving ModdedInstance to: {}", + path.as_ref().to_string_lossy() + ); + let content = toml::to_string_pretty(self)?; let mut file = fs::File::create(path)?; write!(file, "{}", content)?; @@ -125,6 +141,8 @@ impl ModdedInstance { } pub fn add_mod(&mut self, from_mod: &ModConfig, priority: isize, files: &[ModFile]) { + trace!("Adding mod to instance"); + let mut new_mod = InstalledMod::new(from_mod, priority); let mut solver = ConflictSolver::new(); @@ -137,10 +155,12 @@ impl ModdedInstance { } } + trace!("Adding already present files to confict solver"); for (present_file, present_mod) in &already_installed_files { solver.add_file_unchecked(present_file, present_mod); } + trace!("Adding file from mod to confict solver"); // Now add the new files and check for conflicts for file in files { if let Some(conflict) = solver.add_file(file, &new_mod) { @@ -150,6 +170,7 @@ impl ModdedInstance { } } + trace!("No conflicts where found"); // No conflicts. Add files. for file in files { new_mod.add_file(file); diff --git a/src/conflict_resolver.rs b/src/conflict_resolver.rs index 1fe9a57..415a48a 100644 --- a/src/conflict_resolver.rs +++ b/src/conflict_resolver.rs @@ -1,7 +1,6 @@ -use std::{ - collections::HashMap, - path::{Path, PathBuf}, -}; +use std::{collections::HashMap, path::PathBuf}; + +use log::debug; use crate::basic_types::{InstalledMod, ModFile}; @@ -36,11 +35,17 @@ impl<'a> ConflictSolver<'a> { let path = &file.destination(); match self.files.get(path) { Some((current_file, current_file_mod)) => { + debug!( + "Trying to resolve file conflict between at {}", + path.to_string_lossy() + ); + if from_mod == *current_file_mod { // File from the same mod // Check internal priority if file.internal_priority() > current_file.internal_priority() { self.files.insert(path.to_owned(), (file, from_mod)); + debug!("Conflict resolved. Internal priority"); return None; } @@ -58,6 +63,7 @@ impl<'a> ConflictSolver<'a> { if from_mod.priority() > current_file_mod.priority() { self.files.insert(path.to_owned(), (file, from_mod)); + debug!("Conflict resolved. Mod priority"); return None; } diff --git a/src/linker.rs b/src/linker.rs index 14183b2..ec7ee99 100644 --- a/src/linker.rs +++ b/src/linker.rs @@ -1,3 +1,5 @@ +use log::debug; + use crate::{ basic_types::{ModdedInstance, RootConfig}, utils::walk_files_recursive, @@ -10,6 +12,7 @@ pub fn link_instance_to_target( instance: &ModdedInstance, target: impl AsRef, ) -> Result<(), io::Error> { + debug!("Linking instance to {}", target.as_ref().to_string_lossy()); for installed_mod in &instance.mods { let mod_config = root_config.get_mod_by_id(&installed_mod.mod_id()).unwrap(); let mod_source_root = root_config.get_mod_location(&mod_config); @@ -28,6 +31,7 @@ pub fn link_game_to_target( game_dir: impl AsRef, target: impl AsRef, ) -> Result<(), io::Error> { + debug!("Linking install to {}", target.as_ref().to_string_lossy()); walk_files_recursive(&game_dir)?.try_for_each(|file| { let link_target = file.path(); let link_name = target @@ -50,6 +54,7 @@ pub fn create_plugins_txt( instance: &ModdedInstance, target: impl AsRef, ) -> Result<(), io::Error> { + debug!("Generating plugins.txt"); let mut file = fs::File::create(target.as_ref().join("plugins.txt"))?; writeln!(file, "# Auto generated. DO NOT EDIT MANUALLY!")?; diff --git a/src/load_order.rs b/src/load_order.rs index 73b1123..137e0eb 100644 --- a/src/load_order.rs +++ b/src/load_order.rs @@ -4,6 +4,7 @@ use std::{ }; use libloot::{Game, GameType}; +use log::trace; use crate::{ basic_types::{ModdedInstance, RootConfig}, @@ -44,6 +45,7 @@ impl LoadOrder { .collect(); let refs: Vec<_> = mod_plugins.iter().map(|e| e.as_path()).collect(); + trace!("Loading {} plugins to game", refs.len()); self.game.load_plugins(&refs)?; } Ok(()) @@ -55,6 +57,7 @@ impl LoadOrder { .map(|f| f.path()) .collect(); let refs: Vec<_> = plugins.iter().map(|e| e.as_path()).collect(); + trace!("Loading {} plugins to game", refs.len()); self.game.load_plugins(&refs)?; Ok(()) } @@ -67,6 +70,7 @@ impl LoadOrder { } pub fn load_order(&self) -> Result, Box> { + trace!("Generating new load order"); let all_plugins = self.game.loaded_plugins(); let plugins_names: Vec<&str> = all_plugins.iter().map(|e| e.name()).collect(); diff --git a/src/mod_config_installer.rs b/src/mod_config_installer.rs index 242f063..3cff8df 100644 --- a/src/mod_config_installer.rs +++ b/src/mod_config_installer.rs @@ -1,5 +1,7 @@ use std::{collections::HashMap, fmt::Display}; +use log::{debug, warn}; + use crate::fomod::{ CompositeDependency, Config, DependencyOperator, DependencyState, FileList, FileTypeEnum, Group, GroupType, Plugin, PluginTypeDescriptorEnum, PluginTypeEnum, @@ -20,6 +22,7 @@ impl InstallerState { } fn set_flag(&mut self, name: &str, value: &str) { + debug!("Setting flag: {} to {}", name, value); self.flags.insert(name.to_string(), value.to_string()); } @@ -29,6 +32,7 @@ impl InstallerState { fn add_files(&mut self, files: &FileList) { let Some(list) = &files.list else { + debug!("Adding empty file list to installer state"); return; }; @@ -66,12 +70,20 @@ fn evaluate_dependency( CompositeDependency::Game(version) => { // TODO: Check the game version let _ = version; + warn!( + "Trying to eveluate game version dependency: {} - Not implemented yet.", + version.version + ); true } CompositeDependency::Fomm(version) => { // TODO: Check the fomm version let _ = version; + warn!( + "Trying to eveluate FOMM dependency: {} - Not implemented yet.", + version.version + ); true } @@ -189,13 +201,15 @@ impl FomodInstaller { if let Some(install_steps) = &self.config.install_steps { let steps = &install_steps.install_step; - for (step_index, step) in steps.iter().enumerate() { + for step in steps { // Check if the step should be visible - if let Some(visible) = &step.visible { - if !evaluate_dependency(visible, &state, &self.installed_plugins) { - // Dependency to show the step not meet. Skipping. - continue; - } + if step + .visible + .as_ref() + .is_some_and(|v| !evaluate_dependency(v, &state, &self.installed_plugins)) + { + // Dependency to show the step not meet. Skipping. + continue; } for group in &step.optional_file_groups.group {