Add .vhd to the list of supported extensions, allow opening any file

Changelog-entry: Add .vhd to the list of supported extensions, allow opening any file
Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2020-06-19 16:54:17 +02:00
parent 5a45f8b122
commit 406955ca3e
4 changed files with 26 additions and 86 deletions

View File

@ -18,7 +18,7 @@ import * as electron from 'electron';
import * as _ from 'lodash';
import * as errors from '../../../shared/errors';
import { getAllExtensions } from '../../../shared/supported-formats';
import { SUPPORTED_EXTENSIONS } from '../../../shared/supported-formats';
/**
* @summary Open an image selection dialog
@ -40,7 +40,11 @@ export async function selectImage(): Promise<string | undefined> {
filters: [
{
name: 'OS Images',
extensions: [...getAllExtensions()].sort(),
extensions: SUPPORTED_EXTENSIONS,
},
{
name: 'All',
extensions: ['*'],
},
],
};

View File

@ -14,44 +14,28 @@
* limitations under the License.
*/
import * as sdk from 'etcher-sdk';
import * as mime from 'mime-types';
import * as path from 'path';
import { basename } from 'path';
export function getCompressedExtensions(): string[] {
const result = [];
for (const [
mimetype,
cls,
// @ts-ignore (mimetypes is private)
] of sdk.sourceDestination.SourceDestination.mimetypes.entries()) {
if (cls.prototype instanceof sdk.sourceDestination.CompressedSource) {
const extension = mime.extension(mimetype);
if (extension) {
result.push(extension);
}
}
}
return result;
}
export function getNonCompressedExtensions(): string[] {
return sdk.sourceDestination.SourceDestination.imageExtensions;
}
export function getArchiveExtensions(): string[] {
return ['zip', 'etch'];
}
export function getAllExtensions(): string[] {
return [
...getArchiveExtensions(),
...getNonCompressedExtensions(),
...getCompressedExtensions(),
];
}
export const SUPPORTED_EXTENSIONS = [
'bin',
'bz2',
'dmg',
'dsk',
'etch',
'gz',
'hddimg',
'img',
'iso',
'raw',
'rpi-sdimg',
'sdcard',
'vhd',
'wic',
'xz',
'zip',
];
export function looksLikeWindowsImage(imagePath: string): boolean {
const regex = /windows|win7|win8|win10|winxp/i;
return regex.test(path.basename(imagePath));
return regex.test(basename(imagePath));
}

View File

@ -86,7 +86,6 @@
"inactivity-timer": "^1.0.0",
"lint-staged": "^10.2.2",
"lodash": "^4.17.10",
"mime-types": "^2.1.18",
"mini-css-extract-plugin": "^0.9.0",
"mocha": "^8.0.1",
"nan": "^2.14.0",

View File

@ -20,53 +20,6 @@ import * as _ from 'lodash';
import * as supportedFormats from '../../lib/shared/supported-formats';
describe('Shared: SupportedFormats', function () {
describe('.getCompressedExtensions()', function () {
it('should return the supported compressed extensions', function () {
const extensions = supportedFormats.getCompressedExtensions().sort();
expect(extensions).to.deep.equal(['bz2', 'gz', 'xz'].sort());
});
});
describe('.getNonCompressedExtensions()', function () {
it('should return the supported non compressed extensions', function () {
const extensions = supportedFormats.getNonCompressedExtensions();
expect(extensions).to.deep.equal([
'img',
'iso',
'bin',
'dsk',
'hddimg',
'raw',
'dmg',
'sdcard',
'rpi-sdimg',
'wic',
]);
});
});
describe('.getArchiveExtensions()', function () {
it('should return the supported archive extensions', function () {
const extensions = supportedFormats.getArchiveExtensions();
expect(extensions).to.deep.equal(['zip', 'etch']);
});
});
describe('.getAllExtensions()', function () {
it('should return the union of all compressed, uncompressed, and archive extensions', function () {
const archiveExtensions = supportedFormats.getArchiveExtensions();
const compressedExtensions = supportedFormats.getCompressedExtensions();
const nonCompressedExtensions = supportedFormats.getNonCompressedExtensions();
const expected = _.union(
archiveExtensions,
compressedExtensions,
nonCompressedExtensions,
).sort();
const extensions = supportedFormats.getAllExtensions();
expect(extensions.sort()).to.deep.equal(expected);
});
});
describe('.looksLikeWindowsImage()', function () {
_.each(
[