Skip to content

Commit

Permalink
Use hero image if no icon specified
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipK committed Oct 7, 2021
1 parent 978eaaa commit e436b42
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/sync/symlinks.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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(),
);
Expand Down
26 changes: 25 additions & 1 deletion src/sync/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +27,7 @@ pub async fn run_sync(settings: &Settings) -> Result<(), Box<dyn Error>> {
);

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();
Expand All @@ -40,6 +41,29 @@ pub async fn run_sync(settings: &Settings) -> Result<(), Box<dyn Error>> {
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>) {
update_platform_shortcuts(
&EpicPlatform::new(settings.epic_games.clone()),
Expand Down

0 comments on commit e436b42

Please sign in to comment.