diff --git a/Cargo.toml b/Cargo.toml index cee4766..bc8c3e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ serde = "1.0.163" serde_derive = "1.0.163" strsim = "0.10.0" toml = "0.7.4" +walkdir = "2.4.0" diff --git a/src/main.rs b/src/main.rs index af08851..7ae7aaf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,8 @@ use infos::{ use native_dialog::{MessageDialog, MessageType}; use std::path::PathBuf; use std::process::Command; +use wad::get_summary; +use walkdir::{DirEntry, WalkDir}; pub mod config; pub mod infos; @@ -64,18 +66,46 @@ impl Default for RustDoomLauncher { } } +fn is_wad_file(entry: &DirEntry) -> bool { + let filename = entry.file_name().to_str().unwrap().to_lowercase(); + println!("{} - > {}", filename, filename.ends_with("wad")); + filename.ends_with("wad") +} + +fn get_wads_in_folder(path: &PathBuf) -> Vec { + let mut wads = Vec::new(); + for entry in WalkDir::new(path) { + let entry = entry.unwrap(); + if is_wad_file(&entry) { + wads.push(WadInfo { + name: format!("{}", entry.path().display()), + path: entry.path().to_path_buf(), + info_text: None, + }) + } + } + wads +} + impl RustDoomLauncher { fn get_config_file_stuff(&mut self) { // TODO - Throw some kind of error if a config file isn't found and/or missing iwad folder + println!("{:?}", self.config_filename); match load_config(&self.config_filename) { Ok(c) => { + println!("{:?}", c); if let Some(launchers) = &c.launchers { for launcher in launchers { self.launcher_manager.add(&launcher); } } - }, - Err(_e) => {}, + for iwad in get_wads_in_folder(&c.iwads_folder) { + self.iwad_manager.add(&iwad); + } + } + Err(e) => { + println!("{:?}", e); + } }; } @@ -412,7 +442,9 @@ impl eframe::App for RustDoomLauncher { self.iwad_manager.add(&WadInfo { name: self.add_name.clone(), path: self.selected_file_path.clone(), - info_text: Some("I'm sure you know what's in that bloody IWAD!".to_string()), + info_text: Some( + "I'm sure you know what's in that bloody IWAD!".to_string(), + ), }); } FileType::Pwad => {