From 431b70a0f83e9d8c24069c29baec32e38e9b8fb4 Mon Sep 17 00:00:00 2001 From: marko Date: Tue, 29 Sep 2020 17:41:56 -0400 Subject: [PATCH 1/3] New file manager app --- apps.json | 13 +++ apps/fileman/ChangeLog | 1 + apps/fileman/README.md | 11 +++ apps/fileman/fileman-icon.js | 1 + apps/fileman/fileman.app.js | 101 ++++++++++++++++++++++ apps/fileman/icons8-filing-cabinet-48.png | Bin 0 -> 467 bytes 6 files changed, 127 insertions(+) create mode 100644 apps/fileman/ChangeLog create mode 100644 apps/fileman/README.md create mode 100644 apps/fileman/fileman-icon.js create mode 100644 apps/fileman/fileman.app.js create mode 100644 apps/fileman/icons8-filing-cabinet-48.png diff --git a/apps.json b/apps.json index 5b0a5c854..4f1aa4e24 100644 --- a/apps.json +++ b/apps.json @@ -2209,6 +2209,19 @@ {"name":"cscsensor.img","url":"cscsensor-icon.js","evaluate":true} ] }, + { "id": "fileman", + "name": "Simple file manager", + "shortName":"FileManager", + "icon": "icons8-filing-cabinet-48.png", + "version":"0.01", + "description": "Simple file manager, allows to examine storage, display or delete files", + "tags": "tools", + "readme": "README.md", + "storage": [ + {"name":"fileman.app.js","url":"fileman.app.js"}, + {"name":"fileman.img","url":"fileman-icon.js","evaluate":true} + ] + }, { "id": "worldclock", "name": "World Clock - 4 time zones", "shortName":"World Clock", diff --git a/apps/fileman/ChangeLog b/apps/fileman/ChangeLog new file mode 100644 index 000000000..1a3bc1757 --- /dev/null +++ b/apps/fileman/ChangeLog @@ -0,0 +1 @@ +0.01: New app! diff --git a/apps/fileman/README.md b/apps/fileman/README.md new file mode 100644 index 000000000..df589d589 --- /dev/null +++ b/apps/fileman/README.md @@ -0,0 +1,11 @@ +# FileManager + +A small file manager, mostly written for debugging issues on the watch. +Upon opening, the app will display a list of all the files in storage (it will contract the sub-components of a StorageFile into one entry). +When selecting a file the following option occurs (depending on file type detected by extension): + +- Length: file size in bytes +- Display file: print out file contents on screen (will attempt to add back newlines for minimized JS code) +- Load file [*.js files only, no widgets]: load and execute javascript file +- Display image [*.img files only]: attempt to render file contents as image on screen +- Delete file: delete file (asks for confirmation first, will delete all components of a StorageFile) diff --git a/apps/fileman/fileman-icon.js b/apps/fileman/fileman-icon.js new file mode 100644 index 000000000..b96649fff --- /dev/null +++ b/apps/fileman/fileman-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwhC/ABuIABgWIhAXNwAuVGBIXZmYAKC/4XXkQACC9Z3/C7YANC8J3/C8ciAAQXrO/4XbABoXhO/4XjkQACC9Z3/C7YANC78ICxuAC44wOCxAABiMRBKIAtA==")) diff --git a/apps/fileman/fileman.app.js b/apps/fileman/fileman.app.js new file mode 100644 index 000000000..a8acb22f6 --- /dev/null +++ b/apps/fileman/fileman.app.js @@ -0,0 +1,101 @@ +const STOR = require("Storage"); + +const n = 9; +var nstart = 0; +var nend; +var m; +var files; + +function delete_file(fn) { + E.showPrompt("Delete\n"+fn+"?", {buttons: {"No":false, "Yes":true}}).then(function(v) { + if (v) { + if (fn.charCodeAt(fn.length-1)==1) { + var fh = STOR.open(fn.substr(0, fn.length-1), "w"); + fh.erase(); + } + else STOR.erase(fn); + } + }).then(function() { files=get_pruned_file_list(); }).then(drawMenu); +} + +function get_length(fn) { + var len; + if (fn.charCodeAt(fn.length-1)==1) { + var fh = STOR.open(fn.substr(0, fn.length-1), "r"); + len = fh.getLength(); + } + else len = STOR.read(fn).length; + return len; +} + +function display_file(fn, qJS) { + g.clear().setColor(1, 1, 1); + var qStorageFile = (fn.charCodeAt(fn.length-1)==1); + var np = 0; + Terminal.println(""); + var file_len = get_length(fn); + var fb = (qStorageFile ? STOR.open(fn.substr(0, fn.length-1), "r") : STOR.read(fn)); + for (var i=0; i 38) { + Terminal.println(""); + np = 0; + } + var c = (qStorageFile ? fb.read(1) : fb[i]); + if (c=="\n") np = 0; + if (qJS && !qStorageFile && c==";" && fb[i+1]!="\n") { + Terminal.println(";"); + np = 0; + } + else Terminal.print(c); + } + Terminal.println(""); +} + +function visit_file(fn) { + var menu = { + '' : {'title' : fn + (fn.charCodeAt(fn.length-1)==1 ? "(S)" : "")} + }; + var qJS = fn.endsWith(".js"); + menu['Length: '+get_length(fn)+' bytes'] = function() {}; + menu['Display file'] = function () { display_file(fn, qJS); }; + if (qJS && !fn.endsWith(".wid.js")) menu['Load file'] = function() { load(fn); } + if (fn.endsWith(".img")) menu['Display image'] = function() { g.clear().drawImage(STOR.read(fn),0,20); } + menu['Delete file'] = function () { delete_file(fn); } + menu['< Back'] = drawMenu; + E.showMenu(menu); +} + +function drawMenu() { + nend = (nstart+n0 ? files.length-n : 0; + menu = {}; + drawMenu(); + } + for (var i=nstart; i next"] = function() { + if (nstart+n (f.charCodeAt(f.length-1)>31 || f.charCodeAt(f.length-1)<2)); + return fl; +} + +files = get_pruned_file_list(); +drawMenu(); diff --git a/apps/fileman/icons8-filing-cabinet-48.png b/apps/fileman/icons8-filing-cabinet-48.png new file mode 100644 index 0000000000000000000000000000000000000000..75774c9ea10b314dbb232dfc3cd74341a2a6c86b GIT binary patch literal 467 zcmV;^0WAKBP)jMbdSc!#=RqXv!1Z*!>!K4t37z=}PcNU4^VsW#3?%sN2e%;>9&VJv{E(|QdFn>bG z1Qm~~v%Zfb0ILAT%u2#LAj(4!dw1LUDiur`=!$;;kkcYho~9cHi#Iz9^|&C1%F^BW zw8aBJ?o&92R1j$ZonvDKA+h$bM4rAgzd84c>5;F*qT;BxU7Xe?qn{?IIWiUK!<2Xc zm>E^it!&`Gk$D3$cR-1=%d6P`8|!OY*W(KOM)wX=WWEAyz&6Tv;J}+Qp(8PaSAqS) zvk4tNR4bhM3a|m&a4%#V?uBf_25iHm%UK|5)}~FI+P@&Oa+hz97mJ@yl9c5Ml0S z;2fRfWSSO$i@+Df%I^Fl6)g2qAEmIo5=O^f Date: Tue, 29 Sep 2020 17:45:02 -0400 Subject: [PATCH 2/3] Adjust wording --- apps.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps.json b/apps.json index 4f1aa4e24..80fccce3d 100644 --- a/apps.json +++ b/apps.json @@ -2210,11 +2210,11 @@ ] }, { "id": "fileman", - "name": "Simple file manager", + "name": "File manager", "shortName":"FileManager", "icon": "icons8-filing-cabinet-48.png", "version":"0.01", - "description": "Simple file manager, allows to examine storage, display or delete files", + "description": "Simple file manager, allows user to examine watch storage and display, load or delete individual files", "tags": "tools", "readme": "README.md", "storage": [ From 2fdd551aecf467fe41abf2ab1139d5c1d683d19d Mon Sep 17 00:00:00 2001 From: marko Date: Tue, 29 Sep 2020 17:48:16 -0400 Subject: [PATCH 3/3] Fix typo --- apps/fileman/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/fileman/README.md b/apps/fileman/README.md index df589d589..49fa9e31d 100644 --- a/apps/fileman/README.md +++ b/apps/fileman/README.md @@ -2,7 +2,7 @@ A small file manager, mostly written for debugging issues on the watch. Upon opening, the app will display a list of all the files in storage (it will contract the sub-components of a StorageFile into one entry). -When selecting a file the following option occurs (depending on file type detected by extension): +When selecting a file the following options appear (depending on file type detected by extension): - Length: file size in bytes - Display file: print out file contents on screen (will attempt to add back newlines for minimized JS code)