fixed fomod visable condition
This commit is contained in:
14
src/fomod.rs
14
src/fomod.rs
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use std::{fs, io, path::Path};
|
use std::{fs, io, path::Path};
|
||||||
|
|
||||||
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
@@ -55,6 +56,11 @@ pub struct Config {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load_from_file(path: impl AsRef<Path>) -> Result<Self, FOModError> {
|
pub fn load_from_file(path: impl AsRef<Path>) -> Result<Self, FOModError> {
|
||||||
|
debug!(
|
||||||
|
"Loading FOmod config from {}",
|
||||||
|
path.as_ref().to_string_lossy()
|
||||||
|
);
|
||||||
|
|
||||||
let data = fs::read_to_string(path)?;
|
let data = fs::read_to_string(path)?;
|
||||||
let config = quick_xml::de::from_str(&data)?;
|
let config = quick_xml::de::from_str(&data)?;
|
||||||
|
|
||||||
@@ -142,7 +148,7 @@ pub struct InstallStep {
|
|||||||
#[serde(rename = "@name")]
|
#[serde(rename = "@name")]
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
||||||
pub visible: Option<CompositeDependency>,
|
pub visible: Option<ModuleDependency>,
|
||||||
|
|
||||||
#[serde(rename = "optionalFileGroups")]
|
#[serde(rename = "optionalFileGroups")]
|
||||||
pub optional_file_groups: GroupList,
|
pub optional_file_groups: GroupList,
|
||||||
@@ -151,6 +157,7 @@ pub struct InstallStep {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct ModuleDependency {
|
pub struct ModuleDependency {
|
||||||
#[serde(rename = "@operator")]
|
#[serde(rename = "@operator")]
|
||||||
|
#[serde(default)]
|
||||||
pub operator: DependencyOperator,
|
pub operator: DependencyOperator,
|
||||||
#[serde(rename = "$value")]
|
#[serde(rename = "$value")]
|
||||||
pub list: Vec<CompositeDependency>,
|
pub list: Vec<CompositeDependency>,
|
||||||
@@ -207,8 +214,11 @@ pub enum DependencyState {
|
|||||||
Missing,
|
Missing,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(
|
||||||
|
Copy, Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash,
|
||||||
|
)]
|
||||||
pub enum DependencyOperator {
|
pub enum DependencyOperator {
|
||||||
|
#[default]
|
||||||
And,
|
And,
|
||||||
Or,
|
Or,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use log::{debug, warn};
|
|||||||
|
|
||||||
use crate::fomod::{
|
use crate::fomod::{
|
||||||
CompositeDependency, Config, DependencyOperator, DependencyState, FileList, FileTypeEnum,
|
CompositeDependency, Config, DependencyOperator, DependencyState, FileList, FileTypeEnum,
|
||||||
Group, GroupType, Plugin, PluginTypeDescriptorEnum, PluginTypeEnum,
|
Group, GroupType, ModuleDependency, Plugin, PluginTypeDescriptorEnum, PluginTypeEnum,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -101,6 +101,22 @@ fn evaluate_dependency(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn evaluate_module_depbendecy(
|
||||||
|
dep: &ModuleDependency,
|
||||||
|
state: &InstallerState,
|
||||||
|
installed_plugins: &[String],
|
||||||
|
) -> bool {
|
||||||
|
let mut evaluated = dep
|
||||||
|
.list
|
||||||
|
.iter()
|
||||||
|
.map(|e| evaluate_dependency(e, state, installed_plugins));
|
||||||
|
|
||||||
|
match dep.operator {
|
||||||
|
DependencyOperator::And => evaluated.all(|r| r),
|
||||||
|
DependencyOperator::Or => evaluated.any(|r| r),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct GroupPrompt {
|
pub struct GroupPrompt {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub select_type: GroupType,
|
pub select_type: GroupType,
|
||||||
@@ -191,7 +207,7 @@ pub fn run_fomod_installer(
|
|||||||
if step
|
if step
|
||||||
.visible
|
.visible
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|v| !evaluate_dependency(v, &state, installed_plugins))
|
.is_some_and(|v| !evaluate_module_depbendecy(v, &state, installed_plugins))
|
||||||
{
|
{
|
||||||
// Dependency to show the step not meet. Skipping.
|
// Dependency to show the step not meet. Skipping.
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user