wipe registry option

This commit is contained in:
SpikeHD
2022-08-26 17:53:45 -07:00
parent fa38a22117
commit bf8de40caa
6 changed files with 58 additions and 1 deletions

View File

@@ -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",

View File

@@ -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,

View File

@@ -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<String>) {
// 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 {

View File

@@ -161,6 +161,12 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
}
}
// 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,

View File

@@ -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<IProps, IState> {
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<IProps, IState> {
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<IProps, IState> {
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<IProps, IState> {
})
}
async toggleLoginWipe() {
const changedVal = !(await getConfigOption('wipe_login'))
await setConfigOption('wipe_login', changedVal)
this.setState({
wipe_login: changedVal,
})
}
render() {
return (
<Menu closeFn={this.props.closeFn} className="Options" heading="Options">
@@ -302,6 +316,14 @@ export default class Options extends React.Component<IProps, IState> {
<Checkbox onChange={this.toggleProxy} checked={this.state?.use_internal_proxy} id="useProxy" />
</div>
</div>
<div className="OptionSection" id="menuOptionsContainerWipeLogin">
<div className="OptionLabel" id="menuOptionsLabelWipeLogin">
<Tr text="options.wipe_login" />
</div>
<div className="OptionValue" id="menuOptionsCheckboxWipeLogin">
<Checkbox onChange={this.toggleLoginWipe} checked={this.state?.wipe_login} id="wipeLogin" />
</div>
</div>
<Divider />

View File

@@ -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