diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-02-06 00:46:15 +0100 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-02-06 00:46:15 +0100 |
commit | 9093d938a8eb905d524f0b4308e4cb15a64d0c2a (patch) | |
tree | ad3bbc510f4e9a7794082e03858ae25a0dceffbe /src-tauri | |
parent | 38ff76aad91bc1ce344cdb08366c23523dbb8e1b (diff) | |
download | FlightCore-9093d938a8eb905d524f0b4308e4cb15a64d0c2a.tar.gz FlightCore-9093d938a8eb905d524f0b4308e4cb15a64d0c2a.zip |
feat: Parse whether mod is enabled/disabled
Diffstat (limited to 'src-tauri')
-rw-r--r-- | src-tauri/bindings/ParsedLogResults.ts | 3 | ||||
-rw-r--r-- | src-tauri/bindings/ParsedModFromLog.ts | 3 | ||||
-rw-r--r-- | src-tauri/src/repair_and_verify/log_handling.rs | 60 |
3 files changed, 57 insertions, 9 deletions
diff --git a/src-tauri/bindings/ParsedLogResults.ts b/src-tauri/bindings/ParsedLogResults.ts index 5352fc7e..7bc3239e 100644 --- a/src-tauri/bindings/ParsedLogResults.ts +++ b/src-tauri/bindings/ParsedLogResults.ts @@ -1,3 +1,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ParsedModFromLog } from "./ParsedModFromLog"; -export interface ParsedLogResults { northstar_launcher_version: string, installed_mods: Array<string>, }
\ No newline at end of file +export interface ParsedLogResults { northstar_launcher_version: string, installed_mods: Array<ParsedModFromLog>, }
\ No newline at end of file diff --git a/src-tauri/bindings/ParsedModFromLog.ts b/src-tauri/bindings/ParsedModFromLog.ts new file mode 100644 index 00000000..f71ed83d --- /dev/null +++ b/src-tauri/bindings/ParsedModFromLog.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface ParsedModFromLog { mod_name: string, enabled: boolean, }
\ No newline at end of file diff --git a/src-tauri/src/repair_and_verify/log_handling.rs b/src-tauri/src/repair_and_verify/log_handling.rs index e272d056..33e634cb 100644 --- a/src-tauri/src/repair_and_verify/log_handling.rs +++ b/src-tauri/src/repair_and_verify/log_handling.rs @@ -4,15 +4,24 @@ use ts_rs::TS; #[derive(Serialize, Deserialize, Debug, Clone, TS)] #[ts(export)] +pub struct ParsedModFromLog { + mod_name: String, + enabled: bool, +} + +#[derive(Serialize, Deserialize, Debug, Clone, TS)] +#[ts(export)] pub struct ParsedLogResults { northstar_launcher_version: String, - installed_mods: Vec<String>, + installed_mods: Vec<ParsedModFromLog>, } /// Parse logs for installed mods -fn parse_given_log_text_for_installed_mods(log_text: String) -> Result<Vec<String>, String> { - // Regex to capture mod loading - let regex = Regex::new(r"(?m)Loaded mod (.*) successfully\n").unwrap(); +fn parse_given_log_text_for_installed_mods( + log_text: String, +) -> Result<Vec<ParsedModFromLog>, String> { + // Regex to capture mod loading and whether enabled/disabled + let regex = Regex::new(r"(?m)Loaded mod (.*) successfully\n.*\[NORTHSTAR\] \[info\] Mod (.*) is (enabled|disabled)\n").unwrap(); // Run regex, result will be an iterator over tuples containing the start and end indices for each match in the string let result = regex.captures_iter(&log_text); @@ -20,12 +29,47 @@ fn parse_given_log_text_for_installed_mods(log_text: String) -> Result<Vec<Strin let mut mods = Vec::new(); for mat in result { // Get the captured string, which is the first and only capturing group in the regex - match mat.get(1) { - Some(mod_name) => { - mods.push(mod_name.as_str().to_string()); + let mod_name = match mat.get(1) { + Some(mod_name) => mod_name.as_str().to_string(), + None => { + println!("Failed parsing {:?}", mat); // log on failure + continue; + } + }; + let mod_name_copy = match mat.get(2) { + Some(mod_name) => mod_name.as_str().to_string(), + None => { + println!("Failed parsing {:?}", mat); // log on failure + continue; } - None => println!("Failed parsing {:?}", mat), // log on failure }; + let enabled_disabled = match mat.get(3) { + Some(mod_name) => mod_name.as_str().to_string(), + None => { + println!("Failed parsing {:?}", mat); // log on failure + continue; + } + }; + println!("{}, {}, {}", mod_name, mod_name_copy, enabled_disabled); + if mod_name != mod_name_copy { + return Err("Mod names don't match up".to_string()); + } + + // TODO improve checking + let mod_enabled; + if enabled_disabled == "enabled" { + mod_enabled = true; + } else { + mod_enabled = false; + } + + let parsed_mod_from_log = ParsedModFromLog { + mod_name, + enabled: mod_enabled, + }; + + // Add mod to list + mods.push(parsed_mod_from_log); } // Return the captured mod names |