Skip to content

Commit

Permalink
Avoid needing to store notes in ScanInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Aug 8, 2024
1 parent a994f5b commit e4a7b36
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Ludusavi will automatically check for manifest updates once every 24 hours.
Previously, this check only occurred when the app started.
* Manifests may now include a `notes` field.
If a game has notes and is found during a backup scan,
If a game has notes in the manifest,
then the backup screen will show an info icon next to the game,
and you can click the icon to display the notes.
The primary manifest does not (yet) contain any notes,
Expand Down
4 changes: 2 additions & 2 deletions src/gui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ impl Application for App {
let mut cache = Cache::load().unwrap_or_default().migrate_config(&mut config);
TRANSLATOR.set_language(config.language);
let manifest = if Manifest::path().exists() {
match Manifest::load() {
match Manifest::load_with_secondary(&config) {
Ok(y) => y,
Err(e) => {
errors.push(e);
Expand Down Expand Up @@ -1400,7 +1400,7 @@ impl Application for App {

self.save_cache();

match Manifest::load() {
match Manifest::load_with_secondary(&self.config) {
Ok(x) => {
self.manifest = x;
}
Expand Down
5 changes: 3 additions & 2 deletions src/gui/game_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ impl GameListEntry {
})
})
.push_maybe({
(!self.scan_info.notes.is_empty()).then(|| {
button::show_game_notes(self.scan_info.game_name.clone(), self.scan_info.notes.clone())
manifest.0.get(&name).and_then(|data| {
(!restoring && !data.notes.is_empty())
.then(|| button::show_game_notes(name.clone(), data.notes.clone()))
})
})
.push_maybe({
Expand Down
48 changes: 31 additions & 17 deletions src/resource/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ impl Manifest {
})
}

pub fn load_with_secondary(config: &Config) -> Result<Self, Error> {
Self::load().map(|mut manifest| {
manifest.load_secondary_manifests(config);
manifest
})
}

pub fn should_update(url: &str, cache: &cache::Manifests, force: bool, primary: bool) -> bool {
if force {
return true;
Expand Down Expand Up @@ -552,20 +559,16 @@ impl Manifest {
self.0.clear();
}

for secondary in config.manifest.load_secondary_manifests() {
self.incorporate_secondary_manifest(secondary);
}
self.load_secondary_manifests(config);
self.add_custom_games(config);
}

for root in &config.roots {
for (path, secondary) in root.find_secondary_manifests() {
self.incorporate_secondary_manifest(Secondary {
id: path.render(),
path,
data: secondary,
});
}
}
pub fn with_extensions(mut self, config: &Config) -> Self {
self.incorporate_extensions(config);
self
}

fn add_custom_games(&mut self, config: &Config) {
for custom_game in &config.custom_games {
if custom_game.ignore {
continue;
Expand All @@ -574,11 +577,6 @@ impl Manifest {
}
}

pub fn with_extensions(mut self, config: &Config) -> Self {
self.incorporate_extensions(config);
self
}

fn add_custom_game(&mut self, custom: CustomGame) {
let name = custom.name.clone();
let existing = self.0.get(&name);
Expand Down Expand Up @@ -609,6 +607,22 @@ impl Manifest {
self.0.insert(name, game);
}

fn load_secondary_manifests(&mut self, config: &Config) {
for secondary in config.manifest.load_secondary_manifests() {
self.incorporate_secondary_manifest(secondary);
}

for root in &config.roots {
for (path, secondary) in root.find_secondary_manifests() {
self.incorporate_secondary_manifest(Secondary {
id: path.render(),
path,
data: secondary,
});
}
}
}

fn incorporate_secondary_manifest(&mut self, secondary: Secondary) {
log::debug!("incorporating secondary manifest: {}", &secondary.id);
let manifest = secondary.data.0;
Expand Down
1 change: 0 additions & 1 deletion src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,6 @@ pub fn scan_game_for_backup(
available_backups: vec![],
backup: None,
has_backups,
notes: game.notes.clone(),
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/scan/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ impl GameLayout {
available_backups: vec![],
backup: None,
has_backups: true,
notes: vec![],
})
}
}
Expand Down Expand Up @@ -1600,7 +1599,6 @@ impl GameLayout {
available_backups,
backup,
has_backups,
notes: vec![],
}
}

Expand Down Expand Up @@ -3360,7 +3358,6 @@ mod tests {
available_backups: backups.clone(),
backup: Some(backups[0].clone()),
has_backups: true,
notes: vec![],
},
layout.scan_for_restoration(
"game1",
Expand Down Expand Up @@ -3410,7 +3407,6 @@ mod tests {
..Default::default()
})),
has_backups: true,
notes: vec![],
},
layout.scan_for_restoration(
"game3",
Expand Down Expand Up @@ -3443,7 +3439,6 @@ mod tests {
..Default::default()
})),
has_backups: true,
notes: vec![],
},
layout.scan_for_restoration(
"game3",
Expand Down
6 changes: 1 addition & 5 deletions src/scan/preview.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::collections::HashSet;

use crate::{
resource::{
config::{ToggledPaths, ToggledRegistry},
manifest,
},
resource::config::{ToggledPaths, ToggledRegistry},
scan::{layout::Backup, BackupInfo, ScanChange, ScanChangeCount, ScannedFile, ScannedRegistry},
};

Expand All @@ -19,7 +16,6 @@ pub struct ScanInfo {
pub backup: Option<Backup>,
/// Cheaper version of `!available_backups.is_empty()`, always populated.
pub has_backups: bool,
pub notes: Vec<manifest::Note>,
}

impl ScanInfo {
Expand Down

0 comments on commit e4a7b36

Please sign in to comment.