Implement network WIM scan

This commit is contained in:
2Shirt 2025-11-28 23:41:35 -08:00
parent a760773269
commit 70525ae6e0
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 49 additions and 8 deletions

View file

@ -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<Mutex<Vec<Disk>>>,
wim_sources_arc: Arc<Mutex<WimSources>>,
) {
pub fn scan_network_share(config: Config, wim_sources_arc: Arc<Mutex<WimSources>>) {
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;
}

View file

@ -14,6 +14,7 @@
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
//
use std::{
cmp::Ordering,
collections::HashMap,
env, fmt,
fs::File,
@ -67,6 +68,26 @@ pub struct WimFile {
pub images: Vec<WimImage>,
}
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<Ordering> {
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();