1
0
Fork 0
mirror of synced 2024-05-29 00:29:54 +12:00

Fixed text,

Don't delete entry if folder/file wasn't deleted
This commit is contained in:
Rafał Mikrut 2020-10-01 15:55:45 +02:00
parent f05bce615a
commit ecc93484cf
2 changed files with 18 additions and 14 deletions

View file

@ -3,7 +3,7 @@ use gtk::prelude::*;
use gtk::TreeViewColumn; use gtk::TreeViewColumn;
pub enum ColumnsDuplicates { pub enum ColumnsDuplicates {
// Columns for duplicate and empty folder treeview // Columns for duplicate treeview
Name = 0, Name = 0,
Path, Path,
Modification, Modification,
@ -13,7 +13,7 @@ pub enum ColumnsDuplicates {
} }
pub enum ColumnsEmpty { pub enum ColumnsEmpty {
// Columns for duplicate and empty folder treeview // Columns for empty folder treeview
Name = 0, Name = 0,
Path, Path,
Modification, Modification,

View file

@ -412,9 +412,9 @@ fn main() {
for vector in vectors_vector { for vector in vectors_vector {
let values: [&dyn ToValue; 6] = [ let values: [&dyn ToValue; 6] = [
&(vector.len().to_string() + " x " + size.to_string().as_str()), &(vector.len().to_string() + " x " + size.to_string().as_str()),
&("(".to_string() + ((vector.len() - 1) as u64 * *size as u64).to_string().as_str() + ")"), &(format!("{} ({} bytes) lost", ((vector.len() - 1) as u64 * *size as u64).file_size(options::BINARY).unwrap(), (vector.len() - 1) as u64 * *size as u64)),
&"Bytes lost".to_string(), &"".to_string(), // No text in 3 column
&(0), // Not used here &(0), // Not used here
&(HEADER_ROW_COLOR.to_string()), &(HEADER_ROW_COLOR.to_string()),
&(TEXT_COLOR.to_string()), &(TEXT_COLOR.to_string()),
]; ];
@ -442,9 +442,9 @@ fn main() {
for (size, vector) in btreemap.iter().rev() { for (size, vector) in btreemap.iter().rev() {
let values: [&dyn ToValue; 6] = [ let values: [&dyn ToValue; 6] = [
&(vector.len().to_string() + " x " + size.to_string().as_str()), &(vector.len().to_string() + " x " + size.to_string().as_str()),
&("(".to_string() + ((vector.len() - 1) as u64 * *size as u64).to_string().as_str() + ")"), &(format!("{} ({} bytes) lost", ((vector.len() - 1) as u64 * *size as u64).file_size(options::BINARY).unwrap(), (vector.len() - 1) as u64 * *size as u64)),
&"Bytes lost".to_string(), &"".to_string(), // No text in 3 column
&(0), // Not used here &(0), // Not used here
&(HEADER_ROW_COLOR.to_string()), &(HEADER_ROW_COLOR.to_string()),
&(TEXT_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::<String>().unwrap().unwrap(); let name = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsDuplicates::Name as i32).get::<String>().unwrap().unwrap();
let path = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsDuplicates::Path as i32).get::<String>().unwrap().unwrap(); let path = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsDuplicates::Path as i32).get::<String>().unwrap().unwrap();
if fs::remove_file(format!("{}/{}", path, name)).is_err() { match fs::remove_dir(format!("{}/{}", path, name)) {
messages += format!("Failed to remove file {}/{} because file doesn't exists or you don't have permissions.\n", path, name).as_str() 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()); 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::<String>().unwrap().unwrap(); let name = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsEmpty::Name as i32).get::<String>().unwrap().unwrap();
let path = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsEmpty::Path as i32).get::<String>().unwrap().unwrap(); let path = tree_model.get_value(&tree_model.get_iter(&tree_path).unwrap(), ColumnsEmpty::Path as i32).get::<String>().unwrap().unwrap();
if fs::remove_dir(format!("{}/{}", path, name)).is_err() { match fs::remove_dir(format!("{}/{}", path, name)) {
messages += format!("Failed to folder {}/{} due lack of permissions, selected dir is not empty or doesn't exists.\n", path, name).as_str() 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()); text_view_errors.get_buffer().unwrap().set_text(messages.as_str());