From ecd4bff8823aac71328cee3a1adf852b55335095 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 1 Jun 2022 17:40:24 -0700 Subject: [PATCH] get language despite admin or not --- src-tauri/src/lang.rs | 6 ++++-- src-tauri/src/system_helpers.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/lang.rs b/src-tauri/src/lang.rs index 23c518e..8a7f53d 100644 --- a/src-tauri/src/lang.rs +++ b/src-tauri/src/lang.rs @@ -1,9 +1,11 @@ +use crate::system_helpers::*; + #[tauri::command] pub async fn get_lang(window: tauri::Window, lang: String) -> String { let lang = lang.to_lowercase(); // Send contents of language file back - let contents = match std::fs::read_to_string(format!("./lang/{}.json", lang)) { + let contents = match std::fs::read_to_string(format!("{}/lang/{}.json", install_location(), lang)) { Ok(x) => x, Err(e) => { emit_lang_err(window, format!("Failed to read language file: {}", e)); @@ -19,7 +21,7 @@ pub async fn get_languages() -> std::collections::HashMap { // for each lang file, set the key as the filename and the value as the lang_name contained in the file let mut languages = std::collections::HashMap::new(); - let mut lang_files = std::fs::read_dir("./lang").unwrap(); + let mut lang_files = std::fs::read_dir(format!("{}/lang", install_location())).unwrap(); while let Some(entry) = lang_files.next() { let entry = entry.unwrap(); diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 4a79d79..bafcef9 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -54,3 +54,14 @@ pub fn open_in_browser(url: String) { Err(e) => println!("Failed to open URL: {}", e), }; } + +pub fn install_location() -> String { + let mut exe_path = std::env::current_exe().unwrap(); + + // Get the path to the executable. + exe_path.pop(); + + println!("{}", exe_path.to_str().unwrap().to_string()); + + return exe_path.to_str().unwrap().to_string(); +} \ No newline at end of file