use std::process::Command; use std::env; use std::fs; use walkdir::WalkDir; use std::ffi::OsString; use std::path::PathBuf; use crate::config_settings; pub fn extract_wad() { let config = config_settings::load_config(); let wad_files: Vec = WalkDir::new(config.wad_dir) .into_iter() .filter_map(|entry| entry.ok()) .filter(|entry| { let path = entry.path(); let file_name = path.file_name().and_then(|name| name.to_str()).unwrap_or(""); let extension = path.extension().and_then(|ext| ext.to_str()).unwrap_or(""); extension == "client" && file_name.ends_with(".wad.client") && file_name.split('.').count() == 3 }) .map(|entry| entry.path().to_owned().into_os_string()) .collect(); if wad_files.is_empty() { eprintln!("No valid .wad.client files found in the directory"); return; } let current_dir = env::current_dir().expect("Failed to get current directory"); let extraction_path = current_dir.join("wads"); let bat_path = PathBuf::from(config.cslol_dir).join("cslol-tools\\wad-extract.exe"); if !extraction_path.exists() { fs::create_dir_all(&extraction_path).expect("Failed to create extraction folder"); } for (i, wad_file) in wad_files.iter().enumerate() { let status = Command::new(&bat_path) .arg(&wad_file) .arg(&extraction_path) .status() .expect("Failed to execute command"); if status.success() { println!("Successfully executed wad-extract.bat for {:?}", wad_file); } else { eprintln!("wad-extract.bat returned a non-zero status for {:?}", wad_file); } if i >= 3 { break; } } }