mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Delete old images when downloading new (#228)
This commit is contained in:
+38
-18
@@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc, thread::Thread,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -9,6 +9,7 @@ use crate::{
|
|||||||
steam::{get_shortcuts_paths, SteamUsersInfo},
|
steam::{get_shortcuts_paths, SteamUsersInfo},
|
||||||
steamgriddb::{get_image_extension, get_query_type, CachedSearch, ImageType, ToDownload},
|
steamgriddb::{get_image_extension, get_query_type, CachedSearch, ImageType, ToDownload},
|
||||||
};
|
};
|
||||||
|
use config::File;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use egui::{ImageButton, ScrollArea};
|
use egui::{ImageButton, ScrollArea};
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
@@ -521,7 +522,8 @@ impl MyEguiApp {
|
|||||||
if let Ok(possible_images) = search_res {
|
if let Ok(possible_images) = search_res {
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
for possible_image in &possible_images {
|
for possible_image in &possible_images {
|
||||||
let path = thumbnails_folder.join(format!("{}.png", possible_image.id));
|
let ext = get_image_extension(&possible_image.mime);
|
||||||
|
let path = thumbnails_folder.join(format!("{}.{}",possible_image.id,ext));
|
||||||
result.push(PossibleImage {
|
result.push(PossibleImage {
|
||||||
thumbnail_path: path,
|
thumbnail_path: path,
|
||||||
mime: possible_image.mime.clone(),
|
mime: possible_image.mime.clone(),
|
||||||
@@ -529,8 +531,8 @@ impl MyEguiApp {
|
|||||||
full_url: possible_image.url.clone(),
|
full_url: possible_image.url.clone(),
|
||||||
id: possible_image.id,
|
id: possible_image.id,
|
||||||
});
|
});
|
||||||
let _ = tx.send(FetcStatus::Fetched(result.clone()));
|
|
||||||
}
|
}
|
||||||
|
let _ = tx.send(FetcStatus::Fetched(result));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -545,33 +547,47 @@ impl MyEguiApp {
|
|||||||
.image_type_selected
|
.image_type_selected
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let selected_image = self
|
let selected_shortcut = self
|
||||||
.image_selected_state
|
.image_selected_state
|
||||||
.selected_shortcut
|
.selected_shortcut
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let ext = get_image_extension(&image.mime);
|
let ext = get_image_extension(&image.mime);
|
||||||
let to = Path::new(&user.steam_user_data_folder)
|
let to_download_to_path = Path::new(&user.steam_user_data_folder)
|
||||||
.join("config")
|
.join("config")
|
||||||
.join("grid")
|
.join("grid")
|
||||||
.join(selected_image_type.file_name(selected_image.app_id(), ext));
|
.join(selected_image_type.file_name(selected_shortcut.app_id(), ext));
|
||||||
|
|
||||||
if to.exists() {
|
//Delete old possible images
|
||||||
let old_key = to.to_string_lossy().to_string();
|
|
||||||
let new_key = image.thumbnail_path.to_string_lossy().to_string();
|
let data_folder = Path::new(&user.steam_user_data_folder);
|
||||||
let _ = self.image_selected_state.image_handles.remove(&old_key);
|
|
||||||
let swap = self.image_selected_state.image_handles.get(&new_key);
|
|
||||||
if let Some(swp) = swap {
|
//Keep deleting images of this type untill we don't find any more
|
||||||
self.image_selected_state
|
let mut path = self.get_shortcut_image_path(data_folder);
|
||||||
.image_handles
|
while Path::new(&path).exists(){
|
||||||
.insert(old_key, swp.value().clone());
|
let _= std::fs::remove_file(&path);
|
||||||
}
|
path = self.get_shortcut_image_path(data_folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
let app_name = selected_image.name();
|
//Put the loaded thumbnail into the image handler map, we can use that for preview
|
||||||
|
let full_image_key = to_download_to_path.to_string_lossy().to_string();
|
||||||
|
let _ = self.image_selected_state.image_handles.remove(&full_image_key);
|
||||||
|
let thumbnail_key = image.thumbnail_path.to_string_lossy().to_string();
|
||||||
|
let thumbnail = self.image_selected_state.image_handles.remove(&thumbnail_key);
|
||||||
|
if let Some((key,thumbnail)) = thumbnail {
|
||||||
|
dbg!(&full_image_key);
|
||||||
|
dbg!(&key);
|
||||||
|
|
||||||
|
self.image_selected_state
|
||||||
|
.image_handles
|
||||||
|
.insert(full_image_key, thumbnail);
|
||||||
|
}
|
||||||
|
|
||||||
|
let app_name = selected_shortcut.name();
|
||||||
let to_download = ToDownload {
|
let to_download = ToDownload {
|
||||||
path: to,
|
path: to_download_to_path,
|
||||||
url: image.full_url.clone(),
|
url: image.full_url.clone(),
|
||||||
app_name: app_name.to_string(),
|
app_name: app_name.to_string(),
|
||||||
image_type: *selected_image_type,
|
image_type: *selected_image_type,
|
||||||
@@ -587,6 +603,10 @@ impl MyEguiApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_shortcut_image_path(&self, data_folder: &Path) -> String {
|
||||||
|
self.image_selected_state.selected_shortcut.as_ref().unwrap().key(&self.image_selected_state.image_type_selected.unwrap(), data_folder).1
|
||||||
|
}
|
||||||
|
|
||||||
fn clear_loaded_images(&mut self) {
|
fn clear_loaded_images(&mut self) {
|
||||||
if let FetcStatus::Fetched(options) = &*self.image_selected_state.image_options.borrow() {
|
if let FetcStatus::Fetched(options) = &*self.image_selected_state.image_options.borrow() {
|
||||||
for option in options {
|
for option in options {
|
||||||
|
|||||||
Reference in New Issue
Block a user