the big refactor
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::fomod::{
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InstallerState {
|
||||
struct InstallerState {
|
||||
flags: HashMap<String, String>,
|
||||
selected_files: Vec<FileTypeEnum>,
|
||||
}
|
||||
@@ -39,7 +39,7 @@ impl InstallerState {
|
||||
self.selected_files.extend_from_slice(list);
|
||||
}
|
||||
|
||||
pub fn into_file_list(self) -> Vec<FileTypeEnum> {
|
||||
fn into_file_list(self) -> Vec<FileTypeEnum> {
|
||||
self.selected_files
|
||||
}
|
||||
}
|
||||
@@ -171,82 +171,66 @@ fn resolve_plugin_type(
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FomodInstaller {
|
||||
config: Config,
|
||||
installed_plugins: Vec<String>,
|
||||
pub fn run_fomod_installer(
|
||||
fomod_config: Config,
|
||||
installed_plugins: &[String],
|
||||
group_prompt: fn(GroupPrompt) -> Vec<usize>,
|
||||
}
|
||||
) -> anyhow::Result<Vec<FileTypeEnum>> {
|
||||
let mut state = InstallerState::new();
|
||||
|
||||
impl FomodInstaller {
|
||||
pub fn new(
|
||||
config: Config,
|
||||
installed_plugins: Vec<String>,
|
||||
group_promt: fn(GroupPrompt) -> Vec<usize>,
|
||||
) -> Self {
|
||||
Self {
|
||||
config,
|
||||
installed_plugins,
|
||||
group_prompt: group_promt,
|
||||
}
|
||||
// Always-installed files first
|
||||
if let Some(required) = &fomod_config.required_install_files {
|
||||
state.add_files(required);
|
||||
}
|
||||
|
||||
pub fn run(self) -> Vec<FileTypeEnum> {
|
||||
let mut state = InstallerState::new();
|
||||
if let Some(install_steps) = fomod_config.install_steps {
|
||||
let steps = &install_steps.install_step;
|
||||
|
||||
// Always-installed files first
|
||||
if let Some(required) = &self.config.required_install_files {
|
||||
state.add_files(required);
|
||||
}
|
||||
for step in steps {
|
||||
// Check if the step should be visible
|
||||
if step
|
||||
.visible
|
||||
.as_ref()
|
||||
.is_some_and(|v| !evaluate_dependency(v, &state, installed_plugins))
|
||||
{
|
||||
// Dependency to show the step not meet. Skipping.
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(install_steps) = &self.config.install_steps {
|
||||
let steps = &install_steps.install_step;
|
||||
for group in &step.optional_file_groups.group {
|
||||
// TODO: Skip groups where all plugins are NotUsable
|
||||
|
||||
for step in steps {
|
||||
// Check if the step should be visible
|
||||
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;
|
||||
}
|
||||
let prompt = GroupPrompt::new(group, &state, installed_plugins);
|
||||
|
||||
for group in &step.optional_file_groups.group {
|
||||
// TODO: Skip groups where all plugins are NotUsable
|
||||
let selected_plugins = (group_prompt)(prompt);
|
||||
|
||||
let prompt = GroupPrompt::new(group, &state, &self.installed_plugins);
|
||||
for i in selected_plugins {
|
||||
let plugin = &group.plugins.plugin[i];
|
||||
|
||||
let selected_plugins = (self.group_prompt)(prompt);
|
||||
// Add files from selected plugin
|
||||
if let Some(files) = &plugin.files {
|
||||
state.add_files(files);
|
||||
}
|
||||
|
||||
for i in selected_plugins {
|
||||
let plugin = &group.plugins.plugin[i];
|
||||
|
||||
// Add files from selected plugin
|
||||
if let Some(files) = &plugin.files {
|
||||
state.add_files(files);
|
||||
}
|
||||
|
||||
// Set condition flags
|
||||
if let Some(condition_flags) = &plugin.condition_flags {
|
||||
for flag in &condition_flags.flag {
|
||||
state.set_flag(&flag.name, &flag.flag_value);
|
||||
}
|
||||
// Set condition flags
|
||||
if let Some(condition_flags) = &plugin.condition_flags {
|
||||
for flag in &condition_flags.flag {
|
||||
state.set_flag(&flag.name, &flag.flag_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Evaluate conditional file installs based on final flag state
|
||||
if let Some(conditional) = &self.config.conditional_file_installs {
|
||||
for pattern in &conditional.patterns.pattern {
|
||||
if evaluate_dependency(&pattern.dependencies, &state, &self.installed_plugins) {
|
||||
state.add_files(&pattern.files);
|
||||
}
|
||||
// Evaluate conditional file installs based on final flag state
|
||||
if let Some(conditional) = &fomod_config.conditional_file_installs {
|
||||
for pattern in &conditional.patterns.pattern {
|
||||
if evaluate_dependency(&pattern.dependencies, &state, installed_plugins) {
|
||||
state.add_files(&pattern.files);
|
||||
}
|
||||
}
|
||||
|
||||
state.into_file_list()
|
||||
}
|
||||
|
||||
Ok(state.into_file_list())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user