diff --git a/lib/gui/app/os/dialog.ts b/lib/gui/app/os/dialog.ts index e3233cf7..aea6b821 100644 --- a/lib/gui/app/os/dialog.ts +++ b/lib/gui/app/os/dialog.ts @@ -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 { filters: [ { name: 'OS Images', - extensions: [...getAllExtensions()].sort(), + extensions: SUPPORTED_EXTENSIONS, + }, + { + name: 'All', + extensions: ['*'], }, ], }; diff --git a/lib/shared/supported-formats.ts b/lib/shared/supported-formats.ts index 4dee3ba5..c2b0c6dc 100644 --- a/lib/shared/supported-formats.ts +++ b/lib/shared/supported-formats.ts @@ -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)); } diff --git a/package.json b/package.json index 3929270b..382e420e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/shared/supported-formats.spec.ts b/tests/shared/supported-formats.spec.ts index 368321b1..17bb856a 100644 --- a/tests/shared/supported-formats.spec.ts +++ b/tests/shared/supported-formats.spec.ts @@ -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( [