mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Remove unused imports
This commit is contained in:
+11
-79
@@ -1,13 +1,5 @@
|
||||
use crate::steamgriddb::{CachedSearch, ImageType};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env::{self},
|
||||
fmt,
|
||||
fs::File,
|
||||
io::Write,
|
||||
ops::Deref,
|
||||
path::Path,
|
||||
};
|
||||
use crate::steamgriddb::{download_images, CachedSearch};
|
||||
use std::{fs::File, io::Write, path::Path};
|
||||
mod egs;
|
||||
mod legendary;
|
||||
mod platform;
|
||||
@@ -23,10 +15,7 @@ use crate::{
|
||||
steam::{get_shortcuts_for_user, get_shortcuts_paths, get_users_images},
|
||||
};
|
||||
use std::error::Error;
|
||||
use steam_shortcuts_util::{
|
||||
parse_shortcuts, shortcut::ShortcutOwned, shortcuts_to_bytes, Shortcut,
|
||||
};
|
||||
use steamgriddb_api::{search::SearchResult, Client};
|
||||
use steam_shortcuts_util::{shortcut::ShortcutOwned, shortcuts_to_bytes, Shortcut};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
@@ -66,71 +55,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
save_shortcuts(&shortcuts, Path::new(&shortcut_info.path));
|
||||
|
||||
let known_images = get_users_images(user).unwrap();
|
||||
|
||||
let shortcuts_to_search_for = shortcuts.iter().filter(|s| {
|
||||
let images = vec![
|
||||
format!("{}_hero.png", s.app_id),
|
||||
format!("{}p.png", s.app_id),
|
||||
format!("{}_logo.png", s.app_id),
|
||||
];
|
||||
// if we are missing any of the images we need to search for them
|
||||
images.iter().any(|image| !known_images.contains(&image))
|
||||
});
|
||||
|
||||
let mut search_results = HashMap::new();
|
||||
for s in shortcuts_to_search_for {
|
||||
println!("Searching for {}", s.app_name);
|
||||
let search = search.search(s.app_id, s.app_name).await?;
|
||||
if let Some(search) = search {
|
||||
search_results.insert(s.app_id, search);
|
||||
}
|
||||
}
|
||||
|
||||
let types = vec![ImageType::Logo, ImageType::Hero, ImageType::Grid];
|
||||
for image_type in types {
|
||||
let mut images_needed = shortcuts
|
||||
.iter()
|
||||
.filter(|s| search_results.contains_key(&s.app_id))
|
||||
.filter(|s| !known_images.contains(&image_type.file_name(s.app_id)));
|
||||
let image_ids: Vec<usize> = images_needed
|
||||
.clone()
|
||||
.filter_map(|s| search_results.get(&s.app_id))
|
||||
.map(|search| *search)
|
||||
.collect();
|
||||
|
||||
let query_type = match image_type {
|
||||
ImageType::Hero => steamgriddb_api::query_parameters::QueryType::Hero(None),
|
||||
ImageType::Grid => steamgriddb_api::query_parameters::QueryType::Grid(None),
|
||||
ImageType::Logo => steamgriddb_api::query_parameters::QueryType::Logo(None),
|
||||
};
|
||||
|
||||
match client
|
||||
.get_images_for_ids(image_ids.as_slice(), &query_type)
|
||||
.await
|
||||
{
|
||||
Ok(images) => {
|
||||
for image in images {
|
||||
if let Some(shortcut) = images_needed.next() {
|
||||
if let Ok(image) = image {
|
||||
let grid_folder = Path::new(user.steam_user_data_folder.as_str())
|
||||
.join("config/grid");
|
||||
let path = grid_folder.join(image_type.file_name(shortcut.app_id));
|
||||
println!(
|
||||
"Downloading {} to {}",
|
||||
image.url,
|
||||
path.as_path().to_str().unwrap()
|
||||
);
|
||||
let mut file = File::create(path).unwrap();
|
||||
let response = reqwest::get(image.url).await?;
|
||||
let content = response.bytes().await?;
|
||||
file.write(&content).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => println!("Error getting images: {}", err),
|
||||
}
|
||||
}
|
||||
download_images(
|
||||
known_images,
|
||||
user.steam_user_data_folder.as_str(),
|
||||
shortcuts,
|
||||
&mut search,
|
||||
&client,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
search.save();
|
||||
|
||||
Reference in New Issue
Block a user