Update WIM structs

This commit is contained in:
2Shirt 2025-11-08 17:48:00 -08:00
parent 94faae27ac
commit 69c3feb838
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
3 changed files with 26 additions and 7 deletions

View file

@ -102,7 +102,7 @@ impl App<'_> {
} }
let action_tx = self.action_tx.clone(); let action_tx = self.action_tx.clone();
action_tx.send(Action::SetMode(Mode::PEMenu))?; action_tx.send(Action::SetMode(Mode::ScanDisks))?;
loop { loop {
self.handle_events(&mut tui).await?; self.handle_events(&mut tui).await?;
self.handle_actions(&mut tui)?; self.handle_actions(&mut tui)?;
@ -219,6 +219,9 @@ impl App<'_> {
Action::Render => self.render(tui)?, Action::Render => self.render(tui)?,
Action::SetMode(mode) => { Action::SetMode(mode) => {
self.mode = mode; self.mode = mode;
if self.mode == Mode::ScanDisks {
self.state.reset();
}
self.action_tx.send(Action::UpdateFooter(String::from( self.action_tx.send(Action::UpdateFooter(String::from(
"(Enter) to select / (t) for terminal / (p) to power off / (r) to restart", "(Enter) to select / (t) for terminal / (p) to power off / (r) to restart",
)))?; )))?;

View file

@ -40,6 +40,16 @@ impl State<'_> {
} }
} }
pub fn reset(&mut self) {
self.disk_index_dest = None;
self.part_index_boot = None;
self.wim_file_index = None;
self.wim_image_index = None;
if let Ok(mut sources) = self.wim_sources.lock() {
sources.reset();
}
}
pub fn scan_drivers(&mut self) { pub fn scan_drivers(&mut self) {
self.driver_list = drivers::scan(); self.driver_list = drivers::scan();
} }

View file

@ -48,13 +48,13 @@ static WIN_BUILDS: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
}); });
#[derive(Debug)] #[derive(Debug)]
struct WimFile<'a> { pub struct WimFile<'a> {
path: &'a Path, path: &'a Path,
images: Vec<WimImage>, images: Vec<WimImage>,
} }
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
struct WimImage { pub struct WimImage {
build: String, build: String,
index: String, index: String,
name: String, name: String,
@ -90,13 +90,19 @@ impl fmt::Display for WimImage {
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct WimSources<'a> { pub struct WimSources<'a> {
files: Vec<WimFile<'a>>, pub local: Vec<WimFile<'a>>,
pub network: Vec<WimFile<'a>>,
} }
impl WimSources<'_> { impl WimSources<'_> {
pub fn new() -> Self { pub fn new() -> Self {
Default::default() Default::default()
} }
pub fn reset(&mut self) {
self.local.clear();
self.network.clear();
}
} }
fn get_wim_xml(wim_file: &str) -> std::io::Result<File> { fn get_wim_xml(wim_file: &str) -> std::io::Result<File> {
@ -200,13 +206,13 @@ fn parse_wim_file(wim_file: &str) -> std::io::Result<WimFile<'_>> {
// if let Ok(wim_file) = parse_wim_file("./23H2.wim") // if let Ok(wim_file) = parse_wim_file("./23H2.wim")
// && !wim_file.images.is_empty() // && !wim_file.images.is_empty()
// { // {
// sources.files.push(wim_file); // sources.local.push(wim_file);
// } // }
// if let Ok(wim_file) = parse_wim_file("./24H2.wim") { // if let Ok(wim_file) = parse_wim_file("./24H2.wim") {
// sources.files.push(wim_file); // sources.local.push(wim_file);
// } // }
// dbg!(&sources); // dbg!(&sources);
// sources.files.iter().for_each(|f| { // sources.local.iter().for_each(|f| {
// println!("-- {} --", f.path.to_string_lossy()); // println!("-- {} --", f.path.to_string_lossy());
// f.images.iter().for_each(|i| { // f.images.iter().for_each(|i| {
// println!("* {i}"); // println!("* {i}");