diff --git a/src/ui/components/ServerLaunchSection.tsx b/src/ui/components/ServerLaunchSection.tsx index ba5fff9..a8a276c 100644 --- a/src/ui/components/ServerLaunchSection.tsx +++ b/src/ui/components/ServerLaunchSection.tsx @@ -121,23 +121,19 @@ export default class ServerLaunchSection extends React.Component } if (gameVersion?.major == 2 && gameVersion?.minor < 9) { - alert( - 'Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.' - ) + alert('Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.') return } if (gameVersion?.major == 3 && gameVersion?.minor < 1) { - alert( - 'Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.' - ) + alert('Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.') return } const patched = await patchGame() if (!patched) { - alert('Could not patch game!') + alert('Could not patch! Try launching again, or patching manually.') return } } diff --git a/src/utils/rsa.ts b/src/utils/rsa.ts index 0f48e9d..475a014 100644 --- a/src/utils/rsa.ts +++ b/src/utils/rsa.ts @@ -1,35 +1,11 @@ import { invoke } from '@tauri-apps/api' import { dataDir } from '@tauri-apps/api/path' +import { listen } from '@tauri-apps/api/event' import DownloadHandler from './download' import { getGameFolder } from './game' const downloadHandler = new DownloadHandler() -export async function patchRSA() { - const rsaExists = await invoke('dir_exists', { - path: (await getBackupRSAPath()) + '\\version.dll', - }) - - if (rsaExists) { - // Already patched - return true - } - - console.log('Downloading rsa patch to backup location') - - // Download RSA patch to backup location - const downloadedRSA = await downloadRSA(downloadHandler) - - if (!downloadedRSA) { - console.log(await getBackupRSAPath()) - return false - } - - console.log('RSA download successful!') - - return true -} - export async function patchGame() { // Do we have a patch already? const patchedExists = await invoke('dir_exists', { @@ -38,7 +14,7 @@ export async function patchGame() { if (!patchedExists) { // No patch found? Patching creates one - const patched = await patchRSA() + const patched = await downloadRSA() if (!patched) { return false @@ -94,7 +70,7 @@ export async function getBackupRSAPath() { return (await dataDir()) + 'cultivation\\rsa' } -export async function downloadRSA(manager: DownloadHandler) { +export async function downloadRSA() { const rsaLink = 'https://github.com/34736384/RSAPatch/releases/download/v1.1.0/RSAPatch.dll' // Should make sure rsa path exists @@ -103,9 +79,37 @@ export async function downloadRSA(manager: DownloadHandler) { }) // Download the file - manager.addDownload(rsaLink, (await getBackupRSAPath()) + '\\version.dll', () => { + downloadHandler.addDownload(rsaLink, (await getBackupRSAPath()) + '\\version.dll', () => { null }) + let errored = false + listen('download_error', ({ payload }) => { + // @ts-expect-error shut up typescript + const errorData: { + path: string + error: string + } = payload + + errored = true + }) + + // There is 100% a better way to do this but I don't use ts enough to know + let downloadComplete = false + while (!downloadComplete) { + // Waits until download completes before continuing + if ( + (await invoke('dir_exists', { + path: (await getBackupRSAPath()) + '\\version.dll', + })) || + errored + ) { + downloadComplete = true + } + } + + if (errored) { + return false + } return true }