diff --git a/src/steam/utils.rs b/src/steam/utils.rs index 3eaca71..111d946 100644 --- a/src/steam/utils.rs +++ b/src/steam/utils.rs @@ -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 => { @@ -164,11 +164,13 @@ impl Error for SteamUsersDataEmpty { } pub fn get_users_images(user: &SteamUsersInfo) -> Result, Box> { 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) } diff --git a/src/steamgriddb/downloader.rs b/src/steamgriddb/downloader.rs index f5000e7..506ca09 100644 --- a/src/steamgriddb/downloader.rs +++ b/src/steamgriddb/downloader.rs @@ -18,11 +18,10 @@ use super::CachedSearch; const CONCURRENT_REQUESTS: usize = 10; pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec) { - 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; @@ -47,20 +46,23 @@ pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec>>() .await; let to_downloads = to_downloads.iter().flatten().collect::>(); - 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::>() - .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::>() + .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"); } @@ -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();