Progress
This commit is contained in:
parent
2310b7a6e9
commit
86c3ef3a30
|
@ -3,7 +3,7 @@ use std::thread;
|
|||
use crossbeam_channel::Receiver;
|
||||
use slint::ComponentHandle;
|
||||
|
||||
use czkawka_core::common_dir_traversal::{ProgressData, ToolType};
|
||||
use czkawka_core::common_dir_traversal::{CheckingMethod, ProgressData, ToolType};
|
||||
|
||||
use crate::{MainWindow, ProgressToSend};
|
||||
|
||||
|
@ -16,60 +16,117 @@ pub fn connect_progress_gathering(app: &MainWindow, progress_receiver: Receiver<
|
|||
};
|
||||
|
||||
a.upgrade_in_event_loop(move |app| {
|
||||
let to_send;
|
||||
match progress_data.tool_type {
|
||||
ToolType::EmptyFiles => {
|
||||
let (all_progress, current_progress) = no_current_stage_get_data(&progress_data);
|
||||
to_send = ProgressToSend {
|
||||
all_progress,
|
||||
current_progress,
|
||||
step_name: format!("Checked {} files", progress_data.entries_checked).into(),
|
||||
};
|
||||
}
|
||||
ToolType::EmptyFolders => {
|
||||
let (all_progress, current_progress) = no_current_stage_get_data(&progress_data);
|
||||
to_send = ProgressToSend {
|
||||
all_progress,
|
||||
current_progress,
|
||||
step_name: format!("Checked {} folders", progress_data.entries_checked).into(),
|
||||
};
|
||||
}
|
||||
ToolType::SimilarImages => {
|
||||
let step_name;
|
||||
let all_progress;
|
||||
let current_progress;
|
||||
match progress_data.current_stage {
|
||||
0 => {
|
||||
(all_progress, current_progress) = no_current_stage_get_data(&progress_data);
|
||||
step_name = format!("Scanning {} file", progress_data.entries_checked);
|
||||
}
|
||||
1 => {
|
||||
(all_progress, current_progress) = common_get_data(&progress_data);
|
||||
step_name = format!("Hashing {}/{} image", progress_data.entries_checked, progress_data.entries_to_check);
|
||||
}
|
||||
2 => {
|
||||
(all_progress, current_progress) = common_get_data(&progress_data);
|
||||
step_name = format!("Comparing {}/{} image hash", progress_data.entries_checked, progress_data.entries_to_check);
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
let to_send = if progress_data.current_stage == 0 {
|
||||
progress_collect_items(&progress_data, progress_data.tool_type != ToolType::EmptyFolders)
|
||||
} else if check_if_loading_saving_cache(&progress_data) {
|
||||
progress_save_load_cache(&progress_data)
|
||||
} else {
|
||||
progress_default(&progress_data)
|
||||
};
|
||||
|
||||
to_send = ProgressToSend {
|
||||
all_progress,
|
||||
current_progress,
|
||||
step_name: step_name.into(),
|
||||
};
|
||||
}
|
||||
_ => {
|
||||
panic!("Invalid tool type {:?}", progress_data.tool_type);
|
||||
}
|
||||
}
|
||||
app.set_progress_datas(to_send);
|
||||
})
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
pub fn check_if_loading_saving_cache(progress_data: &ProgressData) -> bool {
|
||||
matches!(
|
||||
(progress_data.tool_type, progress_data.current_stage),
|
||||
(ToolType::SameMusic, 1 | 3) | (ToolType::Duplicate, 1 | 3 | 4 | 6)
|
||||
)
|
||||
}
|
||||
|
||||
fn progress_save_load_cache(item: &ProgressData) -> ProgressToSend {
|
||||
let step_name = match (item.tool_type, item.checking_method, item.current_stage) {
|
||||
(ToolType::SameMusic, CheckingMethod::AudioTags | CheckingMethod::AudioContent, 1) => "Loading cache",
|
||||
(ToolType::SameMusic, CheckingMethod::AudioTags | CheckingMethod::AudioContent, 3) => "Saving cache",
|
||||
(ToolType::Duplicate, CheckingMethod::Hash, 1) => "Loading prehash cache",
|
||||
(ToolType::Duplicate, CheckingMethod::Hash, 3) => "Saving prehash cache",
|
||||
(ToolType::Duplicate, CheckingMethod::Hash, 4) => "Loading hash cache",
|
||||
(ToolType::Duplicate, CheckingMethod::Hash, 6) => "Saving hash cache",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let (all_progress, current_progress) = common_get_data(item);
|
||||
ProgressToSend {
|
||||
all_progress,
|
||||
current_progress,
|
||||
step_name: step_name.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn progress_collect_items(item: &ProgressData, files: bool) -> ProgressToSend {
|
||||
let step_name = match (item.tool_type, item.checking_method) {
|
||||
(ToolType::Duplicate, CheckingMethod::Name) => {
|
||||
format!("Scanning name of {} file", item.entries_checked)
|
||||
}
|
||||
(ToolType::Duplicate, CheckingMethod::SizeName) => {
|
||||
format!("Scanning size and name of {} file", item.entries_checked)
|
||||
}
|
||||
(ToolType::Duplicate, CheckingMethod::Size | CheckingMethod::Hash) => {
|
||||
format!("Scanning size of {} file", item.entries_checked)
|
||||
}
|
||||
_ => {
|
||||
if files {
|
||||
format!("Scanning {} file", item.entries_checked)
|
||||
} else {
|
||||
format!("Scanning {} folder", item.entries_checked)
|
||||
}
|
||||
}
|
||||
};
|
||||
let (all_progress, current_progress) = no_current_stage_get_data(item);
|
||||
ProgressToSend {
|
||||
all_progress,
|
||||
current_progress,
|
||||
step_name: step_name.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn progress_default(item: &ProgressData) -> ProgressToSend {
|
||||
let step_name = match (item.tool_type, item.checking_method, item.current_stage) {
|
||||
(ToolType::SameMusic, CheckingMethod::AudioTags, 2) | (ToolType::SameMusic, CheckingMethod::AudioContent, 5) => {
|
||||
format!("Checking tags of {}/{} audio file", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::SameMusic, CheckingMethod::AudioContent, 2) => {
|
||||
format!("Checking content of {}/{} audio file", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::SameMusic, CheckingMethod::AudioTags, 4) => {
|
||||
format!("Scanning tags of {}/{} audio file", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::SameMusic, CheckingMethod::AudioContent, 4) => {
|
||||
format!("Scanning content of {}/{} audio file", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::SimilarImages, _, 1) => {
|
||||
format!("Hashing of {}/{} image", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::SimilarImages, _, 2) => {
|
||||
format!("Comparing {}/{} image hash", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::SimilarVideos, _, 1) => {
|
||||
format!("Hashing of {}/{} video", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::BrokenFiles, _, 1) => {
|
||||
format!("Checking {}/{} file", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::BadExtensions, _, 1) => {
|
||||
format!("Checking {}/{} file", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::Duplicate, CheckingMethod::Hash, 2) => {
|
||||
format!("Analyzing partial hash of {}/{} files", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
(ToolType::Duplicate, CheckingMethod::Hash, 5) => {
|
||||
format!("Analyzing full hash of {}/{} files", item.entries_checked, item.entries_to_check)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let (all_progress, current_progress) = common_get_data(item);
|
||||
ProgressToSend {
|
||||
all_progress,
|
||||
current_progress,
|
||||
step_name: step_name.into(),
|
||||
}
|
||||
}
|
||||
|
||||
// Used when current stage not have enough data to show status, so we show only all_stages
|
||||
// Happens if we searching files and we don't know how many files we need to check
|
||||
fn no_current_stage_get_data(item: &ProgressData) -> (i32, i32) {
|
||||
|
|
|
@ -88,8 +88,8 @@ fn scan_duplicates(a: Weak<MainWindow>, progress_sender: Sender<ProgressData>, s
|
|||
vector = finder
|
||||
.get_files_with_identical_hashes_referenced()
|
||||
.values()
|
||||
.cloned()
|
||||
.flatten()
|
||||
.cloned()
|
||||
.map(|(original, other)| (Some(original), other))
|
||||
.collect::<Vec<_>>();
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ fn scan_duplicates(a: Weak<MainWindow>, progress_sender: Sender<ProgressData>, s
|
|||
} else {
|
||||
match finder.get_check_method() {
|
||||
CheckingMethod::Hash => {
|
||||
vector = finder.get_files_sorted_by_hash().values().cloned().flatten().map(|items| (None, items)).collect::<Vec<_>>();
|
||||
vector = finder.get_files_sorted_by_hash().values().flatten().cloned().map(|items| (None, items)).collect::<Vec<_>>();
|
||||
}
|
||||
CheckingMethod::Name | CheckingMethod::Size | CheckingMethod::SizeName => {
|
||||
let values: Vec<_> = match finder.get_check_method() {
|
||||
|
|
Loading…
Reference in a new issue