From 38ff76aad91bc1ce344cdb08366c23523dbb8e1b Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Sun, 5 Feb 2023 23:47:19 +0100 Subject: feat: Parse for Northstar Launcher version --- src-tauri/bindings/ParsedLogResults.ts | 2 +- src-tauri/src/repair_and_verify/log_handling.rs | 26 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src-tauri/bindings/ParsedLogResults.ts b/src-tauri/bindings/ParsedLogResults.ts index 9d9d5c63..5352fc7e 100644 --- a/src-tauri/bindings/ParsedLogResults.ts +++ b/src-tauri/bindings/ParsedLogResults.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface ParsedLogResults { installed_mods: Array, } \ No newline at end of file +export interface ParsedLogResults { northstar_launcher_version: string, installed_mods: Array, } \ 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 2b394a23..e272d056 100644 --- a/src-tauri/src/repair_and_verify/log_handling.rs +++ b/src-tauri/src/repair_and_verify/log_handling.rs @@ -5,6 +5,7 @@ use ts_rs::TS; #[derive(Serialize, Deserialize, Debug, Clone, TS)] #[ts(export)] pub struct ParsedLogResults { + northstar_launcher_version: String, installed_mods: Vec, } @@ -31,12 +32,33 @@ fn parse_given_log_text_for_installed_mods(log_text: String) -> Result Result { + let regex = Regex::new(r"(?m)NorthstarLauncher version: (.*)\n").unwrap(); + + // result will be an iterator over tuples containing the start and end indices for each match in the string + let mut result = regex.captures_iter(&log_text); + + // Return found Northstar launcher version number + match result.next() { + None => Err("Couldn't parse Northstar launcher version".to_string()), + Some(mat) => match mat.get(1) { + None => Err("Couldn't parse Northstar launcher version".to_string()), + Some(mod_name) => Ok(mod_name.as_str().to_string()), + }, + } +} + /// Parse logs for installed mods #[tauri::command] pub async fn parse_given_log_text(log_text: String) -> Result { - let installed_mods = parse_given_log_text_for_installed_mods(log_text)?; + let installed_mods = parse_given_log_text_for_installed_mods(log_text.clone())?; + let northstar_launcher_version = parse_for_northstar_launcher_version(log_text)?; - let parsed_log_results = ParsedLogResults { installed_mods }; + let parsed_log_results = ParsedLogResults { + northstar_launcher_version, + installed_mods, + }; // Return the parsed results return Ok(parsed_log_results); -- cgit v1.2.3