mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 16:14:48 +01:00
real arg parse
This commit is contained in:
@@ -4,27 +4,27 @@ 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 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: u64,
|
||||
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 fn config_path() -> PathBuf {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use args::{Args, ArgsError};
|
||||
use file_helpers::dir_exists;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::fs;
|
||||
@@ -37,14 +38,34 @@ fn try_flush() {
|
||||
std::io::stdout().flush().unwrap_or(())
|
||||
}
|
||||
|
||||
fn has_arg(args: &[String], arg: &str) -> bool {
|
||||
args.contains(&arg.to_string())
|
||||
}
|
||||
async fn parse_args(inp: &Vec<String>) -> Result<Args, ArgsError> {
|
||||
let mut args = Args::new(
|
||||
"Cultivation",
|
||||
"Private server helper program for an Anime Game",
|
||||
);
|
||||
args.flag("h", "help", "Print various CLI args");
|
||||
args.flag("p", "proxy", "Start the proxy server");
|
||||
args.flag("g", "launch-game", "Launch the game");
|
||||
args.flag(
|
||||
"na",
|
||||
"no-admin",
|
||||
"Launch without requiring admin permissions",
|
||||
);
|
||||
args.flag("ng", "no-gui", "Run in CLI mode");
|
||||
|
||||
args.parse(inp);
|
||||
|
||||
async fn arg_handler(args: &[String]) {
|
||||
let config = config::get_config();
|
||||
|
||||
if has_arg(args, "--proxy") {
|
||||
if args.value_of("help")? {
|
||||
println!("{}", args.full_usage());
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if args.value_of("launch-game")? {}
|
||||
|
||||
if args.value_of("proxy")? {
|
||||
println!("Starting proxy server...");
|
||||
let mut pathbuf = tauri::api::path::data_dir().unwrap();
|
||||
pathbuf.push("cultivation");
|
||||
pathbuf.push("ca");
|
||||
@@ -52,15 +73,14 @@ 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();
|
||||
}
|
||||
Ok(args)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), ArgsError> {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let parsed_args = block_on(parse_args(&args)).unwrap();
|
||||
|
||||
if !is_elevated() && !has_arg(&args, "--no-admin") {
|
||||
if !is_elevated() && parsed_args.value_of("no-admin")? {
|
||||
println!("===============================================================================");
|
||||
println!("You running as a non-elevated user. Some stuff will almost definitely not work.");
|
||||
println!("===============================================================================");
|
||||
@@ -78,8 +98,6 @@ fn main() {
|
||||
exe_path.pop();
|
||||
std::env::set_current_dir(&exe_path).unwrap();
|
||||
|
||||
block_on(arg_handler(&args));
|
||||
|
||||
// For disabled GUI
|
||||
ctrlc::set_handler(|| {
|
||||
disconnect();
|
||||
@@ -87,7 +105,7 @@ fn main() {
|
||||
})
|
||||
.unwrap_or(());
|
||||
|
||||
if !has_arg(&args, "--no-gui") {
|
||||
if !parsed_args.value_of("no-gui")? {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
enable_process_watcher,
|
||||
@@ -149,6 +167,8 @@ fn main() {
|
||||
|
||||
// Always disconnect upon closing the program
|
||||
disconnect();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
Reference in New Issue
Block a user