First working zip feature in device files tab.

This commit is contained in:
Ylian Saint-Hilaire 2020-08-13 14:03:41 -07:00
parent 209778fe7c
commit 027876d169
3 changed files with 1157 additions and 1099 deletions

View File

@ -2140,17 +2140,34 @@ function createMeshCore(agent) {
} }
case 'zip': case 'zip':
// Zip a bunch of files // Zip a bunch of files
sendConsoleText('Zip: ' + JSON.stringify(cmd)); var fp, stat, p = [];
var p = []; for (var i in cmd.files) {
for (var i in cmd.files) { p.push(cmd.path + '/' + cmd.files[i]); } // Right now, we only zip files.
var ofile = cmd.path + '/' + cmd.outfile; // TODO: Support folder compression
sendConsoleText('Writing ' + ofile + '...'); // TODO: Support compression relative to a root path
// TODO: Support the 'cancel' operation below
fp = cmd.path + '/' + cmd.files[i];
stat = null;
try { stat = fs.statSync(fp); } catch (e) { }
if ((stat != null) && (stat.isDirectory() == false) && (stat.size != null) && (stat.size > 0)) { p.push(fp); }
}
if (p.length == 0) return;
var ofile = cmd.path + '/' + cmd.output;
this.write(Buffer.from(JSON.stringify({ action: 'dialogmessage', msg: 'zipping' })));
var out = require('fs').createWriteStream(ofile, { flags: 'wb' }); var out = require('fs').createWriteStream(ofile, { flags: 'wb' });
out.fname = ofile; out.fname = ofile;
out.on('close', function () { sendConsoleText('DONE writing ' + this.fname); }); out.xws = this;
out.on('close', function () {
this.xws.write(Buffer.from(JSON.stringify({ action: 'dialogmessage', msg: null })));
this.xws.write(Buffer.from(JSON.stringify({ action: 'refresh' })));
});
var zip = require('zip-writer').write({ files: p }); var zip = require('zip-writer').write({ files: p });
zip.pipe(out); zip.pipe(out);
break; break;
case 'cancel':
// TODO: Cancel zip operation if present
//sendConsoleText('Cancel operation');
break;
default: default:
// Unknown action, ignore it. // Unknown action, ignore it.
break; break;

File diff suppressed because it is too large Load Diff

View File

@ -7651,6 +7651,7 @@
QV('filesRecordIcon', false); QV('filesRecordIcon', false);
p13setActions(); p13setActions();
if (files != null) { files.Stop(); files = null; } if (files != null) { files.Stop(); files = null; }
if (xxdialogTag == 'fileMsgDialog') { setDialogMode(0); }
break; break;
case 3: case 3:
p13targetpath = ''; p13targetpath = '';
@ -7709,6 +7710,8 @@
var p13targetpath = null; var p13targetpath = null;
var p13filetreelocation = []; var p13filetreelocation = [];
function p13fileOperationDialogEx(b) { if ((b == 0) && (files != null)) { files.sendText({ action: 'cancel' }); } }
function p13gotFiles(data) { function p13gotFiles(data) {
if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; } // This is ok because 4 first bytes is a control value. if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; } // This is ok because 4 first bytes is a control value.
//console.log('p13gotFiles', data); //console.log('p13gotFiles', data);
@ -7718,6 +7721,20 @@
// Process file upload commands // Process file upload commands
if ((data.action != null) && (data.action.startsWith('upload'))) { p13gotUploadData(data); return; } if ((data.action != null) && (data.action.startsWith('upload'))) { p13gotUploadData(data); return; }
// Display a dialog message
if (data.action == 'dialogmessage') {
if ((data.msg == null) && (xxdialogTag == 'fileMsgDialog')) {
setDialogMode(0); // Close the dialog box
} else if ((data.msg == 'zipping') && ((!xxdialogMode) || (xxdialogTag == 'fileMsgDialog'))) {
// Show the dialog box message
setDialogMode(2, "File Operation", 10, p13fileOperationDialogEx, '<div style=margin:10px>' + "Compressing files..." + '<div>', 'fileMsgDialog');
}
return;
}
// Refresh file folder
if (data.action == 'refresh') { p13folderup(9999); return; }
if (data.path != null) { if (data.path != null) {
data.path = data.path.replace(/\//g, '\\'); data.path = data.path.replace(/\//g, '\\');
if ((p13filetree != null) && (data.path == p13filetree.path)) { if ((p13filetree != null) && (data.path == p13filetree.path)) {