Skip to content

Commit

Permalink
Add option to only download images for BoilR shortcuts (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipK authored Apr 30, 2022
1 parent 5589334 commit 44bebfc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/defaultconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ auth_key = "Write your authentication key between these quotes"
enabled = true
prefer_animated = false
banned_images = []
only_download_boilr_images = false

[origin]
enabled = true
Expand Down
23 changes: 13 additions & 10 deletions src/steamgriddb/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use tokio::sync::watch::Sender; // 0.3.1
use steam_shortcuts_util::shortcut::ShortcutOwned;
use steamgriddb_api::Client;

use super::CachedSearch;
use crate::settings::Settings;
use crate::steam::{get_shortcuts_for_user, get_users_images, SteamUsersInfo};
use crate::steamgriddb::ImageType;
use crate::sync::IsBoilRShortcut;
use crate::sync::SyncProgress;

use super::CachedSearch;

const CONCURRENT_REQUESTS: usize = 10;

pub async fn download_images_for_users<'b>(
Expand Down Expand Up @@ -150,14 +150,17 @@ async fn search_for_images_to_download(
types
};

let shortcuts_to_search_for = shortcuts.iter().filter(|s| {
// if we are missing any of the images we need to search for them
types
.iter()
.map(|t| t.file_name(s.app_id))
.any(|image| !known_images.contains(&image))
&& !s.app_name.is_empty()
});
let shortcuts_to_search_for = shortcuts
.iter()
.filter(|s| !settings.steamgrid_db.only_download_boilr_images || s.is_boilr_shortcut())
.filter(|s| {
// if we are missing any of the images we need to search for them
types
.iter()
.map(|t| t.file_name(s.app_id))
.any(|image| !known_images.contains(&image))
&& !s.app_name.is_empty()
});
let shortcuts_to_search_for: Vec<&ShortcutOwned> = shortcuts_to_search_for.collect();
if shortcuts_to_search_for.is_empty() {
return Ok(vec![]);
Expand Down
1 change: 1 addition & 0 deletions src/steamgriddb/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct SteamGridDbSettings {
pub auth_key: Option<String>,
pub prefer_animated: bool,
pub banned_images: Vec<String>,
pub only_download_boilr_images: bool,
}

impl SteamGridDbSettings {
Expand Down
1 change: 1 addition & 0 deletions src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ pub use synchronization::download_images;
pub use synchronization::get_platform_shortcuts;
pub use synchronization::run_sync;

pub use synchronization::IsBoilRShortcut;
pub use synchronization::SyncProgress;
10 changes: 5 additions & 5 deletions src/sync/synchronization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ pub async fn download_images(
}
}

trait IsBoilRShortcut {
fn is_boilr_tag(&self) -> bool;
pub trait IsBoilRShortcut {
fn is_boilr_shortcut(&self) -> bool;
}

impl IsBoilRShortcut for ShortcutOwned {
fn is_boilr_tag(&self) -> bool {
fn is_boilr_shortcut(&self) -> bool {
let boilr_tag = BOILR_TAG.to_string();
self.tags.contains(&boilr_tag) || self.dev_kit_game_id.starts_with(&boilr_tag)
}
Expand All @@ -123,7 +123,7 @@ impl IsBoilRShortcut for ShortcutOwned {
fn remove_old_shortcuts(shortcut_info: &mut ShortcutInfo) {
shortcut_info
.shortcuts
.retain(|shortcut| !shortcut.is_boilr_tag());
.retain(|shortcut| !shortcut.is_boilr_shortcut());
}

fn fix_shortcut_icons(
Expand All @@ -141,7 +141,7 @@ fn fix_shortcut_icons(
};

for shortcut in shortcuts {
if shortcut.is_boilr_tag() {
if shortcut.is_boilr_shortcut() {
let replace_icon = shortcut.icon.trim().eq("")
|| !Path::new(shortcut.icon.trim()).exists()
|| shortcut.icon.eq(&shortcut.exe);
Expand Down
4 changes: 4 additions & 0 deletions src/ui/ui_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ impl MyEguiApp {
)
});
ui.checkbox(&mut self.settings.steamgrid_db.prefer_animated, "Prefer animated images").on_hover_text("Prefer downloading animated images over static images (this can slow Steam down but looks neat)");
ui.checkbox(
&mut self.settings.steamgrid_db.only_download_boilr_images,
"Only download images for BoilR shortcuts",
);
}
ui.add_space(SECTION_SPACING);
}
Expand Down

0 comments on commit 44bebfc

Please sign in to comment.