Use hero image if no icon specified

This commit is contained in:
Philip Kristoffersen
2021-10-07 14:28:11 +02:00
parent 978eaaa1e2
commit e436b425ab
2 changed files with 34 additions and 6 deletions
+9 -5
View File
@@ -1,9 +1,6 @@
use std::path::Path; use std::path::Path;
use steam_shortcuts_util::{ use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
shortcut::{ShortcutOwned},
Shortcut,
};
fn get_boilr_links_path() -> std::path::PathBuf { fn get_boilr_links_path() -> std::path::PathBuf {
let home = std::env::var("HOME").expect("Expected a home variable to be defined"); 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) => { (true, true) => {
let exe = target_link.to_string_lossy().to_string(); let exe = target_link.to_string_lossy().to_string();
let start_dir = workdir_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( let new_shortcut = Shortcut::new(
0, 0,
shortcut.app_name.as_str(), shortcut.app_name.as_str(),
exe.as_str(), exe.as_str(),
&start_dir.as_str(), &start_dir.as_str(),
shortcut.icon.as_str(), icon.as_str(),
shortcut.shortcut_path.as_str(), shortcut.shortcut_path.as_str(),
shortcut.launch_options.as_str(), shortcut.launch_options.as_str(),
); );
+25 -1
View File
@@ -5,7 +5,7 @@ use crate::{
legendary::LegendaryPlatform, legendary::LegendaryPlatform,
platform::Platform, platform::Platform,
settings::Settings, settings::Settings,
steam::{get_shortcuts_for_user, get_shortcuts_paths}, steam::{get_shortcuts_for_user, get_shortcuts_paths, SteamUsersInfo},
steamgriddb::download_images_for_users, steamgriddb::download_images_for_users,
}; };
use std::error::Error; use std::error::Error;
@@ -27,6 +27,7 @@ pub async fn run_sync(settings: &Settings) -> Result<(), Box<dyn Error>> {
); );
update_platforms(settings, &mut shortcut_info.shortcuts); 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)); save_shortcuts(&shortcut_info.shortcuts, Path::new(&shortcut_info.path));
let duration = start_time.elapsed(); let duration = start_time.elapsed();
@@ -40,6 +41,29 @@ pub async fn run_sync(settings: &Settings) -> Result<(), Box<dyn Error>> {
Ok(()) Ok(())
} }
fn fix_shortcut_icons(user: &SteamUsersInfo, shortcuts: &mut Vec<ShortcutOwned>) {
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<ShortcutOwned>) { fn update_platforms(settings: &Settings, new_user_shortcuts: &mut Vec<ShortcutOwned>) {
update_platform_shortcuts( update_platform_shortcuts(
&EpicPlatform::new(settings.epic_games.clone()), &EpicPlatform::new(settings.epic_games.clone()),