Skip to content

Commit

Permalink
Correct logging when no need for download
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipK committed Oct 7, 2021
1 parent fd13ce6 commit 978eaaa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/steam/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn get_shortcuts_for_user(user: &SteamUsersInfo) -> ShortcutInfo {
.unwrap()
.iter()
.map(|s| s.to_owned())
.collect();
.collect();
Path::new(&shortcut_path).to_path_buf()
}
None => {
Expand Down Expand Up @@ -164,11 +164,13 @@ impl Error for SteamUsersDataEmpty {
}
pub fn get_users_images(user: &SteamUsersInfo) -> Result<Vec<String>, Box<dyn Error>> {
let grid_folder = Path::new(user.steam_user_data_folder.as_str()).join("config/grid");
std::fs::create_dir_all(&grid_folder)?;
if !grid_folder.exists() {
std::fs::create_dir_all(&grid_folder)?;
}
let user_folders = std::fs::read_dir(&grid_folder)?;
let file_names = user_folders
.filter_map(|image| image.ok())
.map(|image| image.file_name().into_string().unwrap())
.map(|image| image.file_name().to_string_lossy().to_string())
.collect();
Ok(file_names)
}
35 changes: 19 additions & 16 deletions src/steamgriddb/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ use super::CachedSearch;
const CONCURRENT_REQUESTS: usize = 10;

pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec<SteamUsersInfo>) {
let start_time = std::time::Instant::now();

let auth_key = &settings.steamgrid_db.auth_key;
if let Some(auth_key) = auth_key {
println!("Checking for game images");
let start_time = std::time::Instant::now();
let client = steamgriddb_api::Client::new(auth_key);
let search = CachedSearch::new(&client);
let search = &search;
Expand All @@ -47,20 +46,23 @@ pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec<Stea
.collect::<Vec<Vec<ToDownload>>>()
.await;
let to_downloads = to_downloads.iter().flatten().collect::<Vec<&ToDownload>>();
search.save();

stream::iter(to_downloads)
.map(|to_download| async move {
if let Err(e) = download_to_download(&to_download).await {
println!("Error downloading {:?}: {}", &to_download.path, e);
}
})
.buffer_unordered(CONCURRENT_REQUESTS)
.collect::<Vec<()>>()
.await;
let duration = start_time.elapsed();
if !to_downloads.is_empty() {
search.save();

println!("Finished getting images in: {:?}", duration);
stream::iter(to_downloads)
.map(|to_download| async move {
if let Err(e) = download_to_download(&to_download).await {
println!("Error downloading {:?}: {}", &to_download.path, e);
}
})
.buffer_unordered(CONCURRENT_REQUESTS)
.collect::<Vec<()>>()
.await;
let duration = start_time.elapsed();
println!("Finished getting images in: {:?}", duration);
} else {
println!("No images needed");
}
} else {
println!("Steamgrid DB Auth Key not found, please add one as described here: https://github.com/PhilipK/steam_shortcuts_sync#configuration");
}
Expand All @@ -82,7 +84,8 @@ async fn search_fo_to_download<'b>(
// if we are missing any of the images we need to search for them
images.iter().any(|image| !known_images.contains(&image)) && "" != s.app_name
});
if shortcuts_to_search_for.clone().count() == 0 {
let shortcuts_to_search_for: Vec<&ShortcutOwned> = shortcuts_to_search_for.collect();
if shortcuts_to_search_for.is_empty() {
return Ok(vec![]);
}
let mut search_results = HashMap::new();
Expand Down

0 comments on commit 978eaaa

Please sign in to comment.