Clippy fixes (#309)

* Automatic clippy fixes

* Manual clippy corrections
This commit is contained in:
Philip Kristoffersen
2023-01-04 20:28:43 +01:00
committed by GitHub
parent f1591b7818
commit 4ed9490c57
21 changed files with 42 additions and 46 deletions
+1 -1
View File
@@ -25,5 +25,5 @@ fn main() -> Result<()> {
fn ensure_config_folder() {
let path = config::get_config_folder();
let _ = std::fs::create_dir_all(&path);
let _ = std::fs::create_dir_all(path);
}
+6 -6
View File
@@ -71,18 +71,18 @@ fn get_manifest_item(dir_entry: DirEntry, _path: Option<PathBuf>) -> Option<Mani
item.manifest_location = compat_folder
.join("pfx")
.join("dosdevices")
.join(&item.manifest_location[0..2].to_lowercase())
.join(&item.manifest_location[3..].replace('\\', "/"))
.to_path_buf()
.join(item.manifest_location[0..2].to_lowercase())
.join(item.manifest_location[3..].replace('\\', "/"))
.to_string_lossy()
.to_string();
item.install_location = compat_folder
.join("pfx")
.join("dosdevices")
.join(&item.install_location[0..2].to_lowercase())
.join(&item.install_location[3..].replace('\\', "/"))
.to_path_buf()
.join(item.install_location[0..2].to_lowercase())
.join(item.install_location[3..].replace('\\', "/"))
.to_string_lossy()
.to_string();
+1 -1
View File
@@ -31,7 +31,7 @@ mod unix {
.join("steamapps")
.join("compatdata");
if let Ok(compat_folder) = std::fs::read_dir(&compat_folder_path) {
if let Ok(compat_folder) = std::fs::read_dir(compat_folder_path) {
for dir in compat_folder.flatten() {
let binary_path = dir
.path()
+1 -1
View File
@@ -40,7 +40,7 @@ impl From<GogShortcut> for ShortcutOwned {
fn from(gogs: GogShortcut) -> Self {
let exe = Path::new(&gogs.game_folder).join(gogs.path);
let icon_file = format!("goggame-{}.ico", gogs.game_id);
let icon_path = Path::new(&gogs.game_folder).join(&icon_file);
let icon_path = Path::new(&gogs.game_folder).join(icon_file);
let icon = if icon_path.exists() {
icon_path.to_str().unwrap().to_string()
} else {
+2 -2
View File
@@ -86,7 +86,7 @@ fn get_shortcuts_from_games(games: Vec<(GogGame, PathBuf)>) -> Vec<GogShortcut>
|| t.category.as_ref().unwrap_or(&String::from("")) == "game")
}) {
if let Some(task_path) = &primary_task.path {
let full_path = game_folder.join(&task_path);
let full_path = game_folder.join(task_path);
if let Some(full_path) = full_path.to_str() {
let folder_path = folder_path.to_string();
@@ -201,7 +201,7 @@ fn fix_paths(wine_c_drive: &str, paths: Vec<String>) -> Vec<String> {
}
fn get_install_locations(path: PathBuf) -> eyre::Result<Vec<String>> {
let data_res = std::fs::read_to_string(&path)?;
let data_res = std::fs::read_to_string(path)?;
let config: GogConfig = serde_json::from_str(&data_res)?;
let path_vec = match config.library_path {
Some(path) => vec![path],
+2 -2
View File
@@ -42,7 +42,7 @@ impl ItchPlatform {
//This is done to paths dedupe
let paths: HashSet<&DbPaths> = paths.iter().collect();
let res = paths.iter().filter_map(|e| dbpath_to_game(*e)).collect();
let res = paths.iter().filter_map(|e| dbpath_to_game(e)).collect();
Ok(res)
}
}
@@ -57,7 +57,7 @@ fn dbpath_to_game(paths: &DbPaths) -> Option<ItchGame> {
paths
.paths
.iter()
.filter(|p| Path::new(&paths.base_path).join(&p).is_executable())
.filter(|p| Path::new(&paths.base_path).join(p).is_executable())
.find_map(|executable| {
let gz_bytes = std::fs::read(&recipt).unwrap();
let mut d = GzDecoder::new(gz_bytes.as_slice());
+2 -4
View File
@@ -80,10 +80,8 @@ impl GamesPlatform for MiniGalaxyPlatform{
};
let dirs = games_folder.read_dir()?;
let mut game_folders = vec![];
for game_folder in dirs{
if let Ok(game_folder) = game_folder{
game_folders.push(game_folder.path().to_owned());
}
for game_folder in dirs.flatten(){
game_folders.push(game_folder.path().to_owned());
}
let gog_games = crate::platforms::get_gog_shortcuts_from_game_folders(game_folders);
crate::platforms::to_shortcuts(self, Ok(gog_games))
+2 -2
View File
@@ -68,7 +68,7 @@ fn get_folder_mfst_file_content(game_folder_path: &Path) -> Option<String> {
let mfst_file = game_folder_files
.filter_map(|file| file.ok())
.find(is_mfst_file)
.map(|file| std::fs::read_to_string(&file.path()));
.map(|file| std::fs::read_to_string(file.path()));
return match mfst_file {
Some(mfst_file) => mfst_file.ok(),
None => None,
@@ -111,7 +111,7 @@ fn get_default_locations() -> Option<OriginPathData> {
.join("steamapps")
.join("compatdata");
if let Ok(compat_folder) = std::fs::read_dir(&compat_folder_path) {
if let Ok(compat_folder) = std::fs::read_dir(compat_folder_path) {
for dir in compat_folder.flatten() {
let origin_exe_path = dir
.path()
+1 -1
View File
@@ -154,7 +154,7 @@ pub fn write_collections<S: AsRef<str>>(
}
let new_string = write_vdf_collection_to_string(
&path.clone().to_string_lossy(),
path.clone().to_string_lossy(),
&vdf_collections,
);
if let Some(new_string) = new_string {
+1 -1
View File
@@ -49,7 +49,7 @@ pub fn ensure_steam_started(_settings: &super::SteamSettings) {
if processes.next().is_none() {
//no steam, we need to start it
println!("Starting steam");
let mut command = Command::new(&steam_name);
let mut command = Command::new(steam_name);
if let Err(e) = command.spawn() {
println!("Failed to start steam: {:?}", e);
};
+1 -1
View File
@@ -68,6 +68,6 @@ fn get_search_map() -> SearchMap {
fn save_search_map(search_map: &SearchMap) {
let string = serde_json::to_string(search_map).unwrap();
let path = get_cache_file();
let mut file = File::create(&path).unwrap();
let mut file = File::create(path).unwrap();
file.write_all(string.as_bytes()).unwrap();
}
+2 -2
View File
@@ -15,8 +15,8 @@ pub fn create_sym_links(shortcut: &ShortcutOwned) -> ShortcutOwned {
use std::os::unix::fs::symlink;
// If the links exsists, then they must point towards what is needed, otherwise they would have a different app id
let target_ok = target_link.exists() || symlink(&target_original, &target_link).is_ok();
let workdir_ok = workdir_link.exists() || symlink(&workdir_original, &workdir_link).is_ok();
let target_ok = target_link.exists() || symlink(target_original, &target_link).is_ok();
let workdir_ok = workdir_link.exists() || symlink(workdir_original, &workdir_link).is_ok();
match (target_ok, workdir_ok) {
(true, true) => {
let exe = target_link.to_string_lossy().to_string();
+1 -1
View File
@@ -75,7 +75,7 @@ fn render_possible_image(
}
TextureDownloadState::Downloaded => {
//Need to load
let image_data = load_image_from_path(&path);
let image_data = load_image_from_path(path);
match image_data {
Ok(image_data) => {
let handle = ui.ctx().load_texture(
+6 -8
View File
@@ -5,19 +5,14 @@ pub fn render_user_select<'a>(
steam_users: &'a [SteamUsersInfo],
ui: &mut egui::Ui,
) -> Option<&'a SteamUsersInfo> {
if steam_user.is_none() {
if steam_users.len() > 0 {
return Some(&steam_users[0]);
}
} else {
let mut selected_user = steam_user.as_ref().unwrap().clone();
if let Some(mut selected_user) = steam_user {
let id_before = selected_user.user_id.clone();
if steam_users.len() > 0 {
if !steam_users.is_empty() {
let combo_box = egui::ComboBox::new("ImageUserSelect", "")
.selected_text(format!("Steam user id: {}", &selected_user.user_id));
combo_box.show_ui(ui, |ui| {
for user in steam_users {
ui.selectable_value(&mut selected_user, &user, &user.user_id);
ui.selectable_value(&mut selected_user, user, &user.user_id);
}
});
}
@@ -25,6 +20,9 @@ pub fn render_user_select<'a>(
if !id_before.eq(&id_now) {
return Some(selected_user);
}
} else if !steam_users.is_empty() {
return Some(&steam_users[0]);
}
None
}
+3 -3
View File
@@ -39,8 +39,8 @@ pub mod ui_images {
let image_buffer = image.to_rgba8();
let pixels = image_buffer.as_flat_samples();
IconData {
height: image.height() as u32,
width: image.width() as u32,
height: image.height(),
width: image.width(),
rgba: pixels.as_slice().to_vec(),
}
}
@@ -48,7 +48,7 @@ pub mod ui_images {
pub fn load_image_from_path(path: &std::path::Path) -> eyre::Result<egui::ColorImage> {
let path_owned = path.to_owned();
let handle: JoinHandle<eyre::Result<egui::ColorImage>> = std::thread::spawn(move || {
let image = image::io::Reader::open(&path_owned)?
let image = image::io::Reader::open(path_owned)?
.with_guessed_format()?
.decode()?;
let size = [image.width() as _, image.height() as _];
+1 -1
View File
@@ -56,7 +56,7 @@ fn key_from_extension(
ext: &str,
) -> (bool, PathBuf, String) {
let file_name = image_type.file_name(app_id, ext);
let path = user_path.join("config").join("grid").join(&file_name);
let path = user_path.join("config").join("grid").join(file_name);
let key = path.to_string_lossy().to_string();
(path.exists(), path, key)
}
+1 -1
View File
@@ -64,7 +64,7 @@ pub fn handle_correct_grid_request(app:&mut MyEguiApp) {
.auth_key
.clone()
.unwrap_or_default();
let client = steamgriddb_api::Client::new(&auth_key);
let client = steamgriddb_api::Client::new(auth_key);
let search_results = app.rt.block_on(client.search(app_name));
app.image_selected_state.possible_names = search_results.ok();
}
+1 -1
View File
@@ -64,7 +64,7 @@ pub fn render_page_pick_image(
if render_image_from_path_or_url(
ui,
&state.image_handles,
&path,
path,
column_width,
&image.full_url,
image_type,
+4 -4
View File
@@ -44,7 +44,7 @@ impl MyEguiApp {
let users = state.steam_users.as_ref();
if let Some(users) = users {
if let Some(value) =
render_user_select(state.steam_user.as_ref(), &users, ui)
render_user_select(state.steam_user.as_ref(), users, ui)
{
return Some(UserAction::UserSelected(value.clone()));
}
@@ -67,7 +67,7 @@ impl MyEguiApp {
return value;
}
} else if let Some(image_type) = state.image_type_selected.as_ref() {
if let Some(action) = render_page_pick_image(&self, ui, image_type, state) {
if let Some(action) = render_page_pick_image(self, ui, image_type, state) {
return action;
}
} else if let Some(action) = render_page_shortcut_select_image_type(ui, state) {
@@ -76,7 +76,7 @@ impl MyEguiApp {
} else {
let is_shortcut = state.game_mode.is_shortcuts();
if is_shortcut {
if let Some(action) = render_page_shortcut_images_overview(&self, ui) {
if let Some(action) = render_page_shortcut_images_overview(self, ui) {
return action;
}
} else if let Some(action) = render_page_steam_images_overview(ui, state) {
@@ -246,7 +246,7 @@ impl MyEguiApp {
let path = Path::new(data_folder)
.join("config")
.join("grid")
.join(&file_name);
.join(file_name);
if path.exists() {
let _ = std::fs::remove_file(&path);
}
+2 -2
View File
@@ -80,7 +80,7 @@ pub fn restore_backup(steam_settings: &SteamSettings, shortcut_path: &Path) -> b
pub fn load_backups() -> Vec<PathBuf> {
let backup_folder = get_backups_flder();
let files = std::fs::read_dir(&backup_folder);
let files = std::fs::read_dir(backup_folder);
let mut result = vec![];
if let Ok(files) = files {
for file in files.flatten() {
@@ -118,7 +118,7 @@ pub fn backup_shortcuts(steam_settings: &SteamSettings) {
user_info.user_id, date_string
));
println!("Backed up shortcut at: {:?}", new_path);
std::fs::copy(&shortcut_path, &new_path).unwrap();
std::fs::copy(shortcut_path, &new_path).unwrap();
}
}
}
+1 -1
View File
@@ -372,7 +372,7 @@ pub fn run_ui(args: Vec<String>) {
);
}
fn is_fullscreen(args: &Vec<String>) -> bool {
fn is_fullscreen(args: &[String]) -> bool {
let is_steam_mode = match std::env::var("SteamAppId") {
Ok(value) => !value.is_empty(),
Err(_) => false,