mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 16:14:48 +01:00
simplify metadata processes
This commit is contained in:
@@ -21,6 +21,11 @@ pub fn rename(path: String, new_name: String) {
|
||||
fs::rename(path, &path_replaced).unwrap();
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn dir_create(path: String) {
|
||||
fs::create_dir_all(path).unwrap();
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn dir_exists(path: &str) -> bool {
|
||||
let path_buf = std::path::PathBuf::from(path);
|
||||
|
||||
@@ -42,6 +42,7 @@ fn main() {
|
||||
proxy::generate_ca_files,
|
||||
unzip::unzip,
|
||||
file_helpers::rename,
|
||||
file_helpers::dir_create,
|
||||
file_helpers::dir_exists,
|
||||
file_helpers::dir_is_empty,
|
||||
file_helpers::dir_delete,
|
||||
|
||||
@@ -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
|
||||
const gameIsPatched = await invoke('are_files_identical', {
|
||||
path1: await getBackupMetadataPath() + '\\global-metadata-patched.dat',
|
||||
@@ -142,22 +156,6 @@ export async function unpatchGame() {
|
||||
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', {
|
||||
path: await getBackupMetadataPath() + '\\global-metadata-unpatched.dat',
|
||||
newPath: await getGameMetadataPath(),
|
||||
@@ -201,26 +199,27 @@ export async function globalMetadataLink() {
|
||||
}
|
||||
|
||||
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'
|
||||
})
|
||||
|
||||
if (!backupExists) {
|
||||
console.log('No backup found! Replacing with global metadata link')
|
||||
|
||||
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()
|
||||
})
|
||||
}
|
||||
|
||||
// Download the file
|
||||
manager.addDownload(metaLink, await getBackupMetadataPath() + '\\global-metadata-unpatched.dat', () => {
|
||||
unpatchGame()
|
||||
})
|
||||
console.log('Restoring backedup metadata')
|
||||
|
||||
await unpatchGame()
|
||||
|
||||
Reference in New Issue
Block a user