diff options
Diffstat (limited to '')
-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) { |