diff --git a/deja_vu/src/app.rs b/deja_vu/src/app.rs index 91e2947..d77d901 100644 --- a/deja_vu/src/app.rs +++ b/deja_vu/src/app.rs @@ -178,18 +178,7 @@ impl App { ))?; // Get System32 path - let system32 = if cfg!(windows) { - if let Ok(path) = env::var("SYSTEMROOT") { - format!("{path}/System32") - } else { - self.action_tx.send(Action::Error(String::from( - "ERROR\n\n\nFailed to find SYSTEMROOT", - )))?; - return Ok(()); - } - } else { - String::from(".") - }; + let system32 = get_system32_path(&self.action_tx); // (Re)Enable volume mounting self.tasks.add(TaskType::CommandWait( @@ -227,18 +216,7 @@ impl App { ))?; // Get System32 path - let system32 = if cfg!(windows) { - if let Ok(path) = env::var("SYSTEMROOT") { - format!("{path}/System32") - } else { - self.action_tx.send(Action::Error(String::from( - "ERROR\n\n\nFailed to find SYSTEMROOT", - )))?; - return Ok(()); - } - } else { - String::from(".") - }; + let system32 = get_system32_path(&self.action_tx); // Add actions let disk_list = self.clone.disk_list.lock().unwrap(); @@ -796,3 +774,19 @@ fn build_right_items(app: &App, cur_mode: Mode) -> Action { } Action::UpdateRight(labels, start_index, items) } + +pub fn get_system32_path(action_tx: &mpsc::UnboundedSender) -> String { + let mut system32_path = String::from("."); + if cfg!(windows) { + if let Ok(path) = env::var("SYSTEMROOT") { + system32_path = format!("{path}/System32"); + } else { + action_tx + .send(Action::Error(String::from( + "ERROR\n\n\nFailed to find SYSTEMROOT", + ))) + .expect("Failed to find SYSTEMROOT and then failed to send action"); + } + } + system32_path +}