fix backup

This commit is contained in:
jinook518
2025-01-08 00:37:31 +09:00
parent 64b9b89220
commit 07817c9d8b

View File

@@ -471,14 +471,12 @@ async function getDbBackups() {
} }
else{ else{
const keys = await forageStorage.keys() const keys = await forageStorage.keys()
let backups:number[] = []
for(const key of keys){ const backups = keys
if(key.startsWith("database/dbbackup-")){ .filter(key => key.startsWith('database/dbbackup-'))
let da = key.substring(18) .map(key => parseInt(key.slice(18, -4)))
da = da.substring(0,da.length-4) .sort((a, b) => b - a);
backups.push(parseInt(da))
}
}
while(backups.length > 20){ while(backups.length > 20){
const last = backups.pop() const last = backups.pop()
await forageStorage.removeItem(`database/dbbackup-${last}.bin`) await forageStorage.removeItem(`database/dbbackup-${last}.bin`)
@@ -524,6 +522,7 @@ export async function loadData() {
const backups = await getDbBackups() const backups = await getDbBackups()
let backupLoaded = false let backupLoaded = false
for(const backup of backups){ for(const backup of backups){
if (!backupLoaded) {
try { try {
LoadingStatusState.text = `Reading Backup File ${backup}...` LoadingStatusState.text = `Reading Backup File ${backup}...`
const backupData = await readFile(`database/dbbackup-${backup}.bin`, {baseDir: BaseDirectory.AppData}) const backupData = await readFile(`database/dbbackup-${backup}.bin`, {baseDir: BaseDirectory.AppData})
@@ -535,6 +534,7 @@ export async function loadData() {
console.error(error) console.error(error)
} }
} }
}
if(!backupLoaded){ if(!backupLoaded){
throw "Your save file is corrupted" throw "Your save file is corrupted"
} }