Compare commits

...

2 commits

Author SHA1 Message Date
25b6fe4b7e
Add logo 2025-11-01 21:08:42 -07:00
b777a94c98
Apply fixes suggested by rust-analyzer
Apply more fixes
2025-11-01 21:08:42 -07:00
16 changed files with 374 additions and 381 deletions

View file

@ -132,23 +132,22 @@ impl App {
}
pub fn inject_driver(&mut self, index: usize) {
if let Some(driver) = self.clone.driver_list.get(index) {
if let Some(disk_index) = self.clone.disk_index_dest {
if let Some(driver) = self.clone.driver_list.get(index)
&& let Some(disk_index) = self.clone.disk_index_dest
{
let disk_list = self.clone.disk_list.lock().unwrap();
if let Some(disk) = disk_list.get(disk_index) {
if let Some(os_index) = self.clone.part_index_os {
if let Ok(task) = boot::inject_driver(
if let Some(disk) = disk_list.get(disk_index)
&& let Some(os_index) = self.clone.part_index_os
&& let Ok(task) = boot::inject_driver(
driver,
disk.get_part_letter(os_index).as_str(),
&self.system32,
) {
)
{
self.tasks.add(task);
}
}
}
}
}
}
pub fn next_mode(&mut self) -> Mode {
match self.cur_mode {
@ -175,21 +174,19 @@ impl App {
};
info!("Setting boot mode to: {new_mode}");
let disk_list = self.clone.disk_list.lock().unwrap();
if let Some(disk_index) = self.clone.disk_index_dest {
if let Some(disk) = disk_list.get(disk_index) {
if let Some(boot_index) = self.clone.part_index_boot {
if let Ok(task) = boot::set_mode(
if let Some(disk_index) = self.clone.disk_index_dest
&& let Some(disk) = disk_list.get(disk_index)
&& let Some(boot_index) = self.clone.part_index_boot
&& let Ok(task) = boot::set_mode(
disk.get_part_letter(boot_index).as_str(),
&boot_mode,
&self.system32,
&disk.part_type,
) {
)
{
self.tasks.add(task);
};
}
}
}
}
pub fn set_mode(&mut self, new_mode: Mode) -> Result<()> {
info!("Setting mode to {new_mode:?}");
@ -387,21 +384,21 @@ impl App {
}
}
Mode::InstallDrivers => {
if let Some(index) = one {
if let Some(driver) = self.clone.driver_list.get(index).cloned() {
if let Some(index) = one
&& let Some(driver) = self.clone.driver_list.get(index).cloned()
{
drivers::load(&driver.inf_paths);
self.clone.driver = Some(driver);
}
}
}
Mode::BootSetup => {
if let Some(index) = one {
if let Some(boot_mode) = self.setup_modes.get(index) {
if let Some(index) = one
&& let Some(boot_mode) = self.setup_modes.get(index)
{
info!("create_boot_files?");
create_boot_files(self, boot_mode.clone());
}
}
}
Mode::SelectDisks => {
self.clone.disk_index_dest = one;
}
@ -410,12 +407,12 @@ impl App {
self.clone.part_index_os = two;
}
Mode::SetBootMode => {
if let Some(index) = one {
if let Some(boot_mode) = self.boot_modes.get(index) {
if let Some(index) = one
&& let Some(boot_mode) = self.boot_modes.get(index)
{
self.set_boot_mode(boot_mode.to_owned());
}
}
}
_ => {}
},
Action::SetMode(new_mode) => {
@ -433,7 +430,7 @@ impl App {
text: title.clone(),
})?;
if let Ok(mut diag_groups) = self.diag_groups.lock() {
diag_groups.push(DiagGroup::new(get_diag_type(&title)));
diag_groups.push(DiagGroup::new(get_diag_type(title)));
}
}
}
@ -464,8 +461,9 @@ impl App {
fn handle_task(&mut self, task: &Task) -> Result<()> {
info!("Handling Task: {task:?}");
if self.cur_mode == Mode::BootScan {
if let Ok(mut diag_groups) = self.diag_groups.lock() {
if let Some(current_group) = diag_groups.last_mut() {
if let Ok(mut diag_groups) = self.diag_groups.lock()
&& let Some(current_group) = diag_groups.last_mut()
{
match current_group.diag_type {
DiagType::Bitlocker => {
if let Some(task_result) = &task.result {
@ -515,7 +513,6 @@ impl App {
text: current_group.result.clone(),
})?;
}
}
return Ok(());
}
match task.task_type {
@ -721,14 +718,14 @@ fn build_left_items(app: &App) -> Action {
labels[0] = String::from("boot");
labels[1] = String::from("os");
let disk_list = app.clone.disk_list.lock().unwrap();
if let Some(index) = app.clone.disk_index_dest {
if let Some(disk) = disk_list.get(index) {
if let Some(index) = app.clone.disk_index_dest
&& let Some(disk) = disk_list.get(index)
{
disk.get_parts().iter().for_each(|part| {
items.push(part.to_string());
});
}
}
}
Mode::BootDiags | Mode::LogView => {
select_type = SelectionType::Loop;
let (new_title, _) = get_mode_strings(app.cur_mode);
@ -746,7 +743,7 @@ fn build_left_items(app: &App) -> Action {
format!("{label}{status}")
})
.collect();
items.extend(labels.into_iter());
items.extend(labels);
}
}
Mode::BootSetup => {
@ -841,7 +838,7 @@ fn build_right_items(app: &App) -> Action {
let mut summary: Vec<DVLine> = Vec::new();
diag_groups
.iter()
.for_each(|group| summary.extend(group.get_logs_summary().into_iter()));
.for_each(|group| summary.extend(group.get_logs_summary()));
items.push(summary);
}
}

View file

@ -70,7 +70,7 @@ impl Component for LogView {
Action::KeyUp => {
if self.mode == Mode::LogView {
if self.line_index > 0 {
self.line_index = self.line_index - 1;
self.line_index -= 1;
}
} else {
self.list.previous();
@ -116,20 +116,20 @@ impl Component for LogView {
}
}
Action::KeyEnd => {
if self.mode == Mode::LogView {
if let Some(log_text) = self.list.get_selected() {
if self.mode == Mode::LogView
&& let Some(log_text) = self.list.get_selected()
{
let lines: Vec<&str> = log_text.split('\n').collect();
self.line_index = (lines.len() - 3) as u16;
}
}
}
Action::Process => {
if self.mode == Mode::LogView {
if let Some(command_tx) = self.command_tx.clone() {
if self.mode == Mode::LogView
&& let Some(command_tx) = self.command_tx.clone()
{
command_tx.send(Action::SetMode(Mode::BootDiags))?;
}
}
}
Action::SetMode(new_mode) => {
self.line_index = 0;
self.mode = new_mode;

View file

@ -121,13 +121,13 @@ impl DiagGroup {
let mut summaries: Vec<DVLine> = Vec::new();
self.logs
.iter()
.for_each(|log| summaries.extend(log.summary.clone().into_iter()));
.for_each(|log| summaries.extend(log.summary.clone()));
summaries
}
pub fn get_pass_fail_warn(&self) -> DiagResult {
let all_passed = self.passed.iter().fold(true, |acc, result| acc && *result);
let all_failed = self.passed.iter().fold(true, |acc, result| acc && !*result);
let all_passed = self.passed.iter().all(|result| *result);
let all_failed = self.passed.iter().all(|result| !*result);
if all_passed {
DiagResult::Pass
} else if all_failed {
@ -157,7 +157,7 @@ pub fn get_diag_type(label: &str) -> Type {
pub fn parse_bcd(diag_group: &mut DiagGroup, task_result: TaskResult) {
if !cfg!(windows) {
sleep(Duration::from_millis(500));
return ();
return;
}
match task_result {
TaskResult::Error(err) => {
@ -209,7 +209,7 @@ pub fn parse_bcd(diag_group: &mut DiagGroup, task_result: TaskResult) {
pub fn parse_bitlocker(diag_group: &mut DiagGroup, task_result: TaskResult) {
if !cfg!(windows) {
sleep(Duration::from_millis(500));
return ();
return;
}
let re_bitlocker_locked = REGEXES.bitlocker_locked();
let re_bitlocker_off = REGEXES.bitlocker_off();
@ -276,7 +276,7 @@ pub fn parse_bitlocker(diag_group: &mut DiagGroup, task_result: TaskResult) {
pub fn parse_chkdsk(diag_group: &mut DiagGroup, task_result: TaskResult) {
if !cfg!(windows) {
sleep(Duration::from_millis(500));
return ();
return;
}
match task_result {
TaskResult::Error(err) => {
@ -334,7 +334,7 @@ pub fn parse_chkdsk(diag_group: &mut DiagGroup, task_result: TaskResult) {
pub fn parse_dism(diag_group: &mut DiagGroup, task_result: TaskResult) {
if !cfg!(windows) {
sleep(Duration::from_millis(500));
return ();
return;
}
match task_result {
TaskResult::Error(err) => {
@ -390,7 +390,7 @@ pub fn parse_registry_hives(
) {
if !cfg!(windows) {
sleep(Duration::from_millis(500));
return ();
return;
}
let hive = cmd_args.get(2);
match task_result {
@ -464,7 +464,7 @@ pub fn parse_registry_hives(
pub fn parse_system_files(diag_group: &mut DiagGroup, task_result: TaskResult) {
if !cfg!(windows) {
sleep(Duration::from_millis(500));
return ();
return;
}
match task_result {
TaskResult::Error(err) => {

View file

@ -20,8 +20,9 @@ pub fn queue_boot_scan_tasks(
diag_groups.clear();
}
let disk_list = clone.disk_list.lock().unwrap();
if let Some(disk_index) = clone.disk_index_dest {
if let Some(disk) = disk_list.get(disk_index) {
if let Some(disk_index) = clone.disk_index_dest
&& let Some(disk) = disk_list.get(disk_index)
{
let table_type = disk.part_type.clone();
let letter_boot = disk.get_part_letter(clone.part_index_boot.unwrap());
let letter_os = disk.get_part_letter(clone.part_index_os.unwrap());
@ -164,6 +165,5 @@ pub fn queue_boot_scan_tasks(
);
tasks.add(TaskType::Sleep); // NOTE: DELETEME
}
}
Ok(())
}

View file

@ -159,8 +159,9 @@ impl Component for Right {
}
// First selection
if let Some(first_index) = self.get_first() {
if let Some(first_desc) = self.list.get(first_index) {
if let Some(first_index) = self.get_first()
&& let Some(first_desc) = self.list.get(first_index)
{
if let Some(label) = self.list_labels.first() {
label
.iter()
@ -171,11 +172,11 @@ impl Component for Right {
.iter()
.for_each(|dv| body_text.push(dv.as_line()));
}
}
// Second selection
if let Some(second_index) = self.get_second() {
if let Some(second_desc) = self.list.get(second_index) {
if let Some(second_index) = self.get_second()
&& let Some(second_desc) = self.list.get(second_index)
{
// Divider
body_text.push(Line::from(""));
body_text.push(Line::from(str::repeat("", (body_area.width - 4) as usize)));
@ -190,7 +191,6 @@ impl Component for Right {
.iter()
.for_each(|dv| body_text.push(dv.as_line()));
}
}
// Build Paragraph
let body = Paragraph::new(body_text)

View file

@ -130,26 +130,24 @@ impl Config {
#[must_use]
pub fn get_data_dir() -> PathBuf {
let directory = if let Some(s) = DATA_FOLDER.clone() {
if let Some(s) = DATA_FOLDER.clone() {
s
} else if let Some(proj_dirs) = project_directory() {
proj_dirs.data_local_dir().to_path_buf()
} else {
PathBuf::from(".").join(".data")
};
directory
}
}
#[must_use]
pub fn get_config_dir() -> PathBuf {
let directory = if let Some(s) = CONFIG_FOLDER.clone() {
if let Some(s) = CONFIG_FOLDER.clone() {
s
} else if let Some(proj_dirs) = project_directory() {
proj_dirs.config_local_dir().to_path_buf()
} else {
PathBuf::from(".").join(".config")
};
directory
}
}
fn project_directory() -> Option<ProjectDirs> {
@ -333,8 +331,8 @@ pub fn parse_key_sequence(raw: &str) -> Result<Vec<KeyEvent>, String> {
let raw = if raw.contains("><") {
raw
} else {
let raw = raw.strip_prefix('<').unwrap_or(raw);
let raw = raw.strip_prefix('>').unwrap_or(raw);
let mut raw = raw.strip_prefix('<').unwrap_or(raw);
raw = raw.strip_prefix('>').unwrap_or(raw);
raw
};
let sequences = raw

View file

@ -31,11 +31,11 @@ pub fn init() -> Result<()> {
.into_hooks();
eyre_hook.install()?;
std::panic::set_hook(Box::new(move |panic_info| {
if let Ok(mut t) = crate::tui::Tui::new() {
if let Err(r) = t.exit() {
if let Ok(mut t) = crate::tui::Tui::new()
&& let Err(r) = t.exit()
{
error!("Unable to exit Terminal: {:?}", r);
}
}
#[cfg(not(debug_assertions))]
{

View file

@ -31,7 +31,7 @@ pub struct DVLine {
impl DVLine {
/// Convert to Line with colored span(s)
#[must_use]
pub fn as_line(&self) -> Line {
pub fn as_line(&self) -> Line<'_> {
let mut spans = Vec::new();
zip(self.line_parts.clone(), self.line_colors.clone())
.for_each(|(part, color)| spans.push(Span::styled(part, Style::default().fg(color))));

View file

@ -387,12 +387,11 @@ pub fn run_script_raw(script: &str) -> Output {
script_file
.write_all(script.as_bytes())
.expect("Failed to write script to disk");
let output = Command::new("diskpart")
Command::new("diskpart")
.args(["/s", format!("{}", script_path.display()).as_str()])
.stdout(Stdio::piped())
.output()
.expect("Failed to execute Diskpart script");
output
.expect("Failed to execute Diskpart script")
}
#[must_use]

View file

@ -73,8 +73,9 @@ pub fn scan() -> Vec<Driver> {
let driver_path = exe_path.with_file_name("drivers");
if let Ok(dir_entry) = read_dir(driver_path) {
for entry in dir_entry.flatten() {
if entry.path().is_dir() {
if let Ok(name) = entry.file_name().into_string() {
if entry.path().is_dir()
&& let Ok(name) = entry.file_name().into_string()
{
drivers.push(Driver {
name,
path: entry.path(),
@ -84,7 +85,6 @@ pub fn scan() -> Vec<Driver> {
}
}
}
}
drivers.sort();
drivers.reverse();
for driver in &mut drivers {
@ -95,12 +95,12 @@ pub fn scan() -> Vec<Driver> {
.into_iter()
.filter_map(Result::ok)
{
if let Some(ext) = entry.path().extension() {
if ext == "inf" {
if let Some(ext) = entry.path().extension()
&& ext == "inf"
{
driver.inf_paths.push(entry.into_path());
}
}
}
}
drivers
}

View file

@ -152,12 +152,12 @@ impl Tasks {
pub fn poll(&mut self) -> Result<Option<Task>> {
let mut return_task: Option<Task> = None;
// Handle task channel item(s)
if let Ok(result) = self.task_rx.try_recv() {
if let Some(mut task) = self.cur_task.take() {
if let Ok(result) = self.task_rx.try_recv()
&& let Some(mut task) = self.cur_task.take()
{
task.result.replace(result);
self.cur_task.replace(task);
}
}
// Check status of current task (if one is running).
// NOTE: Action::TasksComplete is sent once all tasks are complete

View file

@ -60,7 +60,6 @@ mod diskpart {
letter: String::from("C"),
part_type: String::from("ebd0a0a2-b9e5-4433-87c0-68b6b72699c7"),
size: 50465865728,
..Default::default()
};
// Right
@ -92,7 +91,7 @@ mod diskpart {
#[test]
fn parse_disk_numbers() {
let disk_numbers =
system::diskpart::parse_disk_numbers(&sample_output::LIST_DISK_DETAIL_DISKS);
system::diskpart::parse_disk_numbers(sample_output::LIST_DISK_DETAIL_DISKS);
assert_eq!(vec!["0", "2"], disk_numbers);
}
@ -111,7 +110,7 @@ mod diskpart {
system::diskpart::parse_partition_details(
&mut disk.parts,
&sample_output::SELECT_PART_DETAIL_ONE_PART,
sample_output::SELECT_PART_DETAIL_ONE_PART,
);
assert_eq!(partition_1, disk.parts[0]);
}

View file

@ -197,14 +197,14 @@ impl App {
// Build Diskpart script to format destination disk
let disk_list = self.clone.disk_list.lock().unwrap();
if let Some(disk_index) = self.clone.disk_index_dest {
if let Some(disk) = disk_list.get(disk_index) {
if let Some(disk_index) = self.clone.disk_index_dest
&& let Some(disk) = disk_list.get(disk_index)
{
let table_type = self.clone.table_type.clone().unwrap();
let diskpart_script = build_dest_format_script(disk.id, &table_type);
self.tasks.add(TaskType::Diskpart(diskpart_script));
}
}
}
Mode::Clone => {
self.action_tx.send(Action::DisplayPopup(
popup::Type::Info,
@ -229,8 +229,9 @@ impl App {
// Add actions
let disk_list = self.clone.disk_list.lock().unwrap();
if let Some(disk_index) = self.clone.disk_index_dest {
if let Some(disk) = disk_list.get(disk_index) {
if let Some(disk_index) = self.clone.disk_index_dest
&& let Some(disk) = disk_list.get(disk_index)
{
let table_type = self.clone.table_type.clone().unwrap();
let letter_boot = disk.get_part_letter(self.clone.part_index_boot.unwrap());
let letter_os = disk.get_part_letter(self.clone.part_index_os.unwrap());
@ -267,7 +268,6 @@ impl App {
}
}
}
}
Mode::Done => {
self.action_tx
.send(Action::DisplayPopup(popup::Type::Success, popup::fortune()))?;
@ -415,13 +415,13 @@ impl App {
Action::Select(one, two) => {
match self.cur_mode {
Mode::InstallDrivers => {
if let Some(index) = one {
if let Some(driver) = self.clone.driver_list.get(index).cloned() {
if let Some(index) = one
&& let Some(driver) = self.clone.driver_list.get(index).cloned()
{
drivers::load(&driver.inf_paths);
self.clone.driver = Some(driver);
}
}
}
Mode::SelectDisks => {
self.clone.disk_index_source = one;
self.clone.disk_index_dest = two;
@ -690,14 +690,14 @@ fn build_left_items(app: &App, cur_mode: Mode) -> Action {
labels.push(String::from("boot"));
labels.push(String::from("os"));
let disk_list = app.clone.disk_list.lock().unwrap();
if let Some(index) = app.clone.disk_index_dest {
if let Some(disk) = disk_list.get(index) {
if let Some(index) = app.clone.disk_index_dest
&& let Some(disk) = disk_list.get(index)
{
disk.get_parts().iter().for_each(|part| {
items.push(part.to_string());
});
}
}
}
Mode::Done | Mode::Failed => {
select_type = SelectionType::Loop;
title = String::from("Done");

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
logo.xcf Normal file

Binary file not shown.

View file

@ -205,8 +205,9 @@ impl App {
Action::ClearScreen => tui.terminal.clear()?,
Action::KeyUp => {
self.list.previous();
if let Some(tool) = self.list.get_selected() {
if tool.separator {
if let Some(tool) = self.list.get_selected()
&& tool.separator
{
// Skip over separator
self.list.previous();
if let Some(index) = self.list.selected() {
@ -214,11 +215,11 @@ impl App {
}
}
}
}
Action::KeyDown => {
self.list.next();
if let Some(tool) = self.list.get_selected() {
if tool.separator {
if let Some(tool) = self.list.get_selected()
&& tool.separator
{
// Skip over separator
self.list.next();
if let Some(index) = self.list.selected() {
@ -226,7 +227,6 @@ impl App {
}
}
}
}
Action::Error(ref msg) => {
self.action_tx
.send(Action::DisplayPopup(popup::Type::Error, msg.clone()))?;
@ -391,13 +391,13 @@ pub fn build_tool_command(app: &App, tool: &Tool) -> TaskType {
cmd_path = PathBuf::from(tool.command.clone());
start_index = 0;
}
if let Some(args) = &tool.args {
if args.len() > start_index {
if let Some(args) = &tool.args
&& args.len() > start_index
{
args[start_index..].iter().for_each(|a| {
cmd_args.push(a.clone());
});
}
}
TaskType::CommandNoWait(cmd_path, cmd_args)
}