Started work on file zip feature.

This commit is contained in:
Ylian Saint-Hilaire 2020-08-13 13:13:21 -07:00
parent 204cca9ef6
commit 2d0f4010be
2 changed files with 36 additions and 17 deletions

View File

@ -2138,6 +2138,19 @@ function createMeshCore(agent) {
} }
break; 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: default:
// Unknown action, ignore it. // Unknown action, ignore it.
break; break;
@ -2518,12 +2531,9 @@ function createMeshCore(agent) {
} }
break; break;
case 'zip': case 'zip':
if (args['_'].length == 0) if (args['_'].length == 0) {
{
response = "Proper usage: zip (output file name), input1 [, input n]"; // Display usage response = "Proper usage: zip (output file name), input1 [, input n]"; // Display usage
} } else {
else
{
var p = args['_'].join(' ').split(','); var p = args['_'].join(' ').split(',');
var ofile = p.shift(); var ofile = p.shift();
sendConsoleText('Writing ' + ofile + '...'); sendConsoleText('Writing ' + ofile + '...');
@ -2536,24 +2546,16 @@ function createMeshCore(agent) {
} }
break; break;
case 'unzip': case 'unzip':
if (args['_'].length == 0) if (args['_'].length == 0) {
{
response = "Proper usage: unzip input, destination"; // Display usage response = "Proper usage: unzip input, destination"; // Display usage
} } else {
else
{
var p = args['_'].join(' ').split(','); var p = args['_'].join(' ').split(',');
if (p.length != 2) if (p.length != 2) { response = "Proper usage: unzip input, destination"; break; } // Display usage
{
response = "Proper usage: unzip input, destination"; // Display usage
break;
}
var prom = require('zip-reader').read(p[0]); var prom = require('zip-reader').read(p[0]);
prom._dest = p[1]; prom._dest = p[1];
prom.self = this; prom.self = this;
prom.sessionid = sessionid; prom.sessionid = sessionid;
prom.then(function (zipped) prom.then(function (zipped) {
{
sendConsoleText('Extracting to ' + this._dest + '...', this.sessionid); 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; 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); }); }, function (e) { sendConsoleText('Error unzipping: ' + e, this.sessionid); });

View File

@ -730,6 +730,7 @@
<input type=button id=p13CutButton disabled="disabled" value="Cut" onclick="p13copyFile(1)" />&nbsp; <input type=button id=p13CutButton disabled="disabled" value="Cut" onclick="p13copyFile(1)" />&nbsp;
<input type=button id=p13CopyButton disabled="disabled" value="Copy" onclick="p13copyFile(0)" />&nbsp; <input type=button id=p13CopyButton disabled="disabled" value="Copy" onclick="p13copyFile(0)" />&nbsp;
<input type=button id=p13PasteButton disabled="disabled" value="Paste" onclick="p13pasteFile()" />&nbsp; <input type=button id=p13PasteButton disabled="disabled" value="Paste" onclick="p13pasteFile()" />&nbsp;
<input type=button id=p13ZipButton disabled="disabled" value="Zip" onclick="p13zipFiles()" />&nbsp;
<input type=button id=p13RefreshButton disabled="disabled" value="Refresh" onclick="p13folderup(9999)" />&nbsp; <input type=button id=p13RefreshButton disabled="disabled" value="Refresh" onclick="p13folderup(9999)" />&nbsp;
</div> </div>
</td> </td>
@ -7839,6 +7840,7 @@
QE('p13RefreshButton', false); QE('p13RefreshButton', false);
QE('p13CutButton', false); QE('p13CutButton', false);
QE('p13CopyButton', false); QE('p13CopyButton', false);
QE('p13ZipButton', false);
QE('p13PasteButton', false); QE('p13PasteButton', false);
} else { } 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) 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('p13RefreshButton', true);
QE('p13CutButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false))); QE('p13CutButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
QE('p13CopyButton', (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))); 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, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% value="" />', { 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; 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 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() { function p13pasteFile() {