mirror of https://github.com/espruino/BangleApps
New file manager app
parent
e908552a0e
commit
431b70a0f8
13
apps.json
13
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",
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
0.01: New app!
|
|
@ -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)
|
|
@ -0,0 +1 @@
|
|||
require("heatshrink").decompress(atob("mEwwhC/ABuIABgWIhAXNwAuVGBIXZmYAKC/4XXkQACC9Z3/C7YANC8J3/C8ciAAQXrO/4XbABoXhO/4XjkQACC9Z3/C7YANC78ICxuAC44wOCxAABiMRBKIAtA=="))
|
|
@ -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<file_len; ++i) {
|
||||
if (np++ > 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+n<files.length)?nstart+n : files.length;
|
||||
var menu = {
|
||||
'': { 'title': 'Dir('+nstart+'-'+nend+')/'+files.length }
|
||||
};
|
||||
menu["< prev"] = function() {
|
||||
nstart -= n;
|
||||
if (nstart<0) nstart = files.length-n>0 ? files.length-n : 0;
|
||||
menu = {};
|
||||
drawMenu();
|
||||
}
|
||||
for (var i=nstart; i<nend; ++i) {
|
||||
menu[files[i]] = visit_file.bind(null, files[i]);
|
||||
}
|
||||
menu["> next"] = function() {
|
||||
if (nstart+n<files.length) nstart += n;
|
||||
else nstart = 0;
|
||||
menu = {};
|
||||
drawMenu();
|
||||
m.move(-1);
|
||||
}
|
||||
m = E.showMenu(menu);
|
||||
}
|
||||
|
||||
function get_pruned_file_list() {
|
||||
var fl = STOR.list(/^[^\.]/);
|
||||
fl.sort();
|
||||
fl = fl.concat(STOR.list(/^\./));
|
||||
fl = fl.filter(f => (f.charCodeAt(f.length-1)>31 || f.charCodeAt(f.length-1)<2));
|
||||
return fl;
|
||||
}
|
||||
|
||||
files = get_pruned_file_list();
|
||||
drawMenu();
|
Binary file not shown.
After Width: | Height: | Size: 467 B |
Loading…
Reference in New Issue