Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive name checking #669

Merged
merged 2 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions czkawka_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ hamming = "0.1.3"

# Needed by same music
bitflags = "1.3.2"
lofty="0.5.3"
lofty="0.6.0"

# Futures - needed by async progress sender
futures = "0.3.21"
Expand All @@ -46,15 +46,15 @@ vid_dup_finder_lib = "0.1.0"
ffmpeg_cmdline_utils = "0.1.1"

# Saving/Loading Cache
serde = "1.0.133"
serde = "1.0.136"
bincode = "1.3.3"
serde_json = "1.0.74"
serde_json = "1.0.79"

# Language
i18n-embed = { version = "0.13", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6.1"
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6.4"
rust-embed = "6.3.0"
once_cell = "1.9.0"
once_cell = "1.10.0"

# Raw image files
rawloader = "0.37.0"
Expand Down
14 changes: 13 additions & 1 deletion czkawka_core/src/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct DuplicateFinder {
minimal_prehash_cache_file_size: u64,
delete_outdated_cache: bool,
use_reference_folders: bool,
case_sensitive_name_comparison: bool,
}

impl DuplicateFinder {
Expand Down Expand Up @@ -134,6 +135,7 @@ impl DuplicateFinder {
minimal_prehash_cache_file_size: 0,
delete_outdated_cache: true,
use_reference_folders: false,
case_sensitive_name_comparison: false,
}
}

Expand Down Expand Up @@ -176,6 +178,10 @@ impl DuplicateFinder {
self.delete_outdated_cache = delete_outdated_cache;
}

pub fn set_case_sensitive_name_comparison(&mut self, case_sensitive_name_comparison: bool) {
self.case_sensitive_name_comparison = case_sensitive_name_comparison;
}

pub const fn get_check_method(&self) -> &CheckingMethod {
&self.check_method
}
Expand Down Expand Up @@ -293,9 +299,15 @@ impl DuplicateFinder {
}

fn check_files_name(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
let group_by_func = if self.case_sensitive_name_comparison {
|fe: &FileEntry| fe.path.file_name().unwrap().to_string_lossy().to_string()
} else {
|fe: &FileEntry| fe.path.file_name().unwrap().to_string_lossy().to_lowercase()
};

let result = DirTraversalBuilder::new()
.root_dirs(self.directories.included_directories.clone())
.group_by(|fe| fe.path.file_name().unwrap().to_string_lossy().to_string())
.group_by(group_by_func)
.stop_receiver(stop_receiver)
.progress_sender(progress_sender)
.checking_method(CheckingMethod::Name)
Expand Down
2 changes: 1 addition & 1 deletion czkawka_core/src/same_music.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::time::{Duration, SystemTime};
use std::{mem, thread};

use crossbeam_channel::Receiver;
use lofty::{read_from_path, ItemKey};
use lofty::{read_from_path, AudioFile, ItemKey};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};

Expand Down
6 changes: 6 additions & 0 deletions czkawka_gui/i18n/en/czkawka_gui.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ music_comparison_checkbox_tooltip =

Świędziżłób --- Świędziżłób (Remix Lato 2021)

duplicate_case_sensitive_name = Case Sensitive
duplicate_case_sensitive_name_tooltip =
When enabled, group only records when they have exactly same name e.g. Żołd <-> Żołd

Disabling such option will group names without checking if each letter is same size e.g. żoŁD <-> Żołd

duplicate_mode_name_combo_box = Name
duplicate_mode_size_combo_box = Size
duplicate_mode_hash_combo_box = Hash
Expand Down
12 changes: 2 additions & 10 deletions czkawka_gui/src/compute_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
(ColumnsDuplicates::Path as u32, &directory),
(
ColumnsDuplicates::Modification as u32,
&(format!(
"{} - ({})",
NaiveDateTime::from_timestamp(base_file_entry.modified_date as i64, 0),
base_file_entry.size.file_size(options::BINARY).unwrap()
)),
&(NaiveDateTime::from_timestamp(base_file_entry.modified_date as i64, 0).to_string()),
),
(ColumnsDuplicates::ModificationAsSecs as u32, &(base_file_entry.modified_date)),
(ColumnsDuplicates::Color as u32, &(HEADER_ROW_COLOR.to_string())),
Expand All @@ -197,11 +193,7 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
(ColumnsDuplicates::Path as u32, &directory),
(
ColumnsDuplicates::Modification as u32,
&(format!(
"{} - ({})",
NaiveDateTime::from_timestamp(entry.modified_date as i64, 0),
entry.size.file_size(options::BINARY).unwrap()
)),
&(NaiveDateTime::from_timestamp(entry.modified_date as i64, 0).to_string()),
),
(ColumnsDuplicates::ModificationAsSecs as u32, &(entry.modified_date)),
(ColumnsDuplicates::Color as u32, &(MAIN_ROW_COLOR.to_string())),
Expand Down
6 changes: 0 additions & 6 deletions czkawka_gui/src/connect_things/connect_button_hardlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,10 @@ fn hardlink_symlink(
if hardlinking == TypeOfTool::Hardlinking {
for symhardlink_data in vec_symhardlink_data {
for file_to_hardlink in symhardlink_data.files_to_symhardlink {
// #[cfg(target_family = "unix")]
if let Err(e) = make_hard_link(&PathBuf::from(&symhardlink_data.original_data), &PathBuf::from(&file_to_hardlink)) {
add_text_to_text_view(text_view_errors, format!("{} {}, reason {}", flg!("hardlink_failed"), file_to_hardlink, e).as_str());
continue;
}
// #[cfg(target_family = "windows")]
// if let Err(e) = fs::hard_link(&PathBuf::from(&symhardlink_data.original_data), &PathBuf::from(&file_to_hardlink)) {
// add_text_to_text_view(text_view_errors, format!("{} {}, reason {}", flg!("hardlink_failed"), file_to_hardlink, e).as_str());
// continue;
// }
}
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions czkawka_gui/src/connect_things/connect_button_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn connect_button_search(
let buttons_names = gui_data.bottom_buttons.buttons_names;
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();
let check_button_duplicate_case_sensitive_name: gtk::CheckButton = gui_data.main_notebook.check_button_duplicate_case_sensitive_name.clone();
let check_button_music_artist: gtk::CheckButton = gui_data.main_notebook.check_button_music_artist.clone();
let check_button_music_title: gtk::CheckButton = gui_data.main_notebook.check_button_music_title.clone();
let check_button_music_year: gtk::CheckButton = gui_data.main_notebook.check_button_music_year.clone();
Expand Down Expand Up @@ -178,6 +179,8 @@ pub fn connect_button_search(
let use_prehash_cache = check_button_duplicates_use_prehash_cache.is_active();
let minimal_prehash_cache_file_size = entry_settings_prehash_cache_file_minimal_size.text().as_str().parse::<u64>().unwrap_or(0);

let case_sensitive_name_comparison = check_button_duplicate_case_sensitive_name.is_active();

let delete_outdated_cache = check_button_settings_duplicates_delete_outdated_cache.is_active();

let futures_sender_duplicate_files = futures_sender_duplicate_files.clone();
Expand All @@ -200,6 +203,7 @@ pub fn connect_button_search(
df.set_use_cache(use_cache);
df.set_use_prehash_cache(use_prehash_cache);
df.set_delete_outdated_cache(delete_outdated_cache);
df.set_case_sensitive_name_comparison(case_sensitive_name_comparison);
df.find_duplicates(Some(&stop_receiver), Some(&futures_sender_duplicate_files));
let _ = glib_stop_sender.send(Message::Duplicates(df));
});
Expand Down
14 changes: 12 additions & 2 deletions czkawka_gui/src/connect_things/connect_duplicate_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ use crate::help_combo_box::DUPLICATES_CHECK_METHOD_COMBO_BOX;
pub fn connect_duplicate_combo_box(gui_data: &GuiData) {
let combo_box_duplicate_check_method = gui_data.main_notebook.combo_box_duplicate_check_method.clone();
let combo_box_duplicate_hash_type = gui_data.main_notebook.combo_box_duplicate_hash_type.clone();
let label_duplicate_hash_type = gui_data.main_notebook.label_duplicate_hash_type.clone();
let check_button_duplicate_case_sensitive_name = gui_data.main_notebook.check_button_duplicate_case_sensitive_name.clone();
combo_box_duplicate_check_method.connect_changed(move |combo_box_duplicate_check_method| {
// None active can be if when adding elements(this signal is activated when e.g. adding new fields or removing them)
if let Some(chosen_index) = combo_box_duplicate_check_method.active() {
if DUPLICATES_CHECK_METHOD_COMBO_BOX[chosen_index as usize].check_method == CheckingMethod::Hash {
combo_box_duplicate_hash_type.set_sensitive(true);
combo_box_duplicate_hash_type.set_visible(true);
label_duplicate_hash_type.set_visible(true);
} else {
combo_box_duplicate_hash_type.set_sensitive(false);
combo_box_duplicate_hash_type.set_visible(false);
label_duplicate_hash_type.set_visible(false);
}

if DUPLICATES_CHECK_METHOD_COMBO_BOX[chosen_index as usize].check_method == CheckingMethod::Name {
check_button_duplicate_case_sensitive_name.set_visible(true);
} else {
check_button_duplicate_case_sensitive_name.set_visible(false);
}
}
});
Expand Down
6 changes: 6 additions & 0 deletions czkawka_gui/src/gui_structs/gui_main_notebook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct GuiMainNotebook {
pub combo_box_duplicate_hash_type: gtk::ComboBoxText,
pub label_duplicate_check_method: gtk::Label,
pub label_duplicate_hash_type: gtk::Label,
pub check_button_duplicate_case_sensitive_name: gtk::CheckButton,

pub image_preview_duplicates: gtk::Image,

Expand Down Expand Up @@ -198,6 +199,7 @@ impl GuiMainNotebook {
let entry_big_files_number: gtk::Entry = builder.object("entry_big_files_number").unwrap();

//// Check Buttons
let check_button_duplicate_case_sensitive_name: gtk::CheckButton = builder.object("check_button_duplicate_case_sensitive_name").unwrap();
let check_button_music_title: gtk::CheckButton = builder.object("check_button_music_title").unwrap();
let check_button_music_artist: gtk::CheckButton = builder.object("check_button_music_artist").unwrap();
let check_button_music_year: gtk::CheckButton = builder.object("check_button_music_year").unwrap();
Expand Down Expand Up @@ -301,6 +303,7 @@ impl GuiMainNotebook {
combo_box_image_hash_size,
check_button_video_ignore_same_size,
check_button_image_fast_compare,
check_button_duplicate_case_sensitive_name,
}
}

Expand All @@ -320,6 +323,7 @@ impl GuiMainNotebook {
}

pub fn update_language(&self) {
self.check_button_duplicate_case_sensitive_name.set_label(&flg!("duplicate_case_sensitive_name"));
self.check_button_music_title.set_label(&flg!("music_title_checkbox"));
self.check_button_music_artist.set_label(&flg!("music_artist_checkbox"));
self.check_button_music_year.set_label(&flg!("music_year_checkbox"));
Expand Down Expand Up @@ -347,6 +351,8 @@ impl GuiMainNotebook {
self.combo_box_duplicate_check_method.set_tooltip_text(Some(&flg!("duplicate_check_method_tooltip")));
self.label_duplicate_hash_type.set_tooltip_text(Some(&flg!("duplicate_hash_type_tooltip")));
self.combo_box_duplicate_hash_type.set_tooltip_text(Some(&flg!("duplicate_hash_type_tooltip")));
self.check_button_duplicate_case_sensitive_name
.set_tooltip_text(Some(&flg!("duplicate_case_sensitive_name_tooltip")));

self.combo_box_image_hash_size.set_tooltip_text(Some(&flg!("image_hash_size_tooltip")));
self.label_image_hash_size.set_tooltip_text(Some(&flg!("image_hash_size_tooltip")));
Expand Down
Loading