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

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)
}
+3 -2
View File
@@ -123,9 +123,10 @@ exports.mergeSetting = (setting, version) => {
/**
* 初始化设置
* @param {*} setting
* @param {*} isShowErrorAlert
*/
exports.initSetting = () => {
const electronStore_list = getStore('playList')
exports.initSetting = isShowErrorAlert => {
const electronStore_list = getStore('playList', true, isShowErrorAlert)
const electronStore_config = getStore('config')
const electronStore_downloadList = getStore('downloadList')
+3 -3
View File
@@ -34,10 +34,10 @@ exports.saveAppHotKeyConfig = config => {
exports.updateSetting = (settings) => {
objectDeepMerge(global.appSetting, settings)
getStore('config').set('setting', global.appSetting)
exports.initSetting()
exports.initSetting(false)
}
exports.initSetting = () => {
const info = initSetting()
exports.initSetting = (isShowErrorAlert = true) => {
const info = initSetting(isShowErrorAlert)
global.appSetting = info.setting
global.appSettingVersion = info.version
}
+1 -1
View File
@@ -33,6 +33,6 @@
"source_alias_all": "聚合大会",
"load_list_file_error_title": "播放列表数据加载错误",
"load_list_file_error_title": "播放列表数据加载错误(建议到GitHub或加群反馈)",
"load_list_file_error_detail": "我们已经帮你把旧的列表文件备份到{path}\n它以 JSON 格式存储,你可以尝试手动修复并恢复它\n\n错误详情:{detail}"
}