From 07815441ae1222e1c923365dda5c75091e00721c Mon Sep 17 00:00:00 2001 From: MCorange Date: Fri, 17 Jan 2025 00:58:36 +0200 Subject: [PATCH] Parser for internal modpack xml file --- Cargo.lock | 79 ++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 ++ config.toml | 5 +++ mp.xml | 10 +++++ mp2.xml | 7 ++++ src/config/mod.rs | 24 +++++++++++ src/lib.rs | 1 + src/main.rs | 6 ++- src/modpack/external/mod.rs | 0 src/modpack/internal/mod.rs | 71 +++++++++++++++++++++++++++++++++ src/modpack/mod.rs | 2 + 11 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 config.toml create mode 100755 mp.xml create mode 100644 mp2.xml create mode 100644 src/modpack/external/mod.rs create mode 100644 src/modpack/internal/mod.rs create mode 100644 src/modpack/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 143fbf3..d4e77da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,12 +7,15 @@ name = "a3l_rs" version = "0.1.0" dependencies = [ "anyhow", + "camino", + "chrono", "clap", "eframe", "egui", "egui_extras", "env_logger", "log", + "quick-xml 0.37.2", "serde", "toml", ] @@ -108,7 +111,7 @@ dependencies = [ "paste", "static_assertions", "windows", - "windows-core", + "windows-core 0.58.0", ] [[package]] @@ -180,6 +183,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -639,6 +648,15 @@ dependencies = [ "wayland-client", ] +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + [[package]] name = "cc" version = "1.2.9" @@ -683,6 +701,21 @@ dependencies = [ "libc", ] +[[package]] +name = "chrono" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-targets 0.52.6", +] + [[package]] name = "clap" version = "4.5.26" @@ -1596,6 +1629,29 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core 0.52.0", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "icu_collections" version = "1.5.0" @@ -2513,6 +2569,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "quick-xml" +version = "0.37.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "165859e9e55f79d67b96c5d96f4e88b6f2695a1972849c15a6a3f5c59fc2c003" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "quote" version = "1.0.38" @@ -3681,7 +3747,16 @@ version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" dependencies = [ - "windows-core", + "windows-core 0.58.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ "windows-targets 0.52.6", ] diff --git a/Cargo.toml b/Cargo.toml index 17f7a4f..b472767 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,14 @@ edition = "2024" [dependencies] anyhow = "1.0.95" +camino = { version = "1.1.9", features = ["serde1"] } +chrono = { version = "0.4.39", features = ["serde"] } clap = { version = "4.5.26", features = ["derive"] } eframe = "0.30.0" egui = { version = "0.30.0", features = ["color-hex"] } egui_extras = { version = "0.30.0", features = ["all_loaders"] } env_logger = "0.11.6" log = "0.4.25" +quick-xml = { version = "0.37.2", features = ["serde", "serialize"] } serde = { version = "1.0.217", features = ["derive"] } toml = "0.8.19" diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..8ef73e2 --- /dev/null +++ b/config.toml @@ -0,0 +1,5 @@ + +[arma] +env = [] +args = [] +steam_library_path = "" diff --git a/mp.xml b/mp.xml new file mode 100755 index 0000000..92a6e87 --- /dev/null +++ b/mp.xml @@ -0,0 +1,10 @@ + + + 2025-01-16T23:28:18.2655417+02:00 + + steam:450814997 + steam:463939057 + local:Z:\HOME\MCORANGE\.LOCAL\SHARE\STEAM\STEAMAPPS\WORKSHOP\CONTENT\107410\2466229756\ + + + \ No newline at end of file diff --git a/mp2.xml b/mp2.xml new file mode 100644 index 0000000..511d9e0 --- /dev/null +++ b/mp2.xml @@ -0,0 +1,7 @@ + + + 1970-01-01T03:00:00+03:00 + + + + diff --git a/src/config/mod.rs b/src/config/mod.rs index e69de29..7838af5 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -0,0 +1,24 @@ +use std::path::Path; +use camino::Utf8PathBuf; +use egui::ahash::HashMap; +use serde::{Deserialize, Serialize}; + + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Config { + arma: ConfigArma3, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ConfigArma3 { + env: Vec<(String, String)>, + args: Vec, + steam_library_path: Utf8PathBuf, +} + +impl Config { + pub fn parse(path: &Path) -> anyhow::Result { + let s = std::fs::read_to_string(path)?; + Ok(toml::from_str(&s)?) + } +} diff --git a/src/lib.rs b/src/lib.rs index 7c6fb13..22f8907 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod gui; pub mod config; pub mod cli; +pub mod modpack; diff --git a/src/main.rs b/src/main.rs index e7a11a9..ec2139b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ +use std::path::Path; + fn main() { - println!("Hello, world!"); + 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); } diff --git a/src/modpack/external/mod.rs b/src/modpack/external/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/modpack/internal/mod.rs b/src/modpack/internal/mod.rs new file mode 100644 index 0000000..63f5ba3 --- /dev/null +++ b/src/modpack/internal/mod.rs @@ -0,0 +1,71 @@ +use std::path::Path; +use std::fmt::Write; +use serde::{Deserialize, Serialize}; + + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +#[serde(rename = "addons-presets")] +pub struct MPInt { + #[serde(rename = "last-update")] + pub last_update: MPIntLastUpdate, + #[serde(rename = "published-ids")] + pub published_ids: MPIntPublishedModIds, + #[serde(rename = "dlcs-appids")] + pub dlcs_appids: MPIntDlcsAppIds, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct MPIntLastUpdate { + // rfc3339 + #[serde(rename = "$value")] + pub value: chrono::DateTime, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct MPIntPublishedModIds { + #[serde(rename = "$value")] + pub value: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct MPIntModId { + #[serde(rename = "$value")] + pub value: String, +} +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct MPIntDlcsAppIds; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub enum MPIntModIdType { + Steam, + Local, +} + +impl MPInt { + pub fn parse(path: &Path) -> anyhow::Result { + let s = std::fs::read_to_string(path)?; + Ok(quick_xml::de::from_str(&s)?) + } + pub fn write(&self, path: &Path) -> anyhow::Result<()> { + let mut indent_idx = 0; + let mut buf = String::new(); + let f = &mut buf; + + writeln!(f, "")?; + writeln!(f, "")?; + writeln!(f, " {}", self.last_update.value.to_rfc3339())?; + writeln!(f, " ")?; + for id in &self.published_ids.value { + writeln!(f, " {}", id.value)?; + } + //steam:463939057 + // local:Z:\HOME\MCORANGE\.LOCAL\SHARE\STEAM\STEAMAPPS\WORKSHOP\CONTENT\107410\2466229756\ + writeln!(f, " ")?; + writeln!(f, " ")?; + writeln!(f, "")?; + + std::fs::write(path, buf)?; + Ok(()) + } +} + diff --git a/src/modpack/mod.rs b/src/modpack/mod.rs new file mode 100644 index 0000000..b9235cd --- /dev/null +++ b/src/modpack/mod.rs @@ -0,0 +1,2 @@ +pub mod internal; +pub mod external;