新增当列表文件损坏时对损坏文件的备份

This commit is contained in:
lyswhut
2020-07-06 18:15:03 +08:00
parent bcd13b6f27
commit 1efd56f48b
10 changed files with 80 additions and 10 deletions
+2
View File
@@ -41,6 +41,8 @@ const names = {
quit: 'quit',
min_toggle: 'min_toggle',
hide_toggle: 'hide_toggle',
get_data_path: 'get_data_path',
show_dialog: 'show_dialog',
},
winLyric: {
close: 'close',
+22 -3
View File
@@ -3,6 +3,9 @@ const Store = require('electron-store')
const { defaultSetting, overwriteSetting } = require('./defaultSetting')
const apiSource = require('../renderer/utils/music/api-source-info')
const defaultHotKey = require('./defaultHotKey')
const { dialog, app } = require('electron')
const path = require('path')
const fs = require('fs')
exports.isLinux = process.platform == 'linux'
exports.isWin = process.platform == 'win32'
@@ -125,9 +128,25 @@ exports.mergeSetting = (setting, version) => {
* @param {*} setting
*/
exports.initSetting = () => {
const electronStore_list = new Store({
name: 'playList',
})
let electronStore_list
try {
electronStore_list = new Store({
name: 'playList',
clearInvalidConfig: false,
})
} catch (error) {
log.error(error)
const backPath = path.join(app.getPath('userData'), 'playList.json.bak')
fs.copyFileSync(path.join(app.getPath('userData'), 'playList.json'), backPath)
dialog.showMessageBoxSync({
type: 'error',
message: 'Playlist data loading error',
detail: `We have helped you back up the old list file to ${backPath}\nYou can try to repair and restore it manually\n\nError detail: ${error.message}`,
})
electronStore_list = new Store({
name: 'playList',
})
}
const electronStore_config = new Store({
name: 'config',
})