From e436b425ab3db0361f755d48e7e3112bc36cf839 Mon Sep 17 00:00:00 2001 From: Philip Kristoffersen Date: Thu, 7 Oct 2021 14:28:11 +0200 Subject: [PATCH] Use hero image if no icon specified --- src/sync/symlinks.rs | 14 +++++++++----- src/sync/sync.rs | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/sync/symlinks.rs b/src/sync/symlinks.rs index f554796..b73e70a 100644 --- a/src/sync/symlinks.rs +++ b/src/sync/symlinks.rs @@ -1,9 +1,6 @@ use std::path::Path; -use steam_shortcuts_util::{ - shortcut::{ShortcutOwned}, - Shortcut, -}; +use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut}; fn get_boilr_links_path() -> std::path::PathBuf { let home = std::env::var("HOME").expect("Expected a home variable to be defined"); @@ -28,12 +25,19 @@ pub fn create_sym_links(shortcut: &ShortcutOwned) -> ShortcutOwned { (true, true) => { let exe = target_link.to_string_lossy().to_string(); let start_dir = workdir_link.to_string_lossy().to_string(); + + let icon = if shortcut.icon.eq(&shortcut.exe) { + &exe + } else { + &shortcut.icon + }; + let new_shortcut = Shortcut::new( 0, shortcut.app_name.as_str(), exe.as_str(), &start_dir.as_str(), - shortcut.icon.as_str(), + icon.as_str(), shortcut.shortcut_path.as_str(), shortcut.launch_options.as_str(), ); diff --git a/src/sync/sync.rs b/src/sync/sync.rs index 8621831..b2fc5c7 100644 --- a/src/sync/sync.rs +++ b/src/sync/sync.rs @@ -5,7 +5,7 @@ use crate::{ legendary::LegendaryPlatform, platform::Platform, settings::Settings, - steam::{get_shortcuts_for_user, get_shortcuts_paths}, + steam::{get_shortcuts_for_user, get_shortcuts_paths, SteamUsersInfo}, steamgriddb::download_images_for_users, }; use std::error::Error; @@ -27,6 +27,7 @@ pub async fn run_sync(settings: &Settings) -> Result<(), Box> { ); update_platforms(settings, &mut shortcut_info.shortcuts); + fix_shortcut_icons(user, &mut shortcut_info.shortcuts); save_shortcuts(&shortcut_info.shortcuts, Path::new(&shortcut_info.path)); let duration = start_time.elapsed(); @@ -40,6 +41,29 @@ pub async fn run_sync(settings: &Settings) -> Result<(), Box> { Ok(()) } +fn fix_shortcut_icons(user: &SteamUsersInfo, shortcuts: &mut Vec) { + let image_folder = Path::new(&user.steam_user_data_folder) + .join("config") + .join("grid"); + for shortcut in shortcuts { + #[cfg(not(target_os = "linux"))] + let replace_icon = shortcut.icon.trim().eq(""); + #[cfg(target_os = "linux")] + let replace_icon = shortcut.icon.trim().eq("") || shortcut.icon.eq(&shortcut.exe); + if replace_icon { + let app_id = steam_shortcuts_util::app_id_generator::calculate_app_id( + &shortcut.exe, + &shortcut.app_name, + ); + let new_icon = image_folder + .join(format!("{}_hero.png", app_id)) + .to_string_lossy() + .to_string(); + shortcut.icon = new_icon; + } + } +} + fn update_platforms(settings: &Settings, new_user_shortcuts: &mut Vec) { update_platform_shortcuts( &EpicPlatform::new(settings.epic_games.clone()),