Remove unused imports

This commit is contained in:
Philip Kristoffersen
2021-09-25 11:54:03 +02:00
parent caba0e459d
commit d634a26035
6 changed files with 105 additions and 90 deletions
+3
View File
@@ -0,0 +1,3 @@
[target.x86_64-pc-windows-gnu]
linker = "/usr/bin/x86_64-w64-mingw32-gcc"
ar = "/usr/x86_64-w64-mingw32/bin/ar"
+4 -2
View File
@@ -1,6 +1,7 @@
use super::{EpicGamesLauncherSettings, ManifestItem};
use std::env::{self, VarError};
use std::error::Error;
#[cfg(target_os = "windows")]
use std::env::{self};
use std::fs::{DirEntry, File};
use std::io::BufReader;
use std::path::Path;
@@ -9,6 +10,7 @@ use failure::*;
#[derive(Debug, Fail)]
pub enum EpicGamesManifestsError {
#[cfg(target_os = "linux")]
#[fail(display = "Path to EpicGamesLauncher not defined, it must be defined on linux")]
PathNotDefined,
+11 -79
View File
@@ -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();
+3 -8
View File
@@ -1,17 +1,12 @@
use std::error::Error;
use std::{
collections::HashMap,
env::{self},
fmt,
fs::File,
io::Write,
ops::Deref,
path::Path,
};
#[cfg(target_os = "windows")]
use std::env::{self};
use steam_shortcuts_util::{
parse_shortcuts, shortcut::ShortcutOwned, shortcuts_to_bytes, Shortcut,
};
use steam_shortcuts_util::{parse_shortcuts, shortcut::ShortcutOwned};
pub fn get_shortcuts_for_user(user: &SteamUsersInfo) -> ShortcutInfo {
let mut shortcuts = vec![];
+81
View File
@@ -0,0 +1,81 @@
use std::fs::File;
use std::io::Write;
use std::{collections::HashMap, path::Path};
use std::error::Error;
use steam_shortcuts_util::Shortcut;
use steamgriddb_api::Client;
use crate::steamgriddb::ImageType;
use super::CachedSearch;
pub async fn download_images<'a, 'b>(
known_images: Vec<String>,
user_data_folder: &str,
shortcuts: Vec<Shortcut<'a>>,
search: &mut CachedSearch<'b>,
client: &Client,
) -> Result<(), Box<dyn Error>> {
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];
Ok(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_data_folder).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),
}
})
}
+3 -1
View File
@@ -1,7 +1,9 @@
mod settings;
mod image_type;
mod cached_search;
mod downloader;
pub use image_type::ImageType;
pub use settings::SteamGridDbSettings;
pub use cached_search::CachedSearch;
pub use cached_search::CachedSearch;
pub use downloader::*;