This commit is contained in:
Philip Kristoffersen
2022-10-03 21:28:52 +02:00
+17 -5
View File
@@ -1,3 +1,4 @@
use eframe::epaint::ahash::HashSet;
use steam_shortcuts_util::{ use steam_shortcuts_util::{
calculate_app_id_for_shortcut, shortcut::ShortcutOwned, shortcuts_to_bytes, Shortcut, calculate_app_id_for_shortcut, shortcut::ShortcutOwned, shortcuts_to_bytes, Shortcut,
}; };
@@ -7,8 +8,8 @@ use crate::{
platforms::{GamesPlatform, ShortcutToImport}, platforms::{GamesPlatform, ShortcutToImport},
settings::Settings, settings::Settings,
steam::{ steam::{
get_shortcuts_for_user, get_shortcuts_paths, write_collections, get_shortcuts_for_user, get_shortcuts_paths, write_collections, Collection, ShortcutInfo,
Collection, ShortcutInfo, SteamUsersInfo, SteamUsersInfo,
}, },
steamgriddb::{download_images_for_users, ImageType}, steamgriddb::{download_images_for_users, ImageType},
}; };
@@ -60,7 +61,7 @@ pub fn sync_shortcuts(
.flat_map(|s| s.1.clone()) .flat_map(|s| s.1.clone())
.filter(|s| !settings.blacklisted_games.contains(&s.app_id)) .filter(|s| !settings.blacklisted_games.contains(&s.app_id))
.collect(); .collect();
for shortcut in &mut all_shortcuts{ for shortcut in &mut all_shortcuts {
shortcut.dev_kit_game_id = BOILR_TAG.to_string(); shortcut.dev_kit_game_id = BOILR_TAG.to_string();
} }
if let Some(sender) = &sender { if let Some(sender) = &sender {
@@ -96,6 +97,7 @@ pub fn sync_shortcuts(
); );
remove_old_shortcuts(&mut shortcut_info); remove_old_shortcuts(&mut shortcut_info);
remove_shortcuts_with_same_appid(&mut shortcut_info, &all_shortcuts);
shortcut_info.shortcuts.extend(all_shortcuts.clone()); shortcut_info.shortcuts.extend(all_shortcuts.clone());
@@ -145,6 +147,16 @@ impl IsBoilRShortcut for ShortcutOwned {
} }
} }
fn remove_shortcuts_with_same_appid(
shortcut_info: &mut ShortcutInfo,
new_shortcuts: &[ShortcutOwned],
) {
let app_ids: HashSet<u32> = new_shortcuts.iter().map(|s| s.app_id).collect();
shortcut_info
.shortcuts
.retain(|shortcut| !app_ids.contains(&shortcut.app_id));
}
fn remove_old_shortcuts(shortcut_info: &mut ShortcutInfo) { fn remove_old_shortcuts(shortcut_info: &mut ShortcutInfo) {
shortcut_info shortcut_info
.shortcuts .shortcuts
@@ -174,7 +186,7 @@ fn fix_shortcut_icons(
for ext in ["ico", "png", "jpg", "webp"] { for ext in ["ico", "png", "jpg", "webp"] {
let path = image_folder.join(image_type.file_name(app_id, ext)); let path = image_folder.join(image_type.file_name(app_id, ext));
if path.exists() { if path.exists() {
shortcut.icon = path.to_string_lossy().to_string(); shortcut.icon = format!("\"{}\"", path.to_string_lossy().to_string());
break; break;
} }
} }
@@ -205,7 +217,7 @@ pub fn get_platform_shortcuts(
) -> eyre::Result<Vec<ShortcutToImport>> { ) -> eyre::Result<Vec<ShortcutToImport>> {
if platform.enabled() { if platform.enabled() {
platform.get_shortcut_info() platform.get_shortcut_info()
}else{ } else {
Ok(vec![]) Ok(vec![])
} }
} }