-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from Grasscutters/more_cli
Passable amount of CLI options
- Loading branch information
Showing
8 changed files
with
263 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"rust-analyzer.linkedProjects": [".\\src-tauri\\Cargo.toml"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use std::path::PathBuf; | ||
use std::string::String; | ||
|
||
#[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 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::config; | ||
use crate::file_helpers; | ||
use crate::system_helpers; | ||
use std::path::PathBuf; | ||
|
||
pub async fn patch_game() -> bool { | ||
let patch_path = PathBuf::from(system_helpers::install_location()).join("patch/version.dll"); | ||
|
||
// Are we already patched with mhypbase? If so, that's fine, just continue as normal | ||
let game_is_patched = file_helpers::are_files_identical( | ||
patch_path.clone().to_str().unwrap(), | ||
PathBuf::from(get_game_rsa_path().await.unwrap()) | ||
.join("mhypbase.dll") | ||
.to_str() | ||
.unwrap(), | ||
); | ||
|
||
// Tell user they won't be unpatched with manual mhypbase patch | ||
if game_is_patched { | ||
println!( | ||
"You are already patched using mhypbase, so you will not be auto patched and unpatched!" | ||
); | ||
return true; | ||
} | ||
|
||
// Copy the patch to game files | ||
let replaced = file_helpers::copy_file_with_new_name( | ||
patch_path.clone().to_str().unwrap().to_string(), | ||
get_game_rsa_path().await.unwrap(), | ||
String::from("version.dll"), | ||
); | ||
|
||
if !replaced { | ||
return false; | ||
} | ||
|
||
true | ||
} | ||
|
||
pub async fn unpatch_game() -> bool { | ||
// Just delete patch since it's not replacing any existing file | ||
let deleted = file_helpers::delete_file( | ||
PathBuf::from(get_game_rsa_path().await.unwrap()) | ||
.join("version.dll") | ||
.to_str() | ||
.unwrap() | ||
.to_string(), | ||
); | ||
|
||
deleted | ||
} | ||
|
||
pub async fn get_game_rsa_path() -> Option<String> { | ||
let config = config::get_config(); | ||
let mut game_folder = PathBuf::from(config.game_install_path); | ||
game_folder.pop(); | ||
|
||
Some(format!("{}/", game_folder.to_str().unwrap()).replace('\\', "/")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.