From 9093d938a8eb905d524f0b4308e4cb15a64d0c2a Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Mon, 6 Feb 2023 00:46:15 +0100 Subject: feat: Parse whether mod is enabled/disabled --- src-tauri/bindings/ParsedLogResults.ts | 3 +- src-tauri/bindings/ParsedModFromLog.ts | 3 ++ src-tauri/src/repair_and_verify/log_handling.rs | 60 +++++++++++++++++++++---- src-vue/src/views/DeveloperView.vue | 22 +++++++++ 4 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 src-tauri/bindings/ParsedModFromLog.ts 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, } \ 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/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 @@ -2,17 +2,26 @@ use regex::Regex; use serde::{Deserialize, Serialize}; 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, + installed_mods: Vec, } /// Parse logs for installed mods -fn parse_given_log_text_for_installed_mods(log_text: String) -> Result, 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, 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 { - 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 diff --git a/src-vue/src/views/DeveloperView.vue b/src-vue/src/views/DeveloperView.vue index d8423450..dea0e1e3 100644 --- a/src-vue/src/views/DeveloperView.vue +++ b/src-vue/src/views/DeveloperView.vue @@ -64,6 +64,25 @@ placeholder="Paste log content here" /> +
+ + + + + + +
@@ -75,6 +94,7 @@ import { ElNotification } from "element-plus"; import { GameInstall } from "../utils/GameInstall"; import { Store } from 'tauri-plugin-store-api'; import { ParsedLogResults } from "../../../src-tauri/bindings/ParsedLogResults"; +import { ParsedModFromLog } from "../../../src-tauri/bindings/ParsedModFromLog"; const persistentStore = new Store('flight-core-settings.json'); export default defineComponent({ @@ -83,6 +103,7 @@ export default defineComponent({ return { mod_to_install_field_string : "", log_content : "", + logResults: [] as ParsedLogResults[] } }, methods: { @@ -228,6 +249,7 @@ export default defineComponent({ await invoke<[ParsedLogResults]>("parse_given_log_text", { logText: current_log_content }) .then((message) => { console.log(message); // TODO present better here + this.logResults.push(message); // Show user notification if task completed. ElNotification({ title: `Done`, -- cgit v1.2.3