diff --git a/Util.js b/Util.js index 71f04e4..fe30d85 100644 --- a/Util.js +++ b/Util.js @@ -303,6 +303,27 @@ const Util = { } }, + /** + * 同步删除文件夹 + * @param {string} dir 要删除的目录 + * @author romin + * @description 同步删除文件夹,https://juejin.im/post/5ab32b20518825557f00d36c + */ + removeDir(dir) { + let files = fs.readdirSync(dir) + for (var i = 0; i < files.length; i++) { + let newPath = path.join(dir, files[i]) + let stat = fs.statSync(newPath) + if (stat.isDirectory()) { + //如果是文件夹就递归下去 + this.removeDir(newPath) + } else { + //删除文件 + fs.unlinkSync(newPath) + } + } + fs.rmdirSync(dir) //如果文件夹是空的,就将自己删除掉 + }, /** * 截取屏幕画面 * @param {Electron.WebContents} webContents @@ -326,7 +347,7 @@ const Util = { ) }, /** - * 退出窗口 + * 退出播放器窗口 */ shutoffPlayer() { audioPlayer.close() diff --git a/manager/manager.js b/manager/manager.js index f5f44aa..50b38bc 100644 --- a/manager/manager.js +++ b/manager/manager.js @@ -4,6 +4,7 @@ const configs = require('../configs') const { ipcRenderer, remote: electronRemote, shell } = require('electron') const dialog = electronRemote.dialog const AdmZip = require('adm-zip') +const Util = require('../Util') const os = require('os') const app = electronRemote.app @@ -23,28 +24,6 @@ const toolsRootDir = path.join(__dirname, '../', configs.TOOLS_DIR) const userConfig = require(configs.USER_CONFIG_PATH) -/** - * 同步删除文件夹 - * @param {string} dir 要删除的目录 - * @author romin - * @description 同步删除文件夹,https://juejin.im/post/5ab32b20518825557f00d36c - */ -function removeDir(dir) { - let files = fs.readdirSync(dir) - for (var i = 0; i < files.length; i++) { - let newPath = path.join(dir, files[i]) - let stat = fs.statSync(newPath) - if (stat.isDirectory()) { - //如果是文件夹就递归下去 - removeDir(newPath) - } else { - //删除文件 - fs.unlinkSync(newPath) - } - } - fs.rmdirSync(dir) //如果文件夹是空的,就将自己删除掉 -} - /** * 刷新所有模组和插件并重新加载DOM * @type {function} @@ -386,7 +365,7 @@ const reloadDOM = (executes, mods, tools) => { } const onremoveFunction = () => { infoCard.DOM.remove() - removeDir(infoCard.infos.filesDir) + Util.removeDir(infoCard.infos.filesDir) refreshFunction() } infoCard.addEventListener('change', onchangeFunction) @@ -467,7 +446,7 @@ const reloadDOM = (executes, mods, tools) => { } const onremoveFunction = () => { infoCard.DOM.remove() - removeDir(infoCard.infos.filesDir) + Util.removeDir(infoCard.infos.filesDir) refreshFunction() } infoCard.addEventListener('change', onchangeFunction) @@ -520,7 +499,7 @@ const reloadDOM = (executes, mods, tools) => { } const onremoveFunction = () => { infoCard.DOM.remove() - removeDir(infoCard.infos.filesDir) + Util.removeDir(infoCard.infos.filesDir) refreshFunction() } infoCard.addEventListener('click', onClickFunction) diff --git a/package.json b/package.json index 4701156..b0dc15e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "majsoul-plus-client", - "version": "1.8.10", + "version": "1.8.11-alpha.1", "productName": "Majsoul Plus", "author": "MajsoulPlus Team", "description": "Majsoul Plus",