From fe15e025aaa9a05ce87cef1512bca898d43be3bf Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 3 May 2025 12:00:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/app.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/app.ts b/src/main/app.ts index 15780026..ee59de4c 100644 --- a/src/main/app.ts +++ b/src/main/app.ts @@ -256,6 +256,20 @@ const initTheme = () => { }) } +const backupDB = (backupPath: string) => { + const dbPath = path.join(global.lxDataPath, 'lx.data.db') + try { + renameSync(dbPath, backupPath) + } catch {} + try { + renameSync(`${dbPath}-wal`, `${backupPath}-wal`) + } catch {} + try { + renameSync(`${dbPath}-shm`, `${backupPath}-shm`) + } catch {} + openDirInExplorer(backupPath) +} + let isInitialized = false export const initAppSetting = async() => { if (!global.lx.inited) { @@ -268,14 +282,13 @@ export const initAppSetting = async() => { if (!isInitialized) { let dbFileExists = await global.lx.worker.dbService.init(global.lxDataPath) if (dbFileExists === null) { - const backPath = path.join(global.lxDataPath, `lx.data.db.${Date.now()}.bak`) + const backupPath = path.join(global.lxDataPath, `lx.data.db.${Date.now()}.bak`) dialog.showMessageBoxSync({ type: 'warning', message: 'Database verify failed', - detail: `数据库表结构校验失败,我们将把有问题的数据库备份到:${backPath}\n若此问题导致你的数据丢失,你可以尝试从备份文件找回它们。\n\nThe database table structure verification failed, we will back up the problematic database to: ${backPath}\nIf this problem causes your data to be lost, you can try to retrieve them from the backup file.`, + detail: `数据库表结构校验失败,我们将把有问题的数据库备份到:${backupPath}\n若此问题导致你的数据丢失,你可以尝试从备份文件找回它们。\n\nThe database table structure verification failed, we will back up the problematic database to: ${backupPath}\nIf this problem causes your data to be lost, you can try to retrieve them from the backup file.`, }) - renameSync(path.join(global.lxDataPath, 'lx.data.db'), backPath) - openDirInExplorer(backPath) + backupDB(backupPath) dbFileExists = await global.lx.worker.dbService.init(global.lxDataPath) } global.lx.appSetting = (await initSetting()).setting