1 mod commands;
2
3 use commands::Commands;
4
5 #[allow(unused_imports)] // It is used in release for print_results().
6 use czkawka_core::common_traits::*;
7
8 use czkawka_core::similar_images::test_image_conversion_speed;
9 use czkawka_core::{
10 big_file::{self, BigFile},
11 broken_files::{self, BrokenFiles},
12 duplicate::DuplicateFinder,
13 empty_files::{self, EmptyFiles},
14 empty_folder::EmptyFolder,
15 invalid_symlinks,
16 invalid_symlinks::InvalidSymlinks,
17 same_music::SameMusic,
18 similar_images::{return_similarity_from_similarity_preset, SimilarImages},
19 temporary::{self, Temporary},
20 zeroed::{self, ZeroedFiles},
21 };
22 use std::process;
23 use structopt::StructOpt;
24
main()25 fn main() {
26 let command = Commands::from_args();
27
28 #[cfg(debug_assertions)]
29 println!("{:?}", command);
30
31 match command {
32 Commands::Duplicates {
33 directories,
34 excluded_directories,
35 excluded_items,
36 minimal_file_size,
37 maximal_file_size,
38 minimal_cached_file_size,
39 allowed_extensions,
40 search_method,
41 delete_method,
42 hash_type,
43 file_to_save,
44 not_recursive,
45 allow_hard_links,
46 dryrun,
47 } => {
48 let mut df = DuplicateFinder::new();
49
50 df.set_included_directory(directories.directories);
51 df.set_excluded_directory(excluded_directories.excluded_directories);
52 df.set_excluded_items(excluded_items.excluded_items);
53 df.set_minimal_file_size(minimal_file_size);
54 df.set_maximal_file_size(maximal_file_size);
55 df.set_minimal_cache_file_size(minimal_cached_file_size);
56 df.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
57 df.set_check_method(search_method);
58 df.set_delete_method(delete_method);
59 df.set_hash_type(hash_type);
60 df.set_recursive_search(!not_recursive.not_recursive);
61 df.set_ignore_hard_links(!allow_hard_links.allow_hard_links);
62 df.set_dryrun(dryrun.dryrun);
63
64 df.find_duplicates(None, None);
65
66 if let Some(file_name) = file_to_save.file_name() {
67 if !df.save_results_to_file(file_name) {
68 df.get_text_messages().print_messages();
69 process::exit(1);
70 }
71 }
72
73 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
74 df.print_results();
75 df.get_text_messages().print_messages();
76 }
77 Commands::EmptyFolders {
78 directories,
79 delete_folders,
80 file_to_save,
81 excluded_directories,
82 excluded_items,
83 } => {
84 let mut ef = EmptyFolder::new();
85
86 ef.set_included_directory(directories.directories);
87 ef.set_excluded_directory(excluded_directories.excluded_directories);
88 ef.set_excluded_items(excluded_items.excluded_items);
89 ef.set_delete_folder(delete_folders);
90
91 ef.find_empty_folders(None, None);
92
93 if let Some(file_name) = file_to_save.file_name() {
94 if !ef.save_results_to_file(file_name) {
95 ef.get_text_messages().print_messages();
96 process::exit(1);
97 }
98 }
99
100 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
101 ef.print_results();
102 ef.get_text_messages().print_messages();
103 }
104 Commands::BiggestFiles {
105 directories,
106 excluded_directories,
107 excluded_items,
108 allowed_extensions,
109 number_of_files,
110 file_to_save,
111 not_recursive,
112 delete_files,
113 } => {
114 let mut bf = BigFile::new();
115
116 bf.set_included_directory(directories.directories);
117 bf.set_excluded_directory(excluded_directories.excluded_directories);
118 bf.set_excluded_items(excluded_items.excluded_items);
119 bf.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
120 bf.set_number_of_files_to_check(number_of_files);
121 bf.set_recursive_search(!not_recursive.not_recursive);
122 if delete_files {
123 bf.set_delete_method(big_file::DeleteMethod::Delete);
124 }
125
126 bf.find_big_files(None, None);
127
128 if let Some(file_name) = file_to_save.file_name() {
129 if !bf.save_results_to_file(file_name) {
130 bf.get_text_messages().print_messages();
131 process::exit(1);
132 }
133 }
134
135 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
136 bf.print_results();
137 bf.get_text_messages().print_messages();
138 }
139 Commands::EmptyFiles {
140 directories,
141 excluded_directories,
142 excluded_items,
143 allowed_extensions,
144 delete_files,
145 file_to_save,
146 not_recursive,
147 } => {
148 let mut ef = EmptyFiles::new();
149
150 ef.set_included_directory(directories.directories);
151 ef.set_excluded_directory(excluded_directories.excluded_directories);
152 ef.set_excluded_items(excluded_items.excluded_items);
153 ef.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
154 ef.set_recursive_search(!not_recursive.not_recursive);
155
156 if delete_files {
157 ef.set_delete_method(empty_files::DeleteMethod::Delete);
158 }
159
160 ef.find_empty_files(None, None);
161
162 if let Some(file_name) = file_to_save.file_name() {
163 if !ef.save_results_to_file(file_name) {
164 ef.get_text_messages().print_messages();
165 process::exit(1);
166 }
167 }
168
169 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
170 ef.print_results();
171 ef.get_text_messages().print_messages();
172 }
173 Commands::Temporary {
174 directories,
175 excluded_directories,
176 excluded_items,
177 delete_files,
178 file_to_save,
179 not_recursive,
180 } => {
181 let mut tf = Temporary::new();
182
183 tf.set_included_directory(directories.directories);
184 tf.set_excluded_directory(excluded_directories.excluded_directories);
185 tf.set_excluded_items(excluded_items.excluded_items);
186 tf.set_recursive_search(!not_recursive.not_recursive);
187
188 if delete_files {
189 tf.set_delete_method(temporary::DeleteMethod::Delete);
190 }
191
192 tf.find_temporary_files(None, None);
193
194 if let Some(file_name) = file_to_save.file_name() {
195 if !tf.save_results_to_file(file_name) {
196 tf.get_text_messages().print_messages();
197 process::exit(1);
198 }
199 }
200
201 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
202 tf.print_results();
203 tf.get_text_messages().print_messages();
204 }
205 Commands::SimilarImages {
206 directories,
207 excluded_directories,
208 excluded_items,
209 file_to_save,
210 minimal_file_size,
211 maximal_file_size,
212 similarity_preset,
213 not_recursive,
214 hash_alg,
215 image_filter,
216 hash_size,
217 } => {
218 let mut sf = SimilarImages::new();
219
220 sf.set_included_directory(directories.directories);
221 sf.set_excluded_directory(excluded_directories.excluded_directories);
222 sf.set_excluded_items(excluded_items.excluded_items);
223 sf.set_minimal_file_size(minimal_file_size);
224 sf.set_maximal_file_size(maximal_file_size);
225 sf.set_recursive_search(!not_recursive.not_recursive);
226 sf.set_image_filter(image_filter);
227 sf.set_hash_alg(hash_alg);
228 sf.set_hash_size(hash_size);
229
230 sf.set_similarity(return_similarity_from_similarity_preset(&similarity_preset, hash_size));
231
232 sf.find_similar_images(None, None);
233
234 if let Some(file_name) = file_to_save.file_name() {
235 if !sf.save_results_to_file(file_name) {
236 sf.get_text_messages().print_messages();
237 process::exit(1);
238 }
239 }
240
241 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
242 sf.print_results();
243 sf.get_text_messages().print_messages();
244 }
245 Commands::ZeroedFiles {
246 directories,
247 excluded_directories,
248 excluded_items,
249 allowed_extensions,
250 delete_files,
251 file_to_save,
252 not_recursive,
253 minimal_file_size,
254 maximal_file_size,
255 } => {
256 let mut zf = ZeroedFiles::new();
257
258 zf.set_included_directory(directories.directories);
259 zf.set_excluded_directory(excluded_directories.excluded_directories);
260 zf.set_excluded_items(excluded_items.excluded_items);
261 zf.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
262 zf.set_minimal_file_size(minimal_file_size);
263 zf.set_maximal_file_size(maximal_file_size);
264 zf.set_recursive_search(!not_recursive.not_recursive);
265
266 if delete_files {
267 zf.set_delete_method(zeroed::DeleteMethod::Delete);
268 }
269
270 zf.find_zeroed_files(None, None);
271
272 if let Some(file_name) = file_to_save.file_name() {
273 if !zf.save_results_to_file(file_name) {
274 zf.get_text_messages().print_messages();
275 process::exit(1);
276 }
277 }
278
279 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
280 zf.print_results();
281 zf.get_text_messages().print_messages();
282 }
283 Commands::SameMusic {
284 directories,
285 excluded_directories,
286 excluded_items,
287 // delete_files,
288 file_to_save,
289 not_recursive,
290 minimal_file_size,
291 maximal_file_size,
292 music_similarity,
293 } => {
294 let mut mf = SameMusic::new();
295
296 mf.set_included_directory(directories.directories);
297 mf.set_excluded_directory(excluded_directories.excluded_directories);
298 mf.set_excluded_items(excluded_items.excluded_items);
299 mf.set_minimal_file_size(minimal_file_size);
300 mf.set_maximal_file_size(maximal_file_size);
301 mf.set_recursive_search(!not_recursive.not_recursive);
302 mf.set_music_similarity(music_similarity);
303
304 // if delete_files {
305 // // TODO mf.set_delete_method(same_music::DeleteMethod::Delete);
306 // }
307
308 mf.find_same_music(None, None);
309
310 if let Some(file_name) = file_to_save.file_name() {
311 if !mf.save_results_to_file(file_name) {
312 mf.get_text_messages().print_messages();
313 process::exit(1);
314 }
315 }
316
317 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
318 mf.print_results();
319 mf.get_text_messages().print_messages();
320 }
321 Commands::InvalidSymlinks {
322 directories,
323 excluded_directories,
324 excluded_items,
325 allowed_extensions,
326 file_to_save,
327 not_recursive,
328 delete_files,
329 } => {
330 let mut ifs = InvalidSymlinks::new();
331
332 ifs.set_included_directory(directories.directories);
333 ifs.set_excluded_directory(excluded_directories.excluded_directories);
334 ifs.set_excluded_items(excluded_items.excluded_items);
335 ifs.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
336 ifs.set_recursive_search(!not_recursive.not_recursive);
337 if delete_files {
338 ifs.set_delete_method(invalid_symlinks::DeleteMethod::Delete);
339 }
340
341 ifs.find_invalid_links(None, None);
342
343 if let Some(file_name) = file_to_save.file_name() {
344 if !ifs.save_results_to_file(file_name) {
345 ifs.get_text_messages().print_messages();
346 process::exit(1);
347 }
348 }
349
350 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
351 ifs.print_results();
352 ifs.get_text_messages().print_messages();
353 }
354 Commands::BrokenFiles {
355 directories,
356 excluded_directories,
357 excluded_items,
358 allowed_extensions,
359 delete_files,
360 file_to_save,
361 not_recursive,
362 } => {
363 let mut br = BrokenFiles::new();
364
365 br.set_included_directory(directories.directories);
366 br.set_excluded_directory(excluded_directories.excluded_directories);
367 br.set_excluded_items(excluded_items.excluded_items);
368 br.set_allowed_extensions(allowed_extensions.allowed_extensions.join(","));
369 br.set_recursive_search(!not_recursive.not_recursive);
370
371 if delete_files {
372 br.set_delete_method(broken_files::DeleteMethod::Delete);
373 }
374
375 br.find_broken_files(None, None);
376
377 if let Some(file_name) = file_to_save.file_name() {
378 if !br.save_results_to_file(file_name) {
379 br.get_text_messages().print_messages();
380 process::exit(1);
381 }
382 }
383
384 #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed
385 br.print_results();
386 br.get_text_messages().print_messages();
387 }
388 Commands::Tester { test_image } => {
389 if test_image {
390 test_image_conversion_speed();
391 } else {
392 println!("At least one test should be choosen!");
393 }
394 }
395 }
396 }
397