From 5f774e03bdb49f46a9ef5d394d6f7922ec4c4ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mikrut?= <41945903+qarmin@users.noreply.github.com> Date: Wed, 8 Dec 2021 23:08:05 +0100 Subject: [PATCH] Add button to ignore images with non unique size. (#493) This will help with finding different images(non 1:1 which could be easily found by duplicate finder tool) --- README.md | 4 +--- czkawka_core/src/similar_images.rs | 25 ++++++++++++++++++++---- czkawka_gui/src/connect_button_search.rs | 4 ++++ czkawka_gui/src/gui_main_notebook.rs | 5 +++++ czkawka_gui/src/initialize_gui.rs | 4 ++++ czkawka_gui/ui/main_window.glade | 16 ++++++++++++++- 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 934ee6b..997c5f1 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ - Cache support - second and further scans should be a lot faster than the first one - CLI frontend - for easy automation - GUI frontend - uses modern GTK 3 and looks similar to FSlint -- Rich search option - allows setting absolute included and excluded directories, set of allowed file extensions - or excluded items with the `*` wildcard - No spying - Czkawka does not have access to the Internet, nor does it collect any user information or statistics - Multiple tools to use: - Duplicates - Finds duplicates based on file name, size or hash @@ -26,7 +24,7 @@ - Broken Files - Finds files with an invalid extension or that are corrupted -![Czkawka](https://user-images.githubusercontent.com/41945903/104711404-9cbb7400-5721-11eb-904d-9677c189f7ab.gif) +![Czkawka](https://user-images.githubusercontent.com/41945903/145280350-506f7e94-4db0-4de7-a68d-6e7c26bbd2bf.gif) ## How do I use it? You can find the instructions on how to use Czkawka [**here**](instructions/Instruction.md). diff --git a/czkawka_core/src/similar_images.rs b/czkawka_core/src/similar_images.rs index 001421c..cafc388 100644 --- a/czkawka_core/src/similar_images.rs +++ b/czkawka_core/src/similar_images.rs @@ -101,6 +101,7 @@ pub struct SimilarImages { image_filter: FilterType, use_cache: bool, delete_outdated_cache: bool, + exclude_images_with_same_size: bool, } /// Info struck with helpful information's about results @@ -140,6 +141,7 @@ impl SimilarImages { image_filter: FilterType::Lanczos3, use_cache: true, delete_outdated_cache: true, + exclude_images_with_same_size: false, } } @@ -156,6 +158,10 @@ impl SimilarImages { self.delete_outdated_cache = delete_outdated_cache; } + pub fn set_exclude_images_with_same_size(&mut self, exclude_images_with_same_size: bool) { + self.exclude_images_with_same_size = exclude_images_with_same_size; + } + pub fn set_hash_alg(&mut self, hash_alg: HashAlg) { self.hash_alg = hash_alg; } @@ -384,6 +390,21 @@ impl SimilarImages { fn sort_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender>) -> bool { let hash_map_modification = SystemTime::now(); + if self.exclude_images_with_same_size { + let mut old_hash_map = Default::default(); + mem::swap(&mut self.images_to_check, &mut old_hash_map); + + let mut new_hash_map: BTreeMap = Default::default(); + + for (_name, file_entry) in old_hash_map { + new_hash_map.insert(file_entry.size, file_entry); + } + self.images_to_check = Default::default(); + for (_size, file_entry) in new_hash_map { + self.images_to_check.insert(file_entry.path.to_string_lossy().to_string(), file_entry); + } + } + let loaded_hash_map; let mut records_already_cached: BTreeMap = Default::default(); @@ -736,10 +757,6 @@ impl PrintResults for SimilarImages { pub fn save_hashes_to_file(hashmap: &BTreeMap, text_messages: &mut Messages, hash_size: u8, hash_alg: HashAlg, image_filter: FilterType) { if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") { - // Lin: /home/username/.cache/czkawka - // Win: C:\Users\Username\AppData\Local\Qarmin\Czkawka\cache - // Mac: /Users/Username/Library/Caches/pl.Qarmin.Czkawka - let cache_dir = PathBuf::from(proj_dirs.cache_dir()); if cache_dir.exists() { if !cache_dir.is_dir() { diff --git a/czkawka_gui/src/connect_button_search.rs b/czkawka_gui/src/connect_button_search.rs index e28f9ce..88f5652 100644 --- a/czkawka_gui/src/connect_button_search.rs +++ b/czkawka_gui/src/connect_button_search.rs @@ -39,6 +39,7 @@ pub fn connect_button_search( futures_sender_broken_files: futures::channel::mpsc::UnboundedSender, ) { let buttons_array = gui_data.bottom_buttons.buttons_array.clone(); + let check_button_image_ignore_same_size = gui_data.main_notebook.check_button_image_ignore_same_size.clone(); let buttons_names = gui_data.bottom_buttons.buttons_names.clone(); let buttons_search_clone = gui_data.bottom_buttons.buttons_search.clone(); let check_button_duplicates_use_prehash_cache = gui_data.settings.check_button_duplicates_use_prehash_cache.clone(); @@ -344,6 +345,8 @@ pub fn connect_button_search( let minimal_file_size = entry_similar_images_minimal_size.text().as_str().parse::().unwrap_or(1024 * 16); let maximal_file_size = entry_similar_images_maximal_size.text().as_str().parse::().unwrap_or(1024 * 1024 * 1024 * 1024); + let ignore_same_size = check_button_image_ignore_same_size.is_active(); + let similarity = similar_images::Similarity::Similar(scale_similarity_similar_images.value() as u32); let delete_outdated_cache = check_button_settings_similar_images_delete_outdated_cache.is_active(); @@ -365,6 +368,7 @@ pub fn connect_button_search( sf.set_hash_size(hash_size); sf.set_image_filter(image_filter); sf.set_delete_outdated_cache(delete_outdated_cache); + sf.set_exclude_images_with_same_size(ignore_same_size); sf.find_similar_images(Some(&stop_receiver), Some(&futures_sender_similar_images)); let _ = glib_stop_sender.send(Message::SimilarImages(sf)); }); diff --git a/czkawka_gui/src/gui_main_notebook.rs b/czkawka_gui/src/gui_main_notebook.rs index f04521c..5497fa7 100644 --- a/czkawka_gui/src/gui_main_notebook.rs +++ b/czkawka_gui/src/gui_main_notebook.rs @@ -89,6 +89,8 @@ pub struct GuiMainNotebook { pub radio_button_similar_hash_size_32: gtk::RadioButton, pub radio_button_similar_hash_size_64: gtk::RadioButton, + pub check_button_image_ignore_same_size: gtk::CheckButton, + pub label_similar_images_minimal_similarity: gtk::Label, pub image_preview_similar_images: gtk::Image, @@ -218,6 +220,8 @@ impl GuiMainNotebook { radio_button_similar_hash_size_32.set_tooltip_text(Some("Hash of this size provide very big similarity which is more than enough for most usages.")); radio_button_similar_hash_size_64.set_tooltip_text(Some("Paranoid mode, such tool create really big cache files and will catch almost same images.")); + let check_button_image_ignore_same_size: gtk::CheckButton = builder.object("check_button_image_ignore_same_size").unwrap(); + let label_similar_images_minimal_similarity: gtk::Label = builder.object("label_similar_images_minimal_similarity").unwrap(); let image_preview_similar_images: gtk::Image = builder.object("image_preview_similar_images").unwrap(); @@ -290,6 +294,7 @@ impl GuiMainNotebook { radio_button_similar_hash_size_16, radio_button_similar_hash_size_32, radio_button_similar_hash_size_64, + check_button_image_ignore_same_size, label_similar_images_minimal_similarity, image_preview_similar_images, entry_duplicate_maximal_size, diff --git a/czkawka_gui/src/initialize_gui.rs b/czkawka_gui/src/initialize_gui.rs index af8bb14..e2aaee0 100644 --- a/czkawka_gui/src/initialize_gui.rs +++ b/czkawka_gui/src/initialize_gui.rs @@ -753,5 +753,9 @@ fn show_preview(tree_view: &TreeView, text_view_errors: &TextView, check_button_ image_preview_similar_images.show(); } else { image_preview_similar_images.hide(); + { + let mut preview_path = preview_path.borrow_mut(); + *preview_path = "".to_string(); + } } } diff --git a/czkawka_gui/ui/main_window.glade b/czkawka_gui/ui/main_window.glade index 908c827..97a5a98 100644 --- a/czkawka_gui/ui/main_window.glade +++ b/czkawka_gui/ui/main_window.glade @@ -1438,7 +1438,7 @@ Author: Rafał Mikrut False True - 4 + 3 @@ -1453,6 +1453,20 @@ Author: Rafał Mikrut True True + 4 + + + + + Ignore same size + True + True + False + True + + + False + True 5