From fa25001d7f2a1962de8990f077f7f1601679a292 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:29:29 +0100 Subject: feat: Add JSON5 support, allows comments in JSON (#50) Some mods have comments in their JSON. Northstar handles it fine, so we should too. --- src-tauri/Cargo.lock | 12 ++++++++++++ src-tauri/Cargo.toml | 2 ++ src-tauri/src/mod_management/mod.rs | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src-tauri') diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index ec50c51c..b6f27065 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -79,6 +79,7 @@ name = "app" version = "0.3.1" dependencies = [ "anyhow", + "json5", "libthermite", "powershell_script", "regex", @@ -1580,6 +1581,17 @@ dependencies = [ "treediff", ] +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + [[package]] name = "keyvalues-parser" version = "0.1.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 4e0d2cba..ab2de8bf 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -38,6 +38,8 @@ sysinfo = "0.26.2" reqwest = { version = "0.11", features = ["blocking"] } # Persistent store for settings tauri-plugin-store = { git = "https://github.com/tauri-apps/tauri-plugin-store", branch = "dev" } +# JSON5 parsing support (allows comments in JSON) +json5 = "0.4.1" [features] # by default Tauri runs in production mode diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index e3034903..ecfd3835 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -7,6 +7,8 @@ use std::path::PathBuf; use app::GameInstall; use app::get_enabled_mods; +use json5; + /// Set the status of a passed mod to enabled/disabled pub fn set_mod_enabled_status( game_install: GameInstall, @@ -42,7 +44,7 @@ pub fn set_mod_enabled_status( fn parse_mod_json_for_mod_name(mod_json_path: String) -> Result { // Read file into string and parse it let data = std::fs::read_to_string(mod_json_path)?; - let parsed_json: serde_json::Value = serde_json::from_str(&data)?; + let parsed_json: serde_json::Value = json5::from_str(&data)?; // Extract mod name let mod_name = match parsed_json.get("Name").and_then(|value| value.as_str()) { -- cgit v1.2.3