summaryrefslogtreecommitdiffstats
path: root/heimdall-frontend/source/qml/FileUtils.js
diff options
context:
space:
mode:
Diffstat (limited to 'heimdall-frontend/source/qml/FileUtils.js')
-rw-r--r--heimdall-frontend/source/qml/FileUtils.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/heimdall-frontend/source/qml/FileUtils.js b/heimdall-frontend/source/qml/FileUtils.js
new file mode 100644
index 0000000..3735a37
--- /dev/null
+++ b/heimdall-frontend/source/qml/FileUtils.js
@@ -0,0 +1,44 @@
+function clipFileExtension(filename) {
+ var periodIndex = filename.lastIndexOf('.');
+
+ if (periodIndex > 0) {
+ return filename.slice(0, periodIndex - 1);
+ } else if (periodIndex === 0) {
+ return "";
+ }
+
+ return filename;
+}
+
+function filenameFromUrl(url) {
+ var urlString = url.toString();
+ return urlString.slice(urlString.lastIndexOf('/') + 1);
+}
+
+function fileExtension(url) {
+ var filename = filenameFromUrl(url);
+ var periodIndex = filename.lastIndexOf('.');
+
+ if (periodIndex >= 0) {
+ return filename.slice(periodIndex + 1);
+ }
+
+ return "";
+}
+
+// TODO: Real implemention - call out to C++ and validate with QFileInfo etc.
+function isFile(url) {
+ 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');
+}
+
+function extractArchive(url) {
+
+}