Skip to content

Commit

Permalink
总得写点什么……想了想就把一些工具再独立一下吧
Browse files Browse the repository at this point in the history
  • Loading branch information
iamapig120 committed Jan 24, 2019
1 parent 9ef0699 commit 8ea34cf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
23 changes: 22 additions & 1 deletion Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -326,7 +347,7 @@ const Util = {
)
},
/**
* 退出窗口
* 退出播放器窗口
*/
shutoffPlayer() {
audioPlayer.close()
Expand Down
29 changes: 4 additions & 25 deletions manager/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 8ea34cf

Please sign in to comment.