From 542dae6279a95f56626338062c666304f713dbd3 Mon Sep 17 00:00:00 2001 From: MCorange Date: Sun, 19 Jan 2025 21:48:12 +0200 Subject: [PATCH] wwawawawawaawaawaww --- .gitignore | 1 + config.toml | 2 +- src/config/mod.rs | 15 ++++++-- src/gui/mod.rs | 87 +++++++++------------------------------------ src/launcher/mod.rs | 36 +++++++++++++++++++ src/lib.rs | 18 ++++++++++ src/main.rs | 7 ++-- 7 files changed, 87 insertions(+), 79 deletions(-) create mode 100644 src/launcher/mod.rs diff --git a/.gitignore b/.gitignore index ea8c4bf..fabfb87 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/config.toml diff --git a/config.toml b/config.toml index 8ef73e2..00394bc 100644 --- a/config.toml +++ b/config.toml @@ -1,5 +1,5 @@ +steam_library_path = "/home/mcorange/.local/share/Steam/" [arma] env = [] args = [] -steam_library_path = "" diff --git a/src/config/mod.rs b/src/config/mod.rs index 7838af5..2d55a19 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,4 +1,4 @@ -use std::path::Path; +use std::path::{PathBuf, Path}; use camino::Utf8PathBuf; use egui::ahash::HashMap; use serde::{Deserialize, Serialize}; @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { + steam_library_path: Utf8PathBuf, arma: ConfigArma3, } @@ -13,7 +14,6 @@ pub struct Config { pub struct ConfigArma3 { env: Vec<(String, String)>, args: Vec, - steam_library_path: Utf8PathBuf, } impl Config { @@ -21,4 +21,15 @@ impl Config { let s = std::fs::read_to_string(path)?; Ok(toml::from_str(&s)?) } + + pub fn get_arma_path(&self) -> PathBuf { + let mut p = self.steam_library_path.clone(); + p.push("steamapps/common/Arma 3/"); + p.into() + } + pub fn get_arma_pfx_path(&self) -> PathBuf { + let mut p = self.steam_library_path.clone(); + p.push("steamapps/compatdata/107410/pfx/drive_c/"); + p.into() + } } diff --git a/src/gui/mod.rs b/src/gui/mod.rs index a29e4e7..e723101 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -1,76 +1,21 @@ -struct MyApp { - selected: String, - presets: Vec, -} - -impl Default for MyApp { - fn default() -> Self { - Self { - selected: String::new(), - presets: Vec::new(), - } +fn draw_central(gc: &mut crate::GloblCtx, ui: &mut egui::Ui, _frame: &mut eframe::Frame) -> anyhow::Result<()> { + for i in crate::launcher::Launcher::get_modpacks(&gc.config)? { + ui.label(i); } -} - -impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - egui::CentralPanel::default().show(ctx, |ui| { - - if self.presets.is_empty() { - let home_dir = std::env::var("HOME").expect("HOME environment variable not set"); - - let steamapps_dir = std::path::PathBuf::from(home_dir).join(".steam/debian-installation/steamapps"); - let preset_dir = steamapps_dir - .join("compatdata") - .join("107410") - .join("pfx") - .join("drive_c") - .join("users") - .join("steamuser") - .join("AppData") - .join("Local") - .join("Arma 3 Launcher") - .join("Presets"); - - if let Ok(entries) = std::fs::read_dir(preset_dir) { - self.presets = entries - .filter_map(|entry| entry.ok()) - .filter_map(|entry| entry.file_name().into_string().ok()) - .collect(); - } - } - - egui::ComboBox::from_label("Select Preset") - .selected_text(&self.selected) - .show_ui(ui, |ui| { - for preset in &self.presets { - ui.selectable_value(&mut self.selected, preset.clone(), preset); - } - }); - - if ui.button("skibidi").clicked() { - println!("Selected preset: {}", self.selected); - } - }); - } -} - -pub fn gui_start() -> anyhow::Result<()> { - let options = eframe::NativeOptions { - viewport: egui::ViewportBuilder::default().with_inner_size([900.0, 540.0]), - ..Default::default() - }; - - eframe::run_native( - "a3lrs", - options, - Box::new(|cc| { - egui_extras::install_image_loaders(&cc.egui_ctx); - Ok(Box::::default()) - }), - ).unwrap(); - + Ok(()) +} + + +pub fn gui_start(mut gc: crate::GloblCtx) -> anyhow::Result<()> { + let options = eframe::NativeOptions::default(); + let _ = eframe::run_simple_native("a3l_rs", options, move |ctx, frame| { + egui::CentralPanel::default().show(ctx, |ui| { + if let Err(e) = draw_central(&mut gc, ui, frame) { + log::error!("GUI ERR: {e}"); + } + }); + }); Ok(()) } diff --git a/src/launcher/mod.rs b/src/launcher/mod.rs new file mode 100644 index 0000000..f2702f9 --- /dev/null +++ b/src/launcher/mod.rs @@ -0,0 +1,36 @@ +use std::ffi::OsStr; +use std::path::PathBuf; +use crate::config::Config; + +#[derive(Debug, Clone)] +pub struct Launcher { + +} + + +impl Launcher { + pub fn new() -> Self { + Self { + + } + } + pub fn get_modpacks(config: &Config) -> anyhow::Result> { + let mut packs = Vec::new(); + let mut modpack_dir = config.get_arma_pfx_path().clone(); + modpack_dir.push("users/steamuser/AppData/Local/Arma 3 Launcher/Presets/"); + for itm in std::fs::read_dir(modpack_dir)? { + let itm = itm?; + if itm.file_type()?.is_file() { + if itm.path().extension() == Some(OsStr::new("preset2")) { + let fln = itm.path().with_extension(""); + packs.push(fln.file_name().unwrap().to_string_lossy().to_string()); + } + } + } + Ok(packs) + } + pub fn start_arma(config: &Config) -> anyhow::Result<()> { + + Ok(()) + } +} diff --git a/src/lib.rs b/src/lib.rs index 22f8907..923d434 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,22 @@ +use std::path::Path; + pub mod gui; pub mod config; pub mod cli; pub mod modpack; +pub mod launcher; + +#[derive(Debug, Clone)] +pub struct GloblCtx { + config: config::Config, +} + +impl GloblCtx { + pub fn new() -> anyhow::Result { + Ok(Self { + config: config::Config::parse(Path::new("./config.toml"))?, + }) + } +} + + diff --git a/src/main.rs b/src/main.rs index a8ab9bd..98b9c6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,7 @@ use std::path::Path; fn main() -> anyhow::Result<()> { - a3l_rs::modpack::internal::MPInt::default().write(Path::new("./mp2.xml")); - let mp = a3l_rs::modpack::internal::MPInt::parse(Path::new("./mp.xml")); - dbg!(mp); - - a3l_rs::gui::gui_start()?; + let gc = a3l_rs::GloblCtx::new()?; + a3l_rs::gui::gui_start(gc)?; Ok(()) }