Compare commits

..

No commits in common. "c4c174b546ad030012ae26289b00f327b25b7d93" and "09b204c0b0531c0b4b84749d73b18e6b8d57405c" have entirely different histories.

4 changed files with 28 additions and 51 deletions

View file

@ -211,7 +211,6 @@
"<Enter>": "Process", "<Enter>": "Process",
"<Up>": "KeyUp", "<Up>": "KeyUp",
"<Down>": "KeyDown", "<Down>": "KeyDown",
"<b>": "PrevScreen",
"<q>": "Quit", "<q>": "Quit",
"<Ctrl-d>": "Quit", "<Ctrl-d>": "Quit",
"<Ctrl-c>": "Quit", "<Ctrl-c>": "Quit",

View file

@ -109,7 +109,19 @@ impl App {
Mode::SelectTableType => Mode::ScanWinSources, Mode::SelectTableType => Mode::ScanWinSources,
Mode::ScanWinSources => Mode::SelectWinSource, Mode::ScanWinSources => Mode::SelectWinSource,
Mode::SelectWinSource => Mode::SelectWinImage, Mode::SelectWinSource => Mode::SelectWinImage,
Mode::SelectWinImage => Mode::SetUserName, Mode::SelectWinImage => {
let mut next_mode = Mode::SetUserName;
// TODO: FIXME - Race condition?
// if let Ok(wim_sources) = self.state.wim_sources.lock()
// && let Some(index) = self.state.wim_image_index
// {
// let image = wim_sources.get_file(index);
// if !image.is_installer {
// next_mode = Mode::Confirm;
// }
// }
next_mode
}
Mode::SetUserName => Mode::Confirm, Mode::SetUserName => Mode::Confirm,
Mode::Confirm => Mode::Process, // i.e. format, apply, etc Mode::Confirm => Mode::Process, // i.e. format, apply, etc
Mode::Process | Mode::Done => Mode::Done, Mode::Process | Mode::Done => Mode::Done,
@ -149,20 +161,7 @@ impl App {
String::from("Scanning Disks..."), String::from("Scanning Disks..."),
))?; ))?;
} }
Mode::ScanWinSources => { Mode::ScanWinSources => self.state.scan_wim_local(ScanType::WindowsInstallers),
self.state.reset_all();
self.state.scan_wim_local(ScanType::WindowsInstallers);
}
Mode::SetUserName => {
if let Ok(wim_sources) = self.state.wim_sources.lock()
&& let Some(index) = self.state.wim_image_index
{
let image = wim_sources.get_file(index);
if !image.is_setup {
self.action_tx.send(Action::NextScreen)?;
}
}
}
Mode::Done => { Mode::Done => {
self.action_tx self.action_tx
.send(Action::DisplayPopup(popup::Type::Success, popup::fortune()))?; .send(Action::DisplayPopup(popup::Type::Success, popup::fortune()))?;
@ -430,7 +429,7 @@ fn build_footer_string(cur_mode: Mode) -> String {
), ),
Mode::SelectTableType => String::from("(Enter) to select / (b) to go back / (q) to quit"), Mode::SelectTableType => String::from("(Enter) to select / (b) to go back / (q) to quit"),
Mode::SelectWinSource | Mode::SelectWinImage => { Mode::SelectWinSource | Mode::SelectWinImage => {
String::from("(Enter) to select / (b) to go back / (q) to quit") String::from("(Enter) to select / (q) to quit")
} }
Mode::ScanWinSources => String::from( Mode::ScanWinSources => String::from(
"(Enter) to continue / (b) to scan for backups / (n) to scan network / (q) to quit", "(Enter) to continue / (b) to scan for backups / (n) to scan network / (q) to quit",
@ -726,7 +725,7 @@ fn build_right_items(app: &App) -> Action {
DVLine::blank(), DVLine::blank(),
]); ]);
} }
if wim_file.is_setup if wim_file.is_installer
&& let Some(username) = &app.state.username && let Some(username) = &app.state.username
{ {
label_dv_lines.append(&mut vec![DVLine { label_dv_lines.append(&mut vec![DVLine {

View file

@ -27,6 +27,8 @@ use core::{
}, },
}; };
use tracing::info;
use crate::{ use crate::{
net::connect_network_share, net::connect_network_share,
wim::{WimFile, WimSources, parse_wim_file}, wim::{WimFile, WimSources, parse_wim_file},
@ -121,7 +123,7 @@ pub fn scan_local_drives(
wim_sources_arc: Arc<Mutex<WimSources>>, wim_sources_arc: Arc<Mutex<WimSources>>,
scan_type: ScanType, scan_type: ScanType,
) { ) {
let mut to_check: Vec<String> = Vec::new(); let mut to_check = vec![String::from(".")];
let mut wim_files: Vec<WimFile> = Vec::new(); let mut wim_files: Vec<WimFile> = Vec::new();
// Get drive letters // Get drive letters
@ -144,13 +146,14 @@ pub fn scan_local_drives(
// Scan drives // Scan drives
to_check.iter().for_each(|scan_path| { to_check.iter().for_each(|scan_path| {
let is_setup = scan_path.ends_with("\\Images"); let installer = scan_path.ends_with("\\Images");
info!("Scanning: {}", &scan_path);
if let Ok(read_dir) = read_dir(scan_path) { if let Ok(read_dir) = read_dir(scan_path) {
read_dir.for_each(|item| { read_dir.for_each(|item| {
if let Ok(item) = item if let Ok(item) = item
&& item.file_name().to_string_lossy().ends_with(".wim") && item.file_name().to_string_lossy().ends_with(".wim")
&& let Some(path_str) = item.path().to_str() && let Some(path_str) = item.path().to_str()
&& let Ok(new_source) = parse_wim_file(path_str, is_setup) && let Ok(new_source) = parse_wim_file(path_str, installer)
{ {
wim_files.push(new_source); wim_files.push(new_source);
} }

View file

@ -1,4 +1,3 @@
use core::system::disk::bytes_to_string;
// This file is part of Deja-Vu. // This file is part of Deja-Vu.
// //
// Deja-Vu is free software: you can redistribute it and/or modify it // Deja-Vu is free software: you can redistribute it and/or modify it
@ -67,7 +66,7 @@ static WIN_BUILDS: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
pub struct WimFile { pub struct WimFile {
pub path: String, pub path: String,
pub images: Vec<WimImage>, pub images: Vec<WimImage>,
pub is_setup: bool, pub is_installer: bool,
} }
impl WimFile { impl WimFile {
@ -113,7 +112,6 @@ pub struct WimImage {
pub build: String, pub build: String,
pub index: String, pub index: String,
pub name: String, pub name: String,
pub size: u64,
pub spbuild: String, pub spbuild: String,
pub version: String, pub version: String,
} }
@ -140,15 +138,7 @@ impl fmt::Display for WimImage {
} else { } else {
format!("{}, ", self.version) format!("{}, ", self.version)
}; };
write!( write!(f, "{} ({}{}.{})", self.name, s, self.build, self.spbuild)
f,
"{} ({}{}.{}) [{}]",
self.name,
s,
self.build,
self.spbuild,
bytes_to_string(self.size)
)
} }
} }
@ -216,7 +206,7 @@ fn get_wim_xml(wim_file: &str) -> std::io::Result<File> {
Ok(file) Ok(file)
} }
pub fn parse_wim_file(wim_file: &str, is_setup: bool) -> std::io::Result<WimFile> { pub fn parse_wim_file(wim_file: &str, installer: bool) -> std::io::Result<WimFile> {
let mut wim_images: Vec<WimImage> = Vec::new(); let mut wim_images: Vec<WimImage> = Vec::new();
if !Path::new(wim_file).exists() { if !Path::new(wim_file).exists() {
return Err(std::io::Error::new( return Err(std::io::Error::new(
@ -259,26 +249,12 @@ pub fn parse_wim_file(wim_file: &str, is_setup: bool) -> std::io::Result<WimFile
if current_element == "SPBUILD" { if current_element == "SPBUILD" {
image.spbuild = char_data.trim().to_string(); image.spbuild = char_data.trim().to_string();
} }
if current_element == "TOTALBYTES" {
let result = char_data.trim().parse::<u64>();
if let Ok(size) = result {
image.size = size;
}
}
} }
Ok(XmlEvent::EndElement { name }) => { Ok(XmlEvent::EndElement { name }) => {
if name.local_name.to_uppercase() == "IMAGE" { if name.local_name.to_uppercase() == "IMAGE" {
if image.size == 0 {
break;
}
// Append image to list // Append image to list
if image.build.is_empty() { if !image.build.is_empty() && !image.name.is_empty() && !image.index.is_empty()
image.build.push('?'); {
}
if image.spbuild.is_empty() {
image.spbuild.push('?');
}
if !image.name.is_empty() && !image.index.is_empty() {
wim_images.push(image.clone()); wim_images.push(image.clone());
} }
@ -295,7 +271,7 @@ pub fn parse_wim_file(wim_file: &str, is_setup: bool) -> std::io::Result<WimFile
let wim_file = WimFile { let wim_file = WimFile {
path: wim_file.to_string(), path: wim_file.to_string(),
images: wim_images, images: wim_images,
is_setup, is_installer: installer,
}; };
Ok(wim_file) Ok(wim_file)