Add option to ban download of images (#105)

This commit is contained in:
Philip Kristoffersen
2022-04-30 08:34:51 +02:00
committed by GitHub
parent 3d68192933
commit 5589334e97
4 changed files with 69 additions and 25 deletions
+1
View File
@@ -5,6 +5,7 @@ blacklisted_games = []
auth_key = "Write your authentication key between these quotes" auth_key = "Write your authentication key between these quotes"
enabled = true enabled = true
prefer_animated = false prefer_animated = false
banned_images = []
[origin] [origin]
enabled = true enabled = true
+3
View File
@@ -51,6 +51,7 @@ pub async fn download_images_for_users<'b>(
client, client,
download_animated, download_animated,
settings.steam.optimize_for_big_picture, settings.steam.optimize_for_big_picture,
settings,
) )
.await; .await;
res.unwrap_or_default() res.unwrap_or_default()
@@ -133,6 +134,7 @@ async fn search_for_images_to_download(
client: &Client, client: &Client,
download_animated: bool, download_animated: bool,
download_big_picture: bool, download_big_picture: bool,
settings: &Settings,
) -> Result<Vec<ToDownload>, Box<dyn Error>> { ) -> Result<Vec<ToDownload>, Box<dyn Error>> {
let types = { let types = {
let mut types = vec![ let mut types = vec![
@@ -185,6 +187,7 @@ async fn search_for_images_to_download(
let images_needed = shortcuts let images_needed = shortcuts
.iter() .iter()
.filter(|s| search_results.contains_key(&s.app_id)) .filter(|s| search_results.contains_key(&s.app_id))
.filter(|s| !settings.steamgrid_db.is_image_banned(&image_type, s.app_id))
.filter(|s| !known_images.contains(&image_type.file_name(s.app_id))); .filter(|s| !known_images.contains(&image_type.file_name(s.app_id)));
let image_ids: Vec<usize> = images_needed let image_ids: Vec<usize> = images_needed
.clone() .clone()
+21
View File
@@ -1,8 +1,29 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::ImageType;
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SteamGridDbSettings { pub struct SteamGridDbSettings {
pub enabled: bool, pub enabled: bool,
pub auth_key: Option<String>, pub auth_key: Option<String>,
pub prefer_animated: bool, pub prefer_animated: bool,
pub banned_images: Vec<String>,
}
impl SteamGridDbSettings {
pub fn is_image_banned(&self, image_type: &ImageType, app_id: u32) -> bool {
let ban_id = format!("{}-{}", app_id, image_type.name());
self.banned_images.contains(&ban_id)
}
pub fn set_image_banned(&mut self, image_type: &ImageType, app_id: u32, should_ban: bool) {
let ban_id = format!("{}-{}", app_id, image_type.name());
let images_banned = &mut self.banned_images;
let is_banned = images_banned.contains(&ban_id);
match (is_banned, should_ban) {
(true, false) => images_banned.retain(|i| !i.eq(&ban_id)),
(false, true) => images_banned.push(ban_id),
_ => {}
}
}
} }
+44 -25
View File
@@ -8,7 +8,7 @@ use crate::{
steamgriddb::{get_query_type, CachedSearch, ImageType, ToDownload}, steamgriddb::{get_query_type, CachedSearch, ImageType, ToDownload},
}; };
use dashmap::DashMap; use dashmap::DashMap;
use egui::{ImageButton, ScrollArea, TextureHandle}; use egui::{ImageButton, ScrollArea};
use futures::executor::block_on; use futures::executor::block_on;
use steam_shortcuts_util::shortcut::ShortcutOwned; use steam_shortcuts_util::shortcut::ShortcutOwned;
use tokio::sync::watch::{self, Receiver}; use tokio::sync::watch::{self, Receiver};
@@ -77,7 +77,7 @@ enum UserAction {
UserSelected(SteamUsersInfo), UserSelected(SteamUsersInfo),
ShortcutSelected(ShortcutOwned), ShortcutSelected(ShortcutOwned),
ImageTypeSelected(ImageType), ImageTypeSelected(ImageType),
ImageTypeCleared(ImageType), ImageTypeCleared(ImageType, bool),
ImageSelected(PossibleImage), ImageSelected(PossibleImage),
GridIdChanged(usize), GridIdChanged(usize),
BackButton, BackButton,
@@ -166,10 +166,21 @@ impl MyEguiApp {
) -> Option<UserAction> { ) -> Option<UserAction> {
ui.heading(image_type.name()); ui.heading(image_type.name());
if ui.small_button("Clear image?").on_hover_text("Click here to clear the image").clicked(){ if ui
return Some(UserAction::ImageTypeCleared(image_type.clone())); .small_button("Clear image?")
.on_hover_text("Click here to clear the image")
.clicked()
{
return Some(UserAction::ImageTypeCleared(image_type.clone(), false));
} }
if ui
.small_button("Stop downloading this image?")
.on_hover_text("Stop downloading this type of image for this shortcut at all")
.clicked()
{
return Some(UserAction::ImageTypeCleared(image_type.clone(), true));
}
match &*state.image_options.borrow() { match &*state.image_options.borrow() {
FetcStatus::Fetched(images) => { FetcStatus::Fetched(images) => {
for image in images { for image in images {
@@ -287,17 +298,40 @@ impl MyEguiApp {
UserAction::CorrectGridId => { UserAction::CorrectGridId => {
self.handle_correct_grid_request(); self.handle_correct_grid_request();
} }
UserAction::ImageTypeCleared(image_type) => { UserAction::ImageTypeCleared(image_type, should_ban) => {
let app_id = self
.image_selected_state
.selected_shortcut
.as_ref()
.unwrap()
.app_id;
self.settings
.steamgrid_db
.set_image_banned(&image_type, app_id, should_ban);
self.handle_image_type_clear(image_type); self.handle_image_type_clear(image_type);
}, }
}; };
} }
fn handle_image_type_clear(&mut self, image_type: ImageType) { fn handle_image_type_clear(&mut self, image_type: ImageType) {
let data_folder = &self.image_selected_state.steam_user.as_ref().unwrap().steam_user_data_folder; let data_folder = &self
let file_name = image_type.file_name(self.image_selected_state.selected_shortcut.as_ref().unwrap().app_id); .image_selected_state
let path = Path::new(data_folder).join("config").join("grid").join(&file_name); .steam_user
if path.exists(){ .as_ref()
.unwrap()
.steam_user_data_folder;
let file_name = image_type.file_name(
self.image_selected_state
.selected_shortcut
.as_ref()
.unwrap()
.app_id,
);
let path = Path::new(data_folder)
.join("config")
.join("grid")
.join(&file_name);
if path.exists() {
let _ = std::fs::remove_file(&path); let _ = std::fs::remove_file(&path);
} }
let key = path.to_string_lossy().to_string(); let key = path.to_string_lossy().to_string();
@@ -601,21 +635,6 @@ fn clamp_to_width(size: &mut egui::Vec2, max_width: f32) {
size.y = y; size.y = y;
} }
fn get_image(
ui: &mut egui::Ui,
shortcut: &ShortcutOwned,
folder: &std::path::Path,
image_type: &ImageType,
) -> Option<egui::TextureHandle> {
let file_name = ImageType::file_name(image_type, shortcut.app_id);
let file_path = folder.join(file_name);
let image = load_image_from_path(file_path.as_path()).map(|img_data| {
ui.ctx()
.load_texture(file_path.to_string_lossy().to_string(), img_data)
});
image
}
trait HasImageKey { trait HasImageKey {
fn key(&self, image_type: &ImageType, user_path: &Path) -> (PathBuf, String); fn key(&self, image_type: &ImageType, user_path: &Path) -> (PathBuf, String);
} }