Skip to content

Commit

Permalink
automatically remove non-existent projects in project manager
Browse files Browse the repository at this point in the history
- remove duplicated projects (also requires runtime checks that prevents adding duplicates in the first place)
  • Loading branch information
mrDIMAS committed Dec 27, 2024
1 parent 77d1703 commit b561709
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion project-manager/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use directories::ProjectDirs;
use fyrox::{
core::{log::Log, pool::Handle, reflect::prelude::*},
fxhash::FxHashSet,
gui::{
inspector::{
editors::{
Expand Down Expand Up @@ -118,7 +119,12 @@ impl SettingsData {

pub fn load() -> Self {
match File::open(Self::actual_path()) {
Ok(file) => ron::de::from_reader(file).unwrap_or_default(),
Ok(file) => {
let mut settings: SettingsData = ron::de::from_reader(file).unwrap_or_default();
settings.remove_non_existent_projects();
settings.remove_duplicates();
settings
}
Err(err) => {
eprintln!("Unable to load project manager settings! Reason: {err:?}");
Default::default()
Expand All @@ -140,6 +146,23 @@ impl SettingsData {
}
}
}

fn remove_non_existent_projects(&mut self) {
self.projects
.retain(|project| project.manifest_path.exists())
}

fn remove_duplicates(&mut self) {
let mut existing = FxHashSet::default();
self.projects.retain(|project| {
if existing.contains(&project.manifest_path) {
false
} else {
existing.insert(project.manifest_path.clone());
true
}
});
}
}

pub struct Settings {
Expand Down

0 comments on commit b561709

Please sign in to comment.