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.
This commit is contained in:
Juan Cruz Viotti 2016-03-07 12:10:20 -04:00
parent 3e352d4224
commit a5322950da
2 changed files with 20 additions and 4 deletions

View File

@ -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;
});
};
/**

View File

@ -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",