diff --git a/src/sync/synchronization.rs b/src/sync/synchronization.rs index 1cea7d1..172c6a1 100644 --- a/src/sync/synchronization.rs +++ b/src/sync/synchronization.rs @@ -99,13 +99,7 @@ pub fn sync_shortcuts( remove_old_shortcuts(&mut shortcut_info); remove_shortcuts_with_same_appid(&mut shortcut_info, &all_shortcuts); - shortcut_info.shortcuts.extend(all_shortcuts.clone()); - - fix_shortcut_icons( - user, - &mut shortcut_info.shortcuts, - settings.steam.optimize_for_big_picture, - ); + shortcut_info.shortcuts.extend(all_shortcuts.clone()); save_shortcuts(&shortcut_info.shortcuts, Path::new(&shortcut_info.path)); @@ -163,11 +157,26 @@ fn remove_old_shortcuts(shortcut_info: &mut ShortcutInfo) { .retain(|shortcut| !shortcut.is_boilr_shortcut()); } +pub fn fix_all_shortcut_icons ( + settings: &Settings, +) -> eyre::Result<()>{ + let mut userinfo_shortcuts = get_shortcuts_paths(&settings.steam).map_err(|e|eyre::format_err!("Could not find steam shortcuts; {e}"))?; + for user in userinfo_shortcuts.iter_mut() { + let mut shortcut_info = get_shortcuts_for_user(user); + let changes = fix_shortcut_icons(user,&mut shortcut_info.shortcuts,settings.steam.optimize_for_big_picture); + if changes{ + save_shortcuts(&shortcut_info.shortcuts, Path::new(&shortcut_info.path)); + } + } + Ok(()) +} + + fn fix_shortcut_icons( user: &SteamUsersInfo, shortcuts: &mut Vec, big_picture_mode: bool, -) { +) -> bool { let image_folder = Path::new(&user.steam_user_data_folder) .join("config") .join("grid"); @@ -177,17 +186,20 @@ fn fix_shortcut_icons( ImageType::Icon }; + let mut has_changes = false; for shortcut in shortcuts { let app_id = shortcut.app_id; let icon_exsists = Path::new(&shortcut.icon).exists() && !shortcut.icon.is_empty(); for ext in ["ico", "png", "jpg", "webp"] { let path = image_folder.join(image_type.file_name(app_id, ext)); if !icon_exsists && path.exists() { - shortcut.icon = format!("\"{}\"", path.to_string_lossy()); + shortcut.icon = path.to_string_lossy().to_string(); + has_changes= true; break; } } } + has_changes } fn write_shortcut_collections>( diff --git a/src/ui/ui_import_games.rs b/src/ui/ui_import_games.rs index 7bbd3c7..d07adc1 100644 --- a/src/ui/ui_import_games.rs +++ b/src/ui/ui_import_games.rs @@ -152,7 +152,9 @@ impl MyEguiApp { let task = download_images(&settings, &usersinfo, &mut some_sender); block_on(task); //Run a second time to fix up shortcuts after images are downloaded - sync::sync_shortcuts(&settings, &import_games, &mut some_sender, &renames).unwrap(); + if let Err(e) = sync::fix_all_shortcut_icons(&settings){ + eprintln!("Could not fix shortcuts with error {e}"); + } if let Some(sender) = some_sender { let _ = sender.send(SyncProgress::Done);