From f857346a51093c47a3715d942968c2f9b30c28e4 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Sun, 5 Feb 2023 00:21:02 +0100 Subject: feat: Add ability to get installed mods from logs Parses the copy/pasted log text --- src-tauri/src/main.rs | 3 ++ src-tauri/src/repair_and_verify/log_handling.rs | 27 ++++++++++++++++ src-tauri/src/repair_and_verify/mod.rs | 2 ++ src-vue/src/views/DeveloperView.vue | 41 ++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src-tauri/src/repair_and_verify/log_handling.rs diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 4eab7a00..06adf784 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -37,6 +37,8 @@ use tauri::Manager; use tauri_plugin_store::PluginBuilder; use tokio::time::sleep; +use crate::repair_and_verify::log_handling::parse_given_log_text_for_installed_mods; + #[derive(Default)] struct Counter(Arc>); @@ -110,6 +112,7 @@ fn main() { delete_northstar_mod, get_server_player_count, delete_thunderstore_mod, + parse_given_log_text_for_installed_mods, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src-tauri/src/repair_and_verify/log_handling.rs b/src-tauri/src/repair_and_verify/log_handling.rs new file mode 100644 index 00000000..3b87f632 --- /dev/null +++ b/src-tauri/src/repair_and_verify/log_handling.rs @@ -0,0 +1,27 @@ +use regex::Regex; + +/// Parse logs for installed mods +#[tauri::command] +pub async 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(); + + // 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); + + 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()); + } + None => println!("Failed parsing {:?}", mat), // log on failure + }; + } + + // Return the captured mod names + return Ok(mods); +} diff --git a/src-tauri/src/repair_and_verify/mod.rs b/src-tauri/src/repair_and_verify/mod.rs index 5d58dfaf..ed00ba16 100644 --- a/src-tauri/src/repair_and_verify/mod.rs +++ b/src-tauri/src/repair_and_verify/mod.rs @@ -1,3 +1,5 @@ +pub mod log_handling; + use crate::{ mod_management::{rebuild_enabled_mods_json, set_mod_enabled_status}, northstar::CORE_MODS, diff --git a/src-vue/src/views/DeveloperView.vue b/src-vue/src/views/DeveloperView.vue index 6770caaa..b3887ebd 100644 --- a/src-vue/src/views/DeveloperView.vue +++ b/src-vue/src/views/DeveloperView.vue @@ -51,6 +51,19 @@ Delete FlightCore persistent store + +

Tech support

+ + + Parse logs + + @@ -63,11 +76,15 @@ import { GameInstall } from "../utils/GameInstall"; import { Store } from 'tauri-plugin-store-api'; const persistentStore = new Store('flight-core-settings.json'); +import { ref } from 'vue' +const textarea = ref('') + export default defineComponent({ name: "DeveloperView", data() { return { mod_to_install_field_string : "", + log_content : "", } }, methods: { @@ -207,7 +224,29 @@ export default defineComponent({ await persistentStore.clear(); // ...and save await persistentStore.save(); - } + }, + async parseGivenLogTextForMods() { + let current_log_content = this.log_content; + await invoke("parse_given_log_text_for_installed_mods", { logText: current_log_content }) + .then((message) => { + console.log(message); // TODO present better here + // Show user notification if task completed. + ElNotification({ + title: `Done`, + message: `${message}`, + type: 'success', + position: 'bottom-right' + }); + }) + .catch((error) => { + ElNotification({ + title: 'Error', + message: error, + type: 'error', + position: 'bottom-right' + }); + }); + }, } }); -- cgit v1.2.3