Compare commits

...

2 Commits

Author SHA1 Message Date
a78e517163 display file conflict to user 2026-03-07 16:01:28 +01:00
8487bafa57 changed log level on some functions 2026-03-07 16:00:55 +01:00
5 changed files with 28 additions and 17 deletions

View File

@@ -6,10 +6,10 @@ use crate::types::{InstalledMod, ModFile};
#[derive(Debug)]
pub struct Conflict<'a> {
rhs_mod: &'a InstalledMod,
lhs_mod: &'a InstalledMod,
rhs_file: &'a ModFile,
lhs_file: &'a ModFile,
pub rhs_mod: &'a InstalledMod,
pub lhs_mod: &'a InstalledMod,
pub rhs_file: &'a ModFile,
pub lhs_file: &'a ModFile,
}
pub struct ConflictSolver<'a> {
@@ -31,10 +31,10 @@ impl<'a> ConflictSolver<'a> {
let path = &file.dst().to_owned();
match self.files.get(path) {
Some((current_file, current_file_mod)) => {
// debug!(
// "Trying to resolve file conflict between at {}",
// path.to_string_lossy()
// );
debug!(
"Trying to resolve file conflict between at {}",
path.to_string_lossy()
);
if from_mod == *current_file_mod {
// File from the same mod

View File

@@ -5,7 +5,7 @@ use std::{
};
use globset::{Glob, GlobSet, GlobSetBuilder};
use log::warn;
use log::{error, warn};
use crate::{
file_conflict_solver::ConflictSolver,
@@ -20,7 +20,7 @@ pub fn insert_mod_to_instance(
from_mod: &ModConfig,
files: &[ModFile],
priority: isize,
) {
) -> bool {
let mut solver = ConflictSolver::new();
let mut installed_files: Vec<(ModFile, &InstalledMod)> = Vec::new();
@@ -40,7 +40,14 @@ pub fn insert_mod_to_instance(
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
error!(
"File conflict detected at: {} between {} and {}",
conflict.rhs_file.dst().to_string_lossy(),
conflict.lhs_mod.mod_id(),
conflict.rhs_mod.mod_id()
);
return false;
}
}
@@ -64,6 +71,8 @@ pub fn insert_mod_to_instance(
for (_, installed_mod) in map {
instance.update_or_create_mod(&installed_mod);
}
true
}
pub fn files_to_install_mod(

View File

@@ -39,7 +39,9 @@ fn command_add(root_config: &RootConfig, instance_id: &str, mod_id: &str) -> any
let files = files_to_install_mod(root_config, &instance, mod_to_install)?;
insert_mod_to_instance(&mut instance, mod_to_install, &files, 0);
if !insert_mod_to_instance(&mut instance, mod_to_install, &files, 0) {
return Err(anyhow!("File conflict"));
}
instance.save_to_file()?;

View File

@@ -4,7 +4,7 @@ use std::{
path::{Path, PathBuf},
};
use log::trace;
use log::debug;
use serde::{Deserialize, Serialize};
use crate::types::{ConfigReadWriteError, installed_mod::InstalledMod, link::Link};
@@ -29,7 +29,7 @@ pub struct ModdedInstance {
impl ModdedInstance {
pub fn load_from_file(path: impl AsRef<Path>) -> Result<Self, ConfigReadWriteError> {
trace!(
debug!(
"Loading ModdedInstance from file: {}",
path.as_ref().to_string_lossy()
);
@@ -43,7 +43,7 @@ impl ModdedInstance {
}
pub fn save_to_file(&self) -> Result<(), ConfigReadWriteError> {
trace!(
debug!(
"Saving ModdedInstance to: {}",
self.self_path.to_string_lossy()
);

View File

@@ -4,7 +4,7 @@ use std::{
path::{Path, PathBuf},
};
use log::trace;
use log::debug;
use serde::Deserialize;
use crate::types::{ConfigReadWriteError, ModConfig, game::Game, modded_instance::ModdedInstance};
@@ -31,7 +31,7 @@ pub struct RootConfig {
impl RootConfig {
pub fn load_from_file(path: impl AsRef<Path>) -> Result<Self, ConfigReadWriteError> {
trace!(
debug!(
"Loading RootConfig from file: {}",
path.as_ref().to_string_lossy()
);