Move clone settings to separate struct
The App struct had too many fields IMO
This commit is contained in:
parent
fc0b82418b
commit
253385c2a7
2 changed files with 48 additions and 34 deletions
|
|
@ -35,12 +35,11 @@ use crate::{
|
|||
footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, title::Title, Component,
|
||||
},
|
||||
config::Config,
|
||||
state::Mode,
|
||||
state::{CloneSettings, Mode},
|
||||
system::{
|
||||
boot,
|
||||
disk::{Disk, PartitionTableType},
|
||||
diskpart::build_dest_format_script,
|
||||
drivers::{self, Driver},
|
||||
drivers::{self},
|
||||
},
|
||||
tasks::{Task, Tasks},
|
||||
tui::{Event, Tui},
|
||||
|
|
@ -58,16 +57,10 @@ pub struct App {
|
|||
should_suspend: bool,
|
||||
tick_rate: f64,
|
||||
// App
|
||||
clone: CloneSettings,
|
||||
cur_mode: Mode,
|
||||
disk_index_dest: Option<usize>,
|
||||
disk_index_source: Option<usize>,
|
||||
disk_list: Arc<Mutex<Vec<Disk>>>,
|
||||
part_index_boot: Option<usize>,
|
||||
part_index_os: Option<usize>,
|
||||
driver: Option<Driver>,
|
||||
prev_mode: Mode,
|
||||
selections: Vec<Option<usize>>,
|
||||
table_type: Option<PartitionTableType>,
|
||||
tasks: Tasks,
|
||||
}
|
||||
|
||||
|
|
@ -96,16 +89,10 @@ impl App {
|
|||
should_suspend: false,
|
||||
tick_rate,
|
||||
// App
|
||||
clone: CloneSettings::new(disk_list_arc),
|
||||
cur_mode: Mode::ScanDisks,
|
||||
disk_index_dest: None,
|
||||
disk_index_source: None,
|
||||
disk_list: disk_list_arc,
|
||||
driver: None,
|
||||
part_index_boot: None,
|
||||
part_index_os: None,
|
||||
prev_mode: Mode::ScanDisks,
|
||||
selections: vec![None, None],
|
||||
table_type: None,
|
||||
tasks,
|
||||
})
|
||||
}
|
||||
|
|
@ -165,10 +152,10 @@ impl App {
|
|||
))?;
|
||||
|
||||
// Build Diskpart script to format destination disk
|
||||
let disk_list = self.disk_list.lock().unwrap();
|
||||
if let Some(disk_index) = self.disk_index_dest {
|
||||
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) {
|
||||
let table_type = self.table_type.clone().unwrap();
|
||||
let table_type = self.clone.table_type.clone().unwrap();
|
||||
let diskpart_script = build_dest_format_script(disk.id, &table_type);
|
||||
self.tasks.add(Task::Diskpart(diskpart_script));
|
||||
}
|
||||
|
|
@ -183,7 +170,7 @@ impl App {
|
|||
self.config.clone_app_path.clone(),
|
||||
Vec::new(),
|
||||
));
|
||||
if let Some(dest_index) = self.disk_index_dest {
|
||||
if let Some(dest_index) = self.clone.disk_index_dest {
|
||||
self.tasks.add(Task::UpdateDestDisk(dest_index));
|
||||
}
|
||||
}
|
||||
|
|
@ -208,12 +195,12 @@ impl App {
|
|||
};
|
||||
|
||||
// Add actions
|
||||
let disk_list = self.disk_list.lock().unwrap();
|
||||
if let Some(disk_index) = self.disk_index_dest {
|
||||
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) {
|
||||
let table_type = self.table_type.clone().unwrap();
|
||||
let letter_boot = disk.get_part_letter(self.part_index_boot.unwrap());
|
||||
let letter_os = disk.get_part_letter(self.part_index_os.unwrap());
|
||||
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());
|
||||
|
||||
// Safety check
|
||||
if letter_boot.is_empty() || letter_os.is_empty() {
|
||||
|
|
@ -231,8 +218,8 @@ impl App {
|
|||
}
|
||||
|
||||
// Inject driver(s) (if selected)
|
||||
if let Some(driver) = &self.driver {
|
||||
if let Ok(task) = boot::inject_driver(&driver, &letter_os, &system32) {
|
||||
if let Some(driver) = &self.clone.driver {
|
||||
if let Ok(task) = boot::inject_driver(driver, &letter_os, &system32) {
|
||||
self.tasks.add(task);
|
||||
} else {
|
||||
self.action_tx.send(Action::Error(format!(
|
||||
|
|
@ -363,12 +350,12 @@ impl App {
|
|||
self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?;
|
||||
}
|
||||
Action::SelectDriver(ref driver) => {
|
||||
self.driver = Some(driver.clone());
|
||||
self.clone.driver = Some(driver.clone());
|
||||
drivers::load(&driver.inf_paths);
|
||||
self.action_tx.send(Action::NextScreen)?;
|
||||
}
|
||||
Action::SelectTableType(ref table_type) => {
|
||||
self.table_type = Some(table_type.clone());
|
||||
self.clone.table_type = Some(table_type.clone());
|
||||
self.action_tx.send(Action::NextScreen)?;
|
||||
}
|
||||
Action::Resize(w, h) => self.handle_resize(tui, w, h)?,
|
||||
|
|
@ -390,12 +377,12 @@ impl App {
|
|||
Action::Select(one, two) => {
|
||||
match self.cur_mode {
|
||||
Mode::SelectDisks => {
|
||||
self.disk_index_source = one;
|
||||
self.disk_index_dest = two;
|
||||
self.clone.disk_index_source = one;
|
||||
self.clone.disk_index_dest = two;
|
||||
}
|
||||
Mode::SelectParts => {
|
||||
self.part_index_boot = one;
|
||||
self.part_index_os = two;
|
||||
self.clone.part_index_boot = one;
|
||||
self.clone.part_index_os = two;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,15 @@
|
|||
// along with Deja-vu. If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::system::{
|
||||
disk::{Disk, PartitionTableType},
|
||||
drivers::Driver,
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum Mode {
|
||||
#[default]
|
||||
|
|
@ -31,3 +38,23 @@ pub enum Mode {
|
|||
Done,
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct CloneSettings {
|
||||
pub disk_index_dest: Option<usize>,
|
||||
pub disk_index_source: Option<usize>,
|
||||
pub disk_list: Arc<Mutex<Vec<Disk>>>,
|
||||
pub part_index_boot: Option<usize>,
|
||||
pub part_index_os: Option<usize>,
|
||||
pub driver: Option<Driver>,
|
||||
pub table_type: Option<PartitionTableType>,
|
||||
}
|
||||
|
||||
impl CloneSettings {
|
||||
pub fn new(disk_list: Arc<Mutex<Vec<Disk>>>) -> Self {
|
||||
CloneSettings {
|
||||
disk_list,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue