simplify metadata processes

This commit is contained in:
SpikeHD
2022-07-16 23:34:55 -07:00
parent 61ac332cee
commit 043f3e7ce4
3 changed files with 38 additions and 33 deletions

View File

@@ -21,6 +21,11 @@ pub fn rename(path: String, new_name: String) {
fs::rename(path, &path_replaced).unwrap(); fs::rename(path, &path_replaced).unwrap();
} }
#[tauri::command]
pub fn dir_create(path: String) {
fs::create_dir_all(path).unwrap();
}
#[tauri::command] #[tauri::command]
pub fn dir_exists(path: &str) -> bool { pub fn dir_exists(path: &str) -> bool {
let path_buf = std::path::PathBuf::from(path); let path_buf = std::path::PathBuf::from(path);

View File

@@ -42,6 +42,7 @@ fn main() {
proxy::generate_ca_files, proxy::generate_ca_files,
unzip::unzip, unzip::unzip,
file_helpers::rename, file_helpers::rename,
file_helpers::dir_create,
file_helpers::dir_exists, file_helpers::dir_exists,
file_helpers::dir_is_empty, file_helpers::dir_is_empty,
file_helpers::dir_delete, file_helpers::dir_delete,

View File

@@ -70,6 +70,20 @@ export async function patchGame() {
} }
} }
// Do we have a patch already?
const patchedExists = await invoke('dir_exists', {
path: await getGameMetadataPath() + '\\global-metadata-patched.dat'
})
if (!patchedExists) {
// No patch found? Patching creates one
const patched = await patchMetadata()
if (!patched) {
return false
}
}
// Are we already patched? If so, that's fine, just continue as normal // Are we already patched? If so, that's fine, just continue as normal
const gameIsPatched = await invoke('are_files_identical', { const gameIsPatched = await invoke('are_files_identical', {
path1: await getBackupMetadataPath() + '\\global-metadata-patched.dat', path1: await getBackupMetadataPath() + '\\global-metadata-patched.dat',
@@ -142,22 +156,6 @@ export async function unpatchGame() {
return true return true
} }
const metaPatched = await invoke('are_files_identical', {
path1: await getBackupMetadataPath() + '\\global-metadata-patched.dat',
path2: await getGameMetadataPath() + '\\global-metadata.dat'
})
const metaExists = await invoke('dir_exists', {
path: await getGameMetadataPath() + '\\global-metadata.dat'
})
if (!metaPatched && metaExists) {
// Game isn't patched
return true
}
console.log('Replacing patched game metadata with unpatched metadata')
const replaced = await invoke('copy_file_with_new_name', { const replaced = await invoke('copy_file_with_new_name', {
path: await getBackupMetadataPath() + '\\global-metadata-unpatched.dat', path: await getBackupMetadataPath() + '\\global-metadata-unpatched.dat',
newPath: await getGameMetadataPath(), newPath: await getGameMetadataPath(),
@@ -201,26 +199,27 @@ export async function globalMetadataLink() {
} }
export async function restoreMetadata(manager: DownloadHandler) { export async function restoreMetadata(manager: DownloadHandler) {
const backupExists = await invoke('dir_exists', { const metaLink = await globalMetadataLink()
if (!metaLink) {
console.log('Could not get global metadata link!')
return false
}
// Should make sure metadata path exists since the user may have deleted it
await invoke('dir_create', {
path: await getBackupMetadataPath()
})
// It is possible the unpatched backup is mistakenly patched
await invoke('delete_file', {
path: await getBackupMetadataPath() + '\\global-metadata-unpatched.dat' path: await getBackupMetadataPath() + '\\global-metadata-unpatched.dat'
}) })
if (!backupExists) { // Download the file
console.log('No backup found! Replacing with global metadata link') manager.addDownload(metaLink, await getBackupMetadataPath() + '\\global-metadata-unpatched.dat', () => {
unpatchGame()
const metaLink = await globalMetadataLink() })
if (!metaLink) {
console.log('Coudl not get global metadata link!')
return false
}
// Download the file
manager.addDownload(metaLink, await getBackupMetadataPath() + '\\global-metadata-unpatched.dat', () => {
unpatchGame()
})
}
console.log('Restoring backedup metadata') console.log('Restoring backedup metadata')
await unpatchGame() await unpatchGame()