diff --git a/src-tauri/src/proxy.rs b/src-tauri/src/proxy.rs index c5c9396..644703a 100644 --- a/src-tauri/src/proxy.rs +++ b/src-tauri/src/proxy.rs @@ -172,7 +172,13 @@ pub(crate) fn generate_ca_files(path: &str) { let cert_crt = cert.serialize_pem().unwrap(); let cert_path = format!("{}\\ca", path); - fs::create_dir(&cert_path).unwrap(); + match fs::create_dir(&cert_path) { + Ok(_) => {}, + Err(e) => { + println!("{}", e); + return; + } + }; println!("{}", cert_crt); @@ -189,17 +195,17 @@ pub(crate) fn generate_ca_files(path: &str) { } // Install certificate into the system's Root CA store. - install_ca_files(); + install_ca_files(path); } /* * Attempts to install the certificate authority's certificate into the Root CA store. */ -pub(crate) fn install_ca_files() { +pub(crate) fn install_ca_files(path: &str) { if cfg!(target_os = "windows") { - run_command("certutil -addstore -f \"ROOT\" ca/certificate.crt".to_string()); + run_command(format!("certutil -addstore -f \"ROOT\" {}\\ca\\certificate.crt", path).to_string()); } else { - run_command("sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca/certificate.crt".to_string()); + run_command(format!("sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain {}/ca/certificate.crt", path).to_string()); } println!("Installed certificate."); diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 9ab463f..7e9e280 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -16,6 +16,7 @@ import NewsSection from './components/news/NewsSection' import RightBar from './components/RightBar' import { getConfigOption, setConfigOption } from '../utils/configuration' import { invoke } from '@tauri-apps/api' +import { dataDir } from '@tauri-apps/api/path' interface IProps { [key: string]: never; @@ -52,6 +53,7 @@ class App extends React.Component { } async componentDidMount() { + const cert_generated = await getConfigOption('cert_generated') const game_exe = await getConfigOption('game_install_path') const game_path = game_exe.substring(0, game_exe.lastIndexOf('\\')) const root_path = game_path.substring(0, game_path.lastIndexOf('\\')) @@ -68,6 +70,15 @@ class App extends React.Component { }) } } + + if (!cert_generated) { + // Generate the certificate + await invoke('generate_ca_files', { + path: await dataDir() + 'cultivation' + }) + + await setConfigOption('cert_generated', true) + } } render() { diff --git a/src/utils/configuration.ts b/src/utils/configuration.ts index 719cc99..f07da09 100644 --- a/src/utils/configuration.ts +++ b/src/utils/configuration.ts @@ -17,6 +17,7 @@ let defaultConfig: Configuration last_port: '', language: 'en', customBackground: '', + cert_generated: false, } })() @@ -35,6 +36,7 @@ export interface Configuration { last_port: string language: string customBackground: string + cert_generated: boolean } export async function setConfigOption(key: string, value: any): Promise { @@ -94,7 +96,6 @@ async function readConfigFile() { await fs.createDir(local + 'cultivation\\grasscutter') } - const dataFiles = await fs.readDir(local + 'cultivation') // Ensure config exists