WIP: Expand boot diag text parsing

This commit is contained in:
2Shirt 2025-03-02 20:39:50 -08:00
parent f22501ce7d
commit 367a290b6d
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 76 additions and 43 deletions

View file

@ -190,7 +190,7 @@ impl App {
// Get System32 path
let system32 = if cfg!(windows) {
if let Ok(path) = env::var("SYSTEMROOT") {
format!("{path}/System32")
format!("{path}\\System32")
} else {
self.action_tx.send(Action::Error(String::from(
"ERROR\n\n\nFailed to find SYSTEMROOT",
@ -219,11 +219,11 @@ impl App {
// BCD
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/bcdedit.exe")),
PathBuf::from(format!("{system32}\\bcdedit.exe")),
vec![
String::from("/store"),
format!(
"{letter_boot}{}\\Boot\\BCD",
"{letter_boot}:{}\\Boot\\BCD",
if table_type == PartitionTableType::Guid {
"\\EFI\\Microsoft"
} else {
@ -236,11 +236,11 @@ impl App {
// Bitlocker
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/manage-bde.exe")),
PathBuf::from(format!("{system32}\\manage-bde.exe")),
vec![String::from("-status"), format!("{letter_os}:")],
));
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/manage-bde.exe")),
PathBuf::from(format!("{system32}\\manage-bde.exe")),
vec![
String::from("-protectors"),
String::from("-get"),
@ -250,19 +250,19 @@ impl App {
// DISM Health
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/dism.exe")),
PathBuf::from(format!("{system32}\\dism.exe")),
vec![format!("{letter_os}:")],
));
// Filesystem Health
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/chkdsk.exe")),
PathBuf::from(format!("{system32}\\chkdsk.exe")),
vec![format!("{letter_os}:")],
));
// Registry
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")),
PathBuf::from(format!("{system32}\\reg.exe")),
vec![
String::from("load"),
String::from("HKLM\\TmpSoftware"),
@ -270,7 +270,7 @@ impl App {
],
));
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")),
PathBuf::from(format!("{system32}\\reg.exe")),
vec![
String::from("load"),
String::from("HKLM\\TmpSystem"),
@ -278,7 +278,7 @@ impl App {
],
));
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")),
PathBuf::from(format!("{system32}\\reg.exe")),
vec![
String::from("load"),
String::from("HKU\\TmpDefault"),
@ -286,15 +286,15 @@ impl App {
],
));
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")),
PathBuf::from(format!("{system32}\\reg.exe")),
vec![String::from("unload"), String::from("HKLM\\TmpSoftware")],
));
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")),
PathBuf::from(format!("{system32}\\reg.exe")),
vec![String::from("unload"), String::from("HKLM\\TmpSystem")],
));
self.tasks.add(TaskType::CommandWait(
PathBuf::from(format!("{system32}/reg.exe")),
PathBuf::from(format!("{system32}\\reg.exe")),
vec![String::from("unload"), String::from("HKU\\TmpDefault")],
));
@ -539,10 +539,10 @@ impl App {
cmd_name = cmd_str;
}
};
let diag_type = diags::get_type(cmd_name);
match diag_type {
diags::Type::BootConfigData => {
let title = "Boot Files";
let diag_title = match diags::get_type(cmd_name) {
diags::Type::BootConfigData => Some("Boot Files"),
diags::Type::Bitlocker => Some("Bitlocker"),
diags::Type::FileSystem => {
if let Some(result) = &task.result {
let passed: bool;
let info: String;
@ -551,26 +551,48 @@ impl App {
passed = false;
info = msg.to_owned();
}
TaskResult::Output(stdout, stderr, success) => {
TaskResult::Output(stdout, _stderr, success) => {
passed = *success;
let div = if !(stdout.is_empty() || stderr.is_empty()) {
"\n\n-----------\n\n"
} else {
""
};
info = format!("{stdout}{div}{stderr}");
info = parse_chkdsk(stdout);
}
}
self.diag_groups
.update(title.to_string(), passed, info.to_owned());
self.diag_groups.update(
String::from("Filesystem"),
passed,
info.to_owned(),
);
}
None // Don't set title since we handle the logic here
}
diags::Type::Bitlocker => {}
diags::Type::FileSystem => {}
diags::Type::Registry => {}
diags::Type::FilesAndFolders => {}
diags::Type::Registry => Some("Registry"),
diags::Type::FilesAndFolders => Some("Critical Files"),
_ => {
warn!("Unrecognized command: {:?}", &cmd_path)
warn!("Unrecognized command: {:?}", &cmd_path);
None
}
};
if let Some(title) = diag_title {
// Just use command output
if let Some(result) = &task.result {
let passed: bool;
let info: String;
match result {
TaskResult::Error(msg) => {
passed = false;
info = msg.to_owned();
}
TaskResult::Output(stdout, stderr, success) => {
passed = *success;
let div = if !(stdout.is_empty() || stderr.is_empty()) {
"\n\n-----------\n\n"
} else {
""
};
info = format!("{stdout}{div}{stderr}");
}
}
self.diag_groups
.update(title.to_string(), passed, info.to_owned());
}
}
}
@ -846,14 +868,6 @@ fn build_right_items(app: &App) -> Action {
line_parts: vec![String::from("-----")],
line_colors: vec![Color::Reset],
},
DVLine {
line_parts: vec![format!("diag_groups: {:?}", &app.diag_groups)],
line_colors: vec![Color::Yellow],
},
DVLine {
line_parts: vec![String::from("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")],
line_colors: vec![Color::Reset],
},
]);
// TODO: DELETE THIS SECTION
match app.cur_mode {
@ -1010,3 +1024,22 @@ fn get_mode_strings(mode: Mode) -> (String, String) {
_ => panic!("This shouldn't happen"),
}
}
fn parse_chkdsk(output: &str) -> String {
// Split lines
let lines: Vec<_> = output.split("\r\n").collect();
// Omit progress lines and unhelpful messages
lines
.into_iter()
.filter(|line| {
!(line.contains("\r")
|| line.contains("Class not registered")
|| line.contains("/F parameter")
|| line.contains("Running CHKDSK")
|| line.contains("Total duration:")
|| line.contains("Failed to transfer logged messages"))
})
.collect::<Vec<_>>()
.join("\n")
}

View file

@ -83,19 +83,19 @@ pub fn get_type(cmd_name: &str) -> Type {
if cmd_name == "exa" {
return Type::BootConfigData;
}
if cmd_name == "bcdedit" {
if cmd_name == "bcdedit.exe" {
return Type::BootConfigData;
}
if cmd_name == "dir" {
return Type::FilesAndFolders;
}
if cmd_name == "reg" {
if cmd_name == "reg.exe" {
return Type::Registry;
}
if cmd_name == "chkdsk" {
if cmd_name == "chkdsk.exe" {
return Type::FileSystem;
}
if cmd_name == "manage-bde" {
if cmd_name == "manage-bde.exe" {
return Type::Bitlocker;
}
Type::Unknown