mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Add option to ban download of images (#105)
This commit is contained in:
@@ -5,6 +5,7 @@ blacklisted_games = []
|
||||
auth_key = "Write your authentication key between these quotes"
|
||||
enabled = true
|
||||
prefer_animated = false
|
||||
banned_images = []
|
||||
|
||||
[origin]
|
||||
enabled = true
|
||||
|
||||
@@ -51,6 +51,7 @@ pub async fn download_images_for_users<'b>(
|
||||
client,
|
||||
download_animated,
|
||||
settings.steam.optimize_for_big_picture,
|
||||
settings,
|
||||
)
|
||||
.await;
|
||||
res.unwrap_or_default()
|
||||
@@ -133,6 +134,7 @@ async fn search_for_images_to_download(
|
||||
client: &Client,
|
||||
download_animated: bool,
|
||||
download_big_picture: bool,
|
||||
settings: &Settings,
|
||||
) -> Result<Vec<ToDownload>, Box<dyn Error>> {
|
||||
let types = {
|
||||
let mut types = vec![
|
||||
@@ -185,6 +187,7 @@ async fn search_for_images_to_download(
|
||||
let images_needed = shortcuts
|
||||
.iter()
|
||||
.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)));
|
||||
let image_ids: Vec<usize> = images_needed
|
||||
.clone()
|
||||
|
||||
@@ -1,8 +1,29 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::ImageType;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct SteamGridDbSettings {
|
||||
pub enabled: bool,
|
||||
pub auth_key: Option<String>,
|
||||
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
@@ -8,7 +8,7 @@ use crate::{
|
||||
steamgriddb::{get_query_type, CachedSearch, ImageType, ToDownload},
|
||||
};
|
||||
use dashmap::DashMap;
|
||||
use egui::{ImageButton, ScrollArea, TextureHandle};
|
||||
use egui::{ImageButton, ScrollArea};
|
||||
use futures::executor::block_on;
|
||||
use steam_shortcuts_util::shortcut::ShortcutOwned;
|
||||
use tokio::sync::watch::{self, Receiver};
|
||||
@@ -77,7 +77,7 @@ enum UserAction {
|
||||
UserSelected(SteamUsersInfo),
|
||||
ShortcutSelected(ShortcutOwned),
|
||||
ImageTypeSelected(ImageType),
|
||||
ImageTypeCleared(ImageType),
|
||||
ImageTypeCleared(ImageType, bool),
|
||||
ImageSelected(PossibleImage),
|
||||
GridIdChanged(usize),
|
||||
BackButton,
|
||||
@@ -166,10 +166,21 @@ impl MyEguiApp {
|
||||
) -> Option<UserAction> {
|
||||
ui.heading(image_type.name());
|
||||
|
||||
if ui.small_button("Clear image?").on_hover_text("Click here to clear the image").clicked(){
|
||||
return Some(UserAction::ImageTypeCleared(image_type.clone()));
|
||||
if ui
|
||||
.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() {
|
||||
FetcStatus::Fetched(images) => {
|
||||
for image in images {
|
||||
@@ -287,17 +298,40 @@ impl MyEguiApp {
|
||||
UserAction::CorrectGridId => {
|
||||
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);
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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 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 data_folder = &self
|
||||
.image_selected_state
|
||||
.steam_user
|
||||
.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 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;
|
||||
}
|
||||
|
||||
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 {
|
||||
fn key(&self, image_type: &ImageType, user_path: &Path) -> (PathBuf, String);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user