Thread handler bad extensions
This commit is contained in:
parent
b24b60fe0e
commit
34ea3bc96e
|
@ -5,7 +5,7 @@ use std::io::BufWriter;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread::sleep;
|
use std::thread::{sleep, JoinHandle};
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
use std::{mem, thread};
|
use std::{mem, thread};
|
||||||
|
|
||||||
|
@ -317,28 +317,27 @@ impl BadExtensions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn look_for_bad_extensions_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
fn prepare_bad_extension_thread_handler(
|
||||||
let system_time = SystemTime::now();
|
&self,
|
||||||
|
progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>,
|
||||||
let check_was_stopped = AtomicBool::new(false); // Used for breaking from GUI and ending check thread
|
progress_thread_run: Arc<AtomicBool>,
|
||||||
|
atomic_counter: Arc<AtomicUsize>,
|
||||||
//// PROGRESS THREAD START
|
current_stage: u8,
|
||||||
let progress_thread_run = Arc::new(AtomicBool::new(true));
|
max_stage: u8,
|
||||||
let atomic_file_counter = Arc::new(AtomicUsize::new(0));
|
max_value: usize,
|
||||||
|
) -> JoinHandle<()> {
|
||||||
let progress_thread_handle = if let Some(progress_sender) = progress_sender {
|
if let Some(progress_sender) = progress_sender {
|
||||||
let progress_send = progress_sender.clone();
|
let progress_send = progress_sender.clone();
|
||||||
let progress_thread_run = progress_thread_run.clone();
|
let progress_thread_run = progress_thread_run;
|
||||||
let atomic_file_counter = atomic_file_counter.clone();
|
let atomic_counter = atomic_counter;
|
||||||
let entries_to_check = self.files_to_check.len();
|
|
||||||
thread::spawn(move || loop {
|
thread::spawn(move || loop {
|
||||||
progress_send
|
progress_send
|
||||||
.unbounded_send(ProgressData {
|
.unbounded_send(ProgressData {
|
||||||
checking_method: CheckingMethod::None,
|
checking_method: CheckingMethod::None,
|
||||||
current_stage: 1,
|
current_stage,
|
||||||
max_stage: 1,
|
max_stage,
|
||||||
entries_checked: atomic_file_counter.load(Ordering::Relaxed),
|
entries_checked: atomic_counter.load(Ordering::Relaxed),
|
||||||
entries_to_check,
|
entries_to_check: max_value,
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if !progress_thread_run.load(Ordering::Relaxed) {
|
if !progress_thread_run.load(Ordering::Relaxed) {
|
||||||
|
@ -348,7 +347,21 @@ impl BadExtensions {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
thread::spawn(|| {})
|
thread::spawn(|| {})
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn look_for_bad_extensions_files(&mut self, stop_receiver: Option<&Receiver<()>>, progress_sender: Option<&futures::channel::mpsc::UnboundedSender<ProgressData>>) -> bool {
|
||||||
|
let system_time = SystemTime::now();
|
||||||
|
|
||||||
|
let check_was_stopped = AtomicBool::new(false); // Used for breaking from GUI and ending check thread
|
||||||
|
|
||||||
|
//// PROGRESS THREAD START
|
||||||
|
|
||||||
|
let progress_thread_run = Arc::new(AtomicBool::new(true));
|
||||||
|
let atomic_file_counter = Arc::new(AtomicUsize::new(0));
|
||||||
|
|
||||||
|
let progress_thread_handle =
|
||||||
|
self.prepare_bad_extension_thread_handler(progress_sender, progress_thread_run.clone(), atomic_file_counter.clone(), 1, 1, self.files_to_check.len());
|
||||||
|
|
||||||
let mut files_to_check = Default::default();
|
let mut files_to_check = Default::default();
|
||||||
mem::swap(&mut files_to_check, &mut self.files_to_check);
|
mem::swap(&mut files_to_check, &mut self.files_to_check);
|
||||||
|
|
|
@ -240,6 +240,7 @@ impl Common {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Function to check if directory match expression
|
/// Function to check if directory match expression
|
||||||
|
#[must_use]
|
||||||
pub fn regex_check(expression: &str, directory: impl AsRef<Path>) -> bool {
|
pub fn regex_check(expression: &str, directory: impl AsRef<Path>) -> bool {
|
||||||
if expression == "*" {
|
if expression == "*" {
|
||||||
return true;
|
return true;
|
||||||
|
@ -292,6 +293,7 @@ impl Common {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn normalize_windows_path(path_to_change: impl AsRef<Path>) -> PathBuf {
|
pub fn normalize_windows_path(path_to_change: impl AsRef<Path>) -> PathBuf {
|
||||||
let path = path_to_change.as_ref();
|
let path = path_to_change.as_ref();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue