mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
83 lines
1.8 KiB
JavaScript
83 lines
1.8 KiB
JavaScript
var async = require('async')
|
|
var events = require('events')
|
|
var filesize = require('filesize')
|
|
var fs = require('fs.extra')
|
|
var glob = require('glob')
|
|
var path = require('path')
|
|
|
|
var folderSize = require('./folderSize')
|
|
var modFile = require('./modFile')
|
|
var steamMeta = require('./steamMeta')
|
|
|
|
var Mods = function (config) {
|
|
this.config = config
|
|
this.mods = []
|
|
}
|
|
|
|
Mods.prototype = new events.EventEmitter()
|
|
|
|
Mods.prototype.delete = function (mod, cb) {
|
|
var self = this
|
|
fs.rmrf(path.join(this.config.path, mod), function (err) {
|
|
cb(err)
|
|
|
|
if (!err) {
|
|
self.updateMods()
|
|
}
|
|
})
|
|
}
|
|
|
|
Mods.prototype.updateMods = function () {
|
|
var self = this
|
|
glob('**/{@*,csla,gm,rf,spe,vn,ws}/addons', { cwd: self.config.path }, function (err, files) {
|
|
if (err) {
|
|
console.log(err)
|
|
return
|
|
}
|
|
|
|
var mods = files.map(function (file) {
|
|
// Find actual parent mod folder from addons folder
|
|
return path.join(file, '..')
|
|
})
|
|
|
|
async.map(mods, self.resolveModData.bind(self), function (err, mods) {
|
|
if (err) {
|
|
console.log(err)
|
|
return
|
|
}
|
|
|
|
self.mods = mods
|
|
self.emit('mods', mods)
|
|
})
|
|
})
|
|
}
|
|
|
|
Mods.prototype.resolveModData = function (modPath, cb) {
|
|
var self = this
|
|
async.parallel({
|
|
folderSize: function (cb) {
|
|
folderSize(modPath, self.config, cb)
|
|
},
|
|
modFile: function (cb) {
|
|
modFile(modPath, self.config, cb)
|
|
},
|
|
steamMeta: function (cb) {
|
|
steamMeta(modPath, self.config, cb)
|
|
}
|
|
}, function (err, results) {
|
|
if (err) {
|
|
return cb(err)
|
|
}
|
|
|
|
cb(null, {
|
|
name: modPath,
|
|
size: results.folderSize,
|
|
formattedSize: filesize(results.folderSize),
|
|
modFile: results.modFile,
|
|
steamMeta: results.steamMeta
|
|
})
|
|
})
|
|
}
|
|
|
|
module.exports = Mods
|