From bd54a78e4bc19d1968132145944b48ce21816458 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Fri, 15 Jul 2022 19:35:57 -0700 Subject: [PATCH] emergency metadata recovery --- src-tauri/lang/en.json | 1 + src-tauri/src/file_helpers.rs | 8 ++++- src-tauri/src/main.rs | 1 + src-tauri/src/web.rs | 6 ++++ src/ui/App.tsx | 1 + src/ui/components/menu/Options.tsx | 19 +++++++++++ src/utils/metadata.ts | 54 +++++++++++++++++++++++++++++- 7 files changed, 88 insertions(+), 2 deletions(-) diff --git a/src-tauri/lang/en.json b/src-tauri/lang/en.json index 8ae6c5a..842ba42 100644 --- a/src-tauri/lang/en.json +++ b/src-tauri/lang/en.json @@ -15,6 +15,7 @@ "disabled": "Disabled", "game_path": "Set Game Install Path", "game_executable": "Set Game Executable", + "recover_metadata": "Emergency Metadata Recovery", "grasscutter_jar": "Set Grasscutter JAR", "toggle_encryption": "Toggle Encryption", "java_path": "Set Custom Java Path", diff --git a/src-tauri/src/file_helpers.rs b/src-tauri/src/file_helpers.rs index eda3f6c..6ad14b6 100644 --- a/src-tauri/src/file_helpers.rs +++ b/src-tauri/src/file_helpers.rs @@ -66,7 +66,13 @@ pub fn copy_file_with_new_name(path: String, new_path: String, new_name: String) // If the new path doesn't exist, create it. if !dir_exists(new_path_buf.pop().to_string().as_str()) { - std::fs::create_dir_all(&new_path).unwrap(); + match std::fs::create_dir_all(&new_path) { + Ok(_) => {} + Err(e) => { + println!("Failed to create directory: {}", e); + return false; + } + }; } // Copy old to new diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 055516d..766e9ec 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -54,6 +54,7 @@ fn main() { lang::get_lang, lang::get_languages, web::valid_url, + web::web_get, metadata_patcher::patch_metadata ]) .run(tauri::generate_context!()) diff --git a/src-tauri/src/web.rs b/src-tauri/src/web.rs index af5864d..d363039 100644 --- a/src-tauri/src/web.rs +++ b/src-tauri/src/web.rs @@ -15,4 +15,10 @@ pub(crate) async fn valid_url(url: String) -> bool { let response = client.get(url).header(USER_AGENT, "cultivation").send().await.unwrap(); response.status().as_str() == "200" +} + +#[tauri::command] +pub async fn web_get(url: String) -> String { + // Send a GET request to the specified URL and send the response body back to the client. + query(&url).await } \ No newline at end of file diff --git a/src/ui/App.tsx b/src/ui/App.tsx index dc8aa1e..e05d4db 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -206,6 +206,7 @@ class App extends React.Component { // Options menu this.state.optionsOpen ? ( this.setState({ optionsOpen: !this.state.optionsOpen })} /> ) : null diff --git a/src/ui/components/menu/Options.tsx b/src/ui/components/menu/Options.tsx index e118d23..495c0bd 100644 --- a/src/ui/components/menu/Options.tsx +++ b/src/ui/components/menu/Options.tsx @@ -12,9 +12,12 @@ import * as server from '../../../utils/server' import './Options.css' import BigButton from '../common/BigButton' +import DownloadHandler from '../../../utils/download' +import * as meta from '../../../utils/metadata' interface IProps { closeFn: () => void; + downloadManager: DownloadHandler; } interface IState { @@ -62,6 +65,7 @@ export default class Options extends React.Component { this.toggleGrasscutterWithGame = this.toggleGrasscutterWithGame.bind(this) this.setCustomBackground = this.setCustomBackground.bind(this) this.toggleEncryption = this.toggleEncryption.bind(this) + this.restoreMetadata = this.restoreMetadata.bind(this) } async componentDidMount() { @@ -190,6 +194,11 @@ export default class Options extends React.Component { }) } + async restoreMetadata() { + console.log(this.props) + await meta.restoreMetadata(this.props.downloadManager) + } + render() { return ( @@ -201,6 +210,16 @@ export default class Options extends React.Component { + { this.state.swag && (