Skip to content

Commit

Permalink
Fix errors in progress bar caused by dividing by 0 (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin authored Dec 7, 2020
1 parent 6fab1a9 commit c1afbe6
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions czkawka_gui/src/connect_progress_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,24 @@ pub fn connect_progress_window(
1 => {
progress_bar_current_stage.show();
// progress_bar_all_stages.show();
progress_bar_all_stages.set_fraction((1f64 + (item.files_checked) as f64 / item.files_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.files_checked) as f64 / item.files_to_check as f64);
if item.files_to_check != 0 {
progress_bar_all_stages.set_fraction((1f64 + (item.files_checked) as f64 / item.files_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.files_checked) as f64 / item.files_to_check as f64);
} else {
progress_bar_all_stages.set_fraction((1f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction(0f64);
}
label_stage.set_text(format!("Analyzed partial hash of {}/{} files", item.files_checked, item.files_to_check).as_str());
}
// Hash - first 1MB of file or normal hash
2 => {
progress_bar_all_stages.set_fraction((2f64 + (item.files_checked) as f64 / item.files_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.files_checked) as f64 / item.files_to_check as f64);
if item.files_to_check != 0 {
progress_bar_all_stages.set_fraction((2f64 + (item.files_checked) as f64 / item.files_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.files_checked) as f64 / item.files_to_check as f64);
} else {
progress_bar_all_stages.set_fraction((2f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction(0f64);
}
label_stage.set_text(format!("Analyzed full hash of {}/{} files", item.files_checked, item.files_to_check).as_str());
}
_ => {
Expand Down Expand Up @@ -121,13 +131,23 @@ pub fn connect_progress_window(
}
1 => {
progress_bar_current_stage.show();
progress_bar_all_stages.set_fraction((1f64 + (item.music_checked) as f64 / item.music_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.music_checked) as f64 / item.music_to_check as f64);
if item.music_to_check != 0 {
progress_bar_all_stages.set_fraction((1f64 + (item.music_checked) as f64 / item.music_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.music_checked) as f64 / item.music_to_check as f64);
} else {
progress_bar_all_stages.set_fraction((1f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction(0f64);
}
label_stage.set_text(format!("Reading tags of {}/{} music files", item.music_checked, item.music_to_check).as_str());
}
2 => {
progress_bar_all_stages.set_fraction((2f64 + (item.music_checked) as f64 / item.music_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.music_checked) as f64 / item.music_to_check as f64);
if item.music_to_check != 0 {
progress_bar_all_stages.set_fraction((2f64 + (item.music_checked) as f64 / item.music_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.music_checked) as f64 / item.music_to_check as f64);
} else {
progress_bar_all_stages.set_fraction((2f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction(0f64);
}
label_stage.set_text(format!("Checking for duplicates of {}/{} music files", item.music_checked, item.music_to_check).as_str());
}
_ => {
Expand All @@ -152,8 +172,13 @@ pub fn connect_progress_window(
}
1 => {
progress_bar_current_stage.show();
progress_bar_all_stages.set_fraction((1f64 + (item.images_checked) as f64 / item.images_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.images_checked) as f64 / item.images_to_check as f64);
if item.images_to_check != 0 {
progress_bar_all_stages.set_fraction((1f64 + (item.images_checked) as f64 / item.images_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.images_checked) as f64 / item.images_to_check as f64);
} else {
progress_bar_all_stages.set_fraction((1f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction(0f64);
}
label_stage.set_text(format!("Hashing {}/{} image", item.images_checked, item.images_to_check).as_str());
}
_ => {
Expand Down Expand Up @@ -188,8 +213,13 @@ pub fn connect_progress_window(
}
1 => {
progress_bar_current_stage.show();
progress_bar_all_stages.set_fraction((1f64 + (item.files_checked) as f64 / item.files_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.files_checked) as f64 / item.files_to_check as f64);
if item.files_to_check != 0 {
progress_bar_all_stages.set_fraction((1f64 + (item.files_checked) as f64 / item.files_to_check as f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction((item.files_checked) as f64 / item.files_to_check as f64);
} else {
progress_bar_all_stages.set_fraction((1f64) / (item.max_stage + 1) as f64);
progress_bar_current_stage.set_fraction(0f64);
}
label_stage.set_text(format!("Checking {}/{} file", item.files_checked, item.files_to_check).as_str());
}
_ => {
Expand Down

0 comments on commit c1afbe6

Please sign in to comment.