diff --git a/win_installer/src/state.rs b/win_installer/src/state.rs index 1fa47f9..d679d48 100644 --- a/win_installer/src/state.rs +++ b/win_installer/src/state.rs @@ -89,10 +89,9 @@ impl State { pub fn scan_wim_network(&mut self) { let config = self.config.clone(); - let disk_list_arc = self.disk_list.clone(); let wim_sources_arc = self.wim_sources.clone(); tokio::task::spawn(async move { - scan_network_share(config, disk_list_arc, wim_sources_arc); + scan_network_share(config, wim_sources_arc); }); } } @@ -125,18 +124,14 @@ pub fn scan_local_drives( && let Ok(new_source) = parse_wim_file(path_str) && let Ok(mut wim_sources) = wim_sources_arc.lock() { - wim_sources.local.push(new_source); + wim_sources.add_local(new_source); } }); } }); } -pub fn scan_network_share( - config: Config, - disk_list_arc: Arc>>, - wim_sources_arc: Arc>, -) { +pub fn scan_network_share(config: Config, wim_sources_arc: Arc>) { let result = connect_network_share( &config.network_server, &config.network_share, @@ -150,5 +145,20 @@ pub fn scan_network_share( } // Scan share + let share_dir = format!("\\\\{}\\{}", &config.network_server, &config.network_share); + if let Ok(read_dir) = read_dir(share_dir) { + read_dir.for_each(|item| { + if let Ok(item) = item + && item.file_name().to_string_lossy().ends_with(".wim") + && let Some(path_str) = item.path().to_str() + && let Ok(new_source) = parse_wim_file(path_str) + && let Ok(mut wim_sources) = wim_sources_arc.lock() + { + wim_sources.add_network(new_source); + } + }); + } + + // Done let _ = 14; } diff --git a/win_installer/src/wim.rs b/win_installer/src/wim.rs index b6bc057..c222325 100644 --- a/win_installer/src/wim.rs +++ b/win_installer/src/wim.rs @@ -14,6 +14,7 @@ // along with Deja-Vu. If not, see . // use std::{ + cmp::Ordering, collections::HashMap, env, fmt, fs::File, @@ -67,6 +68,26 @@ pub struct WimFile { pub images: Vec, } +impl PartialEq for WimFile { + fn eq(&self, other: &Self) -> bool { + self.path == other.path + } +} + +impl Eq for WimFile {} + +impl Ord for WimFile { + fn cmp(&self, other: &Self) -> Ordering { + self.path.cmp(&other.path) + } +} + +impl PartialOrd for WimFile { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + #[derive(Clone, Debug, Default)] pub struct WimImage { pub build: String, @@ -113,6 +134,16 @@ impl WimSources { Default::default() } + pub fn add_local(&mut self, wim_file: WimFile) { + self.local.push(wim_file); + self.local.sort(); + } + + pub fn add_network(&mut self, wim_file: WimFile) { + self.network.push(wim_file); + self.network.sort(); + } + pub fn reset_all(&mut self) { self.local.clear(); self.network.clear();