diff --git a/agents/meshcore.js b/agents/meshcore.js index 77cf14a7..6d5fc964 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -2138,6 +2138,19 @@ function createMeshCore(agent) { } break; } + case 'zip': + // Zip a bunch of files + sendConsoleText('Zip: ' + JSON.stringify(cmd)); + var p = []; + for (var i in cmd.files) { p.push(cmd.path + '/' + cmd.files[i]); } + var ofile = cmd.path + '/' + cmd.outfile; + sendConsoleText('Writing ' + ofile + '...'); + var out = require('fs').createWriteStream(ofile, { flags: 'wb' }); + out.fname = ofile; + out.on('close', function () { sendConsoleText('DONE writing ' + this.fname); }); + var zip = require('zip-writer').write({ files: p }); + zip.pipe(out); + break; default: // Unknown action, ignore it. break; @@ -2518,12 +2531,9 @@ function createMeshCore(agent) { } break; case 'zip': - if (args['_'].length == 0) - { + if (args['_'].length == 0) { response = "Proper usage: zip (output file name), input1 [, input n]"; // Display usage - } - else - { + } else { var p = args['_'].join(' ').split(','); var ofile = p.shift(); sendConsoleText('Writing ' + ofile + '...'); @@ -2536,24 +2546,16 @@ function createMeshCore(agent) { } break; case 'unzip': - if (args['_'].length == 0) - { + if (args['_'].length == 0) { response = "Proper usage: unzip input, destination"; // Display usage - } - else - { + } else { var p = args['_'].join(' ').split(','); - if (p.length != 2) - { - response = "Proper usage: unzip input, destination"; // Display usage - break; - } + if (p.length != 2) { response = "Proper usage: unzip input, destination"; break; } // Display usage var prom = require('zip-reader').read(p[0]); prom._dest = p[1]; prom.self = this; prom.sessionid = sessionid; - prom.then(function (zipped) - { + prom.then(function (zipped) { sendConsoleText('Extracting to ' + this._dest + '...', this.sessionid); zipped.extractAll(this._dest).then(function () { sendConsoleText('finished unzipping', this.sessionid); }, function (e) { sendConsoleText('Error unzipping: ' + e, this.sessionid); }).parentPromise.sessionid = this.sessionid; }, function (e) { sendConsoleText('Error unzipping: ' + e, this.sessionid); }); diff --git a/views/default.handlebars b/views/default.handlebars index 9f6db7e6..eeb41c32 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -730,6 +730,7 @@       +     @@ -7839,6 +7840,7 @@ QE('p13RefreshButton', false); QE('p13CutButton', false); QE('p13CopyButton', false); + QE('p13ZipButton', false); QE('p13PasteButton', false); } else { var cc = p13getFileSelCount(), tc = p13getFileCount(), sfc = p13getFileSelCount(false); // In order: number of entires selected, number of total entries, number of selected entires that are files (not folders) @@ -7853,6 +7855,7 @@ QE('p13RefreshButton', true); QE('p13CutButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false))); QE('p13CopyButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false))); + QE('p13ZipButton', (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false))); QE('p13PasteButton', ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0))); } } @@ -7883,6 +7886,20 @@ } } + function p13zipFiles() { + var inputFiles = [], checkboxes = document.getElementsByName('fd'); + for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { inputFiles.push(p13filetree.dir[checkboxes[i].value].n); } } + setDialogMode(2, "Zip Filename", 3, p13zipFilesEx, '', { action: 'zip', path: p13filetreelocation.join('/'), files: inputFiles}); + focusTextBox('p13renameinput'); + p13fileNameCheck(); + } + + function p13zipFilesEx(b, tag) { + tag.output = Q('p13renameinput').value; + if (!tag.output.toLowerCase().endsWith('.zip')) { tag.output += '.zip'; } + files.sendText(tag); + } + var p13clipboard = null, p13clipboardFolder = null, p13clipboardCut = 0; function p13copyFile(cut) { var checkboxes = document.getElementsByName('fd'); p13clipboard = []; p13clipboardCut = cut, p13clipboardFolder = p13targetpath; for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == '3')) { p13clipboard.push(p13filetree.dir[checkboxes[i].value].n); } } p13updateClipview(); } function p13pasteFile() {