diff options
author | Benjamin Dobell <benjamin.dobell+git@glassechidna.com.au> | 2015-03-11 18:01:41 +0100 |
---|---|---|
committer | Benjamin Dobell <benjamin.dobell+git@glassechidna.com.au> | 2015-03-11 18:09:40 +0100 |
commit | 7c6ee7f1a24faeafc793414e877bf014743d9cfe (patch) | |
tree | 805b7839234bae16eeac75f33c471e7ee22f0c0f /heimdall-frontend/source/qml/FileUtils.js | |
parent | Lots of Frontend refactoring with a few bug fixes (diff) | |
download | Heimdall-7c6ee7f1a24faeafc793414e877bf014743d9cfe.tar Heimdall-7c6ee7f1a24faeafc793414e877bf014743d9cfe.tar.gz Heimdall-7c6ee7f1a24faeafc793414e877bf014743d9cfe.tar.bz2 Heimdall-7c6ee7f1a24faeafc793414e877bf014743d9cfe.tar.lz Heimdall-7c6ee7f1a24faeafc793414e877bf014743d9cfe.tar.xz Heimdall-7c6ee7f1a24faeafc793414e877bf014743d9cfe.tar.zst Heimdall-7c6ee7f1a24faeafc793414e877bf014743d9cfe.zip |
Diffstat (limited to 'heimdall-frontend/source/qml/FileUtils.js')
-rw-r--r-- | heimdall-frontend/source/qml/FileUtils.js | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/heimdall-frontend/source/qml/FileUtils.js b/heimdall-frontend/source/qml/FileUtils.js index 3735a37..1b19818 100644 --- a/heimdall-frontend/source/qml/FileUtils.js +++ b/heimdall-frontend/source/qml/FileUtils.js @@ -1,42 +1,46 @@ function clipFileExtension(filename) { - var periodIndex = filename.lastIndexOf('.'); + var periodIndex = filename.lastIndexOf('.'); - if (periodIndex > 0) { - return filename.slice(0, periodIndex - 1); - } else if (periodIndex === 0) { - return ""; - } + if (periodIndex > 0) { + return filename.slice(0, periodIndex); + } else if (periodIndex === 0) { + return ""; + } - return filename; + return filename; } function filenameFromUrl(url) { - var urlString = url.toString(); - return urlString.slice(urlString.lastIndexOf('/') + 1); + var urlString = url.toString(); + return urlString.slice(urlString.lastIndexOf('/') + 1); +} + +function filenameFromPath(path) { + return filenameFromUrl(path); } function fileExtension(url) { - var filename = filenameFromUrl(url); - var periodIndex = filename.lastIndexOf('.'); + var filename = filenameFromUrl(url); + var periodIndex = filename.lastIndexOf('.'); - if (periodIndex >= 0) { - return filename.slice(periodIndex + 1); - } + if (periodIndex >= 0) { + return filename.slice(periodIndex + 1); + } - return ""; + return ""; } // TODO: Real implemention - call out to C++ and validate with QFileInfo etc. function isFile(url) { - var filename = filenameFromUrl(url); - return filename.length > 0; + var filename = filenameFromUrl(url); + return filename.length > 0; } function isArchive(url) { - var filename = filenameFromUrl(url); - var extension = fileExtension(filename); - return (extension === 'tar' || extension === 'zip') - || (extension === 'gz' && fileExtension(clipFileExtension(filename)) === 'tar'); + var filename = filenameFromUrl(url); + var extension = fileExtension(filename); + return (extension === 'tar' || extension === 'zip') + || (extension === 'gz' && fileExtension(clipFileExtension(filename)) === 'tar'); } function extractArchive(url) { |