Skip to content

Commit

Permalink
refactor: improve blacklist applying logic
Browse files Browse the repository at this point in the history
  • Loading branch information
std-microblock committed Feb 15, 2024
1 parent fa1781f commit 881e618
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/blacklist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ pub fn apply_mod_blacklist_profile(

let blacklist = Path::new(game_path).join("Mods").join("blacklist.txt");

let mods = get_installed_mods_sync(game_path.clone() + "/Mods");

fs::write(
blacklist,
(format!(
"# Profile: {}\n# This file is generated by CeleMod\n\n\n",
profile_name
) + &profile
.mods
.iter()
.map(|v| v.file.clone())
) + &mods.iter()
.filter_map(|v| {
profile.mods.iter().find(|m| m.name == v.name).map(|mod_name| format!("# {}\n", mod_name.file))
})
.collect::<Vec<String>>()
.join("\n")),
)?;
Expand Down Expand Up @@ -91,8 +93,8 @@ pub fn get_mod_blacklist_profiles(game_path: &String) -> Vec<ModBlacklistProfile
.lines()
.map(|v|v.trim())
.filter(|v| !v.starts_with('#'))
.filter_map(|v| {
Some(ModBlacklist {
.map(|v| {
ModBlacklist {
name: {
if let Some(mod_name) = mods.iter().find(|m| m.file == v) {
mod_name.name.clone()
Expand All @@ -101,7 +103,7 @@ pub fn get_mod_blacklist_profiles(game_path: &String) -> Vec<ModBlacklistProfile
}
},
file: v.to_string(),
})
}
})
.collect(),
};
Expand Down

0 comments on commit 881e618

Please sign in to comment.