Compare commits
7 Commits
main
...
folder_bas
| Author | SHA1 | Date | |
|---|---|---|---|
| 5859fcdb02 | |||
| 97b3e98041 | |||
| f3b9ba6259 | |||
| 2589c7fc3d | |||
| da4a89ddf6 | |||
| d14edf6e94 | |||
| 6122f99ff7 |
@@ -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"
|
||||
|
||||
133
src/config.rs
133
src/config.rs
@@ -1,24 +1,18 @@
|
||||
use crate::infos::{LauncherInfo, WadInfo};
|
||||
use crate::infos::{LauncherInfo};
|
||||
use directories;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use toml;
|
||||
use directories;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum AddMode {
|
||||
DoNothing,
|
||||
Copy,
|
||||
Move,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||
pub struct Config {
|
||||
pub iwads_added_folder: Option<PathBuf>,
|
||||
pub iwads_removed_folder: Option<PathBuf>,
|
||||
pub add_mode: Option<AddMode>,
|
||||
pub iwads: Option<Vec<WadInfo>>,
|
||||
pub pwads: Option<Vec<WadInfo>>,
|
||||
pub launchers: Option<Vec<LauncherInfo>>,
|
||||
pub iwads_folder: PathBuf,
|
||||
pub iwads_old_folder: Option<PathBuf>,
|
||||
pub pwads_folder: Option<PathBuf>,
|
||||
pub pwads_old_folder: Option<PathBuf>,
|
||||
pub mods_folder: Option<PathBuf>,
|
||||
pub mods_old_folder: Option<PathBuf>,
|
||||
}
|
||||
|
||||
pub fn load_config(path: &PathBuf) -> Result<Config, Box<dyn std::error::Error>> {
|
||||
@@ -29,18 +23,11 @@ pub fn load_config(path: &PathBuf) -> Result<Config, Box<dyn std::error::Error>>
|
||||
Ok(toml::from_str(&content)?)
|
||||
}
|
||||
|
||||
pub fn save_config(path: &PathBuf, config: &Config) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let prefix = path.parent().unwrap();
|
||||
std::fs::create_dir_all(prefix).unwrap();
|
||||
let toml_string = toml::to_string(&config).unwrap();
|
||||
Ok(std::fs::write(path, toml_string)?)
|
||||
}
|
||||
|
||||
pub fn default_save_filename() -> PathBuf {
|
||||
pub fn default_config_filename() -> PathBuf {
|
||||
let project = directories::ProjectDirs::from("party", "arfy", "rdl").unwrap();
|
||||
let mut full_path = PathBuf::new();
|
||||
full_path.push(project.config_dir());
|
||||
full_path.push("wads_and_stuff.toml");
|
||||
full_path.push("wad_folders.toml");
|
||||
full_path
|
||||
}
|
||||
|
||||
@@ -49,85 +36,51 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn basic_iwad() {
|
||||
let config_str = "[[iwads]]\n\
|
||||
name = \"DOOM2.WAD\"\n\
|
||||
path = \"/home/wads/doom.wad\"\n";
|
||||
fn basic_folder() {
|
||||
let config_str = "iwads_folder = \"/home/arthurr/Games/doom_wads/iwads\"";
|
||||
let config: Config = toml::from_str(&config_str).unwrap();
|
||||
assert_eq!(
|
||||
config.iwads_folder,
|
||||
PathBuf::from("/home/arthurr/Games/doom_wads/iwads")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_launcher() {
|
||||
let config_str = "iwads_folder = \"/home/arthurr/Games/doom_wads/iwads\"
|
||||
[[launchers]]\n\
|
||||
name = \"GZDoom\"\n\
|
||||
path = \"/home/guy/gzdoom\"\n";
|
||||
let config: Result<Config, _> = toml::from_str(&config_str);
|
||||
assert!(config.is_ok());
|
||||
let config = config.unwrap();
|
||||
assert_eq!(config.iwads.unwrap().len(), 1);
|
||||
assert_eq!(config.launchers.unwrap().len(), 1);
|
||||
}
|
||||
#[test]
|
||||
fn basic_iwads() {
|
||||
let config_str = "[[iwads]]
|
||||
name = \"DOOM2.WAD\"
|
||||
path = \"/home/wads/doom.wad\"
|
||||
fn basic_launchers() {
|
||||
let config_str = "iwads_folder = \"/home/arthurr/Games/doom_wads/iwads\"
|
||||
[[launchers]]
|
||||
name = \"GZDoom\"
|
||||
path = \"/home/guy/gzdoom\"
|
||||
|
||||
[[iwads]]
|
||||
name = \"DOOM1.WAD1.9\"
|
||||
path = \"/home/wads/doom1.9.wad\"";
|
||||
[[launchers]]
|
||||
name = \"PrBoom\"
|
||||
path = \"/home/guy/prboom\"";
|
||||
|
||||
let config: Config = toml::from_str(&config_str).unwrap();
|
||||
// I'm not 100% sure why I need all of these as_ref
|
||||
assert_eq!(config.iwads.as_ref().unwrap().len(), 2);
|
||||
assert_eq!(config.iwads.as_ref().unwrap()[0].name, "DOOM2.WAD");
|
||||
assert_eq!(config.iwads.as_ref().unwrap()[1].name, "DOOM1.WAD1.9");
|
||||
assert_eq!(config.launchers.as_ref().unwrap().len(), 2);
|
||||
assert_eq!(config.launchers.as_ref().unwrap()[0].name, "GZDoom");
|
||||
assert_eq!(config.launchers.as_ref().unwrap()[1].name, "PrBoom");
|
||||
assert_eq!(
|
||||
config.iwads.unwrap()[0].path,
|
||||
PathBuf::from("/home/wads/doom.wad")
|
||||
config.launchers.unwrap()[0].path,
|
||||
PathBuf::from("/home/guy/gzdoom")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iwads_and_pwads() {
|
||||
let config_str = "[[iwads]]
|
||||
name = \"DOOM2.WAD\"
|
||||
path = \"/home/wads/doom.wad\"
|
||||
|
||||
[[iwads]]
|
||||
name = \"DOOM1.WAD1.9\"
|
||||
path = \"/home/wads/doom1.9.wad\"
|
||||
|
||||
[[pwads]]
|
||||
name = \"Ancient Aliens\"
|
||||
path = \"/home/pwads/aa.pk3\"";
|
||||
|
||||
let config: Config = toml::from_str(&config_str).unwrap();
|
||||
assert_eq!(config.iwads.as_ref().unwrap().len(), 2);
|
||||
assert_eq!(config.iwads.unwrap()[0].name, "DOOM2.WAD");
|
||||
assert_eq!(config.pwads.as_ref().unwrap()[0].name, "Ancient Aliens");
|
||||
assert_eq!(
|
||||
config.pwads.unwrap()[0].path,
|
||||
PathBuf::from("/home/pwads/aa.pk3")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iwads_back_and_forth() {
|
||||
let iwad1 = WadInfo {
|
||||
path: PathBuf::from("/home/wads/doom.wad"),
|
||||
name: "DOOM.WAD".to_string(),
|
||||
};
|
||||
let iwad2 = WadInfo {
|
||||
path: PathBuf::from("/home/wads/doom2.wad"),
|
||||
name: "DOOM2.WAD".to_string(),
|
||||
};
|
||||
let iwads = vec![iwad1, iwad2];
|
||||
let launcher = LauncherInfo {
|
||||
path: PathBuf::from("/home/bin/gzdoom/gzdoom"),
|
||||
name: "GZDoom".to_string(),
|
||||
};
|
||||
let config = Config {
|
||||
iwads: Some(iwads),
|
||||
launchers: Some(vec![launcher]),
|
||||
pwads: None,
|
||||
iwads_added_folder: None,
|
||||
iwads_removed_folder: None,
|
||||
add_mode: None,
|
||||
};
|
||||
let toml_as_str = toml::to_string(&config).unwrap();
|
||||
let new_config: Config = toml::from_str(&toml_as_str).unwrap();
|
||||
assert_eq!(config.iwads.unwrap().len(), new_config.iwads.unwrap().len());
|
||||
fn missing_iwad_folder() {
|
||||
let config_str = "pwads_folder = \"/home/arthurr/Games/doom_wads/pwads\"";
|
||||
let config = toml::from_str::<Config>(&config_str);
|
||||
assert!(config.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,6 @@ impl CommandManager {
|
||||
pub struct WadInfo {
|
||||
pub path: PathBuf,
|
||||
pub name: String,
|
||||
#[serde(skip_deserializing)]
|
||||
pub info_text: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
153
src/main.rs
153
src/main.rs
@@ -1,5 +1,4 @@
|
||||
use config::{default_save_filename, load_config, save_config, Config};
|
||||
use wad::get_summary;
|
||||
use config::{default_config_filename, load_config, Config};
|
||||
use eframe::egui;
|
||||
use eframe::egui::Color32;
|
||||
use infos::{
|
||||
@@ -8,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;
|
||||
@@ -44,8 +45,6 @@ struct RustDoomLauncher {
|
||||
add_stuff_window_displayed: bool,
|
||||
selected_file_type: FileType,
|
||||
selected_file_path: PathBuf,
|
||||
save_config_window_displayed: bool,
|
||||
close_application: bool,
|
||||
}
|
||||
|
||||
impl Default for RustDoomLauncher {
|
||||
@@ -56,44 +55,64 @@ impl Default for RustDoomLauncher {
|
||||
pwad_manager: MultiManager::new(),
|
||||
command_manager: CommandManager::default(),
|
||||
add_name: "".to_string(),
|
||||
config_filename: default_save_filename(),
|
||||
config_filename: default_config_filename(),
|
||||
config: None, // TODO: put the config_filename in the config stuct - or something
|
||||
config_tried: false,
|
||||
display_command: false,
|
||||
add_stuff_window_displayed: false,
|
||||
selected_file_type: FileType::Pwad,
|
||||
selected_file_path: PathBuf::new(),
|
||||
save_config_window_displayed: false,
|
||||
close_application: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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") || filename.ends_with("pk3")
|
||||
}
|
||||
|
||||
fn get_wads_in_folder(path: &PathBuf) -> Vec<WadInfo> {
|
||||
let mut wads = Vec::new();
|
||||
for entry in WalkDir::new(path).max_depth(2) {
|
||||
let entry = entry.unwrap();
|
||||
if is_wad_file(&entry) {
|
||||
|
||||
wads.push(WadInfo {
|
||||
name: format!("{}", entry.path().file_name().unwrap().to_str().unwrap()),
|
||||
path: entry.path().to_path_buf(),
|
||||
info_text: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
wads
|
||||
}
|
||||
|
||||
impl RustDoomLauncher {
|
||||
// There must be a better way than this - maybe for the RustDoomLauncher to
|
||||
// have a config thing
|
||||
fn get_config_file_stuff(&mut self) {
|
||||
self.config = match load_config(&self.config_filename) {
|
||||
Ok(c) => Some(c),
|
||||
Err(_e) => None,
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
for iwad in get_wads_in_folder(&c.iwads_folder) {
|
||||
self.iwad_manager.add(&iwad);
|
||||
}
|
||||
if let Some(pwad_folder) = &c.pwads_folder {
|
||||
for pwad in get_wads_in_folder(pwad_folder) {
|
||||
self.pwad_manager.add(&pwad)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{:?}", e);
|
||||
}
|
||||
};
|
||||
if let Some(config) = &self.config {
|
||||
if let Some(iwads) = &config.iwads {
|
||||
for iwad in iwads {
|
||||
self.iwad_manager.add(&iwad);
|
||||
}
|
||||
}
|
||||
if let Some(pwads) = &config.pwads {
|
||||
for pwad in pwads {
|
||||
self.pwad_manager.add(&pwad.clone());
|
||||
}
|
||||
}
|
||||
if let Some(launchers) = &config.launchers {
|
||||
for launcher in launchers {
|
||||
self.launcher_manager.add(&launcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn launch_doom(&self) {
|
||||
@@ -140,11 +159,6 @@ impl RustDoomLauncher {
|
||||
}
|
||||
|
||||
impl eframe::App for RustDoomLauncher {
|
||||
fn on_close_event(&mut self) -> bool {
|
||||
self.save_config_window_displayed = true;
|
||||
self.close_application
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
if !self.config_tried {
|
||||
self.get_config_file_stuff();
|
||||
@@ -239,31 +253,37 @@ impl eframe::App for RustDoomLauncher {
|
||||
ui.label("PWADs");
|
||||
let mut remove_pos: Option<usize> = None;
|
||||
let mut add_pos: Option<usize> = None;
|
||||
for (pwad, pos, selected) in
|
||||
self.pwad_manager.iter_selectable_with_pos_and_selected()
|
||||
{
|
||||
ui.horizontal(|ui| {
|
||||
if ui
|
||||
.add(egui::SelectableLabel::new(selected, &pwad.name))
|
||||
.clicked()
|
||||
{
|
||||
add_pos = Some(pos);
|
||||
}
|
||||
if ui.button("❌").clicked() {
|
||||
remove_pos = Some(pos);
|
||||
}
|
||||
});
|
||||
}
|
||||
ui.columns(2, |columns| {
|
||||
for (i, (pwad, pos, selected)) in
|
||||
self.pwad_manager.iter_selectable_with_pos_and_selected().enumerate()
|
||||
{
|
||||
columns[i%2].horizontal(|ui| {
|
||||
if ui
|
||||
.add(egui::SelectableLabel::new(selected, &pwad.name))
|
||||
.clicked()
|
||||
{
|
||||
add_pos = Some(pos);
|
||||
}
|
||||
if ui.button("❌").clicked() {
|
||||
remove_pos = Some(pos);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
if let Some(rp) = remove_pos {
|
||||
self.pwad_manager.remove_selectable(rp);
|
||||
self.command_manager
|
||||
.add_pwads(&self.pwad_manager.get_current())
|
||||
}
|
||||
*/
|
||||
if let Some(ap) = add_pos {
|
||||
self.pwad_manager.set_current(ap);
|
||||
self.command_manager
|
||||
.add_pwads(&self.pwad_manager.get_current())
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
@@ -371,37 +391,6 @@ impl eframe::App for RustDoomLauncher {
|
||||
}
|
||||
});
|
||||
|
||||
if self.save_config_window_displayed {
|
||||
egui::Window::new("Save WADs?")
|
||||
.collapsible(false)
|
||||
.resizable(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.label("Would you like to save the WADs you've added/deleted?");
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Yes").clicked() {
|
||||
self.close_application = true;
|
||||
let config = Config {
|
||||
iwads: Some(self.iwad_manager.selectable.clone()),
|
||||
pwads: Some(self.pwad_manager.selectable.clone()),
|
||||
launchers: Some(self.launcher_manager.selectable.clone()),
|
||||
..Default::default()
|
||||
};
|
||||
save_config(&self.config_filename, &config).unwrap();
|
||||
frame.close();
|
||||
}
|
||||
if ui.button("No").clicked() {
|
||||
self.close_application = true;
|
||||
frame.close();
|
||||
};
|
||||
if ui.button("Don't Quit").clicked() {
|
||||
self.save_config_window_displayed = false;
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
egui::Window::new("Add WAD or Launcher")
|
||||
.open(&mut self.add_stuff_window_displayed)
|
||||
.show(ctx, |ui| {
|
||||
@@ -465,7 +454,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 => {
|
||||
|
||||
Reference in New Issue
Block a user