Skip to content

Commit

Permalink
Fix logic for clearing processed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Nov 4, 2024
1 parent ae5d80e commit 406873b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/gui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl App {
);
if scan_info.can_report_game() {
if let Some(backup_info) = backup_info.as_ref() {
scan_info.clear_processed_changes(backup_info);
scan_info.clear_processed_changes(backup_info, false);
}

let duplicates = self.backup_screen.duplicate_detector.add_game(
Expand Down Expand Up @@ -893,7 +893,7 @@ impl App {
);
if scan_info.can_report_game() {
if let Some(backup_info) = backup_info.as_ref() {
scan_info.clear_processed_changes(backup_info);
scan_info.clear_processed_changes(backup_info, true);
}

let comment = scan_info.backup.as_ref().and_then(|x| x.comment()).map(|x| x.as_str());
Expand Down
21 changes: 13 additions & 8 deletions src/scan/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,22 @@ impl ScanInfo {

/// This is meant to be used for the GUI after a backup/restore,
/// so we don't show the previous change state anymore.
pub fn clear_processed_changes(&mut self, backup_info: &BackupInfo) {
pub fn clear_processed_changes(&mut self, backup_info: &BackupInfo, restoring: bool) {
let resolve = |old: ScanChange, ignored: bool| match (restoring, ignored) {
(true, true) => old,
(true, false) => ScanChange::Same,
(false, true) => ScanChange::New,
(false, false) => ScanChange::Same,
};

self.found_files = self
.found_files
.clone()
.into_iter()
.filter(|(_, v)| v.change != ScanChange::Removed)
.map(|(scan_key, mut v)| {
if !v.ignored && !backup_info.failed_files.contains_key(&scan_key) {
v.change = ScanChange::Same;
if !backup_info.failed_files.contains_key(&scan_key) {
v.change = resolve(v.change, v.ignored);
}
(scan_key, v)
})
Expand All @@ -252,13 +259,11 @@ impl ScanInfo {
.into_iter()
.filter(|(_, v)| v.change != ScanChange::Removed)
.map(|(scan_key, mut v)| {
if !v.ignored && !backup_info.failed_registry.contains_key(&scan_key) {
v.change = ScanChange::Same;
if !backup_info.failed_registry.contains_key(&scan_key) {
v.change = resolve(v.change, v.ignored);

for item in v.values.values_mut() {
if !item.ignored {
item.change = ScanChange::Same;
}
item.change = resolve(item.change, item.ignored);
}
}
(scan_key, v)
Expand Down

0 comments on commit 406873b

Please sign in to comment.