mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-28 05:36:34 +00:00
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:
parent
5a45f8b122
commit
406955ca3e
@ -18,7 +18,7 @@ import * as electron from 'electron';
|
|||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import * as errors from '../../../shared/errors';
|
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
|
* @summary Open an image selection dialog
|
||||||
@ -40,7 +40,11 @@ export async function selectImage(): Promise<string | undefined> {
|
|||||||
filters: [
|
filters: [
|
||||||
{
|
{
|
||||||
name: 'OS Images',
|
name: 'OS Images',
|
||||||
extensions: [...getAllExtensions()].sort(),
|
extensions: SUPPORTED_EXTENSIONS,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'All',
|
||||||
|
extensions: ['*'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -14,44 +14,28 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as sdk from 'etcher-sdk';
|
import { basename } from 'path';
|
||||||
import * as mime from 'mime-types';
|
|
||||||
import * as path from 'path';
|
|
||||||
|
|
||||||
export function getCompressedExtensions(): string[] {
|
export const SUPPORTED_EXTENSIONS = [
|
||||||
const result = [];
|
'bin',
|
||||||
for (const [
|
'bz2',
|
||||||
mimetype,
|
'dmg',
|
||||||
cls,
|
'dsk',
|
||||||
// @ts-ignore (mimetypes is private)
|
'etch',
|
||||||
] of sdk.sourceDestination.SourceDestination.mimetypes.entries()) {
|
'gz',
|
||||||
if (cls.prototype instanceof sdk.sourceDestination.CompressedSource) {
|
'hddimg',
|
||||||
const extension = mime.extension(mimetype);
|
'img',
|
||||||
if (extension) {
|
'iso',
|
||||||
result.push(extension);
|
'raw',
|
||||||
}
|
'rpi-sdimg',
|
||||||
}
|
'sdcard',
|
||||||
}
|
'vhd',
|
||||||
return result;
|
'wic',
|
||||||
}
|
'xz',
|
||||||
|
'zip',
|
||||||
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 function looksLikeWindowsImage(imagePath: string): boolean {
|
export function looksLikeWindowsImage(imagePath: string): boolean {
|
||||||
const regex = /windows|win7|win8|win10|winxp/i;
|
const regex = /windows|win7|win8|win10|winxp/i;
|
||||||
return regex.test(path.basename(imagePath));
|
return regex.test(basename(imagePath));
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,6 @@
|
|||||||
"inactivity-timer": "^1.0.0",
|
"inactivity-timer": "^1.0.0",
|
||||||
"lint-staged": "^10.2.2",
|
"lint-staged": "^10.2.2",
|
||||||
"lodash": "^4.17.10",
|
"lodash": "^4.17.10",
|
||||||
"mime-types": "^2.1.18",
|
|
||||||
"mini-css-extract-plugin": "^0.9.0",
|
"mini-css-extract-plugin": "^0.9.0",
|
||||||
"mocha": "^8.0.1",
|
"mocha": "^8.0.1",
|
||||||
"nan": "^2.14.0",
|
"nan": "^2.14.0",
|
||||||
|
@ -20,53 +20,6 @@ import * as _ from 'lodash';
|
|||||||
import * as supportedFormats from '../../lib/shared/supported-formats';
|
import * as supportedFormats from '../../lib/shared/supported-formats';
|
||||||
|
|
||||||
describe('Shared: SupportedFormats', function () {
|
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 () {
|
describe('.looksLikeWindowsImage()', function () {
|
||||||
_.each(
|
_.each(
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user