Parser for internal modpack xml file
This commit is contained in:
parent
6d97033506
commit
07815441ae
79
Cargo.lock
generated
79
Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
5
config.toml
Normal file
5
config.toml
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
[arma]
|
||||
env = []
|
||||
args = []
|
||||
steam_library_path = ""
|
10
mp.xml
Executable file
10
mp.xml
Executable file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<addons-presets>
|
||||
<last-update>2025-01-16T23:28:18.2655417+02:00</last-update>
|
||||
<published-ids>
|
||||
<id>steam:450814997</id>
|
||||
<id>steam:463939057</id>
|
||||
<id>local:Z:\HOME\MCORANGE\.LOCAL\SHARE\STEAM\STEAMAPPS\WORKSHOP\CONTENT\107410\2466229756\</id>
|
||||
</published-ids>
|
||||
<dlcs-appids />
|
||||
</addons-presets>
|
7
mp2.xml
Normal file
7
mp2.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<addons-presets>
|
||||
<last-update>1970-01-01T03:00:00+03:00</last-update>
|
||||
<published-ids>
|
||||
</published-ids>
|
||||
<dlcs-appids />
|
||||
</addons-presets>
|
|
@ -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<String>,
|
||||
steam_library_path: Utf8PathBuf,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn parse(path: &Path) -> anyhow::Result<Self> {
|
||||
let s = std::fs::read_to_string(path)?;
|
||||
Ok(toml::from_str(&s)?)
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub mod gui;
|
||||
pub mod config;
|
||||
pub mod cli;
|
||||
pub mod modpack;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
0
src/modpack/external/mod.rs
vendored
Normal file
0
src/modpack/external/mod.rs
vendored
Normal file
71
src/modpack/internal/mod.rs
Normal file
71
src/modpack/internal/mod.rs
Normal file
|
@ -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<chrono::Local>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct MPIntPublishedModIds {
|
||||
#[serde(rename = "$value")]
|
||||
pub value: Vec<MPIntModId>,
|
||||
}
|
||||
|
||||
#[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<Self> {
|
||||
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, "<?xml version=\"1.0\" encoding=\"utf-8\"?>")?;
|
||||
writeln!(f, "<addons-presets>")?;
|
||||
writeln!(f, " <last-update>{}</last-update>", self.last_update.value.to_rfc3339())?;
|
||||
writeln!(f, " <published-ids>")?;
|
||||
for id in &self.published_ids.value {
|
||||
writeln!(f, " <id>{}</id>", id.value)?;
|
||||
}
|
||||
//<id>steam:463939057</id>
|
||||
// <id>local:Z:\HOME\MCORANGE\.LOCAL\SHARE\STEAM\STEAMAPPS\WORKSHOP\CONTENT\107410\2466229756\</id>
|
||||
writeln!(f, " </published-ids>")?;
|
||||
writeln!(f, " <dlcs-appids />")?;
|
||||
writeln!(f, "</addons-presets>")?;
|
||||
|
||||
std::fs::write(path, buf)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
2
src/modpack/mod.rs
Normal file
2
src/modpack/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod internal;
|
||||
pub mod external;
|
Loading…
Reference in New Issue
Block a user