diff --git a/js/dllpatcher.js b/js/dllpatcher.js index 02bb480..1e60dc3 100644 --- a/js/dllpatcher.js +++ b/js/dllpatcher.js @@ -31,14 +31,14 @@ StandardPatch.prototype.createUI = function(parent) { }; StandardPatch.prototype.updateUI = function(file) { - this.checkbox.checked = this.checkPatchBytes(file) == "on"; + this.checkbox.checked = this.checkPatchBytes(file) === "on"; }; StandardPatch.prototype.validatePatch = function(file) { var status = this.checkPatchBytes(file); - if(status == "on") { + if(status === "on") { console.log('"' + this.name + '"', "is enabled!"); - } else if(status == "off") { + } else if(status === "off") { console.log('"' + this.name + '"', "is disabled!"); } else { return '"' + this.name + '" is neither on nor off! Have you got the right dll?'; @@ -61,13 +61,13 @@ StandardPatch.prototype.checkPatchBytes = function(file) { for(var i = 0; i < this.patches.length; i++) { var patch = this.patches[i]; if(bytesMatch(file, patch.offset, patch.off)) { - if(patchStatus == "") { + if(patchStatus === "") { patchStatus = "off"; } else if(patchStatus != "off"){ return "on/off mismatch within patch"; } } else if(bytesMatch(file, patch.offset, patch.on)) { - if(patchStatus == "") { + if(patchStatus === "") { patchStatus = "on"; } else if(patchStatus != "on"){ return "on/off mismatch within patch"; @@ -92,7 +92,7 @@ var UnionPatch = function(options) { UnionPatch.prototype.createUI = function(parent) { this.radios = []; var radio_id = createID(); - + var container = $("
", {"class": "patch-union"}); container.append('' + this.name + ':'); for(var i = 0; i < this.patches.length; i++) { @@ -102,7 +102,7 @@ UnionPatch.prototype.createUI = function(parent) { var patchDiv = $('
', {'class' : 'patch'}); var radio = $('')[0]; this.radios.push(radio); - + patchDiv.append(radio); patchDiv.append(''); if(patch.tooltip) { @@ -148,62 +148,162 @@ UnionPatch.prototype.getSelected = function() { return null; } +var DllPatcherContainer = function (patchers) { + this.patchers = patchers; + this.createUI(); +}; + +DllPatcherContainer.prototype.getSupportedDLLs = function () { + var dlls = []; + for (var i = 0; i < this.patchers.length; i++) { + var name = this.patchers[i].filename + ".dll"; + if (dlls.indexOf(name) === -1) { + dlls.push(name); + } + } + return dlls; +}; + +DllPatcherContainer.prototype.getSupportedVersions = function () { + var descriptions = []; + for (var i = 0; i < this.patchers.length; i++) { + if ($.type(this.patchers[i].description) === "string") { + descriptions.push(this.patchers[i].description); + } + } + return descriptions; +}; + +DllPatcherContainer.prototype.createUI = function () { + var self = this; + var container = $("
", {"class": "patchContainer"}); + var header = this.getSupportedDLLs().join(", "); + container.html("

" + header + "

"); + + var supportedDlls = $("
    "); + var versions = this.getSupportedVersions(); + for (var i = 0; i < versions.length; i++) { + $("
  • ").text(versions[i]).appendTo(supportedDlls); + } + + $("html").on("dragover dragenter", function () { + container.addClass("dragover"); + return true; + }) + .on("dragleave dragend drop", function () { + container.removeClass("dragover"); + return true; + }) + .on("dragover dragenter dragleave dragend drop", function (e) { + e.preventDefault(); + }); + + container.on("drop", function (e) { + var files = e.originalEvent.dataTransfer.files; + if (files && files.length > 0) + self.loadFile(files[0]); + }); + + this.fileInput = $("", + { + "class": "fileInput", + "id": "any-file", + "type": "file", + }); + var label = $("