Skip to content

Commit

Permalink
arg update fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD authored and NotThorny committed Apr 26, 2023
1 parent d1786a9 commit 8742f1d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
45 changes: 23 additions & 22 deletions src-tauri/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::string::String;

// Config may not exist, or may be old, so it's okay if these are optional
#[derive(Serialize, Deserialize, Debug)]
pub struct Configuration {
pub toggle_grasscutter: bool,
pub game_install_path: String,
pub grasscutter_with_game: bool,
pub grasscutter_path: String,
pub java_path: String,
pub close_action: u64,
pub startup_launch: bool,
pub last_ip: String,
pub last_port: String,
pub language: String,
pub customBackground: String,
pub cert_generated: bool,
pub theme: String,
pub https_enabled: bool,
pub debug_enabled: bool,
pub patch_rsa: bool,
pub use_internal_proxy: bool,
pub wipe_login: bool,
pub horny_mode: bool,
pub auto_mongodb: bool,
pub un_elevated: bool,
pub toggle_grasscutter: Option<bool>,
pub game_install_path: Option<String>,
pub grasscutter_with_game: Option<bool>,
pub grasscutter_path: Option<String>,
pub java_path: Option<String>,
pub close_action: Option<u64>,
pub startup_launch: Option<bool>,
pub last_ip: Option<String>,
pub last_port: Option<String>,
pub language: Option<String>,
pub customBackground: Option<String>,
pub cert_generated: Option<bool>,
pub theme: Option<String>,
pub https_enabled: Option<bool>,
pub debug_enabled: Option<bool>,
pub patch_rsa: Option<bool>,
pub use_internal_proxy: Option<bool>,
pub wipe_login: Option<bool>,
pub horny_mode: Option<bool>,
pub auto_mongodb: Option<bool>,
pub un_elevated: Option<bool>,
}

pub fn config_path() -> PathBuf {
Expand All @@ -37,7 +38,7 @@ pub fn config_path() -> PathBuf {

pub fn get_config() -> Configuration {
let path = config_path();
let config = std::fs::read_to_string(path).unwrap();
let config = std::fs::read_to_string(path).unwrap_or("{}".to_string());
let config: Configuration = serde_json::from_str(&config).unwrap();

config
Expand Down
18 changes: 10 additions & 8 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,17 @@ async fn parse_args(inp: &Vec<String>) -> Result<Args, ArgsError> {
patch::patch_game().await;
}

if args.value_of("non-elevated-game")? {
system_helpers::run_un_elevated(game_path.to_string(), Some(game_args))
} else {
system_helpers::run_program(game_path.to_string(), Some(game_args))
if game_path.is_some() {
if args.value_of("non-elevated-game")? {
system_helpers::run_un_elevated(game_path.unwrap().to_string(), Some(game_args))
} else {
system_helpers::run_program(game_path.unwrap().to_string(), Some(game_args))
}
}
}

if args.value_of("server")? {
let server_jar = config.grasscutter_path;
if args.value_of("server")? && config.grasscutter_path.is_some() && config.java_path.is_some() {
let server_jar = config.grasscutter_path.unwrap();
let mut server_path = server_jar.clone();
// Strip jar name from path
if server_path.contains('/') {
Expand All @@ -124,7 +126,7 @@ async fn parse_args(inp: &Vec<String>) -> Result<Args, ArgsError> {
let len = server_jar.rfind('\\').unwrap();
server_path.truncate(len);
}
let java_path = config.java_path;
let java_path = config.java_path.unwrap();

system_helpers::run_jar(server_jar, server_path.to_string(), java_path);
}
Expand Down Expand Up @@ -155,7 +157,7 @@ fn main() -> Result<(), ArgsError> {
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
Expand Down
7 changes: 6 additions & 1 deletion src-tauri/src/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ pub async fn unpatch_game() -> bool {

pub async fn get_game_rsa_path() -> Option<String> {
let config = config::get_config();
let mut game_folder = PathBuf::from(config.game_install_path);

if config.game_install_path.is_none() {
return None;
}

let mut game_folder = PathBuf::from(config.game_install_path.unwrap());
game_folder.pop();

Some(format!("{}/", game_folder.to_str().unwrap()).replace('\\', "/"))
Expand Down

0 comments on commit 8742f1d

Please sign in to comment.