Skip to content

Commit 5f774e0

Browse files
authored
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)
1 parent 457b55a commit 5f774e0

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
- Cache support - second and further scans should be a lot faster than the first one
1111
- CLI frontend - for easy automation
1212
- GUI frontend - uses modern GTK 3 and looks similar to FSlint
13-
- Rich search option - allows setting absolute included and excluded directories, set of allowed file extensions
14-
or excluded items with the `*` wildcard
1513
- No spying - Czkawka does not have access to the Internet, nor does it collect any user information or statistics
1614
- Multiple tools to use:
1715
- Duplicates - Finds duplicates based on file name, size or hash
@@ -26,7 +24,7 @@
2624
- Broken Files - Finds files with an invalid extension or that are corrupted
2725

2826
<!-- The GIF thingy -->
29-
![Czkawka](https://user-images.githubusercontent.com/41945903/104711404-9cbb7400-5721-11eb-904d-9677c189f7ab.gif)
27+
![Czkawka](https://user-images.githubusercontent.com/41945903/145280350-506f7e94-4db0-4de7-a68d-6e7c26bbd2bf.gif)
3028

3129
## How do I use it?
3230
You can find the instructions on how to use Czkawka [**here**](instructions/Instruction.md).

czkawka_core/src/similar_images.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub struct SimilarImages {
101101
image_filter: FilterType,
102102
use_cache: bool,
103103
delete_outdated_cache: bool,
104+
exclude_images_with_same_size: bool,
104105
}
105106

106107
/// Info struck with helpful information's about results
@@ -140,6 +141,7 @@ impl SimilarImages {
140141
image_filter: FilterType::Lanczos3,
141142
use_cache: true,
142143
delete_outdated_cache: true,
144+
exclude_images_with_same_size: false,
143145
}
144146
}
145147

@@ -156,6 +158,10 @@ impl SimilarImages {
156158
self.delete_outdated_cache = delete_outdated_cache;
157159
}
158160

161+
pub fn set_exclude_images_with_same_size(&mut self, exclude_images_with_same_size: bool) {
162+
self.exclude_images_with_same_size = exclude_images_with_same_size;
163+
}
164+
159165
pub fn set_hash_alg(&mut self, hash_alg: HashAlg) {
160166
self.hash_alg = hash_alg;
161167
}
@@ -384,6 +390,21 @@ impl SimilarImages {
384390
fn sort_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
385391
let hash_map_modification = SystemTime::now();
386392

393+
if self.exclude_images_with_same_size {
394+
let mut old_hash_map = Default::default();
395+
mem::swap(&mut self.images_to_check, &mut old_hash_map);
396+
397+
let mut new_hash_map: BTreeMap<u64, FileEntry> = Default::default();
398+
399+
for (_name, file_entry) in old_hash_map {
400+
new_hash_map.insert(file_entry.size, file_entry);
401+
}
402+
self.images_to_check = Default::default();
403+
for (_size, file_entry) in new_hash_map {
404+
self.images_to_check.insert(file_entry.path.to_string_lossy().to_string(), file_entry);
405+
}
406+
}
407+
387408
let loaded_hash_map;
388409

389410
let mut records_already_cached: BTreeMap<String, FileEntry> = Default::default();
@@ -736,10 +757,6 @@ impl PrintResults for SimilarImages {
736757

737758
pub fn save_hashes_to_file(hashmap: &BTreeMap<String, FileEntry>, text_messages: &mut Messages, hash_size: u8, hash_alg: HashAlg, image_filter: FilterType) {
738759
if let Some(proj_dirs) = ProjectDirs::from("pl", "Qarmin", "Czkawka") {
739-
// Lin: /home/username/.cache/czkawka
740-
// Win: C:\Users\Username\AppData\Local\Qarmin\Czkawka\cache
741-
// Mac: /Users/Username/Library/Caches/pl.Qarmin.Czkawka
742-
743760
let cache_dir = PathBuf::from(proj_dirs.cache_dir());
744761
if cache_dir.exists() {
745762
if !cache_dir.is_dir() {

czkawka_gui/src/connect_button_search.rs

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn connect_button_search(
3939
futures_sender_broken_files: futures::channel::mpsc::UnboundedSender<broken_files::ProgressData>,
4040
) {
4141
let buttons_array = gui_data.bottom_buttons.buttons_array.clone();
42+
let check_button_image_ignore_same_size = gui_data.main_notebook.check_button_image_ignore_same_size.clone();
4243
let buttons_names = gui_data.bottom_buttons.buttons_names.clone();
4344
let buttons_search_clone = gui_data.bottom_buttons.buttons_search.clone();
4445
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(
344345
let minimal_file_size = entry_similar_images_minimal_size.text().as_str().parse::<u64>().unwrap_or(1024 * 16);
345346
let maximal_file_size = entry_similar_images_maximal_size.text().as_str().parse::<u64>().unwrap_or(1024 * 1024 * 1024 * 1024);
346347

348+
let ignore_same_size = check_button_image_ignore_same_size.is_active();
349+
347350
let similarity = similar_images::Similarity::Similar(scale_similarity_similar_images.value() as u32);
348351

349352
let delete_outdated_cache = check_button_settings_similar_images_delete_outdated_cache.is_active();
@@ -365,6 +368,7 @@ pub fn connect_button_search(
365368
sf.set_hash_size(hash_size);
366369
sf.set_image_filter(image_filter);
367370
sf.set_delete_outdated_cache(delete_outdated_cache);
371+
sf.set_exclude_images_with_same_size(ignore_same_size);
368372
sf.find_similar_images(Some(&stop_receiver), Some(&futures_sender_similar_images));
369373
let _ = glib_stop_sender.send(Message::SimilarImages(sf));
370374
});

czkawka_gui/src/gui_main_notebook.rs

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub struct GuiMainNotebook {
8989
pub radio_button_similar_hash_size_32: gtk::RadioButton,
9090
pub radio_button_similar_hash_size_64: gtk::RadioButton,
9191

92+
pub check_button_image_ignore_same_size: gtk::CheckButton,
93+
9294
pub label_similar_images_minimal_similarity: gtk::Label,
9395

9496
pub image_preview_similar_images: gtk::Image,
@@ -218,6 +220,8 @@ impl GuiMainNotebook {
218220
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."));
219221
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."));
220222

223+
let check_button_image_ignore_same_size: gtk::CheckButton = builder.object("check_button_image_ignore_same_size").unwrap();
224+
221225
let label_similar_images_minimal_similarity: gtk::Label = builder.object("label_similar_images_minimal_similarity").unwrap();
222226

223227
let image_preview_similar_images: gtk::Image = builder.object("image_preview_similar_images").unwrap();
@@ -290,6 +294,7 @@ impl GuiMainNotebook {
290294
radio_button_similar_hash_size_16,
291295
radio_button_similar_hash_size_32,
292296
radio_button_similar_hash_size_64,
297+
check_button_image_ignore_same_size,
293298
label_similar_images_minimal_similarity,
294299
image_preview_similar_images,
295300
entry_duplicate_maximal_size,

czkawka_gui/src/initialize_gui.rs

+4
Original file line numberDiff line numberDiff line change
@@ -753,5 +753,9 @@ fn show_preview(tree_view: &TreeView, text_view_errors: &TextView, check_button_
753753
image_preview_similar_images.show();
754754
} else {
755755
image_preview_similar_images.hide();
756+
{
757+
let mut preview_path = preview_path.borrow_mut();
758+
*preview_path = "".to_string();
759+
}
756760
}
757761
}

czkawka_gui/ui/main_window.glade

+15-1
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ Author: Rafał Mikrut
14381438
<packing>
14391439
<property name="expand">False</property>
14401440
<property name="fill">True</property>
1441-
<property name="position">4</property>
1441+
<property name="position">3</property>
14421442
</packing>
14431443
</child>
14441444
<child>
@@ -1453,6 +1453,20 @@ Author: Rafał Mikrut
14531453
<packing>
14541454
<property name="expand">True</property>
14551455
<property name="fill">True</property>
1456+
<property name="position">4</property>
1457+
</packing>
1458+
</child>
1459+
<child>
1460+
<object class="GtkCheckButton" id="check_button_image_ignore_same_size">
1461+
<property name="label" translatable="yes">Ignore same size</property>
1462+
<property name="visible">True</property>
1463+
<property name="can-focus">True</property>
1464+
<property name="receives-default">False</property>
1465+
<property name="draw-indicator">True</property>
1466+
</object>
1467+
<packing>
1468+
<property name="expand">False</property>
1469+
<property name="fill">True</property>
14561470
<property name="position">5</property>
14571471
</packing>
14581472
</child>

0 commit comments

Comments
 (0)