Split TaskType::Command into wait and no-wait variants

Allows for apps to be simply launched
This commit is contained in:
2Shirt 2025-02-22 20:44:28 -08:00
parent c5a9dc80cb
commit f1c3743584
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
5 changed files with 66 additions and 35 deletions

View file

@ -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 {

View file

@ -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<TaskType> {
//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,
))

View file

@ -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<String>), // (command, args)
Diskpart(String), // (script_as_string)
CommandNoWait(PathBuf, Vec<String>), // (command, args)
CommandWait(PathBuf, Vec<String>), // (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<JoinHandle<()>>,
@ -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(),

View file

@ -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
)))?;
}
}
}

View file

@ -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<Rect> {
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<String> = 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 {