mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 07:34:36 +01:00
Add profiles
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"lang_name": "English",
|
||||
"main": {
|
||||
"title": "Cultivation",
|
||||
"title": "Cultivation: Thorny Edition",
|
||||
"launch_button": "Launch",
|
||||
"gc_enable": "Connect to Grasscutter",
|
||||
"https_enable": "Use HTTPS",
|
||||
@@ -39,7 +39,9 @@
|
||||
"web_cache": "Delete webCaches folder",
|
||||
"launch_args": "Launch Args",
|
||||
"offline_mode": "Offline Mode",
|
||||
"fix_res": "Fix Login Timeout"
|
||||
"fix_res": "Fix Login Timeout",
|
||||
"show_version": "Show game version in buttons",
|
||||
"save_profile": "Save profile"
|
||||
},
|
||||
"downloads": {
|
||||
"grasscutter_fullbuild": "Download Grasscutter 4.0 All-in-One",
|
||||
|
||||
@@ -30,20 +30,33 @@ pub struct Configuration {
|
||||
pub redirect_more: Option<bool>,
|
||||
pub launch_args: Option<String>,
|
||||
pub offline_mode: Option<bool>,
|
||||
pub show_version: Option<bool>,
|
||||
pub profile: Option<String>,
|
||||
}
|
||||
|
||||
pub fn config_path() -> PathBuf {
|
||||
pub fn config_path(profile: String) -> PathBuf {
|
||||
let mut path = tauri::api::path::data_dir().unwrap();
|
||||
path.push("cultivation");
|
||||
path.push("configuration.json");
|
||||
if profile.as_str() == "default" {
|
||||
path.push("configuration.json");
|
||||
} else {
|
||||
path.push("profile");
|
||||
path.push(profile);
|
||||
}
|
||||
|
||||
path
|
||||
}
|
||||
|
||||
pub fn get_config() -> Configuration {
|
||||
let path = config_path();
|
||||
pub fn get_config(profile_name: String) -> Configuration {
|
||||
let path = config_path(profile_name);
|
||||
let config = std::fs::read_to_string(path).unwrap_or("{}".to_string());
|
||||
let config: Configuration = serde_json::from_str(&config).unwrap_or_default();
|
||||
|
||||
let default = String::from("default");
|
||||
let prof = config.profile.as_ref().unwrap_or(&default);
|
||||
if *prof != String::from("default") {
|
||||
get_config(prof.clone());
|
||||
}
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ async fn parse_args(inp: &Vec<String>) -> Result<Args, ArgsError> {
|
||||
|
||||
args.parse(inp).unwrap();
|
||||
|
||||
let config = config::get_config();
|
||||
let config = config::get_config(String::from("default"));
|
||||
|
||||
if args.value_of("help")? {
|
||||
println!("{}", args.full_usage());
|
||||
@@ -207,6 +207,7 @@ fn main() -> Result<(), ArgsError> {
|
||||
is_grasscutter_running,
|
||||
restart_grasscutter,
|
||||
get_theme_list,
|
||||
get_profile_list,
|
||||
system_helpers::run_command,
|
||||
system_helpers::run_program,
|
||||
system_helpers::run_program_args,
|
||||
@@ -536,3 +537,20 @@ async fn get_theme_list(data_dir: String) -> Vec<HashMap<String, String>> {
|
||||
|
||||
themes
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn get_profile_list(data_dir: String) -> Vec<String> {
|
||||
let profile_loc = format!("{}/profiles", data_dir);
|
||||
|
||||
// Ensure folder exists
|
||||
if !std::path::Path::new(&profile_loc).exists() {
|
||||
std::fs::create_dir_all(&profile_loc).unwrap();
|
||||
}
|
||||
|
||||
let mut p_list = Vec::new();
|
||||
for entry in std::fs::read_dir(&profile_loc).unwrap() {
|
||||
p_list.push(entry.unwrap().file_name().into_string().unwrap());
|
||||
}
|
||||
|
||||
p_list
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ pub async fn unpatch_game() -> bool {
|
||||
}
|
||||
|
||||
pub async fn get_game_rsa_path() -> Option<String> {
|
||||
let config = config::get_config();
|
||||
let config = config::get_config(String::from("default"));
|
||||
|
||||
config.game_install_path.as_ref()?;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
},
|
||||
"package": {
|
||||
"productName": "Cultivation",
|
||||
"version": "1.6.3"
|
||||
"version": "1.7.0"
|
||||
},
|
||||
"tauri": {
|
||||
"allowlist": {
|
||||
|
||||
Reference in New Issue
Block a user