diff --git a/lib/mods.js b/lib/mods.js index f7c825e..466c194 100644 --- a/lib/mods.js +++ b/lib/mods.js @@ -1,14 +1,9 @@ -var async = require('async') var events = require('events') -var filesize = require('filesize') var fs = require('fs.extra') -var _ = require('lodash') var path = require('path') -var playwithsix = require('playwithsix') var Mods = function (config) { this.config = config - this.liteMods = true this.mods = [] } @@ -25,52 +20,6 @@ Mods.prototype.delete = function (mod, cb) { }) } -Mods.prototype.download = function (mod, cb) { - var self = this - var currentDownloadMod = null - - playwithsix.downloadMod(this.config.path, mod, {lite: this.liteMods}, function (err, mods) { - if (currentDownloadMod) { - currentDownloadMod.progress = null - self.emit('mods', self.mods) - } - self.updateMods() - - if (cb) { - cb(err, mods) - } - }).on('progress', function (progress) { - var modName = progress.mod - - if (!currentDownloadMod || currentDownloadMod.name !== modName) { - if (currentDownloadMod) { - currentDownloadMod.progress = null - } - - var mod = _.find(self.mods, {name: modName}) - - if (mod) { - currentDownloadMod = mod - } else { - currentDownloadMod = { - name: modName, - outdated: false, - playWithSix: true - } - self.mods.push(currentDownloadMod) - } - } - - // Progress in whole percent - var newProgress = parseInt(progress.completed / progress.size * 100, 10) - - if (newProgress !== currentDownloadMod.progress) { - currentDownloadMod.progress = newProgress - self.emit('mods', self.mods) - } - }) -} - Mods.prototype.updateMods = function () { var self = this fs.readdir(self.config.path, function (err, files) { @@ -79,52 +28,14 @@ Mods.prototype.updateMods = function () { } else { var mods = files.filter(function (file) { return file.charAt(0) === '@' - }) - - playwithsix.checkOutdated(self.config.path, function (err, outdatedMods) { - if (err) { - console.log('Error checking for outdated mods: ' + err) + }).map(function (name) { + return { + name: name } - - async.map(mods, function (mod, cb) { - var modPath = path.join(self.config.path, mod) - self.isPlayWithSixMod(modPath, function (isPlayWithSixMod) { - cb(null, { - name: mod, - outdated: outdatedMods && outdatedMods.indexOf(mod) >= 0, - progress: null, - playWithSix: isPlayWithSixMod - }) - }) - }, function (err, mods) { - if (!err) { - self.mods = mods - self.emit('mods', mods) - } - }) }) - } - }) -} -Mods.prototype.isPlayWithSixMod = function (modPath, cb) { - var pwsFile = path.join(modPath, '.synq.json') - fs.exists(pwsFile, function (exists) { - if (cb) { - cb(exists) - } - }) -} - -Mods.prototype.search = function (query, cb) { - playwithsix.search(query, function (err, mods) { - if (err) { - cb(err) - } else { - mods.map(function (mod) { - mod.formattedSize = filesize(mod.size) - }) - cb(null, mods) + self.mods = mods + self.emit('mods', mods) } }) } diff --git a/package.json b/package.json index de8993e..4cee135 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "lodash": "^3.6.0", "morgan": "^1.8.1", "multer": "^1.3.0", - "playwithsix": "0.0.13", "serve-static": "^1.12.1", "slugify": "^1.1.0", "socket.io": "^1.0.4", diff --git a/public/js/app/views/mods/form.js b/public/js/app/views/mods/form.js deleted file mode 100644 index 97bf5b4..0000000 --- a/public/js/app/views/mods/form.js +++ /dev/null @@ -1,89 +0,0 @@ -define(function (require) { - - 'use strict'; - - var $ = require('jquery'), - _ = require('underscore'), - Backbone = require('backbone'), - Marionette = require('marionette'), - ListItemView = require('app/views/mods/search/list_item'), - Ladda = require('ladda'), - Mods = require('app/collections/mods'), - tpl = require('text!tpl/mods/form.html'); - - return Marionette.CompositeView.extend({ - - events: { - 'submit': 'beforeSubmit', - }, - - itemView: ListItemView, - itemViewContainer: "tbody", - template: _.template(tpl), - - initialize: function (options) { - this.mods = options.mods; - this.collection = new Mods(); - this.bind('ok', this.submit); - this.bind('shown', this.shown); - - var self = this; - this.listenTo(this.mods, "change reset add remove", function () { - self.collection.trigger('reset'); - }); - }, - - itemViewOptions: function(options) { - options.set('mods', this.mods); - }, - - beforeSubmit: function(e) { - e.preventDefault(); - this.submit(); - }, - - shown: function (modal) { - var $okBtn = modal.$el.find('.btn.ok'); - $okBtn.addClass('ladda-button').attr('data-style', 'expand-left'); - - this.laddaBtn = Ladda.create($okBtn.get(0)); - - this.$el.find('form .mod').focus(); - }, - - submit: function (modal) { - var self = this; - var $form = this.$el.find('form'); - - if (modal) { - self.modal.preventClose(); - } - - $form.find('.form-group').removeClass('has-error'); - $form.find('.help-block').text(''); - - this.laddaBtn.start(); - self.modal.$el.find('.btn.cancel').addClass('disabled'); - - $.ajax({ - url: '/api/mods/search', - type: 'POST', - data: { - query: $form.find('.query').val() - }, - dataType: 'json', - success: function (data) { - self.laddaBtn.stop(); - self.modal.$el.find('.btn.cancel').removeClass('disabled'); - self.collection.set(data); - }, - error: function () { - self.laddaBtn.stop(); - $form.find('.form-group').addClass('has-error'); - $form.find('.help-block').text('Problem searching, try again'); - self.modal.$el.find('.btn.cancel').removeClass('disabled'); - } - }); - }, - }); -}); diff --git a/public/js/app/views/mods/list.js b/public/js/app/views/mods/list.js index e8befc2..168c6a5 100644 --- a/public/js/app/views/mods/list.js +++ b/public/js/app/views/mods/list.js @@ -7,7 +7,6 @@ define(function (require) { Backbone = require('backbone'), Marionette = require('marionette'), ListItemView = require('app/views/mods/list_item'), - FormView = require('app/views/mods/form'), tpl = require('text!tpl/mods/list.html'), template = _.template(tpl); @@ -18,7 +17,6 @@ define(function (require) { template: template, events: { - "click #download": "download", "click #refresh": "refresh", }, @@ -26,19 +24,6 @@ define(function (require) { this.listenTo(this.collection, "change reset", this.render); }, - download: function (event) { - event.preventDefault(); - var view = new FormView({mods: this.collection}); - var modal = new Backbone.BootstrapModal({ - content: view, - animate: true, - cancelText: 'Close', - okText: 'Search', - }); - view.modal = modal; - modal.open(); - }, - refresh: function (event) { event.preventDefault(); $.ajax({ diff --git a/public/js/app/views/mods/list_item.js b/public/js/app/views/mods/list_item.js index 46a23d9..93351c8 100644 --- a/public/js/app/views/mods/list_item.js +++ b/public/js/app/views/mods/list_item.js @@ -18,7 +18,6 @@ define(function (require) { events: { "click .destroy": "destroy", - "click .update": "update", }, destroy: function (event) { @@ -35,25 +34,5 @@ define(function (require) { self.model.destroy(); }); }, - - update: function (event) { - var self = this; - event.preventDefault(); - - var $updateBtn = this.$el.find(".update"); - var laddaBtn = Ladda.create($updateBtn.get(0)); - laddaBtn.start(); - - $.ajax({ - url: "/api/mods/" + this.model.get('name'), - type: 'PUT', - success: function (resp) { - laddaBtn.stop(); - }, - error: function (resp) { - laddaBtn.stop(); - }, - }); - }, }); }); diff --git a/public/js/app/views/mods/search/list_item.js b/public/js/app/views/mods/search/list_item.js deleted file mode 100644 index b88edd9..0000000 --- a/public/js/app/views/mods/search/list_item.js +++ /dev/null @@ -1,58 +0,0 @@ -define(function (require) { - - "use strict"; - - var $ = require('jquery'), - _ = require('underscore'), - Backbone = require('backbone'), - Marionette = require('marionette'), - Ladda = require('ladda'), - tpl = require('text!tpl/mods/search/list_item.html'), - - template = _.template(tpl); - - return Marionette.ItemView.extend({ - tagName: "tr", - template: template, - - events: { - "click .install": "install" - }, - - templateHelpers: { - progress: function() { - if (this.mods.get(this.name)) { - return this.mods.get(this.name).get('progress'); - } - - return null; - } - }, - - install: function (event) { - var self = this; - event.preventDefault(); - - this.laddaBtn = Ladda.create(this.$el.find(".ladda-button").get(0)); - this.laddaBtn.start(); - this.$el.find('.ladda-button').addClass('disabled'); - - $.ajax({ - url: "/api/mods/", - type: 'POST', - data: { - name: this.model.get('name'), - }, - dataType: 'json', - success: function (resp) { - self.laddaBtn.stop(); - self.$el.find('.ladda-button').removeClass('disabled'); - }, - error: function (resp) { - self.laddaBtn.stop(); - self.$el.find('.ladda-button').removeClass('disabled'); - }, - }); - }, - }); -}); diff --git a/public/js/tpl/mods/form.html b/public/js/tpl/mods/form.html deleted file mode 100644 index 12907b2..0000000 --- a/public/js/tpl/mods/form.html +++ /dev/null @@ -1,23 +0,0 @@ -

- Install mods from Play withSIX -

- -
-
- - - -
-
- - - - - - - - - - - -
Mod
diff --git a/public/js/tpl/mods/list.html b/public/js/tpl/mods/list.html index 369e682..bc65135 100644 --- a/public/js/tpl/mods/list.html +++ b/public/js/tpl/mods/list.html @@ -3,11 +3,6 @@ Refresh - - - Search & Download - - diff --git a/public/js/tpl/mods/list_item.html b/public/js/tpl/mods/list_item.html index 09377fa..4b5ab12 100644 --- a/public/js/tpl/mods/list_item.html +++ b/public/js/tpl/mods/list_item.html @@ -1,30 +1,11 @@ diff --git a/public/js/tpl/mods/search/list_item.html b/public/js/tpl/mods/search/list_item.html deleted file mode 100644 index 22c247f..0000000 --- a/public/js/tpl/mods/search/list_item.html +++ /dev/null @@ -1,34 +0,0 @@ - - diff --git a/routes/mods.js b/routes/mods.js index 560465f..ebc47aa 100644 --- a/routes/mods.js +++ b/routes/mods.js @@ -7,16 +7,6 @@ module.exports = function (modsManager) { res.send(modsManager.mods) }) - router.post('/', function (req, res) { - modsManager.download(req.body.name) - res.status(204).send() - }) - - router.put('/:mod', function (req, res) { - modsManager.download(req.params.mod) - res.status(204).send() - }) - router.delete('/:mod', function (req, res) { modsManager.delete(req.params.mod, function (err) { if (err) { @@ -32,16 +22,5 @@ module.exports = function (modsManager) { res.status(204).send() }) - router.post('/search', function (req, res) { - var query = req.body.query || '' - modsManager.search(query, function (err, mods) { - if (err || !mods) { - res.status(500).send(err) - } else { - res.send(mods) - } - }) - }) - return router } diff --git a/test/lib/mods.js b/test/lib/mods.js deleted file mode 100644 index b272589..0000000 --- a/test/lib/mods.js +++ /dev/null @@ -1,16 +0,0 @@ -var should = require('should') - -var Mods = require('../../lib/mods.js') - -describe('Mods', function () { - describe('search()', function () { - it('should find mods', function (done) { - var mods = new Mods() - mods.search('', function (err, mods) { - should(err).be.null() - mods.should.not.be.empty() - done() - }) - }) - }) -})
<%-name%> - - <% if (playWithSix) { %> - - <% } %> - <% if (progress) { %> -
-
- <%-progress%>% -
-
- <% } else { %> - - - Delete - + + + Delete + - <% if (outdated) { %> - - - Update - - <% } %> - -
- <% } %> +
-

- <%-name%> - - <% if (typeof(type) != "undefined" && type) { %> - <%-type%> - <% } else { %> - Unknown - <% } %> - -

-

<%-title%>

-
-

- <% if (progress()) { %> -

-
- <%-progress()%>% -
-
- <% } else { %> - - - Install - - <% } %> -
-

-

- <%-formattedSize%> -

-

-