From bf8de40caae131ba40fe741ad0562f802b0196e0 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Fri, 26 Aug 2022 17:53:45 -0700 Subject: [PATCH] wipe registry option --- src-tauri/lang/en.json | 3 ++- src-tauri/src/main.rs | 1 + src-tauri/src/system_helpers.rs | 25 +++++++++++++++++++++++ src/ui/components/ServerLaunchSection.tsx | 6 ++++++ src/ui/components/menu/Options.tsx | 22 ++++++++++++++++++++ src/utils/configuration.ts | 2 ++ 6 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src-tauri/lang/en.json b/src-tauri/lang/en.json index d6059aa..315eef5 100644 --- a/src-tauri/lang/en.json +++ b/src-tauri/lang/en.json @@ -25,7 +25,8 @@ "background": "Set Custom Background (link or image file)", "theme": "Set Theme", "patch_metadata": "Automatically Patch Metadata", - "use_proxy": "Use Internal Proxy" + "use_proxy": "Use Internal Proxy", + "wipe_login": "Wipe Login Cache" }, "downloads": { "grasscutter_stable_data": "Download Grasscutter Stable Data", diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index f591428..645d845 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -46,6 +46,7 @@ fn main() { system_helpers::install_location, system_helpers::is_elevated, system_helpers::set_migoto_target, + system_helpers::wipe_registry, proxy::set_proxy_addr, proxy::generate_ca_files, unzip::unzip, diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index b72ddaa..5a72302 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -2,6 +2,9 @@ use duct::cmd; use ini::Ini; use std::path::PathBuf; +#[cfg(windows)] +use registry::{Data, Hive, Security}; + #[tauri::command] pub fn run_program(path: String, args: Option) { // Without unwrap_or, this can crash when UAC prompt is denied @@ -127,6 +130,28 @@ pub fn set_migoto_target(path: String, migoto_path: String) -> bool { } } +#[tauri::command] +pub fn wipe_registry(exec_name: String) { + // Fetch the 'Internet Settings' registry key. + let settings = + match Hive::CurrentUser.open(format!("Software\\miHoYo\\{}", exec_name), Security::Write) { + Ok(s) => s, + Err(e) => { + println!("Error getting registry setting: {}", e); + return; + } + }; + + // Wipe login cache + match settings.set_value( + "MIHOYOSDK_ADL_PROD_OVERSEA_h1158948810", + &Data::String("".parse().unwrap()), + ) { + Ok(_) => (), + Err(e) => println!("Error wiping registry: {}", e), + } +} + #[cfg(windows)] #[tauri::command] pub fn is_elevated() -> bool { diff --git a/src/ui/components/ServerLaunchSection.tsx b/src/ui/components/ServerLaunchSection.tsx index 70a0aa7..0f8a186 100644 --- a/src/ui/components/ServerLaunchSection.tsx +++ b/src/ui/components/ServerLaunchSection.tsx @@ -161,6 +161,12 @@ export default class ServerLaunchSection extends React.Component } } + // First wipe registry if we have to + await invoke('wipe_registry', { + // The exe is always PascalCase so we can get the dir using regex + execName: (await getGameExecutable())?.split('.exe')[0].replace(/([a-z\d])([A-Z])/g, '$1 $2'), + }) + // Launch the program const gameExists = await invoke('dir_exists', { path: exe || config.game_install_path, diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index df69bf8..86116c4 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -34,6 +34,7 @@ interface IState { encryption: boolean patch_metadata: boolean use_internal_proxy: boolean + wipe_login: boolean swag: boolean // Swag stuff @@ -59,6 +60,7 @@ export default class Options extends React.Component { encryption: false, patch_metadata: false, use_internal_proxy: false, + wipe_login: false, swag: false, // Swag stuff @@ -78,6 +80,7 @@ export default class Options extends React.Component { this.restoreMetadata = this.restoreMetadata.bind(this) this.toggleMetadata = this.toggleMetadata.bind(this) this.toggleProxy = this.toggleProxy.bind(this) + this.toggleLoginWipe = this.toggleLoginWipe.bind(this) } async componentDidMount() { @@ -102,6 +105,7 @@ export default class Options extends React.Component { encryption: await translate(encEnabled ? 'options.enabled' : 'options.disabled'), patch_metadata: config.patch_metadata || false, use_internal_proxy: config.use_internal_proxy || false, + wipe_login: config.wipe_login || false, swag: config.swag_mode || false, // Swag stuff @@ -262,6 +266,16 @@ export default class Options extends React.Component { }) } + async toggleLoginWipe() { + const changedVal = !(await getConfigOption('wipe_login')) + + await setConfigOption('wipe_login', changedVal) + + this.setState({ + wipe_login: changedVal, + }) + } + render() { return ( @@ -302,6 +316,14 @@ export default class Options extends React.Component { + diff --git a/src/utils/configuration.ts b/src/utils/configuration.ts index d43774c..f39bf0b 100644 --- a/src/utils/configuration.ts +++ b/src/utils/configuration.ts @@ -22,6 +22,7 @@ let defaultConfig: Configuration debug_enabled: false, patch_metadata: true, use_internal_proxy: true, + wipe_login: false, } })() @@ -46,6 +47,7 @@ export interface Configuration { debug_enabled: boolean patch_metadata: boolean use_internal_proxy: boolean + wipe_login: boolean swag_mode?: boolean // Swag stuff