Compare commits

..

3 Commits

Author SHA1 Message Date
b1c7d96f29 updated example use in main 2026-02-28 20:19:53 +01:00
984246b263 add link_mod_file to linker 2026-02-28 20:19:31 +01:00
0e97a77288 added export_files to conflict_solver 2026-02-28 20:19:09 +01:00
3 changed files with 44 additions and 3 deletions

View File

@@ -67,4 +67,8 @@ impl<'a> ConflictSolver<'a> {
None
}
pub fn export_files(&self) -> Vec<(&ModFile, &Mod)> {
self.files.values().copied().collect()
}
}

View File

@@ -4,7 +4,7 @@ use std::{
path::{Path, PathBuf},
};
use crate::fomod::FileTypeEnum;
use crate::{Mod, ModFile, fomod::FileTypeEnum};
pub struct Linker {
target: PathBuf,
@@ -49,6 +49,12 @@ impl Linker {
Ok(())
}
pub fn link_mod_file(&self, file: &ModFile, from_mod: &Mod) -> Result<(), LinkerError> {
let src = from_mod.source.join(&file.source);
self.link_file(&src, &file.dest)
}
pub fn link_plugin_files(
&self,
entries: &[FileTypeEnum],

View File

@@ -5,7 +5,9 @@ use std::{
};
use crate::{
conflict_resolver::ConflictSolver,
fomod::{FileType, FileTypeEnum},
linker::Linker,
mod_config_installer::FomodInstaller,
};
@@ -95,14 +97,43 @@ struct Mod {
fn main() -> Result<(), Box<dyn Error>> {
const XML_PATH: &str = "./data/xml/ineed.xml";
let xml = fs::read_to_string(XML_PATH)?;
let loaded_mod = Mod {
name: "INeed".to_owned(),
source: Path::new("./data/mods/iNeed v1").to_owned(),
priority: 0,
};
let config: fomod::Config = quick_xml::de::from_str(&xml)?;
let installer = FomodInstaller::new(config, vec![], install_prompt::prompt);
dbg!(installer.run());
let files = installer.run();
let converted_files: Vec<_> = files
.iter()
.flat_map(|f| ModFile::from_installer(f.clone(), &loaded_mod).unwrap())
.collect();
let mut solver = ConflictSolver::new();
for file in &converted_files {
if let Some(conflict) = solver.add_file(file, &loaded_mod) {
println!("Conflict deteced: {:?}", conflict);
return Ok(());
}
}
let files_to_link = solver.export_files();
let linker = Linker::new(Path::new("./data/target"), Path::new("./data/install"));
linker.link_install_to_target()?;
for (file, from_mod) in files_to_link {
linker.link_mod_file(file, from_mod)?;
}
Ok(())
}