Fix cargo clippy suggestions

This commit is contained in:
Philip
2021-10-10 13:49:00 +02:00
parent 0bcbdba158
commit 1a14e24173
8 changed files with 35 additions and 48 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ impl From<ManifestItem> for ShortcutOwned {
manifest.install_location, manifest.launch_executable
);
let mut start_dir = manifest.install_location.clone();
if !manifest.install_location.starts_with("\"") {
if !manifest.install_location.starts_with('"') {
start_dir = format!("\"{}\"", manifest.install_location);
}
let shortcut = Shortcut::new(
+4 -10
View File
@@ -54,8 +54,7 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
if path.exists() {
let dirs = path.read_dir();
if let Ok(dirs) = dirs {
for dir in dirs {
if let Ok(dir) = dir {
for dir in dirs.flatten() {
if let Ok(file_type) = dir.file_type() {
if file_type.is_dir() {
game_folders.push(dir.path());
@@ -65,21 +64,17 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
}
}
}
}
let mut games = vec![];
for game_folder in &game_folders {
if let Ok(files) = game_folder.read_dir() {
for file in files {
if let Ok(file) = file {
for file in files.flatten() {
if let Some(file_name) = file.file_name().to_str() {
if file_name.starts_with("goggame-") {
if let Some(extension) = file.path().extension() {
if let Some(extension) = extension.to_str() {
if extension == "info" {
// Finally we know we can parse this as a game
if let Ok(content) =
std::fs::read_to_string(file.path())
{
if let Ok(content) = std::fs::read_to_string(file.path()) {
if let Ok(gog_game) =
serde_json::from_str::<GogGame>(&content)
{
@@ -94,7 +89,6 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
}
}
}
}
let mut shortcuts = vec![];
for (game, game_folder) in games {
@@ -114,7 +108,7 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
Some(working_dir) => game_folder
.join(working_dir)
.to_str()
.unwrap_or(folder_path.as_str())
.unwrap_or_else(|| folder_path.as_str())
.to_string(),
None => folder_path.to_string(),
};
+1 -2
View File
@@ -2,7 +2,6 @@ use super::butler_db_parser::*;
use super::receipt::Receipt;
use super::{ItchGame, ItchSettings};
use crate::platform::Platform;
use _core::iter::FromIterator;
use failure::*;
use flate2::read::GzDecoder;
use std::collections::HashSet;
@@ -50,7 +49,7 @@ impl Platform<ItchGame, ItchErrors> for ItchPlatform {
}?;
//This is done to remove douplicates
let paths: HashSet<&DbPaths> = HashSet::from_iter(paths.iter());
let paths: HashSet<&DbPaths> = paths.iter().collect();
let res = paths.iter().filter_map(|e| dbpath_to_game(*e)).collect();
Ok(res)
+1 -1
View File
@@ -16,7 +16,7 @@ impl From<LegendaryGame> for ShortcutOwned {
let exe = format!("\"{}\\{}\"", game.install_path, game.executable);
let launch = format!("legendary launch {}", game.app_name);
let mut start_dir = game.install_path.clone();
if !game.install_path.starts_with("\"") {
if !game.install_path.starts_with('"') {
start_dir = format!("\"{}\"", game.install_path);
}
let shortcut = Shortcut::new(
+3 -5
View File
@@ -32,7 +32,7 @@ impl Platform<OriginGame, OriginErrors> for OriginPlatform {
.settings
.path
.clone()
.unwrap_or_else(|| get_default_location()),
.unwrap_or_else(get_default_location),
)
.join("LocalContent");
if !origin_folder.exists() {
@@ -59,7 +59,7 @@ impl Platform<OriginGame, OriginErrors> for OriginPlatform {
None => None,
};
id.map(|id| OriginGame {
id: id.to_string(),
id,
title: game_title,
})
});
@@ -72,8 +72,7 @@ fn get_folder_mfst_file_content(game_folder_path: &Path) -> Option<String> {
if let Ok(game_folder_files) = game_folder_files {
let mfst_file = game_folder_files
.filter_map(|file| file.ok())
.filter(is_mfst_file)
.next()
.find(is_mfst_file)
.map(|file| std::fs::read_to_string(&file.path()));
return match mfst_file {
Some(mfst_file) => mfst_file.ok(),
@@ -99,7 +98,6 @@ fn parse_id_from_file(i: &str) -> nom::IResult<&str, &str> {
#[cfg(target_os = "linux")]
pub fn get_default_location() -> String {
//TODO implement this for linux:
// https://www.toptensoftware.com/blog/running-ea-origin-games-under-linux-via-steam-and-proton/
+9 -13
View File
@@ -17,7 +17,7 @@ use super::CachedSearch;
const CONCURRENT_REQUESTS: usize = 10;
pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec<SteamUsersInfo>) {
pub async fn download_images_for_users<'b>(settings: &Settings, users: &[SteamUsersInfo]) {
let auth_key = &settings.steamgrid_db.auth_key;
if let Some(auth_key) = auth_key {
println!("Checking for game images");
@@ -51,7 +51,7 @@ pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec<Stea
stream::iter(to_downloads)
.map(|to_download| async move {
if let Err(e) = download_to_download(&to_download).await {
if let Err(e) = download_to_download(to_download).await {
println!("Error downloading {:?}: {}", &to_download.path, e);
}
})
@@ -68,11 +68,11 @@ pub async fn download_images_for_users<'b>(settings: &Settings, users: &Vec<Stea
}
}
async fn search_fo_to_download<'b>(
async fn search_fo_to_download(
known_images: Vec<String>,
user_data_folder: &str,
shortcuts: &Vec<ShortcutOwned>,
search: &CachedSearch<'b>,
shortcuts: &[ShortcutOwned],
search: &CachedSearch<'_>,
client: &Client,
) -> Result<Vec<ToDownload>, Box<dyn Error>> {
let shortcuts_to_search_for = shortcuts.iter().filter(|s| {
@@ -82,7 +82,7 @@ async fn search_fo_to_download<'b>(
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)) && "" != s.app_name
images.iter().any(|image| !known_images.contains(image)) && !s.app_name.is_empty()
});
let shortcuts_to_search_for: Vec<&ShortcutOwned> = shortcuts_to_search_for.collect();
if shortcuts_to_search_for.is_empty() {
@@ -96,20 +96,16 @@ async fn search_fo_to_download<'b>(
return None;
}
let search_result = search_result.unwrap();
if search_result.is_none() {
return None;
}
search_result?;
let search_result = search_result.unwrap();
Some((s.app_id, search_result))
})
.buffer_unordered(CONCURRENT_REQUESTS)
.collect::<Vec<Option<(u32, usize)>>>()
.await;
for r in search_results_a {
if let Some((app_id, search)) = r {
for (app_id, search) in search_results_a.into_iter().flatten() {
search_results.insert(app_id, search);
}
}
let types = vec![ImageType::Logo, ImageType::Hero, ImageType::Grid];
let mut to_download = vec![];
for image_type in types {
@@ -120,7 +116,7 @@ async fn search_fo_to_download<'b>(
let image_ids: Vec<usize> = images_needed
.clone()
.filter_map(|s| search_results.get(&s.app_id))
.map(|search| *search)
.copied()
.collect();
use steamgriddb_api::query_parameters::QueryType::*;
let query_type = match image_type {
+2 -2
View File
@@ -1,5 +1,5 @@
#[cfg(target_os = "linux")]
mod symlinks;
mod sync;
mod synchronization;
pub use sync::run_sync;
pub use synchronization::run_sync;
@@ -92,7 +92,7 @@ fn update_platforms(settings: &Settings, new_user_shortcuts: &mut Vec<ShortcutOw
);
}
fn save_shortcuts(shortcuts: &Vec<ShortcutOwned>, path: &Path) {
fn save_shortcuts(shortcuts: &[ShortcutOwned], path: &Path) {
let mut shortcuts_refs = vec![];
for shortcut in shortcuts {
shortcuts_refs.push(shortcut.borrow());