From 48dff50a5dc884b0f2fbe8a019f96d5c16cf67e0 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Fri, 21 Apr 2023 16:28:56 -0700 Subject: [PATCH] config reading --- .vscode/settings.json | 3 +++ src-tauri/src/config.rs | 44 +++++++++++++++++++++++++++++++++++++++++ src-tauri/src/main.rs | 9 ++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 src-tauri/src/config.rs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..53e875e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.linkedProjects": [".\\src-tauri\\Cargo.toml"] +} diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs new file mode 100644 index 0000000..c0f7dd9 --- /dev/null +++ b/src-tauri/src/config.rs @@ -0,0 +1,44 @@ +use serde::{Deserialize, Serialize}; +use std::path::PathBuf; +use std::string::String; + +#[derive(Serialize, Deserialize, Debug)] +pub struct Configuration { + toggle_grasscutter: bool, + game_install_path: String, + grasscutter_with_game: bool, + grasscutter_path: String, + java_path: String, + close_action: u64, + startup_launch: bool, + last_ip: String, + last_port: u64, + language: String, + customBackground: String, + cert_generated: bool, + theme: String, + https_enabled: bool, + debug_enabled: bool, + patch_rsa: bool, + use_internal_proxy: bool, + wipe_login: bool, + horny_mode: bool, + auto_mongodb: bool, + un_elevated: bool, +} + +pub fn config_path() -> PathBuf { + let mut path = tauri::api::path::data_dir().unwrap(); + path.push("cultivation"); + path.push("configuration.json"); + + path +} + +pub fn get_config() -> Configuration { + let path = config_path(); + let config = std::fs::read_to_string(path).unwrap(); + let config: Configuration = serde_json::from_str(&config).unwrap(); + + config +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3715e31..222224f 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -18,6 +18,7 @@ use sysinfo::{Pid, ProcessExt, System, SystemExt}; use crate::admin::reopen_as_admin; mod admin; +mod config; mod downloader; mod file_helpers; mod gamebanana; @@ -41,6 +42,8 @@ fn has_arg(args: &[String], arg: &str) -> bool { } async fn arg_handler(args: &[String]) { + let config = config::get_config(); + if has_arg(args, "--proxy") { let mut pathbuf = tauri::api::path::data_dir().unwrap(); pathbuf.push("cultivation"); @@ -48,6 +51,10 @@ async fn arg_handler(args: &[String]) { connect(8035, pathbuf.to_str().unwrap().to_string()).await; } + + if has_arg(args, "--launch-game") { + let game_exe = config.game_install_path.clone(); + } } fn main() { @@ -58,7 +65,7 @@ fn main() { println!("You running as a non-elevated user. Some stuff will almost definitely not work."); println!("==============================================================================="); - reopen_as_admin(); + //reopen_as_admin(); } // Setup datadir/cultivation just in case something went funky and it wasn't made