Skip to content

Commit 8ea34cf

Browse files
committed
总得写点什么……想了想就把一些工具再独立一下吧
1 parent 9ef0699 commit 8ea34cf

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

Util.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,27 @@ const Util = {
303303
}
304304
},
305305

306+
/**
307+
* 同步删除文件夹
308+
* @param {string} dir 要删除的目录
309+
* @author romin
310+
* @description 同步删除文件夹,https://juejin.im/post/5ab32b20518825557f00d36c
311+
*/
312+
removeDir(dir) {
313+
let files = fs.readdirSync(dir)
314+
for (var i = 0; i < files.length; i++) {
315+
let newPath = path.join(dir, files[i])
316+
let stat = fs.statSync(newPath)
317+
if (stat.isDirectory()) {
318+
//如果是文件夹就递归下去
319+
this.removeDir(newPath)
320+
} else {
321+
//删除文件
322+
fs.unlinkSync(newPath)
323+
}
324+
}
325+
fs.rmdirSync(dir) //如果文件夹是空的,就将自己删除掉
326+
},
306327
/**
307328
* 截取屏幕画面
308329
* @param {Electron.WebContents} webContents
@@ -326,7 +347,7 @@ const Util = {
326347
)
327348
},
328349
/**
329-
* 退出窗口
350+
* 退出播放器窗口
330351
*/
331352
shutoffPlayer() {
332353
audioPlayer.close()

manager/manager.js

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const configs = require('../configs')
44
const { ipcRenderer, remote: electronRemote, shell } = require('electron')
55
const dialog = electronRemote.dialog
66
const AdmZip = require('adm-zip')
7+
const Util = require('../Util')
78
const os = require('os')
89

910
const app = electronRemote.app
@@ -23,28 +24,6 @@ const toolsRootDir = path.join(__dirname, '../', configs.TOOLS_DIR)
2324

2425
const userConfig = require(configs.USER_CONFIG_PATH)
2526

26-
/**
27-
* 同步删除文件夹
28-
* @param {string} dir 要删除的目录
29-
* @author romin
30-
* @description 同步删除文件夹,https://juejin.im/post/5ab32b20518825557f00d36c
31-
*/
32-
function removeDir(dir) {
33-
let files = fs.readdirSync(dir)
34-
for (var i = 0; i < files.length; i++) {
35-
let newPath = path.join(dir, files[i])
36-
let stat = fs.statSync(newPath)
37-
if (stat.isDirectory()) {
38-
//如果是文件夹就递归下去
39-
removeDir(newPath)
40-
} else {
41-
//删除文件
42-
fs.unlinkSync(newPath)
43-
}
44-
}
45-
fs.rmdirSync(dir) //如果文件夹是空的,就将自己删除掉
46-
}
47-
4827
/**
4928
* 刷新所有模组和插件并重新加载DOM
5029
* @type {function}
@@ -386,7 +365,7 @@ const reloadDOM = (executes, mods, tools) => {
386365
}
387366
const onremoveFunction = () => {
388367
infoCard.DOM.remove()
389-
removeDir(infoCard.infos.filesDir)
368+
Util.removeDir(infoCard.infos.filesDir)
390369
refreshFunction()
391370
}
392371
infoCard.addEventListener('change', onchangeFunction)
@@ -467,7 +446,7 @@ const reloadDOM = (executes, mods, tools) => {
467446
}
468447
const onremoveFunction = () => {
469448
infoCard.DOM.remove()
470-
removeDir(infoCard.infos.filesDir)
449+
Util.removeDir(infoCard.infos.filesDir)
471450
refreshFunction()
472451
}
473452
infoCard.addEventListener('change', onchangeFunction)
@@ -520,7 +499,7 @@ const reloadDOM = (executes, mods, tools) => {
520499
}
521500
const onremoveFunction = () => {
522501
infoCard.DOM.remove()
523-
removeDir(infoCard.infos.filesDir)
502+
Util.removeDir(infoCard.infos.filesDir)
524503
refreshFunction()
525504
}
526505
infoCard.addEventListener('click', onClickFunction)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "majsoul-plus-client",
3-
"version": "1.8.10",
3+
"version": "1.8.11-alpha.1",
44
"productName": "Majsoul Plus",
55
"author": "MajsoulPlus Team",
66
"description": "Majsoul Plus",

0 commit comments

Comments
 (0)