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

pull/277/head
lyswhut 2020-07-06 18:15:03 +08:00
parent bcd13b6f27
commit 1efd56f48b
10 changed files with 80 additions and 10 deletions

View File

@ -17,6 +17,7 @@
- 新增托盘图标样式设置,可到设置-其他切换
- 新增开关下载功能控制,默认关闭,可到设置-下载设置开启
- 新增将歌词嵌入音频文件中,默认关闭,可到设置-下载设置开启
- 新增当列表文件损坏时对损坏文件的备份,若出现该情况可打开`%HOMEPATH%\AppData\Roaming\lx-music-desktop`找到`playList.json.bak`尝试手动修复列表文件,列表文件以`JSON`格式存储
### 优化

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',

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',
})

View File

@ -0,0 +1,5 @@
const { mainHandle, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
const { app } = require('electron')
mainHandle(ipcMainWindowNames.get_data_path, async() => app.getPath('userData'))

View File

@ -14,6 +14,8 @@ require('./getEnvParams')
require('./setAppSetting')
require('./setLyricInfo')
require('./hotKey')
require('./getDataPath')
require('./showDialog')
require('./xm_verify')

View File

@ -0,0 +1,12 @@
const { mainOn, NAMES: { mainWindow: ipcMainWindowNames } } = require('../../common/ipc')
const { dialog } = require('electron')
mainOn(ipcMainWindowNames.show_dialog, (event, { type, message, detail }) => {
if (!global.modules.mainWindow) throw new Error('mainWindow is undefined')
dialog.showMessageBoxSync(global.modules.mainWindow, {
type,
message,
detail,
})
})

View File

@ -30,5 +30,8 @@
"source_alias_xm": "XM Music",
"source_alias_bd": "BD Music",
"source_alias_all": "Aggregated"
"source_alias_all": "Aggregated",
"load_list_file_error_title": "Error loading playlist data",
"load_list_file_error_detail": "We have helped you back up the old list file to {path}\nIt is stored in JSON format, you can try to repair and restore it manually\n\nError details: {detail}"
}

View File

@ -31,5 +31,8 @@
"source_alias_xm": "小霞音乐",
"source_alias_bd": "小杜音乐",
"source_alias_all": "聚合大会"
"source_alias_all": "聚合大会",
"load_list_file_error_title": "播放列表数据加载错误",
"load_list_file_error_detail": "我们已经帮你把旧的列表文件备份到{path}\n它以 JSON 格式存储,你可以尝试手动修复并恢复它\n\n错误详情{detail}"
}

View File

@ -27,5 +27,8 @@
"source_alias_mg": "小蜜音樂",
"source_alias_bd": "小杜音樂",
"source_alias_xm": "小霞音樂",
"source_alias_all": "聚合大會"
"source_alias_all": "聚合大會",
"load_list_file_error_title": "播放列表數據加載錯誤",
"load_list_file_error_detail": "我們已經幫你把舊的列表文件備份到{path}\n它以 JSON 格式存儲,你可以嘗試手動修復並恢復它\n\n錯誤詳情{detail}"
}

View File

@ -3,12 +3,11 @@
import Store from 'electron-store'
import { windowSizeList } from '../../common/config'
import { version } from '../../../package.json'
import { rendererSend, NAMES } from '../../common/ipc'
import { rendererSend, rendererInvoke, NAMES } from '../../common/ipc'
import languageList from '@/lang/languages.json'
import path from 'path'
window.electronStore_list = new Store({
name: 'playList',
})
const electronStore_config = window.electronStore_config = new Store({
name: 'config',
})
@ -40,6 +39,27 @@ if (!window.i18n.availableLocales.includes(setting.langId)) {
window.i18n.locale = setting.langId
try {
window.electronStore_list = new Store({
name: 'playList',
clearInvalidConfig: false,
})
} catch (error) {
rendererInvoke(NAMES.mainWindow.get_data_path).then(dataPath => {
rendererSend(NAMES.mainWindow.show_dialog, {
type: 'error',
message: window.i18n.t('store.state.load_list_file_error_title'),
detail: window.i18n.t('store.state.load_list_file_error_detail', {
path: path.join(dataPath, 'playList.json.bak'),
detail: error.message,
}),
})
})
window.electronStore_list = new Store({
name: 'playList',
})
}
export default {
themes: [