1
0
Fork 0
mirror of synced 2024-06-14 16:35:23 +12:00

Pydantic part 1

This commit is contained in:
Rafał Mikrut 2023-01-26 22:48:57 +01:00
parent 368e670780
commit 10b50adc50
31 changed files with 259 additions and 170 deletions

View file

@ -166,6 +166,7 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -188,6 +189,7 @@ pub struct BadExtensions {
}
impl BadExtensions {
#[must_use]
pub fn new() -> Self {
Self {
text_messages: Messages::new(),
@ -219,10 +221,12 @@ impl BadExtensions {
self.debug_print();
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
#[must_use]
pub const fn get_bad_extensions_files(&self) -> &Vec<BadFileEntry> {
&self.bad_extensions_files
}
@ -246,10 +250,12 @@ impl BadExtensions {
#[cfg(not(target_family = "unix"))]
pub fn set_exclude_other_filesystems(&mut self, _exclude_other_filesystems: bool) {}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -388,12 +394,12 @@ impl BadExtensions {
}
// Text longer than 10 characters is not considered as extension
if extension.len() > 10 {
current_extension = "".to_string();
current_extension = String::new();
} else {
current_extension = extension;
}
} else {
current_extension = "".to_string();
current_extension = String::new();
}
// Already have proper extension, no need to do more things
@ -404,7 +410,7 @@ impl BadExtensions {
// Check for all extensions that file can use(not sure if it is worth to do it)
let mut all_available_extensions: BTreeSet<&str> = Default::default();
let think_extension = match current_extension.is_empty() {
true => "".to_string(),
true => String::new(),
false => {
for mim in mime_guess::from_ext(proper_extension) {
if let Some(all_ext) = get_mime_extensions(&mim) {
@ -456,8 +462,8 @@ impl BadExtensions {
}))
})
.while_some()
.filter(|file_entry| file_entry.is_some())
.map(|file_entry| file_entry.unwrap())
.filter(std::option::Option::is_some)
.map(std::option::Option::unwrap)
.collect::<Vec<_>>();
// End thread which send info to gui
@ -540,7 +546,7 @@ impl SaveResults for BadExtensions {
if !self.bad_extensions_files.is_empty() {
writeln!(writer, "Found {} files with invalid extension.", self.information.number_of_files_with_bad_extension).unwrap();
for file_entry in self.bad_extensions_files.iter() {
for file_entry in &self.bad_extensions_files {
writeln!(writer, "{} ----- {}", file_entry.path.display(), file_entry.proper_extensions).unwrap();
}
} else {
@ -557,7 +563,7 @@ impl PrintResults for BadExtensions {
fn print_results(&self) {
let start_time: SystemTime = SystemTime::now();
println!("Found {} files with invalid extension.\n", self.information.number_of_files_with_bad_extension);
for file_entry in self.bad_extensions_files.iter() {
for file_entry in &self.bad_extensions_files {
println!("{} ----- {}", file_entry.path.display(), file_entry.proper_extensions);
}

View file

@ -56,6 +56,7 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -77,6 +78,7 @@ pub struct BigFile {
}
impl BigFile {
#[must_use]
pub fn new() -> Self {
Self {
text_messages: Default::default(),
@ -102,6 +104,7 @@ impl BigFile {
self.delete_files();
self.debug_print();
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
@ -110,14 +113,17 @@ impl BigFile {
self.search_mode = search_mode;
}
#[must_use]
pub const fn get_big_files(&self) -> &Vec<(u64, FileEntry)> {
&self.big_files
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -470,7 +476,7 @@ impl SaveResults for BigFile {
} else {
write!(writer, "{} the smallest files.\n\n", self.information.number_of_real_files).unwrap();
}
for (size, file_entry) in self.big_files.iter() {
for (size, file_entry) in &self.big_files {
writeln!(writer, "{} ({}) - {}", format_size(*size, BINARY), size, file_entry.path.display()).unwrap();
}
} else {
@ -489,7 +495,7 @@ impl PrintResults for BigFile {
} else {
println!("{} the smallest files.\n\n", self.information.number_of_real_files);
}
for (size, file_entry) in self.big_files.iter() {
for (size, file_entry) in &self.big_files {
println!("{} ({}) - {}", format_size(*size, BINARY), size, file_entry.path.display());
}
Common::print_time(start_time, SystemTime::now(), "print_entries".to_string());

View file

@ -75,6 +75,7 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -98,6 +99,7 @@ pub struct BrokenFiles {
}
impl BrokenFiles {
#[must_use]
pub fn new() -> Self {
Self {
text_messages: Messages::new(),
@ -131,10 +133,12 @@ impl BrokenFiles {
self.debug_print();
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
#[must_use]
pub const fn get_broken_files(&self) -> &Vec<FileEntry> {
&self.broken_files
}
@ -143,10 +147,12 @@ impl BrokenFiles {
self.checked_types = checked_types;
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -354,7 +360,7 @@ impl BrokenFiles {
},
size: metadata.len(),
type_of_file,
error_string: "".to_string(),
error_string: String::new(),
};
fe_result.push((current_file_name.to_string_lossy().to_string(), fe));
@ -556,8 +562,8 @@ impl BrokenFiles {
}
})
.while_some()
.filter(|file_entry| file_entry.is_some())
.map(|file_entry| file_entry.unwrap())
.filter(std::option::Option::is_some)
.map(std::option::Option::unwrap)
.collect::<Vec<FileEntry>>();
// End thread which send info to gui
@ -602,7 +608,7 @@ impl BrokenFiles {
match self.delete_method {
DeleteMethod::Delete => {
for file_entry in self.broken_files.iter() {
for file_entry in &self.broken_files {
if fs::remove_file(&file_entry.path).is_err() {
self.text_messages.warnings.push(file_entry.path.display().to_string());
}
@ -680,7 +686,7 @@ impl SaveResults for BrokenFiles {
if !self.broken_files.is_empty() {
writeln!(writer, "Found {} broken files.", self.information.number_of_broken_files).unwrap();
for file_entry in self.broken_files.iter() {
for file_entry in &self.broken_files {
writeln!(writer, "{} - {}", file_entry.path.display(), file_entry.error_string).unwrap();
}
} else {
@ -697,7 +703,7 @@ impl PrintResults for BrokenFiles {
fn print_results(&self) {
let start_time: SystemTime = SystemTime::now();
println!("Found {} broken files.\n", self.information.number_of_broken_files);
for file_entry in self.broken_files.iter() {
for file_entry in &self.broken_files {
println!("{} - {}", file_entry.path.display(), file_entry.error_string);
}

View file

@ -26,6 +26,7 @@ pub fn get_number_of_threads() -> usize {
pub fn set_default_number_of_threads() {
set_number_of_threads(num_cpus::get());
}
#[must_use]
pub fn get_default_number_of_threads() -> usize {
num_cpus::get()
}
@ -181,6 +182,7 @@ pub fn get_dynamic_image_from_raw_image(path: impl AsRef<Path> + std::fmt::Debug
Some(DynamicImage::ImageRgb8(image))
}
#[must_use]
pub fn split_path(path: &Path) -> (String, String) {
match (path.parent(), path.file_name()) {
(Some(dir), Some(file)) => (dir.display().to_string(), file.to_string_lossy().into_owned()),
@ -189,6 +191,7 @@ pub fn split_path(path: &Path) -> (String, String) {
}
}
#[must_use]
pub fn create_crash_message(library_name: &str, file_path: &str, home_library_url: &str) -> String {
format!("{library_name} library crashed when opening \"{file_path}\", please check if this is fixed with the latest version of {library_name} (e.g. with https://github.com/qarmin/crates_tester) and if it is not fixed, please report bug here - {home_library_url}")
}
@ -205,6 +208,7 @@ impl Common {
);
}
#[must_use]
pub fn delete_multiple_entries(entries: &[String]) -> Vec<String> {
let mut path: &Path;
let mut warnings: Vec<String> = Vec::new();
@ -220,9 +224,10 @@ impl Common {
}
warnings
}
#[must_use]
pub fn delete_one_entry(entry: &str) -> String {
let path: &Path = Path::new(entry);
let mut warning: String = String::from("");
let mut warning: String = String::new();
if path.is_dir() {
if let Err(e) = fs::remove_dir_all(entry) {
warning = format!("Failed to remove folder {entry}, reason {e}")

View file

@ -62,7 +62,7 @@ pub enum ErrorType {
// Empty folders
/// Enum with values which show if folder is empty.
/// In function "optimize_folders" automatically "Maybe" is changed to "Yes", so it is not necessary to put it here
/// In function "`optimize_folders`" automatically "Maybe" is changed to "Yes", so it is not necessary to put it here
#[derive(Eq, PartialEq, Copy, Clone)]
pub(crate) enum FolderEmptiness {
No,
@ -134,6 +134,7 @@ impl<'a, 'b> Default for DirTraversalBuilder<'a, 'b, ()> {
}
impl<'a, 'b> DirTraversalBuilder<'a, 'b, ()> {
#[must_use]
pub fn new() -> DirTraversalBuilder<'a, 'b, ()> {
DirTraversalBuilder {
group_by: None,
@ -413,7 +414,7 @@ where
}
};
match (entry_type(&metadata), collect) {
(EntryType::Dir, Collect::Files) | (EntryType::Dir, Collect::InvalidSymlinks) => {
(EntryType::Dir, Collect::Files | Collect::InvalidSymlinks) => {
if !recursive_search {
continue 'dir;
}
@ -540,14 +541,14 @@ where
0
}
},
hash: "".to_string(),
hash: String::new(),
symlink_info: None,
};
fe_result.push(fe);
}
}
(EntryType::File, Collect::EmptyFolders) | (EntryType::Symlink, Collect::EmptyFolders) => {
(EntryType::File | EntryType::Symlink, Collect::EmptyFolders) => {
#[cfg(target_family = "unix")]
if directories.exclude_other_filesystems() {
match directories.is_on_other_filesystems(current_folder) {
@ -653,7 +654,7 @@ where
}
},
size: 0,
hash: "".to_string(),
hash: String::new(),
symlink_info: Some(SymlinkInfo { destination_path, type_of_error }),
};

View file

@ -19,6 +19,7 @@ pub struct Directories {
}
impl Directories {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -323,6 +324,7 @@ impl Directories {
}
#[cfg(target_family = "unix")]
#[must_use]
pub fn exclude_other_filesystems(&self) -> bool {
self.exclude_other_filesystems.unwrap_or(false)
}

View file

@ -9,6 +9,7 @@ pub struct Extensions {
}
impl Extensions {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -24,7 +25,7 @@ impl Extensions {
allowed_extensions = allowed_extensions.replace("MUSIC", "mp3,flac,ogg,tta,wma,webm");
allowed_extensions = allowed_extensions.replace("TEXT", "txt,doc,docx,odt,rtf");
let extensions: Vec<String> = allowed_extensions.split(',').map(|e| e.trim()).map(String::from).collect();
let extensions: Vec<String> = allowed_extensions.split(',').map(str::trim).map(String::from).collect();
for mut extension in extensions {
if extension.is_empty() || extension.replace(['.', ' '], "").trim().is_empty() {
continue;
@ -59,6 +60,7 @@ impl Extensions {
Common::print_time(start_time, SystemTime::now(), "set_allowed_extensions".to_string());
}
#[must_use]
pub fn matches_filename(&self, file_name: &str) -> bool {
// assert_eq!(file_name, file_name.to_lowercase());
if !self.file_extensions.is_empty() && !self.file_extensions.iter().any(|e| file_name.ends_with(e)) {
@ -67,6 +69,7 @@ impl Extensions {
true
}
#[must_use]
pub fn using_custom_extensions(&self) -> bool {
!self.file_extensions.is_empty()
}
@ -74,7 +77,7 @@ impl Extensions {
pub fn extend_allowed_extensions(&mut self, file_extensions: &[&str]) {
for extension in file_extensions {
assert!(extension.starts_with('.'));
self.file_extensions.push(extension.to_string());
self.file_extensions.push((*extension).to_string());
}
}
@ -83,8 +86,8 @@ impl Extensions {
for extension in file_extensions {
assert!(extension.starts_with('.'));
if self.file_extensions.contains(&extension.to_string()) {
current_file_extensions.push(extension.to_string());
if self.file_extensions.contains(&(*extension).to_string()) {
current_file_extensions.push((*extension).to_string());
}
}
self.file_extensions = current_file_extensions;

View file

@ -10,6 +10,7 @@ pub struct ExcludedItems {
}
impl ExcludedItems {
#[must_use]
pub fn new() -> Self {
Default::default()
}

View file

@ -6,14 +6,16 @@ pub struct Messages {
}
impl Messages {
#[must_use]
pub fn new() -> Self {
Default::default()
}
pub fn print_messages(&self) {
println!("{}", self.create_messages_text());
}
#[must_use]
pub fn create_messages_text(&self) -> String {
let mut text_to_return: String = "".to_string();
let mut text_to_return: String = String::new();
if !self.messages.is_empty() {
text_to_return += "-------------------------------MESSAGES--------------------------------\n";

View file

@ -73,6 +73,7 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -109,6 +110,7 @@ pub struct DuplicateFinder {
}
impl DuplicateFinder {
#[must_use]
pub fn new() -> Self {
Self {
text_messages: Messages::new(),
@ -184,10 +186,12 @@ impl DuplicateFinder {
self.case_sensitive_name_comparison = case_sensitive_name_comparison;
}
#[must_use]
pub const fn get_check_method(&self) -> &CheckingMethod {
&self.check_method
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
@ -200,6 +204,7 @@ impl DuplicateFinder {
self.minimal_prehash_cache_file_size = minimal_prehash_cache_file_size;
}
#[must_use]
pub const fn get_files_sorted_by_names(&self) -> &BTreeMap<String, Vec<FileEntry>> {
&self.files_with_identical_names
}
@ -212,10 +217,12 @@ impl DuplicateFinder {
self.use_prehash_cache = use_prehash_cache;
}
#[must_use]
pub const fn get_files_sorted_by_size(&self) -> &BTreeMap<u64, Vec<FileEntry>> {
&self.files_with_identical_size
}
#[must_use]
pub const fn get_files_sorted_by_hash(&self) -> &BTreeMap<u64, Vec<Vec<FileEntry>>> {
&self.files_with_identical_hashes
}
@ -226,10 +233,12 @@ impl DuplicateFinder {
};
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -261,6 +270,7 @@ impl DuplicateFinder {
};
}
#[must_use]
pub fn get_use_reference(&self) -> bool {
self.use_reference_folders
}
@ -295,14 +305,17 @@ impl DuplicateFinder {
self.allowed_extensions.set_allowed_extensions(allowed_extensions, &mut self.text_messages);
}
#[must_use]
pub fn get_files_with_identical_hashes_referenced(&self) -> &BTreeMap<u64, Vec<(FileEntry, Vec<FileEntry>)>> {
&self.files_with_identical_hashes_referenced
}
#[must_use]
pub fn get_files_with_identical_name_referenced(&self) -> &BTreeMap<String, (FileEntry, Vec<FileEntry>)> {
&self.files_with_identical_names_referenced
}
#[must_use]
pub fn get_files_with_identical_size_referenced(&self) -> &BTreeMap<u64, (FileEntry, Vec<FileEntry>)> {
&self.files_with_identical_size_referenced
}
@ -520,7 +533,7 @@ impl DuplicateFinder {
let progress_send = progress_sender.clone();
let progress_thread_run = progress_thread_run.clone();
let atomic_file_counter = atomic_file_counter.clone();
let files_to_check = self.files_with_identical_size.values().map(|e| e.len()).sum();
let files_to_check = self.files_with_identical_size.values().map(std::vec::Vec::len).sum();
let checking_method = self.check_method;
thread::spawn(move || loop {
progress_send
@ -679,7 +692,7 @@ impl DuplicateFinder {
let progress_send = progress_sender.clone();
let progress_thread_run = progress_thread_run.clone();
let atomic_file_counter = atomic_file_counter.clone();
let files_to_check = pre_checked_map.values().map(|vec_file_entry| vec_file_entry.len()).sum();
let files_to_check = pre_checked_map.values().map(std::vec::Vec::len).sum();
let checking_method = self.check_method;
thread::spawn(move || loop {
progress_send
@ -895,7 +908,7 @@ impl DuplicateFinder {
true
}
/// Function to delete files, from filed before BTreeMap
/// Function to delete files, from filed before `BTreeMap`
/// Using another function to delete files to avoid duplicates data
fn delete_files(&mut self) {
let start_time: SystemTime = SystemTime::now();
@ -1127,7 +1140,7 @@ impl PrintResults for DuplicateFinder {
}
}
CheckingMethod::Hash => {
for (_size, vector) in self.files_with_identical_hashes.iter() {
for (_size, vector) in &self.files_with_identical_hashes {
for j in vector {
number_of_files += j.len() as u64;
number_of_groups += 1;
@ -1190,7 +1203,7 @@ fn delete_files(vector: &[FileEntry], delete_method: &DeleteMethod, text_message
DeleteMethod::OneNewest | DeleteMethod::AllExceptOldest | DeleteMethod::HardLink => values.min_by(|(_, l), (_, r)| l.modified_date.cmp(&r.modified_date)),
DeleteMethod::None => values.next(),
};
let q_index = q_index.map(|t| t.0).unwrap_or(0);
let q_index = q_index.map_or(0, |t| t.0);
let n = match delete_method {
DeleteMethod::OneNewest | DeleteMethod::OneOldest => 1,
DeleteMethod::AllExceptNewest | DeleteMethod::AllExceptOldest | DeleteMethod::None | DeleteMethod::HardLink => usize::MAX,
@ -1372,7 +1385,7 @@ pub fn load_hashes_from_file(text_messages: &mut Messages, delete_outdated_cache
text_messages.messages.push(flc!(
"core_loading_from_cache",
generate_translation_hashmap(vec![("number", hashmap_loaded_entries.values().map(|e| e.len()).sum::<usize>().to_string())])
generate_translation_hashmap(vec![("number", hashmap_loaded_entries.values().map(std::vec::Vec::len).sum::<usize>().to_string())])
));
return Some(hashmap_loaded_entries);

View file

@ -28,6 +28,7 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -47,6 +48,7 @@ pub struct EmptyFiles {
}
impl EmptyFiles {
#[must_use]
pub fn new() -> Self {
Self {
text_messages: Messages::new(),
@ -72,18 +74,22 @@ impl EmptyFiles {
self.debug_print();
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
#[must_use]
pub const fn get_empty_files(&self) -> &Vec<FileEntry> {
&self.empty_files
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -239,7 +245,7 @@ impl SaveResults for EmptyFiles {
if !self.empty_files.is_empty() {
writeln!(writer, "Found {} empty files.", self.information.number_of_empty_files).unwrap();
for file_entry in self.empty_files.iter() {
for file_entry in &self.empty_files {
writeln!(writer, "{}", file_entry.path.display()).unwrap();
}
} else {
@ -256,7 +262,7 @@ impl PrintResults for EmptyFiles {
fn print_results(&self) {
let start_time: SystemTime = SystemTime::now();
println!("Found {} empty files.\n", self.information.number_of_empty_files);
for file_entry in self.empty_files.iter() {
for file_entry in &self.empty_files {
println!("{}", file_entry.path.display());
}

View file

@ -32,14 +32,16 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
}
/// Method implementation for EmptyFolder
/// Method implementation for `EmptyFolder`
impl EmptyFolder {
/// New function providing basics values
#[must_use]
pub fn new() -> Self {
Self {
information: Default::default(),
@ -52,17 +54,21 @@ impl EmptyFolder {
}
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
#[must_use]
pub const fn get_empty_folder_list(&self) -> &BTreeMap<PathBuf, FolderEntry> {
&self.empty_folder_list
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -121,7 +127,7 @@ impl EmptyFolder {
}
/// Function to check if folder are empty.
/// Parameter initial_checking for second check before deleting to be sure that checked folder is still empty
/// Parameter `initial_checking` for second check before deleting to be sure that checked folder is still empty
fn check_for_empty_folders(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
let result = DirTraversalBuilder::new()
.root_dirs(self.directories.included_directories.clone())

View file

@ -28,6 +28,7 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -47,6 +48,7 @@ pub struct InvalidSymlinks {
}
impl InvalidSymlinks {
#[must_use]
pub fn new() -> Self {
Self {
text_messages: Messages::new(),
@ -71,18 +73,22 @@ impl InvalidSymlinks {
self.debug_print();
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
#[must_use]
pub const fn get_invalid_symlinks(&self) -> &Vec<FileEntry> {
&self.invalid_symlinks
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -235,7 +241,7 @@ impl SaveResults for InvalidSymlinks {
if !self.invalid_symlinks.is_empty() {
writeln!(writer, "Found {} invalid symlinks.", self.information.number_of_invalid_symlinks).unwrap();
for file_entry in self.invalid_symlinks.iter() {
for file_entry in &self.invalid_symlinks {
writeln!(
writer,
"{}\t\t{}\t\t{}",
@ -262,7 +268,7 @@ impl PrintResults for InvalidSymlinks {
fn print_results(&self) {
let start_time: SystemTime = SystemTime::now();
println!("Found {} invalid symlinks.\n", self.information.number_of_invalid_symlinks);
for file_entry in self.invalid_symlinks.iter() {
for file_entry in &self.invalid_symlinks {
println!(
"{}\t\t{}\t\t{}",
file_entry.path.display(),

View file

@ -31,10 +31,12 @@ macro_rules! flc {
}
// Get the `Localizer` to be used for localizing this library.
#[must_use]
pub fn localizer_core() -> Box<dyn Localizer> {
Box::from(DefaultLocalizer::new(&*LANGUAGE_LOADER_CORE, &Localizations))
}
#[must_use]
pub fn generate_translation_hashmap(vec: Vec<(&'static str, String)>) -> HashMap<&'static str, String> {
let mut hashmap: HashMap<&'static str, String> = Default::default();
for (key, value) in vec {

View file

@ -39,7 +39,7 @@ bitflags! {
const YEAR = 0b100;
const LENGTH = 0b1000;
const GENRE = 0b10000;
const BITRATE = 0b100000;
const BITRATE = 0b10_0000;
}
}
@ -65,11 +65,11 @@ impl FileEntry {
path: self.path.clone(),
modified_date: self.modified_date,
track_title: "".to_string(),
track_artist: "".to_string(),
year: "".to_string(),
length: "".to_string(),
genre: "".to_string(),
track_title: String::new(),
track_artist: String::new(),
year: String::new(),
length: String::new(),
genre: String::new(),
bitrate: 0,
}
}
@ -83,6 +83,7 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -113,6 +114,7 @@ pub struct SameMusic {
}
impl SameMusic {
#[must_use]
pub fn new() -> Self {
Self {
text_messages: Messages::new(),
@ -157,21 +159,26 @@ impl SameMusic {
self.debug_print();
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
#[must_use]
pub const fn get_duplicated_music_entries(&self) -> &Vec<Vec<MusicEntry>> {
&self.duplicated_music_entries
}
#[must_use]
pub const fn get_music_similarity(&self) -> &MusicSimilarity {
&self.music_similarity
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -235,10 +242,12 @@ impl SameMusic {
};
}
#[must_use]
pub fn get_similar_music_referenced(&self) -> &Vec<(MusicEntry, Vec<MusicEntry>)> {
&self.duplicated_music_entries_referenced
}
#[must_use]
pub fn get_number_of_base_duplicated_files(&self) -> usize {
if self.use_reference_folders {
self.duplicated_music_entries_referenced.len()
@ -247,6 +256,7 @@ impl SameMusic {
}
}
#[must_use]
pub fn get_use_reference(&self) -> bool {
self.use_reference_folders
}
@ -402,10 +412,10 @@ impl SameMusic {
let properties = tagged_file.properties();
let mut track_title = "".to_string();
let mut track_artist = "".to_string();
let mut year = "".to_string();
let mut genre = "".to_string();
let mut track_title = String::new();
let mut track_artist = String::new();
let mut year = String::new();
let mut genre = String::new();
let bitrate = properties.audio_bitrate().unwrap_or(0);
let mut length = properties.duration().as_millis().to_string();
@ -451,10 +461,10 @@ impl SameMusic {
// That means, that audio have length smaller that second, but length is properly read
length = "0:01".to_string();
} else {
length = "".to_string();
length = String::new();
}
} else {
length = "".to_string();
length = String::new();
}
music_entry.track_title = track_title;
@ -467,8 +477,8 @@ impl SameMusic {
Some(Some(music_entry))
})
.while_some()
.filter(|music_entry| music_entry.is_some())
.map(|music_entry| music_entry.unwrap())
.filter(std::option::Option::is_some)
.map(std::option::Option::unwrap)
.collect::<Vec<_>>();
// End thread which send info to gui
@ -502,9 +512,7 @@ impl SameMusic {
true
}
fn check_for_duplicates(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
if MusicSimilarity::NONE == self.music_similarity {
panic!("This can't be none");
}
assert!(MusicSimilarity::NONE != self.music_similarity, "This can't be none");
let start_time: SystemTime = SystemTime::now();
//// PROGRESS THREAD START
@ -915,7 +923,7 @@ impl SaveResults for SameMusic {
if !self.music_entries.is_empty() {
writeln!(writer, "Found {} same music files.", self.information.number_of_duplicates).unwrap();
for file_entry in self.music_entries.iter() {
for file_entry in &self.music_entries {
writeln!(writer, "{}", file_entry.path.display()).unwrap();
}
} else {
@ -932,7 +940,7 @@ impl PrintResults for SameMusic {
fn print_results(&self) {
let start_time: SystemTime = SystemTime::now();
println!("Found {} similar music files.\n", self.duplicated_music_entries.len());
for vec_file_entry in self.duplicated_music_entries.iter() {
for vec_file_entry in &self.duplicated_music_entries {
for file_entry in vec_file_entry {
println!(
"TT: {} - TA: {} - Y: {} - L: {} - G: {} - B: {} - P: {}",

View file

@ -119,14 +119,16 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
}
/// Method implementation for EmptyFolder
/// Method implementation for `EmptyFolder`
impl SimilarImages {
/// New function providing basics values
#[must_use]
pub fn new() -> Self {
Self {
information: Default::default(),
@ -184,26 +186,32 @@ impl SimilarImages {
self.save_also_as_json = save_also_as_json;
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_similar_images(&self) -> &Vec<Vec<FileEntry>> {
&self.similar_vectors
}
#[must_use]
pub fn get_similar_images_referenced(&self) -> &Vec<(FileEntry, Vec<FileEntry>)> {
&self.similar_referenced_vectors
}
#[must_use]
pub fn get_use_reference(&self) -> bool {
self.use_reference_folders
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -270,7 +278,7 @@ impl SimilarImages {
// }
/// Function to check if folder are empty.
/// Parameter initial_checking for second check before deleting to be sure that checked folder is still empty
/// Parameter `initial_checking` for second check before deleting to be sure that checked folder is still empty
fn check_for_similar_images(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
let start_time: SystemTime = SystemTime::now();
let mut folders_to_check: Vec<PathBuf> = Vec::with_capacity(1024 * 2); // This should be small enough too not see to big difference and big enough to store most of paths without needing to resize vector
@ -422,7 +430,7 @@ impl SimilarImages {
let fe: FileEntry = FileEntry {
path: current_file_name.clone(),
size: metadata.len(),
dimensions: "".to_string(),
dimensions: String::new(),
modified_date: match metadata.modified() {
Ok(t) => match t.duration_since(UNIX_EPOCH) {
Ok(d) => d.as_secs(),
@ -629,8 +637,8 @@ impl SimilarImages {
Some(Some((file_entry, buf)))
})
.while_some()
.filter(|file_entry| file_entry.is_some())
.map(|file_entry| file_entry.unwrap())
.filter(std::option::Option::is_some)
.map(std::option::Option::unwrap)
.collect::<Vec<(FileEntry, Vec<u8>)>>();
// End thread which send info to gui
@ -760,7 +768,7 @@ impl SimilarImages {
if vec_files.len() >= 2 {
hashes_with_multiple_images.insert(hash);
}
self.bktree.add(hash.to_vec());
self.bktree.add(hash.clone());
}
for (hash, vec_files) in &files_from_referenced_folders {
if vec_files.len() >= 2 {
@ -781,7 +789,7 @@ impl SimilarImages {
additional_chunk_to_check.push(hash);
hashes_with_multiple_images.insert(hash);
} else {
self.bktree.add(hash.to_vec());
self.bktree.add(hash.clone());
}
}
chunk_size = all_hashes.len() / number_of_processors;
@ -809,7 +817,7 @@ impl SimilarImages {
for (index, hash_to_check) in hashes_to_check.iter().enumerate() {
// Don't check for user stop too often
// Also don't add too often data to atomic variable
const CYCLES_COUNTER: usize = 0b111111;
const CYCLES_COUNTER: usize = 0b11_1111;
if ((index & CYCLES_COUNTER) == CYCLES_COUNTER) && index != 0 {
atomic_mode_counter.fetch_add(CYCLES_COUNTER, Ordering::Relaxed);
if stop_receiver.is_some() && stop_receiver.unwrap().try_recv().is_ok() {
@ -959,7 +967,7 @@ impl SimilarImages {
{
let mut result_hashset: HashSet<String> = Default::default();
let mut found = false;
for (_hash, vec_file_entry) in collected_similar_images.iter() {
for (_hash, vec_file_entry) in &collected_similar_images {
if vec_file_entry.is_empty() {
println!("Empty Element {vec_file_entry:?}");
found = true;
@ -980,9 +988,7 @@ impl SimilarImages {
}
}
}
if found {
panic!("Found Invalid entries");
}
assert!(!found, "Found Invalid entries");
}
self.similar_vectors = collected_similar_images.into_values().collect();
@ -1179,7 +1185,7 @@ impl SaveResults for SimilarImages {
if !self.similar_vectors.is_empty() {
write!(writer, "{} images which have similar friends\n\n", self.similar_vectors.len()).unwrap();
for struct_similar in self.similar_vectors.iter() {
for struct_similar in &self.similar_vectors {
writeln!(writer, "Found {} images which have similar friends", self.similar_vectors.len()).unwrap();
for file_entry in struct_similar {
writeln!(
@ -1364,6 +1370,7 @@ pub fn get_string_from_similarity(similarity: &u32, hash_size: u8) -> String {
}
}
#[must_use]
pub fn return_similarity_from_similarity_preset(similarity_preset: &SimilarityPreset, hash_size: u8) -> u32 {
let index_preset = match hash_size {
8 => 0,
@ -1466,7 +1473,7 @@ fn debug_check_for_duplicated_things(
println!("------1--HASH--{} {:?}", numm, all_hashed_images.get(*hash).unwrap());
found_broken_thing = true;
}
hashmap_hashes.insert(hash.to_vec());
hashmap_hashes.insert((*hash).clone());
for i in all_hashed_images.get(*hash).unwrap() {
let name = i.path.to_string_lossy().to_string();
@ -1483,7 +1490,7 @@ fn debug_check_for_duplicated_things(
println!("------2--HASH--{} {:?}", numm, all_hashed_images.get(*hash).unwrap());
found_broken_thing = true;
}
hashmap_hashes.insert(hash.to_vec());
hashmap_hashes.insert((*hash).clone());
for i in all_hashed_images.get(*hash).unwrap() {
let name = i.path.to_string_lossy().to_string();

View file

@ -93,14 +93,16 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
}
/// Method implementation for EmptyFolder
/// Method implementation for `EmptyFolder`
impl SimilarVideos {
/// New function providing basics values
#[must_use]
pub fn new() -> Self {
Self {
information: Default::default(),
@ -141,10 +143,12 @@ impl SimilarVideos {
self.save_also_as_json = save_also_as_json;
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
@ -153,10 +157,12 @@ impl SimilarVideos {
self.allowed_extensions.set_allowed_extensions(allowed_extensions, &mut self.text_messages);
}
#[must_use]
pub const fn get_similar_videos(&self) -> &Vec<Vec<FileEntry>> {
&self.similar_vectors
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -188,10 +194,12 @@ impl SimilarVideos {
t => t,
};
}
#[must_use]
pub fn get_similar_videos_referenced(&self) -> &Vec<(FileEntry, Vec<FileEntry>)> {
&self.similar_referenced_vectors
}
#[must_use]
pub fn get_number_of_base_duplicated_files(&self) -> usize {
if self.use_reference_folders {
self.similar_referenced_vectors.len()
@ -200,6 +208,7 @@ impl SimilarVideos {
}
}
#[must_use]
pub fn get_use_reference(&self) -> bool {
self.use_reference_folders
}
@ -238,7 +247,7 @@ impl SimilarVideos {
// }
/// Function to check if folder are empty.
/// Parameter initial_checking for second check before deleting to be sure that checked folder is still empty
/// Parameter `initial_checking` for second check before deleting to be sure that checked folder is still empty
fn check_for_similar_videos(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
let start_time: SystemTime = SystemTime::now();
let mut folders_to_check: Vec<PathBuf> = Vec::with_capacity(1024 * 2); // This should be small enough too not see to big difference and big enough to store most of paths without needing to resize vector
@ -406,7 +415,7 @@ impl SimilarVideos {
}
},
vhash: Default::default(),
error: "".to_string(),
error: String::new(),
};
fe_result.push((current_file_name.to_string_lossy().to_string(), fe));
@ -712,7 +721,7 @@ impl SaveResults for SimilarVideos {
if !self.similar_vectors.is_empty() {
write!(writer, "{} videos which have similar friends\n\n", self.similar_vectors.len()).unwrap();
for struct_similar in self.similar_vectors.iter() {
for struct_similar in &self.similar_vectors {
writeln!(writer, "Found {} videos which have similar friends", self.similar_vectors.len()).unwrap();
for file_entry in struct_similar {
writeln!(writer, "{} - {}", file_entry.path.display(), format_size(file_entry.size, BINARY)).unwrap();
@ -813,6 +822,7 @@ fn get_cache_file() -> String {
"cache_similar_videos.bin".to_string()
}
#[must_use]
pub fn check_if_ffmpeg_is_installed() -> bool {
let vid = "9999czekoczekoczekolada999.txt";
if let Err(DetermineVideo {

View file

@ -45,6 +45,7 @@ pub struct Info {
}
impl Info {
#[must_use]
pub fn new() -> Self {
Default::default()
}
@ -63,6 +64,7 @@ pub struct Temporary {
}
impl Temporary {
#[must_use]
pub fn new() -> Self {
Self {
text_messages: Messages::new(),
@ -86,17 +88,21 @@ impl Temporary {
self.delete_files();
self.debug_print();
}
#[must_use]
pub fn get_stopped_search(&self) -> bool {
self.stopped_search
}
#[must_use]
pub const fn get_temporary_files(&self) -> &Vec<FileEntry> {
&self.temporary_files
}
#[must_use]
pub const fn get_text_messages(&self) -> &Messages {
&self.text_messages
}
#[must_use]
pub const fn get_information(&self) -> &Info {
&self.information
}
@ -413,7 +419,7 @@ impl SaveResults for Temporary {
if !self.temporary_files.is_empty() {
writeln!(writer, "Found {} temporary files.", self.information.number_of_temporary_files).unwrap();
for file_entry in self.temporary_files.iter() {
for file_entry in &self.temporary_files {
writeln!(writer, "{}", file_entry.path.display()).unwrap();
}
} else {
@ -428,7 +434,7 @@ impl PrintResults for Temporary {
fn print_results(&self) {
let start_time: SystemTime = SystemTime::now();
println!("Found {} temporary files.\n", self.information.number_of_temporary_files);
for file_entry in self.temporary_files.iter() {
for file_entry in &self.temporary_files {
println!("{}", file_entry.path.display());
}

View file

@ -352,11 +352,11 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
let values: [(u32, &dyn ToValue); 10] = [
(ColumnsDuplicates::ActivatableSelectButton as u32, &false),
(ColumnsDuplicates::SelectionButton as u32, &false),
(ColumnsDuplicates::Size as u32, (&"".to_string())),
(ColumnsDuplicates::Name as u32, (&"".to_string())),
(ColumnsDuplicates::Size as u32, (&String::new())),
(ColumnsDuplicates::Name as u32, (&String::new())),
(ColumnsDuplicates::Path as u32, (&(format!("{} results", vector.len())))),
(ColumnsDuplicates::Modification as u32, (&"".to_string())), // No text in 3 column
(ColumnsDuplicates::ModificationAsSecs as u32, (&(0))), // Not used here
(ColumnsDuplicates::Modification as u32, (&String::new())), // No text in 3 column
(ColumnsDuplicates::ModificationAsSecs as u32, (&(0))), // Not used here
(ColumnsDuplicates::Color as u32, &(HEADER_ROW_COLOR.to_string())),
(ColumnsDuplicates::IsHeader as u32, &true),
(ColumnsDuplicates::TextColor as u32, &(TEXT_COLOR.to_string())),
@ -408,10 +408,10 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
let values: [(u32, &dyn ToValue); 10] = [
(ColumnsDuplicates::ActivatableSelectButton as u32, &false),
(ColumnsDuplicates::SelectionButton as u32, &false),
(ColumnsDuplicates::Size as u32, (&"".to_string())),
(ColumnsDuplicates::Name as u32, (&"".to_string())),
(ColumnsDuplicates::Path as u32, (&"".to_string())),
(ColumnsDuplicates::Modification as u32, &"".to_string()), // No text in 3 column
(ColumnsDuplicates::Size as u32, (&String::new())),
(ColumnsDuplicates::Name as u32, (&String::new())),
(ColumnsDuplicates::Path as u32, (&String::new())),
(ColumnsDuplicates::Modification as u32, &String::new()), // No text in 3 column
(ColumnsDuplicates::ModificationAsSecs as u32, &(0)),
(ColumnsDuplicates::Color as u32, &(HEADER_ROW_COLOR.to_string())),
(ColumnsDuplicates::IsHeader as u32, &true),
@ -461,11 +461,11 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
let values: [(u32, &dyn ToValue); 10] = [
(ColumnsDuplicates::ActivatableSelectButton as u32, &false),
(ColumnsDuplicates::SelectionButton as u32, &false),
(ColumnsDuplicates::Size as u32, (&"".to_string())),
(ColumnsDuplicates::Name as u32, (&"".to_string())),
(ColumnsDuplicates::Path as u32, (&"".to_string())),
(ColumnsDuplicates::Modification as u32, &"".to_string()), // No text in 3 column
(ColumnsDuplicates::ModificationAsSecs as u32, &(0)), // Not used here
(ColumnsDuplicates::Size as u32, (&String::new())),
(ColumnsDuplicates::Name as u32, (&String::new())),
(ColumnsDuplicates::Path as u32, (&String::new())),
(ColumnsDuplicates::Modification as u32, &String::new()), // No text in 3 column
(ColumnsDuplicates::ModificationAsSecs as u32, &(0)), // Not used here
(ColumnsDuplicates::Color as u32, &(HEADER_ROW_COLOR.to_string())),
(ColumnsDuplicates::IsHeader as u32, &true),
(ColumnsDuplicates::TextColor as u32, &(TEXT_COLOR.to_string())),
@ -831,7 +831,7 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
let values: [(u32, &dyn ToValue); 13] = [
(ColumnsSimilarImages::ActivatableSelectButton as u32, &false),
(ColumnsSimilarImages::SelectionButton as u32, &false),
(ColumnsSimilarImages::Similarity as u32, &"".to_string()),
(ColumnsSimilarImages::Similarity as u32, &String::new()),
(ColumnsSimilarImages::Size as u32, &format_size(base_file_entry.size, BINARY)),
(ColumnsSimilarImages::SizeAsBytes as u32, &base_file_entry.size),
(ColumnsSimilarImages::Dimensions as u32, &base_file_entry.dimensions),
@ -849,7 +849,7 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
list_store.set(&list_store.append(), &values);
// Meat
for file_entry in vec_file_entry.iter() {
for file_entry in &vec_file_entry {
let (directory, file) = split_path(&file_entry.path);
let values: [(u32, &dyn ToValue); 13] = [
(ColumnsSimilarImages::ActivatableSelectButton as u32, &true),
@ -892,13 +892,13 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
let values: [(u32, &dyn ToValue); 13] = [
(ColumnsSimilarImages::ActivatableSelectButton as u32, &false),
(ColumnsSimilarImages::SelectionButton as u32, &false),
(ColumnsSimilarImages::Similarity as u32, &"".to_string()),
(ColumnsSimilarImages::Size as u32, &"".to_string()),
(ColumnsSimilarImages::Similarity as u32, &String::new()),
(ColumnsSimilarImages::Size as u32, &String::new()),
(ColumnsSimilarImages::SizeAsBytes as u32, &(0)),
(ColumnsSimilarImages::Dimensions as u32, &"".to_string()),
(ColumnsSimilarImages::Name as u32, &"".to_string()),
(ColumnsSimilarImages::Path as u32, &"".to_string()),
(ColumnsSimilarImages::Modification as u32, &"".to_string()),
(ColumnsSimilarImages::Dimensions as u32, &String::new()),
(ColumnsSimilarImages::Name as u32, &String::new()),
(ColumnsSimilarImages::Path as u32, &String::new()),
(ColumnsSimilarImages::Modification as u32, &String::new()),
(ColumnsSimilarImages::ModificationAsSecs as u32, &(0)),
(ColumnsSimilarImages::Color as u32, &(HEADER_ROW_COLOR.to_string())),
(ColumnsSimilarImages::IsHeader as u32, &true),
@ -907,7 +907,7 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
list_store.set(&list_store.append(), &values);
// Meat
for file_entry in vec_file_entry.iter() {
for file_entry in &vec_file_entry {
let (directory, file) = split_path(&file_entry.path);
let values: [(u32, &dyn ToValue); 13] = [
(ColumnsSimilarImages::ActivatableSelectButton as u32, &true),
@ -1030,7 +1030,7 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
list_store.set(&list_store.append(), &values);
// Meat
for file_entry in vec_file_entry.iter() {
for file_entry in &vec_file_entry {
let (directory, file) = split_path(&file_entry.path);
let values: [(u32, &dyn ToValue); 11] = [
(ColumnsSimilarVideos::ActivatableSelectButton as u32, &true),
@ -1071,11 +1071,11 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
let values: [(u32, &dyn ToValue); 11] = [
(ColumnsSimilarVideos::ActivatableSelectButton as u32, &false),
(ColumnsSimilarVideos::SelectionButton as u32, &false),
(ColumnsSimilarVideos::Size as u32, &"".to_string()),
(ColumnsSimilarVideos::Size as u32, &String::new()),
(ColumnsSimilarVideos::SizeAsBytes as u32, &(0)),
(ColumnsSimilarVideos::Name as u32, &"".to_string()),
(ColumnsSimilarVideos::Path as u32, &"".to_string()),
(ColumnsSimilarVideos::Modification as u32, &"".to_string()),
(ColumnsSimilarVideos::Name as u32, &String::new()),
(ColumnsSimilarVideos::Path as u32, &String::new()),
(ColumnsSimilarVideos::Modification as u32, &String::new()),
(ColumnsSimilarVideos::ModificationAsSecs as u32, &(0)),
(ColumnsSimilarVideos::Color as u32, &(HEADER_ROW_COLOR.to_string())),
(ColumnsSimilarVideos::IsHeader as u32, &true),
@ -1084,7 +1084,7 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
list_store.set(&list_store.append(), &values);
// Meat
for file_entry in vec_file_entry.iter() {
for file_entry in &vec_file_entry {
let (directory, file) = split_path(&file_entry.path);
let values: [(u32, &dyn ToValue); 11] = [
(ColumnsSimilarVideos::ActivatableSelectButton as u32, &true),
@ -1265,36 +1265,36 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
let values: [(u32, &dyn ToValue); 18] = [
(ColumnsSameMusic::ActivatableSelectButton as u32, &false),
(ColumnsSameMusic::SelectionButton as u32, &false),
(ColumnsSameMusic::Size as u32, &"".to_string()),
(ColumnsSameMusic::Size as u32, &String::new()),
(ColumnsSameMusic::SizeAsBytes as u32, &(0)),
(ColumnsSameMusic::Name as u32, &"".to_string()),
(ColumnsSameMusic::Path as u32, &"".to_string()),
(ColumnsSameMusic::Name as u32, &String::new()),
(ColumnsSameMusic::Path as u32, &String::new()),
(
ColumnsSameMusic::Title as u32,
&(match is_track_title {
true => text.clone(),
false => "".to_string(),
false => String::new(),
}),
),
(
ColumnsSameMusic::Artist as u32,
&(match is_track_artist {
true => text.clone(),
false => "".to_string(),
false => String::new(),
}),
),
(
ColumnsSameMusic::Year as u32,
&(match is_year {
true => text.clone(),
false => "".to_string(),
false => String::new(),
}),
),
(
ColumnsSameMusic::Bitrate as u32,
&(match is_bitrate {
true => text.clone(),
false => "".to_string(),
false => String::new(),
}),
),
(ColumnsSameMusic::BitrateAsNumber as u32, &(0)),
@ -1302,17 +1302,17 @@ pub fn connect_compute_results(gui_data: &GuiData, glib_stop_receiver: Receiver<
ColumnsSameMusic::Genre as u32,
&(match is_genre {
true => text.clone(),
false => "".to_string(),
false => String::new(),
}),
),
(
ColumnsSameMusic::Length as u32,
&(match is_length {
true => text.clone(),
false => "".to_string(),
false => String::new(),
}),
),
(ColumnsSameMusic::Modification as u32, &"".to_string()),
(ColumnsSameMusic::Modification as u32, &String::new()),
(ColumnsSameMusic::ModificationAsSecs as u32, &(0)),
(ColumnsSameMusic::Color as u32, &(HEADER_ROW_COLOR.to_string())),
(ColumnsSameMusic::IsHeader as u32, &true),

View file

@ -457,9 +457,7 @@ fn get_all_path(model: &TreeModel, current_path: &TreePath, column_header: i32,
returned_vector.push((full_name, name, model.path(&used_iter)));
}
if !model.iter_next(&used_iter) {
panic!("Found only header!");
}
assert!(model.iter_next(&used_iter), "Found only header!");
loop {
let name = model.get::<String>(&used_iter, column_name);
@ -490,13 +488,9 @@ fn move_iter(model: &TreeModel, tree_path: &TreePath, column_header: i32, go_nex
assert!(model.get::<bool>(&tree_iter, column_header));
if go_next {
if !model.iter_next(&tree_iter) {
panic!("Found only header!");
}
assert!(model.iter_next(&tree_iter), "Found only header!");
} else {
if !model.iter_previous(&tree_iter) {
panic!("Found only header!");
}
assert!(model.iter_previous(&tree_iter), "Found only header!");
}
loop {

View file

@ -108,7 +108,7 @@ pub async fn delete_things(gui_data: GuiData) {
} else {
image_preview_duplicates.hide();
}
*preview_path.borrow_mut() = "".to_string();
*preview_path.borrow_mut() = String::new();
}
_ => {}
}
@ -294,7 +294,7 @@ pub fn empty_folder_remover(
return; // No selected rows
}
let mut messages: String = "".to_string();
let mut messages: String = String::new();
// Must be deleted from end to start, because when deleting entries, TreePath(and also TreeIter) will points to invalid data
for tree_path in selected_rows.iter().rev() {
@ -334,7 +334,7 @@ pub fn empty_folder_remover(
}
};
if metadata.is_dir() {
next_folder = "".to_owned()
next_folder = String::new()
+ &current_folder
+ "/"
+ match &entry_data.file_name().into_string() {
@ -392,7 +392,7 @@ pub fn basic_remove(
let model = get_list_store(tree_view);
let mut messages: String = "".to_string();
let mut messages: String = String::new();
let mut selected_rows = Vec::new();
@ -468,7 +468,7 @@ pub fn tree_remove(
let model = get_list_store(tree_view);
let mut messages: String = "".to_string();
let mut messages: String = String::new();
let mut vec_path_to_delete: Vec<(String, String)> = Vec::new();
let mut map_with_path_to_delete: BTreeMap<String, Vec<String>> = Default::default(); // BTreeMap<Path,Vec<FileName>>

View file

@ -91,7 +91,7 @@ async fn sym_hard_link_things(gui_data: GuiData, hardlinking: TypeOfTool) {
} else {
image_preview_duplicates.hide();
}
*preview_path.borrow_mut() = "".to_string();
*preview_path.borrow_mut() = String::new();
}
_ => {}
}
@ -154,9 +154,7 @@ fn hardlink_symlink(
}
current_symhardlink_data = None;
if !model.iter_next(&current_iter) {
panic!("HEADER, shouldn't be a last item.");
}
assert!(model.iter_next(&current_iter), "HEADER, shouldn't be a last item.");
continue;
}
@ -201,7 +199,7 @@ fn hardlink_symlink(
}
if hardlinking == TypeOfTool::Hardlinking {
for symhardlink_data in vec_symhardlink_data {
for file_to_hardlink in symhardlink_data.files_to_symhardlink.into_iter() {
for file_to_hardlink in symhardlink_data.files_to_symhardlink {
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;
@ -210,7 +208,7 @@ fn hardlink_symlink(
}
} else {
for symhardlink_data in vec_symhardlink_data {
for file_to_symlink in symhardlink_data.files_to_symhardlink.into_iter() {
for file_to_symlink in symhardlink_data.files_to_symhardlink {
if let Err(e) = fs::remove_file(&file_to_symlink) {
add_text_to_text_view(
text_view_errors,

View file

@ -55,7 +55,7 @@ pub fn connect_button_move(gui_data: &GuiData) {
} else {
image_preview_duplicates.hide();
}
*preview_path.borrow_mut() = "".to_string();
*preview_path.borrow_mut() = String::new();
}
_ => {}
}
@ -215,7 +215,7 @@ fn move_files_common(
entry_info: &gtk4::Entry,
text_view_errors: &gtk4::TextView,
) {
let mut messages: String = "".to_string();
let mut messages: String = String::new();
let mut moved_files: u32 = 0;

View file

@ -132,7 +132,13 @@ pub fn connect_button_search(
Some(ColumnsIncludedDirectory::ReferenceButton as i32),
));
let recursive_search = check_button_recursive.is_active();
let excluded_items = entry_excluded_items.text().as_str().to_string().split(',').map(|e| e.to_string()).collect::<Vec<String>>();
let excluded_items = entry_excluded_items
.text()
.as_str()
.to_string()
.split(',')
.map(std::string::ToString::to_string)
.collect::<Vec<String>>();
let allowed_extensions = entry_allowed_extensions.text().as_str().to_string();
let hide_hard_links = check_button_settings_hide_hard_links.is_active();
let use_cache = check_button_settings_use_cache.is_active();

View file

@ -39,7 +39,7 @@ pub fn load_system_language(gui_data: &GuiData) {
if let Some(language) = requested_languages.get(0) {
let old_short_lang = language.to_string();
let mut short_lang = "".to_string();
let mut short_lang = String::new();
// removes from e.g. en_zb, ending _zd since Czkawka don't support this(maybe could add this in future, but only when)
for i in old_short_lang.chars() {
if i.is_ascii_alphabetic() {

View file

@ -290,7 +290,7 @@ fn popover_custom_select_unselect(
let message;
let text_to_check = entry_rust_regex.text().to_string();
if text_to_check.is_empty() {
message = "".to_string();
message = String::new();
} else {
match Regex::new(&text_to_check) {
Ok(_) => message = flg!("popover_valid_regex"),

View file

@ -121,7 +121,7 @@ pub fn connect_settings(gui_data: &GuiData) {
if response_type == ResponseType::Ok {
let mut messages: Messages = Messages::new();
for use_prehash in [true, false] {
for type_of_hash in [HashType::Xxh3, HashType::Blake3, HashType::Crc32].iter() {
for type_of_hash in &[HashType::Xxh3, HashType::Blake3, HashType::Crc32] {
if let Some(cache_entries) = czkawka_core::duplicate::load_hashes_from_file(&mut messages, true, type_of_hash, use_prehash) {
let mut hashmap_to_save: BTreeMap<String, czkawka_core::common_dir_traversal::FileEntry> = Default::default();
for (_, vec_file_entry) in cache_entries {
@ -161,17 +161,15 @@ pub fn connect_settings(gui_data: &GuiData) {
dialog.connect_response(move |dialog, response_type| {
if response_type == ResponseType::Ok {
let mut messages: Messages = Messages::new();
for hash_size in [8, 16, 32, 64].iter() {
for image_filter in [
for hash_size in &[8, 16, 32, 64] {
for image_filter in &[
FilterType::Lanczos3,
FilterType::CatmullRom,
FilterType::Gaussian,
FilterType::Nearest,
FilterType::Triangle,
]
.iter()
{
for hash_alg in [HashAlg::Blockhash, HashAlg::Gradient, HashAlg::DoubleGradient, HashAlg::VertGradient, HashAlg::Mean].iter() {
] {
for hash_alg in &[HashAlg::Blockhash, HashAlg::Gradient, HashAlg::DoubleGradient, HashAlg::VertGradient, HashAlg::Mean] {
if let Some(cache_entries) = czkawka_core::similar_images::load_hashes_from_file(&mut messages, true, *hash_size, *hash_alg, *image_filter) {
czkawka_core::similar_images::save_hashes_to_file(&cache_entries, &mut messages, false, *hash_size, *hash_alg, *image_filter);
}

View file

@ -139,9 +139,9 @@ impl GuiData {
let shared_buttons: Rc<RefCell<_>> = Rc::new(RefCell::new(HashMap::<NotebookMainEnum, HashMap<BottomButtonsEnum, bool>>::new()));
// Show by default only search button
for i in get_all_main_tabs().iter() {
for i in &get_all_main_tabs() {
let mut temp_hashmap: HashMap<BottomButtonsEnum, bool> = Default::default();
for button_name in bottom_buttons.buttons_names.iter() {
for button_name in &bottom_buttons.buttons_names {
if *button_name == BottomButtonsEnum::Search {
temp_hashmap.insert(*button_name, true);
} else {
@ -165,7 +165,7 @@ impl GuiData {
let shared_broken_files_state: Rc<RefCell<_>> = Rc::new(RefCell::new(BrokenFiles::new()));
let shared_bad_extensions_state: Rc<RefCell<_>> = Rc::new(RefCell::new(BadExtensions::new()));
let preview_path: Rc<RefCell<_>> = Rc::new(RefCell::new("".to_string()));
let preview_path: Rc<RefCell<_>> = Rc::new(RefCell::new(String::new()));
//// Entry
let entry_info: gtk4::Entry = builder.object("entry_info").unwrap();

View file

@ -258,7 +258,7 @@ pub fn get_path_buf_from_vector_of_strings(vec_string: Vec<String>) -> Vec<PathB
}
pub fn print_text_messages_to_text_view(text_messages: &Messages, text_view: &TextView) {
let mut messages: String = String::from("");
let mut messages: String = String::new();
if !text_messages.messages.is_empty() {
messages += format!("############### {}({}) ###############\n", flg!("text_view_messages"), text_messages.messages.len()).as_str();
}
@ -395,9 +395,8 @@ pub fn clean_invalid_headers(model: &ListStore, column_header: i32, column_path:
if let Some(first_iter) = model.iter_first() {
let mut vec_tree_path_to_delete: Vec<gtk4::TreePath> = Vec::new();
let mut current_iter = first_iter;
if !model.get::<bool>(&current_iter, column_header) {
panic!("First deleted element, should be a header"); // First element should be header
};
// First element should be header
assert!(model.get::<bool>(&current_iter, column_header), "First deleted element, should be a header");
let mut next_iter;
let mut next_next_iter;
@ -405,9 +404,8 @@ pub fn clean_invalid_headers(model: &ListStore, column_header: i32, column_path:
// Empty means default check type
if model.get::<String>(&current_iter, column_path).is_empty() {
'main: loop {
if !model.get::<bool>(&current_iter, column_header) {
panic!("First deleted element, should be a header"); // First element should be header
};
// First element should be header
assert!(model.get::<bool>(&current_iter, column_header), "First deleted element, should be a header");
next_iter = current_iter;
if !model.iter_next(&next_iter) {
@ -458,9 +456,8 @@ pub fn clean_invalid_headers(model: &ListStore, column_header: i32, column_path:
// Non empty means that header points at reference folder
else {
'reference: loop {
if !model.get::<bool>(&current_iter, column_header) {
panic!("First deleted element, should be a header"); // First element should be header
};
// First element should be header
assert!(model.get::<bool>(&current_iter, column_header), "First deleted element, should be a header");
next_iter = current_iter;
if !model.iter_next(&next_iter) {
@ -614,8 +611,8 @@ pub fn get_max_file_name(file_name: &str, max_length: usize) -> String {
let start_characters = 10;
let difference = characters_in_filename - max_length;
let second_part_start = start_characters + difference;
let mut string_pre = "".to_string();
let mut string_after = "".to_string();
let mut string_pre = String::new();
let mut string_after = String::new();
for (index, character) in file_name.chars().enumerate() {
if index < start_characters {

View file

@ -1,5 +1,5 @@
use std::cell::RefCell;
use std::ops::Deref;
use std::path::Path;
use std::rc::Rc;
@ -581,7 +581,7 @@ fn show_preview(
{
let preview_path = preview_path.borrow();
let preview_path = preview_path.deref();
let preview_path = &*preview_path;
if file_name == preview_path {
return; // Preview is already created, no need to recreate it
}
@ -697,7 +697,7 @@ fn show_preview(
image_preview.hide();
{
let mut preview_path = preview_path.borrow_mut();
*preview_path = "".to_string();
*preview_path = String::new();
}
}
}

View file

@ -113,7 +113,7 @@ impl LoadSaveStruct {
return if item.len() == 1 {
item[0].clone()
} else if item.is_empty() {
"".to_string()
String::new()
} else {
add_text_to_text_view(
&self.text_view,
@ -312,7 +312,7 @@ impl LoadSaveStruct {
return;
}
let mut header: String = "".to_string();
let mut header: String = String::new();
let lines: Vec<String> = loaded_data.replace('\r', "").split('\n').map(String::from).collect::<Vec<String>>();
for (index, line) in lines.iter().enumerate() {
let line = line.trim();
@ -732,7 +732,7 @@ pub fn load_configuration(
hashmap_ls.get(&LoadText::ExcludedItems).unwrap().clone(),
upper_notebook.entry_excluded_items.text().to_string(),
);
let allowed_extensions: String = loaded_entries.get_string(hashmap_ls.get(&LoadText::AllowedExtensions).unwrap().clone(), "".to_string());
let allowed_extensions: String = loaded_entries.get_string(hashmap_ls.get(&LoadText::AllowedExtensions).unwrap().clone(), String::new());
let minimal_file_size: String = loaded_entries.get_integer_string(hashmap_ls.get(&LoadText::MinimalFileSize).unwrap().clone(), DEFAULT_MINIMAL_FILE_SIZE.to_string());
let maximal_file_size: String = loaded_entries.get_integer_string(hashmap_ls.get(&LoadText::MaximalFileSize).unwrap().clone(), DEFAULT_MAXIMAL_FILE_SIZE.to_string());
@ -999,7 +999,7 @@ pub fn reset_configuration(manual_clearing: bool, upper_notebook: &GuiUpperNoteb
add_text_to_text_view(&text_view_errors, "Failed to read current directory, setting C:\\ instead");
"C:\\".to_string()
} else {
"".to_string()
String::new()
}
}
};