Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/PhilipK/BoilR
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipK committed Oct 3, 2022
2 parents ecfca36 + ef44c9d commit ea6b913
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/sync/synchronization.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use eframe::epaint::ahash::HashSet;
use steam_shortcuts_util::{
calculate_app_id_for_shortcut, shortcut::ShortcutOwned, shortcuts_to_bytes, Shortcut,
};
Expand All @@ -7,8 +8,8 @@ use crate::{
platforms::{GamesPlatform, ShortcutToImport},
settings::Settings,
steam::{
get_shortcuts_for_user, get_shortcuts_paths, write_collections,
Collection, ShortcutInfo, SteamUsersInfo,
get_shortcuts_for_user, get_shortcuts_paths, write_collections, Collection, ShortcutInfo,
SteamUsersInfo,
},
steamgriddb::{download_images_for_users, ImageType},
};
Expand Down Expand Up @@ -60,7 +61,7 @@ pub fn sync_shortcuts(
.flat_map(|s| s.1.clone())
.filter(|s| !settings.blacklisted_games.contains(&s.app_id))
.collect();
for shortcut in &mut all_shortcuts{
for shortcut in &mut all_shortcuts {
shortcut.dev_kit_game_id = BOILR_TAG.to_string();
}
if let Some(sender) = &sender {
Expand Down Expand Up @@ -96,6 +97,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());

Expand Down Expand Up @@ -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) {
shortcut_info
.shortcuts
Expand Down Expand Up @@ -174,7 +186,7 @@ fn fix_shortcut_icons(
for ext in ["ico", "png", "jpg", "webp"] {
let path = image_folder.join(image_type.file_name(app_id, ext));
if path.exists() {
shortcut.icon = path.to_string_lossy().to_string();
shortcut.icon = format!("\"{}\"", path.to_string_lossy().to_string());
break;
}
}
Expand Down Expand Up @@ -205,7 +217,7 @@ pub fn get_platform_shortcuts(
) -> eyre::Result<Vec<ShortcutToImport>> {
if platform.enabled() {
platform.get_shortcut_info()
}else{
} else {
Ok(vec![])
}
}
Expand Down

0 comments on commit ea6b913

Please sign in to comment.