Add disk helper functions
This commit is contained in:
parent
c9e33bb848
commit
92e2e53b16
4 changed files with 16 additions and 8 deletions
|
|
@ -346,7 +346,7 @@ impl App {
|
||||||
let disk_list = self.disk_list.lock().unwrap();
|
let disk_list = self.disk_list.lock().unwrap();
|
||||||
if let Some(disk_index) = self.disk_index_dest {
|
if let Some(disk_index) = self.disk_index_dest {
|
||||||
if let Some(disk) = disk_list.get(disk_index) {
|
if let Some(disk) = disk_list.get(disk_index) {
|
||||||
let disk_id = disk.id.to_owned();
|
let disk_id = disk.get_id();
|
||||||
let table_type = self.table_type.clone().unwrap();
|
let table_type = self.table_type.clone().unwrap();
|
||||||
let diskpart_script =
|
let diskpart_script =
|
||||||
build_dest_format_script(&disk_id, &table_type);
|
build_dest_format_script(&disk_id, &table_type);
|
||||||
|
|
|
||||||
|
|
@ -221,19 +221,19 @@ impl Component for Left {
|
||||||
// Get list of partitions for destination disk
|
// Get list of partitions for destination disk
|
||||||
if let Some(index) = &self.disk_id_dest {
|
if let Some(index) = &self.disk_id_dest {
|
||||||
if let Some(disk) = self.list_disks.get(*index).to_owned() {
|
if let Some(disk) = self.list_disks.get(*index).to_owned() {
|
||||||
self.list_parts.set_items(disk.parts.clone());
|
self.list_parts.set_items(disk.get_parts());
|
||||||
|
|
||||||
// Auto-select first partition and highlight likely OS partition
|
// Auto-select first partition and highlight likely OS partition
|
||||||
if let Some(table_type) = &self.table_type {
|
if let Some(table_type) = &self.table_type {
|
||||||
match table_type {
|
match table_type {
|
||||||
PartitionTableType::Guid => {
|
PartitionTableType::Guid => {
|
||||||
if disk.parts.len() >= 3 {
|
if disk.num_parts() >= 3 {
|
||||||
self.selections[0] = Some(0);
|
self.selections[0] = Some(0);
|
||||||
self.list_parts.select(2);
|
self.list_parts.select(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PartitionTableType::Legacy => {
|
PartitionTableType::Legacy => {
|
||||||
if disk.parts.len() >= 2 {
|
if disk.num_parts() >= 2 {
|
||||||
self.selections[0] = Some(0);
|
self.selections[0] = Some(0);
|
||||||
self.list_parts.select(1);
|
self.list_parts.select(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,10 +64,18 @@ impl Disk {
|
||||||
self.parts_description.push(format!("{part}"));
|
self.parts_description.push(format!("{part}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn get_id(&self) -> &str {
|
pub fn get_id(&self) -> &str {
|
||||||
self.id.as_str()
|
self.id.as_str()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_parts(&self) -> Vec<Partition> {
|
||||||
|
self.parts.clone()
|
||||||
|
}
|
||||||
|
pub fn num_parts(&self) -> usize {
|
||||||
|
self.parts.len()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Disk {
|
impl fmt::Display for Disk {
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ pub fn add_disk_details(disk: &mut Disk, disk_details: Option<&str>) {
|
||||||
if let Some(details_str) = disk_details {
|
if let Some(details_str) = disk_details {
|
||||||
details = String::from(details_str);
|
details = String::from(details_str);
|
||||||
} else {
|
} else {
|
||||||
let script = format!("select disk {}\r\ndetail disk", disk.id);
|
let script = format!("select disk {}\r\ndetail disk", disk.get_id());
|
||||||
details = run_script(&script);
|
details = run_script(&script);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ pub fn add_disk_details(disk: &mut Disk, disk_details: Option<&str>) {
|
||||||
} else {
|
} else {
|
||||||
disk.part_type = PartitionTableType::Legacy;
|
disk.part_type = PartitionTableType::Legacy;
|
||||||
}
|
}
|
||||||
disk.serial = get_disk_serial_number(&disk.id);
|
disk.serial = get_disk_serial_number(&disk.get_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +78,7 @@ pub fn add_partition_details(
|
||||||
if let Some(details) = disk_details {
|
if let Some(details) = disk_details {
|
||||||
contents = String::from(details);
|
contents = String::from(details);
|
||||||
} else {
|
} else {
|
||||||
let script = format!("select disk {}\r\nlist partition", disk.id);
|
let script = format!("select disk {}\r\nlist partition", disk.get_id());
|
||||||
contents = run_script(&script);
|
contents = run_script(&script);
|
||||||
};
|
};
|
||||||
for (_, [number, size]) in RE_LIS.captures_iter(&contents).map(|c| c.extract()) {
|
for (_, [number, size]) in RE_LIS.captures_iter(&contents).map(|c| c.extract()) {
|
||||||
|
|
@ -94,7 +94,7 @@ pub fn add_partition_details(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detail parititon
|
// Detail parititon
|
||||||
let mut script = vec![format!("select disk {}", disk.id)];
|
let mut script = vec![format!("select disk {}", disk.get_id())];
|
||||||
for part in &disk.parts {
|
for part in &disk.parts {
|
||||||
if part_details.is_some() {
|
if part_details.is_some() {
|
||||||
// Currently only used by tests
|
// Currently only used by tests
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue