序启动时对数据文件做读取校验,数据出现损坏时自动备份损坏的数据

This commit is contained in:
lyswhut
2021-03-14 02:06:35 +08:00
parent b1ccdeb0d3
commit 8171fcd346
5 changed files with 13 additions and 8 deletions
+2 -1
View File
@@ -10,6 +10,7 @@ const stores = {}
* 获取 Store 对象
* @param {*} name store 名
* @param {*} isIgnoredError 是否忽略错误
* @param {*} isShowErrorAlert 是否显示错误弹窗
* @returns Store
*/
module.exports = (name, isIgnoredError = true, isShowErrorAlert = true) => {
@@ -25,13 +26,13 @@ module.exports = (name, isIgnoredError = true, isShowErrorAlert = true) => {
const backPath = path.join(app.getPath('userData'), name + '.json.bak')
fs.copyFileSync(path.join(app.getPath('userData'), name + '.json'), backPath)
shell.showItemInFolder(backPath)
if (isShowErrorAlert) {
dialog.showMessageBoxSync({
type: 'error',
message: name + ' data load error',
detail: `We have helped you back up the old ${name} file to: ${backPath}\nYou can try to repair and restore it manually\n\nError detail: ${error.message}`,
})
shell.showItemInFolder(backPath)
}