diff --git a/boot_diags/src/app.rs b/boot_diags/src/app.rs index 7e2cbea..4c29f20 100644 --- a/boot_diags/src/app.rs +++ b/boot_diags/src/app.rs @@ -218,7 +218,7 @@ impl App { } // BCD - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/bcdedit.exe")), vec![ String::from("/store"), @@ -235,11 +235,11 @@ impl App { )); // Bitlocker - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/manage-bde.exe")), vec![String::from("-status"), format!("{letter_os}:")], )); - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/manage-bde.exe")), vec![ String::from("-protectors"), @@ -249,19 +249,19 @@ impl App { )); // DISM Health - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/dism.exe")), vec![format!("{letter_os}:")], )); // Filesystem Health - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/chkdsk.exe")), vec![format!("{letter_os}:")], )); // Registry - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/reg.exe")), vec![ String::from("load"), @@ -269,7 +269,7 @@ impl App { format!("{letter_os}:\\Windows\\System32\\config\\SOFTWARE"), ], )); - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/reg.exe")), vec![ String::from("load"), @@ -277,7 +277,7 @@ impl App { format!("{letter_os}:\\Windows\\System32\\config\\SYSTEM"), ], )); - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/reg.exe")), vec![ String::from("load"), @@ -285,15 +285,15 @@ impl App { format!("{letter_os}:\\Windows\\System32\\config\\DEFAULT"), ], )); - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/reg.exe")), vec![String::from("unload"), String::from("HKLM\\TmpSoftware")], )); - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/reg.exe")), vec![String::from("unload"), String::from("HKLM\\TmpSystem")], )); - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/reg.exe")), vec![String::from("unload"), String::from("HKU\\TmpDefault")], )); @@ -532,7 +532,7 @@ impl App { info!("Handling Task: {task:?}"); match self.cur_mode { Mode::BootScan => { - if let TaskType::Command(cmd_path, cmd_args) = &task.task_type { + if let TaskType::CommandWait(cmd_path, _cmd_args) = &task.task_type { let mut cmd_name = ""; if let Some(path) = cmd_path.file_name() { if let Some(cmd_str) = path.to_str() { @@ -577,7 +577,9 @@ impl App { } _ => { match task.task_type { - TaskType::Command(_, _) | TaskType::Diskpart(_) => { + TaskType::CommandNoWait(_, _) + | TaskType::CommandWait(_, _) + | TaskType::Diskpart(_) => { // Check result if let Some(result) = &task.result { match result { diff --git a/core/src/system/boot.rs b/core/src/system/boot.rs index 97862ef..3a87d2d 100644 --- a/core/src/system/boot.rs +++ b/core/src/system/boot.rs @@ -34,7 +34,7 @@ pub fn configure_disk( let mut tasks = Vec::new(); // Create - tasks.push(TaskType::Command( + tasks.push(TaskType::CommandWait( PathBuf::from(format!("{system32}/bcdboot.exe")), vec![ format!("{letter_os}:\\Windows"), @@ -50,7 +50,7 @@ pub fn configure_disk( // Update boot sector (for legacy setups) if table_type == PartitionTableType::Legacy { - tasks.push(TaskType::Command( + tasks.push(TaskType::CommandWait( PathBuf::from(format!("{system32}/bootsect.exe")), vec![ String::from("/nt60"), @@ -74,7 +74,7 @@ pub fn configure_disk( pub fn inject_driver(driver: &Driver, letter_os: &str, system32: &str) -> Result { //if let Some(driver_path_str) = driver.path.to_str() { let driver_path = driver.path.to_str().unwrap(); - Ok(TaskType::Command( + Ok(TaskType::CommandWait( PathBuf::from(format!("{system32}/dism.exe")), vec![ format!("/image:{letter_os}:\\"), @@ -100,7 +100,7 @@ pub fn set_mode( } }; - // Build Command + // Build CommandWait let mut cmd_args = vec![String::from("/store"), bcd_path]; match mode { SafeMode::Disable => { @@ -115,7 +115,7 @@ pub fn set_mode( cmd_args.push(String::from("minimal")); } } - Ok(TaskType::Command( + Ok(TaskType::CommandWait( PathBuf::from(format!("{system32}/bcdedit.exe")), cmd_args, )) diff --git a/core/src/tasks.rs b/core/src/tasks.rs index 92fe95b..b0bd7a9 100644 --- a/core/src/tasks.rs +++ b/core/src/tasks.rs @@ -16,6 +16,7 @@ use std::{ collections::VecDeque, + fmt, path::PathBuf, process::{Command, Stdio}, sync::{Arc, Mutex}, @@ -41,14 +42,36 @@ pub enum TaskResult { #[derive(Clone, Debug)] pub enum TaskType { - Command(PathBuf, Vec), // (command, args) - Diskpart(String), // (script_as_string) + CommandNoWait(PathBuf, Vec), // (command, args) + CommandWait(PathBuf, Vec), // (command, args) + Diskpart(String), // (script_as_string) ScanDisks, Sleep, UpdateDestDisk(usize), // (disk_index) UpdateDiskList, } +impl fmt::Display for TaskType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + TaskType::CommandNoWait(cmd_path, _) | TaskType::CommandWait(cmd_path, _) => { + write!( + f, + "Command(\"{}\")", + cmd_path.file_name().unwrap().to_string_lossy() + ) + } + TaskType::Diskpart(_) => { + write!(f, "Diskpart") + } + TaskType::ScanDisks => write!(f, "ScanDisks"), + TaskType::Sleep => write!(f, "Sleep"), + TaskType::UpdateDestDisk(_) => write!(f, "UpdateDestDisk"), + TaskType::UpdateDiskList => write!(f, "UpdateDiskList"), + } + } +} + #[derive(Debug)] pub struct Task { pub handle: Option>, @@ -145,7 +168,11 @@ impl Tasks { if let Some(task) = self.cur_task.take() { let task_tx = self.task_tx.clone(); match task.task_type { - TaskType::Command(ref cmd_path, ref cmd_args) => { + TaskType::CommandNoWait(ref cmd_path, ref cmd_args) => { + self.cur_handle = None; + run_task_command(cmd_path.clone(), cmd_args.clone(), task_tx); + } + TaskType::CommandWait(ref cmd_path, ref cmd_args) => { self.cur_handle = Some(run_task_command( cmd_path.clone(), cmd_args.clone(), diff --git a/deja_vu/src/app.rs b/deja_vu/src/app.rs index 9c7a125..635b62a 100644 --- a/deja_vu/src/app.rs +++ b/deja_vu/src/app.rs @@ -193,7 +193,7 @@ impl App { }; // (Re)Enable volume mounting - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from(format!("{system32}/mountvol.exe")), vec![String::from("/e")], )); @@ -213,7 +213,7 @@ impl App { popup::Type::Info, String::from("Running Clone Tool"), ))?; - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( self.config.clone_app_path.clone(), Vec::new(), )); @@ -520,13 +520,13 @@ impl App { fn handle_task(&mut self, task: &Task) -> Result<()> { match task.task_type { - TaskType::Command(_, _) | TaskType::Diskpart(_) => { + TaskType::CommandWait(_, _) | TaskType::Diskpart(_) => { // Check result if let Some(result) = &task.result { match result { TaskResult::Error(msg) => { self.action_tx - .send(Action::Error(format!("{task:?} Failed: {msg}")))?; + .send(Action::Error(format!("{} Failed: {msg}", task.task_type)))?; } TaskResult::Output(stdout, stderr, success) => { if !success { @@ -537,8 +537,10 @@ impl App { } else { String::from("Unknown Error") }; - self.action_tx - .send(Action::Error(format!("{task:?} Failed: {msg}")))?; + self.action_tx.send(Action::Error(format!( + "{} Failed: {msg}", + task.task_type + )))?; } } } diff --git a/pe_menu/src/app.rs b/pe_menu/src/app.rs index 0e5345c..b817f2f 100644 --- a/pe_menu/src/app.rs +++ b/pe_menu/src/app.rs @@ -230,7 +230,7 @@ impl App { // Run selected tool if let Some(tool) = self.list.get_selected() { info!("Run tool: {:?}", &tool); - self.tasks.add(build_command(&self, &tool)); + self.tasks.add(build_tool_command(&self, &tool)); } } Action::Resize(w, h) => self.handle_resize(tui, w, h)?, @@ -245,7 +245,7 @@ impl App { self.action_tx.send(Action::Select(None, None))?; } Action::OpenTerminal => { - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandNoWait( PathBuf::from("cmd.exe"), vec![String::from("-new_console:n")], )); @@ -255,11 +255,11 @@ impl App { popup::Type::Info, String::from("Restarting..."), ))?; - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from("X:/Windows/System32/sync64.exe"), vec![String::from("-r")], )); - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from("X:/Windows/System32/wpeutil.exe"), vec![String::from("reboot")], )); @@ -270,11 +270,11 @@ impl App { popup::Type::Info, String::from("Powering off..."), ))?; - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from("X:/Windows/System32/sync64.exe"), vec![String::from("-r")], )); - self.tasks.add(TaskType::Command( + self.tasks.add(TaskType::CommandWait( PathBuf::from("X:/Windows/System32/wpeutil.exe"), vec![String::from("shutdown")], )); @@ -371,7 +371,7 @@ fn get_chunks(r: Rect) -> Vec { chunks } -pub fn build_command(app: &App, tool: &Tool) -> TaskType { +pub fn build_tool_command(app: &App, tool: &Tool) -> TaskType { let cmd_path: PathBuf; let mut cmd_args: Vec = Vec::new(); let start_index: usize; @@ -392,7 +392,7 @@ pub fn build_command(app: &App, tool: &Tool) -> TaskType { }); } } - TaskType::Command(cmd_path, cmd_args) + TaskType::CommandNoWait(cmd_path, cmd_args) } fn build_left_items(app: &App) -> Action {