From a5322950da7e967dbe5e9d64681b480957988836 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 7 Mar 2016 12:10:20 -0400 Subject: [PATCH] Add support for zip images in select image dialog The "Select Image" dialog now permits the user selecting zip files. Once the zip file is selected, `resin-zip-image` scans the archive to ensure its validity. If its not valid, an error alert is shown and nothing is selected. --- lib/src/dialog.js | 22 +++++++++++++++++++--- package.json | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/src/dialog.js b/lib/src/dialog.js index 9dc088c0..4657cb1d 100644 --- a/lib/src/dialog.js +++ b/lib/src/dialog.js @@ -18,6 +18,7 @@ const electron = require('electron'); const Bluebird = require('bluebird'); +const zipImage = require('resin-zip-image'); /** * @summary Open an image selection dialog @@ -25,7 +26,10 @@ const Bluebird = require('bluebird'); * @public * * @description - * Notice that by image, we mean *.img/*.iso files. + * Notice that by image, we mean *.img/*.iso/*.zip files. + * + * If the user selects an invalid zip image, an error alert + * is shown, and the promise resolves `undefined`. * * @fulfil {String} - selected image * @returns {Promise}; @@ -41,15 +45,27 @@ exports.selectImage = function() { properties: [ 'openFile' ], filters: [ { - name: 'IMG/ISO', + name: 'IMG/ISO/ZIP', extensions: [ + 'zip', 'img', 'iso' ] } ] }, resolve); - }).get(0); + }).get(0).then(function(file) { + if (zipImage.isZip(file) && !zipImage.isValidZipImage(file)) { + electron.dialog.showErrorBox( + 'Invalid zip image', + 'Etcher can only open Zip archives that contain exactly one image file inside.' + ); + + return; + } + + return file; + }); }; /** diff --git a/package.json b/package.json index fecdd74b..efca094a 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "lodash": "^4.5.1", "ngstorage": "^0.3.10", "resin-image-write": "^2.0.5", - "resin-zip-image": "^1.1.0", + "resin-zip-image": "^1.1.1", "sudo-prompt": "^2.2.0", "trackjs": "^2.1.16", "umount": "^1.1.1",