Fix could not patch on very first run

This commit is contained in:
Thoronium
2023-03-01 21:05:16 -07:00
parent f44dfeb79d
commit 20a80e5625
2 changed files with 35 additions and 35 deletions

View File

@@ -121,23 +121,19 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
}
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
}
}

View File

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