2017-08-24 09:15:06 +00:00
|
|
|
var events = require('events')
|
|
|
|
var fs = require('fs.extra')
|
|
|
|
var path = require('path')
|
2015-01-21 03:00:09 +00:00
|
|
|
|
|
|
|
var Mods = function (config) {
|
2017-08-24 09:15:06 +00:00
|
|
|
this.config = config
|
|
|
|
this.mods = []
|
|
|
|
}
|
2015-02-01 04:27:12 +00:00
|
|
|
|
2017-08-24 09:15:06 +00:00
|
|
|
Mods.prototype = new events.EventEmitter()
|
2015-02-01 04:27:12 +00:00
|
|
|
|
2015-07-22 18:16:30 +00:00
|
|
|
Mods.prototype.delete = function (mod, cb) {
|
2017-08-24 09:15:06 +00:00
|
|
|
var self = this
|
2015-07-22 18:16:30 +00:00
|
|
|
fs.rmrf(path.join(this.config.path, mod), function (err) {
|
2017-08-24 09:15:06 +00:00
|
|
|
cb(err)
|
2015-07-22 19:20:05 +00:00
|
|
|
|
|
|
|
if (!err) {
|
2017-08-24 09:15:06 +00:00
|
|
|
self.updateMods()
|
2015-07-22 19:20:05 +00:00
|
|
|
}
|
2017-08-24 09:15:06 +00:00
|
|
|
})
|
|
|
|
}
|
2015-07-22 18:16:30 +00:00
|
|
|
|
2015-02-01 04:27:12 +00:00
|
|
|
Mods.prototype.updateMods = function () {
|
2017-08-24 09:15:06 +00:00
|
|
|
var self = this
|
2015-01-21 03:00:09 +00:00
|
|
|
fs.readdir(self.config.path, function (err, files) {
|
|
|
|
if (err) {
|
2017-08-24 09:15:06 +00:00
|
|
|
console.log(err)
|
2015-01-21 03:00:09 +00:00
|
|
|
} else {
|
|
|
|
var mods = files.filter(function (file) {
|
2017-08-24 09:15:06 +00:00
|
|
|
return file.charAt(0) === '@'
|
2017-02-21 19:22:28 +00:00
|
|
|
}).map(function (name) {
|
|
|
|
return {
|
|
|
|
name: name
|
2017-08-24 09:15:06 +00:00
|
|
|
}
|
|
|
|
})
|
2015-01-21 03:00:09 +00:00
|
|
|
|
2017-02-21 19:22:28 +00:00
|
|
|
self.mods = mods
|
|
|
|
self.emit('mods', mods)
|
2015-02-04 23:42:18 +00:00
|
|
|
}
|
2017-08-24 09:15:06 +00:00
|
|
|
})
|
|
|
|
}
|
2015-02-01 04:01:50 +00:00
|
|
|
|
2017-08-24 09:15:06 +00:00
|
|
|
module.exports = Mods
|