From ecc93484cf30543fc19217956fcac1e666dc709c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mikrut?= Date: Thu, 1 Oct 2020 15:55:45 +0200 Subject: [PATCH] Fixed text, Don't delete entry if folder/file wasn't deleted --- czkawka_gui/src/help_functions.rs | 4 ++-- czkawka_gui/src/main.rs | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/czkawka_gui/src/help_functions.rs b/czkawka_gui/src/help_functions.rs index b9e3436..e46dff6 100644 --- a/czkawka_gui/src/help_functions.rs +++ b/czkawka_gui/src/help_functions.rs @@ -3,7 +3,7 @@ use gtk::prelude::*; use gtk::TreeViewColumn; pub enum ColumnsDuplicates { - // Columns for duplicate and empty folder treeview + // Columns for duplicate treeview Name = 0, Path, Modification, @@ -13,7 +13,7 @@ pub enum ColumnsDuplicates { } pub enum ColumnsEmpty { - // Columns for duplicate and empty folder treeview + // Columns for empty folder treeview Name = 0, Path, Modification, diff --git a/czkawka_gui/src/main.rs b/czkawka_gui/src/main.rs index 0608b3c..ec6a7e2 100644 --- a/czkawka_gui/src/main.rs +++ b/czkawka_gui/src/main.rs @@ -412,9 +412,9 @@ fn main() { for vector in vectors_vector { let values: [&dyn ToValue; 6] = [ &(vector.len().to_string() + " x " + size.to_string().as_str()), - &("(".to_string() + ((vector.len() - 1) as u64 * *size as u64).to_string().as_str() + ")"), - &"Bytes lost".to_string(), - &(0), // Not used here + &(format!("{} ({} bytes) lost", ((vector.len() - 1) as u64 * *size as u64).file_size(options::BINARY).unwrap(), (vector.len() - 1) as u64 * *size as u64)), + &"".to_string(), // No text in 3 column + &(0), // Not used here &(HEADER_ROW_COLOR.to_string()), &(TEXT_COLOR.to_string()), ]; @@ -442,9 +442,9 @@ fn main() { for (size, vector) in btreemap.iter().rev() { let values: [&dyn ToValue; 6] = [ &(vector.len().to_string() + " x " + size.to_string().as_str()), - &("(".to_string() + ((vector.len() - 1) as u64 * *size as u64).to_string().as_str() + ")"), - &"Bytes lost".to_string(), - &(0), // Not used here + &(format!("{} ({} bytes) lost", ((vector.len() - 1) as u64 * *size as u64).file_size(options::BINARY).unwrap(), (vector.len() - 1) as u64 * *size as u64)), + &"".to_string(), // No text in 3 column + &(0), // Not used here &(HEADER_ROW_COLOR.to_string()), &(TEXT_COLOR.to_string()), ]; @@ -584,10 +584,12 @@ fn main() { let name = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsDuplicates::Name as i32).get::().unwrap().unwrap(); let path = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsDuplicates::Path as i32).get::().unwrap().unwrap(); - if fs::remove_file(format!("{}/{}", path, name)).is_err() { - messages += format!("Failed to remove file {}/{} because file doesn't exists or you don't have permissions.\n", path, name).as_str() + match fs::remove_dir(format!("{}/{}", path, name)) { + Ok(_) => messages += format!("Failed to remove file {}/{} because file doesn't exists or you don't have permissions.\n", path, name).as_str(), + Err(_) => { + list_store.remove(&list_store.get_iter(&tree_path).unwrap()); + } } - list_store.remove(&list_store.get_iter(&tree_path).unwrap()); } text_view_errors.get_buffer().unwrap().set_text(messages.as_str()); @@ -614,10 +616,12 @@ fn main() { let name = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsEmpty::Name as i32).get::().unwrap().unwrap(); let path = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsEmpty::Path as i32).get::().unwrap().unwrap(); - if fs::remove_dir(format!("{}/{}", path, name)).is_err() { - messages += format!("Failed to folder {}/{} due lack of permissions, selected dir is not empty or doesn't exists.\n", path, name).as_str() + match fs::remove_dir(format!("{}/{}", path, name)) { + Ok(_) => messages += format!("Failed to folder {}/{} due lack of permissions, selected dir is not empty or doesn't exists.\n", path, name).as_str(), + Err(_) => { + list_store.remove(&list_store.get_iter(&tree_path).unwrap()); + } } - list_store.remove(&list_store.get_iter(&tree_path).unwrap()); } text_view_errors.get_buffer().unwrap().set_text(messages.as_str());