Make progress
This commit is contained in:
parent
3ce36c5a0f
commit
2aed8d130b
4 changed files with 79 additions and 98 deletions
|
|
@ -45,7 +45,7 @@ use ratatui::{
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::{components::wim_scan::WimScan, state::State, wim::parse_wim_file};
|
use crate::{components::wim_scan::WimScan, state::State, wim::scan_local_drives};
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
// TUI
|
// TUI
|
||||||
|
|
@ -144,11 +144,11 @@ impl App {
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
Mode::ScanWinImages => {
|
Mode::ScanWinImages => {
|
||||||
// TODO: DELETEME
|
let disk_list_arc = self.state.disk_list.clone();
|
||||||
let mut wim_sources = self.state.wim_sources.lock().unwrap();
|
let wim_sources_arc = self.state.wim_sources.clone();
|
||||||
wim_sources
|
tokio::task::spawn(async move {
|
||||||
.local
|
scan_local_drives(disk_list_arc, wim_sources_arc);
|
||||||
.push(parse_wim_file("/home/twoshirt/Projects/deja-vu/23H2.wim")?);
|
});
|
||||||
}
|
}
|
||||||
Mode::Done => {
|
Mode::Done => {
|
||||||
self.action_tx
|
self.action_tx
|
||||||
|
|
@ -290,13 +290,6 @@ impl App {
|
||||||
}
|
}
|
||||||
Action::FindWimNetwork => {
|
Action::FindWimNetwork => {
|
||||||
self.state.reset_network();
|
self.state.reset_network();
|
||||||
let mut wim_sources = self.state.wim_sources.lock().unwrap();
|
|
||||||
wim_sources
|
|
||||||
.network
|
|
||||||
.push(parse_wim_file("/home/twoshirt/Projects/deja-vu/23H2.wim")?);
|
|
||||||
wim_sources
|
|
||||||
.network
|
|
||||||
.push(parse_wim_file("/home/twoshirt/Projects/deja-vu/24H2.wim")?);
|
|
||||||
// TODO: Actually scan network!
|
// TODO: Actually scan network!
|
||||||
}
|
}
|
||||||
Action::NextScreen => {
|
Action::NextScreen => {
|
||||||
|
|
|
||||||
|
|
@ -95,76 +95,45 @@ impl Component for WimScan {
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([Constraint::Length(1), Constraint::Min(1)])
|
.constraints([Constraint::Length(1), Constraint::Min(1)])
|
||||||
.areas(right);
|
.areas(right);
|
||||||
let [local_area, network_area] = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
|
||||||
.areas(left_body);
|
|
||||||
|
|
||||||
// Titles
|
// Titles
|
||||||
let titles = vec![
|
let titles = vec![
|
||||||
Paragraph::new(Line::from("Scanning").centered())
|
Paragraph::new(Line::from("Local").centered())
|
||||||
.block(Block::default().borders(Borders::NONE)),
|
.block(Block::default().borders(Borders::NONE)),
|
||||||
Paragraph::new(Line::from("Info").centered())
|
Paragraph::new(Line::from("Network").centered())
|
||||||
.block(Block::default().borders(Borders::NONE)),
|
.block(Block::default().borders(Borders::NONE)),
|
||||||
];
|
];
|
||||||
for (title, area) in zip(titles, [left_title, right_title]) {
|
for (title, area) in zip(titles, [left_title, right_title]) {
|
||||||
frame.render_widget(title, area);
|
frame.render_widget(title, area);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local Scan
|
|
||||||
let local_area = if self.scan_network {
|
|
||||||
local_area
|
|
||||||
} else {
|
|
||||||
left_body
|
|
||||||
};
|
|
||||||
let local_words = "Lorem ipsum dolor sit amet".split_whitespace().to_owned();
|
|
||||||
let local_list = List::new(local_words)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.padding(Padding::new(1, 1, 1, 1)),
|
|
||||||
)
|
|
||||||
.highlight_spacing(HighlightSpacing::Always)
|
|
||||||
.highlight_style(Style::new().green().bold())
|
|
||||||
.highlight_symbol(" --> ")
|
|
||||||
.repeat_highlight_symbol(false);
|
|
||||||
frame.render_widget(local_list, local_area);
|
|
||||||
|
|
||||||
// Network Scan
|
|
||||||
if self.scan_network {
|
|
||||||
let network_words = "Adipiscing elit quisque faucibus ex sapien"
|
|
||||||
.split_whitespace()
|
|
||||||
.to_owned();
|
|
||||||
let network_list = List::new(network_words)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.padding(Padding::new(1, 1, 1, 1)),
|
|
||||||
)
|
|
||||||
.highlight_spacing(HighlightSpacing::Always)
|
|
||||||
.highlight_style(Style::new().green().bold())
|
|
||||||
.highlight_symbol(" --> ")
|
|
||||||
.repeat_highlight_symbol(false);
|
|
||||||
frame.render_widget(network_list, network_area);
|
|
||||||
}
|
|
||||||
|
|
||||||
// WIM Info
|
// WIM Info
|
||||||
let wim_sources = self.wim_sources.lock().unwrap();
|
if let Ok(wim_sources) = self.wim_sources.lock() {
|
||||||
let mut right_list = Vec::new();
|
// Local
|
||||||
if !wim_sources.network.is_empty() {
|
let mut left_list = Vec::new();
|
||||||
right_list.push(ListItem::new("-- Network --\n\n"));
|
left_list.extend(
|
||||||
right_list.extend(
|
|
||||||
wim_sources
|
wim_sources
|
||||||
.network
|
.local
|
||||||
.iter()
|
.iter()
|
||||||
.map(|wimfile| ListItem::new(format!("{}\n\n", wimfile.path))),
|
.map(|wimfile| ListItem::new(format!("{}\n\n", wimfile.path))),
|
||||||
);
|
);
|
||||||
right_list.push(ListItem::new(""));
|
let left_list = List::new(left_list)
|
||||||
}
|
.block(
|
||||||
right_list.push(ListItem::new("-- Local --\n\n"));
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.padding(Padding::new(1, 1, 1, 1)),
|
||||||
|
)
|
||||||
|
.highlight_spacing(HighlightSpacing::Always)
|
||||||
|
.highlight_style(Style::new().green().bold())
|
||||||
|
.highlight_symbol(" --> ")
|
||||||
|
.repeat_highlight_symbol(false);
|
||||||
|
frame.render_widget(left_list, left_body);
|
||||||
|
|
||||||
|
// Network
|
||||||
|
let mut right_list = Vec::new();
|
||||||
right_list.extend(
|
right_list.extend(
|
||||||
wim_sources
|
wim_sources
|
||||||
.local
|
.network
|
||||||
.iter()
|
.iter()
|
||||||
.map(|wimfile| ListItem::new(format!("{}\n\n", wimfile.path))),
|
.map(|wimfile| ListItem::new(format!("{}\n\n", wimfile.path))),
|
||||||
);
|
);
|
||||||
|
|
@ -179,6 +148,7 @@ impl Component for WimScan {
|
||||||
.highlight_symbol(" --> ")
|
.highlight_symbol(" --> ")
|
||||||
.repeat_highlight_symbol(false);
|
.repeat_highlight_symbol(false);
|
||||||
frame.render_widget(right_list, right_body);
|
frame.render_widget(right_list, right_body);
|
||||||
|
}
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,10 @@ pub struct State {
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
pub fn new(disk_list: Arc<Mutex<Vec<Disk>>>) -> Self {
|
pub fn new(disk_list: Arc<Mutex<Vec<Disk>>>) -> Self {
|
||||||
|
let wim_sources = WimSources::new();
|
||||||
State {
|
State {
|
||||||
disk_list,
|
disk_list,
|
||||||
|
wim_sources: Arc::new(Mutex::new(wim_sources)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use core::system::disk::Disk;
|
||||||
// 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
|
||||||
|
|
@ -14,11 +15,17 @@
|
||||||
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//
|
//
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap, fmt, fs::File, io::BufReader, path::Path, process::Command,
|
collections::HashMap,
|
||||||
sync::LazyLock,
|
fmt,
|
||||||
|
fs::{File, read_dir},
|
||||||
|
io::BufReader,
|
||||||
|
path::Path,
|
||||||
|
process::Command,
|
||||||
|
sync::{Arc, LazyLock, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
use tracing::info;
|
||||||
use xml::reader::{EventReader, XmlEvent};
|
use xml::reader::{EventReader, XmlEvent};
|
||||||
|
|
||||||
static WIN_BUILDS: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
|
static WIN_BUILDS: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
|
||||||
|
|
@ -139,13 +146,11 @@ pub fn parse_wim_file(wim_file: &str) -> std::io::Result<WimFile> {
|
||||||
let mut image = WimImage::new();
|
let mut image = WimImage::new();
|
||||||
|
|
||||||
let parser = EventReader::new(file);
|
let parser = EventReader::new(file);
|
||||||
let mut depth = 0;
|
|
||||||
for e in parser {
|
for e in parser {
|
||||||
match e {
|
match e {
|
||||||
Ok(XmlEvent::StartElement {
|
Ok(XmlEvent::StartElement {
|
||||||
name, attributes, ..
|
name, attributes, ..
|
||||||
}) => {
|
}) => {
|
||||||
depth += 1;
|
|
||||||
current_element = name.local_name.to_uppercase();
|
current_element = name.local_name.to_uppercase();
|
||||||
|
|
||||||
if current_element == "IMAGE" {
|
if current_element == "IMAGE" {
|
||||||
|
|
@ -171,8 +176,6 @@ pub fn parse_wim_file(wim_file: &str) -> std::io::Result<WimFile> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(XmlEvent::EndElement { name }) => {
|
Ok(XmlEvent::EndElement { name }) => {
|
||||||
depth -= 1;
|
|
||||||
|
|
||||||
if name.local_name.to_uppercase() == "IMAGE" {
|
if name.local_name.to_uppercase() == "IMAGE" {
|
||||||
// Append image to list
|
// Append image to list
|
||||||
if !image.build.is_empty() && !image.name.is_empty() && !image.index.is_empty()
|
if !image.build.is_empty() && !image.name.is_empty() && !image.index.is_empty()
|
||||||
|
|
@ -184,7 +187,7 @@ pub fn parse_wim_file(wim_file: &str) -> std::io::Result<WimFile> {
|
||||||
image.reset()
|
image.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(_) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
@ -198,24 +201,37 @@ pub fn parse_wim_file(wim_file: &str) -> std::io::Result<WimFile> {
|
||||||
Ok(wim_file)
|
Ok(wim_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn main() -> std::io::Result<()> {
|
pub fn scan_local_drives(
|
||||||
// let mut sources = WimSources::new();
|
disk_list_arc: Arc<Mutex<Vec<Disk>>>,
|
||||||
// if let Ok(wim_file) = parse_wim_file("./23H2.wim")
|
wim_sources_arc: Arc<Mutex<WimSources>>,
|
||||||
// && !wim_file.images.is_empty()
|
) {
|
||||||
// {
|
let mut to_check = vec![String::from(".")];
|
||||||
// sources.local.push(wim_file);
|
|
||||||
// }
|
// Get drive letters
|
||||||
// if let Ok(wim_file) = parse_wim_file("./24H2.wim") {
|
if let Ok(disk_list) = disk_list_arc.lock() {
|
||||||
// sources.local.push(wim_file);
|
disk_list.iter().for_each(|d| {
|
||||||
// }
|
d.parts.iter().for_each(|p| {
|
||||||
// dbg!(&sources);
|
if !p.letter.is_empty() {
|
||||||
// sources.local.iter().for_each(|f| {
|
to_check.push(format!("{}/Images", &p.letter));
|
||||||
// println!("-- {} --", f.path.to_string_lossy());
|
}
|
||||||
// f.images.iter().for_each(|i| {
|
});
|
||||||
// println!("* {i}");
|
})
|
||||||
// });
|
}
|
||||||
// println!();
|
|
||||||
// });
|
// Scan drives
|
||||||
//
|
to_check.iter().for_each(|scan_path| {
|
||||||
// Ok(())
|
info!("Scanning: {}", &scan_path);
|
||||||
// }
|
if let Ok(read_dir) = read_dir(scan_path) {
|
||||||
|
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.local.push(new_source);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue