wwawawawawaawaawaww

This commit is contained in:
Gvidas Juknevičius 2025-01-19 21:48:12 +02:00
parent b75f65d824
commit 542dae6279
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
7 changed files with 87 additions and 79 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target /target
/config.toml

View File

@ -1,5 +1,5 @@
steam_library_path = "/home/mcorange/.local/share/Steam/"
[arma] [arma]
env = [] env = []
args = [] args = []
steam_library_path = ""

View File

@ -1,4 +1,4 @@
use std::path::Path; use std::path::{PathBuf, Path};
use camino::Utf8PathBuf; use camino::Utf8PathBuf;
use egui::ahash::HashMap; use egui::ahash::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config { pub struct Config {
steam_library_path: Utf8PathBuf,
arma: ConfigArma3, arma: ConfigArma3,
} }
@ -13,7 +14,6 @@ pub struct Config {
pub struct ConfigArma3 { pub struct ConfigArma3 {
env: Vec<(String, String)>, env: Vec<(String, String)>,
args: Vec<String>, args: Vec<String>,
steam_library_path: Utf8PathBuf,
} }
impl Config { impl Config {
@ -21,4 +21,15 @@ impl Config {
let s = std::fs::read_to_string(path)?; let s = std::fs::read_to_string(path)?;
Ok(toml::from_str(&s)?) 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()
}
} }

View File

@ -1,76 +1,21 @@
struct MyApp { fn draw_central(gc: &mut crate::GloblCtx, ui: &mut egui::Ui, _frame: &mut eframe::Frame) -> anyhow::Result<()> {
selected: String, for i in crate::launcher::Launcher::get_modpacks(&gc.config)? {
presets: Vec<String>, ui.label(i);
}
impl Default for MyApp {
fn default() -> Self {
Self {
selected: String::new(),
presets: Vec::new(),
}
} }
} Ok(())
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { pub fn gui_start(mut gc: crate::GloblCtx) -> anyhow::Result<()> {
let options = eframe::NativeOptions::default();
if self.presets.is_empty() { let _ = eframe::run_simple_native("a3l_rs", options, move |ctx, frame| {
let home_dir = std::env::var("HOME").expect("HOME environment variable not set"); egui::CentralPanel::default().show(ctx, |ui| {
if let Err(e) = draw_central(&mut gc, ui, frame) {
let steamapps_dir = std::path::PathBuf::from(home_dir).join(".steam/debian-installation/steamapps"); log::error!("GUI ERR: {e}");
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::<MyApp>::default())
}),
).unwrap();
Ok(()) Ok(())
} }

36
src/launcher/mod.rs Normal file
View File

@ -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<Vec<String>> {
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(())
}
}

View File

@ -1,4 +1,22 @@
use std::path::Path;
pub mod gui; pub mod gui;
pub mod config; pub mod config;
pub mod cli; pub mod cli;
pub mod modpack; pub mod modpack;
pub mod launcher;
#[derive(Debug, Clone)]
pub struct GloblCtx {
config: config::Config,
}
impl GloblCtx {
pub fn new() -> anyhow::Result<Self> {
Ok(Self {
config: config::Config::parse(Path::new("./config.toml"))?,
})
}
}

View File

@ -1,10 +1,7 @@
use std::path::Path; use std::path::Path;
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
a3l_rs::modpack::internal::MPInt::default().write(Path::new("./mp2.xml")); let gc = a3l_rs::GloblCtx::new()?;
let mp = a3l_rs::modpack::internal::MPInt::parse(Path::new("./mp.xml")); a3l_rs::gui::gui_start(gc)?;
dbg!(mp);
a3l_rs::gui::gui_start()?;
Ok(()) Ok(())
} }