Add app-wget, bump versions to 2 for safety, and make the FM better

I might be worryingly forgetful regarding version bumps, it seems.
This commit is contained in:
20kdc 2018-04-24 02:24:10 +01:00
parent 0b7e6557a5
commit 6e44b1a834
3 changed files with 169 additions and 59 deletions

64
code/apps/app-wget.lua Normal file
View File

@ -0,0 +1,64 @@
-- This is released into the public domain.
-- No warranty is provided, implied or otherwise.
local event = require("event")(neo)
local neoux = require("neoux")(event, neo)
local primaryINet = neo.requireAccess("c.internet", "internet access").list()()
-- Enter URL dialog
local running = true
-- useful to perform a system update
local url = "http://20kdc.duckdns.org/neo/inst.lua"
local w = neoux.create(25, 3, nil, neoux.tcwindow(25, 3, {
neoux.tcrawview(1, 1, {"URL to download?"}),
neoux.tcfield(1, 2, 25, function (t)
url = t or url
return url
end),
neoux.tcbutton(16, 3, "Confirm", function (w)
local nurl = url
local fd = neoux.fileDialog(true)
if not fd then return end
-- download!
local req, err = primaryINet.request(nurl)
if not req then
neoux.startDialog("failed request:\n" .. tostring(err))
end
-- OpenComputers#535
req.finishConnect()
while true do
local n, n2 = req.read(neo.readBufSize)
if not n then
req.close()
fd.close()
if n2 then
neoux.startDialog("failed download:\n" .. tostring(n2))
return
else
break
end
else
if n == "" then
yielder()
else
local o, r = fd.write(n)
if not o then
req.close()
fd.close()
neoux.startDialog("failed write:\n" .. tostring(r))
return
end
end
end
end
end)
}, function (w)
w.close()
running = false
end, 0xFFFFFF, 0))
while running do
event.pull()
end

View File

@ -25,7 +25,7 @@ return {
}, },
["neo-init"] = { ["neo-init"] = {
desc = "KittenOS NEO / sys-init (startup)", desc = "KittenOS NEO / sys-init (startup)",
v = 0, v = 2,
deps = { deps = {
"neo", "neo",
"neo-icecap", "neo-icecap",
@ -40,7 +40,7 @@ return {
}, },
["neo-launcher"] = { ["neo-launcher"] = {
desc = "KittenOS NEO / Default app-launcher", desc = "KittenOS NEO / Default app-launcher",
v = 0, v = 2,
deps = { deps = {
"neo" "neo"
}, },
@ -66,7 +66,7 @@ return {
}, },
["neo-icecap"] = { ["neo-icecap"] = {
desc = "KittenOS NEO / Icecap", desc = "KittenOS NEO / Icecap",
v = 1, v = 2,
deps = { deps = {
"neo" "neo"
}, },
@ -148,9 +148,22 @@ return {
"apps/app-flash.lua" "apps/app-flash.lua"
}, },
}, },
["app-wget"] = {
desc = "KittenOS Web Retriever",
v = 2,
deps = {
"neo"
},
dirs = {
"apps"
},
files = {
"apps/app-wget.lua"
},
},
["app-claw"] = { ["app-claw"] = {
desc = "KittenOS NEO Package Manager", desc = "KittenOS NEO Package Manager",
v = 1, v = 2,
deps = { deps = {
"neo" "neo"
}, },
@ -165,7 +178,7 @@ return {
}, },
["neo-meta"] = { ["neo-meta"] = {
desc = "KittenOS NEO: Use 'All' to install to other disks", desc = "KittenOS NEO: Use 'All' to install to other disks",
v = 0, v = 2,
deps = { deps = {
"neo", "neo",
"neo-init", "neo-init",

View File

@ -16,12 +16,12 @@ end
local getFsNode, getRoot local getFsNode, getRoot
local setupCopyNode local setupCopyNode
function setupCopyNode(parent, myRoot, op, complete) function setupCopyNode(parent, myRoot, op, complete, impliedName)
local function handleResult(aRes, res) local function handleResult(aRes, res)
if aRes then if aRes then
return complete(res) return complete(res, true)
else else
return nil, setupCopyNode(parent, res, op, complete) return nil, setupCopyNode(parent, res, op, complete, impliedName)
end end
end end
return { return {
@ -29,8 +29,14 @@ function setupCopyNode(parent, myRoot, op, complete)
list = function () list = function ()
local l = {} local l = {}
table.insert(l, {"Cancel Operation: " .. op, function () table.insert(l, {"Cancel Operation: " .. op, function ()
complete(nil, false)
return false, parent return false, parent
end}) end})
if impliedName and myRoot.unknownAvailable then
table.insert(l, {"Implied: " .. impliedName, function ()
return handleResult(myRoot.selectUnknown(impliedName))
end})
end
for _, v in ipairs(myRoot.list()) do for _, v in ipairs(myRoot.list()) do
table.insert(l, {v[1], function () table.insert(l, {v[1], function ()
return handleResult(v[2]()) return handleResult(v[2]())
@ -44,16 +50,20 @@ function setupCopyNode(parent, myRoot, op, complete)
end end
} }
end end
local function setupCopyVirtualEnvironment(fs, parent, fwrap) local function setupCopyVirtualEnvironment(fs, parent, fwrap, impliedName)
if not fwrap then if not fwrap then
return false, dialog("Could not open source", parent) return false, dialog("Could not open source", parent)
end end
local myRoot = getRoot(fs, true) local myRoot = getRoot(fs, true)
-- Setup wrapping node -- Setup wrapping node
return setupCopyNode(parent, myRoot, "Copy", function (fwrap2) return setupCopyNode(parent, myRoot, "Copy", function (fwrap2, intent)
if not fwrap2 then if not fwrap2 then
fwrap.close()
if intent then
return false, dialog("Could not open dest.", parent) return false, dialog("Could not open dest.", parent)
end end
return false, parent
end
local data = fwrap.read(neo.readBufSize) local data = fwrap.read(neo.readBufSize)
while data do while data do
fwrap2.write(data) fwrap2.write(data)
@ -62,10 +72,11 @@ local function setupCopyVirtualEnvironment(fs, parent, fwrap)
fwrap.close() fwrap.close()
fwrap2.close() fwrap2.close()
return false, dialog("Completed copy.", parent) return false, dialog("Completed copy.", parent)
end) end, impliedName)
end end
getFsNode = function (fs, parent, fsc, path, mode) function getFsNode(fs, parent, fsc, path, mode)
local va = fsc.address:sub(1, 4) local va = fsc.address:sub(1, 4)
local fscrw = not fsc.isReadOnly()
if path:sub(#path, #path) == "/" then if path:sub(#path, #path) == "/" then
local t local t
local confirmedDel = false local confirmedDel = false
@ -84,11 +95,12 @@ getFsNode = function (fs, parent, fsc, path, mode)
end end
n[k + 1] = {nm, function () return nil, getFsNode(fs, t, fsc, fp, mode) end} n[k + 1] = {nm, function () return nil, getFsNode(fs, t, fsc, fp, mode) end}
end end
if fscrw then
if path ~= "/" then
local delText = "Delete" local delText = "Delete"
if confirmedDel then if confirmedDel then
delText = "Delete <ARMED>" delText = "Delete <ARMED>"
end end
if path ~= "/" then
table.insert(n, {delText, function () table.insert(n, {delText, function ()
if not confirmedDel then if not confirmedDel then
confirmedDel = true confirmedDel = true
@ -97,6 +109,23 @@ getFsNode = function (fs, parent, fsc, path, mode)
fsc.remove(path) fsc.remove(path)
return nil, dialog("Done.", parent) return nil, dialog("Done.", parent)
end}) end})
else
table.insert(n, {"Relabel Disk", function ()
return nil, {
name = "Disk Relabel...",
list = function () return {{
fsc.getLabel() or "Cancel",
function ()
return false, t
end
}} end,
unknownAvailable = true,
selectUnknown = function (tx)
fsc.setLabel(tx)
return false, t
end
}
end})
end end
table.insert(n, {"Mk. Directory", function () table.insert(n, {"Mk. Directory", function ()
return nil, { return nil, {
@ -109,9 +138,10 @@ getFsNode = function (fs, parent, fsc, path, mode)
end end
} }
end}) end})
end
return n return n
end, end,
unknownAvailable = mode ~= nil, unknownAvailable = (mode ~= nil) and ((mode == false) or fscrw),
selectUnknown = function (text) selectUnknown = function (text)
local rt, re = require("sys-filewrap").create(fsc, path .. text, mode) local rt, re = require("sys-filewrap").create(fsc, path .. text, mode)
if not rt then if not rt then
@ -136,6 +166,7 @@ getFsNode = function (fs, parent, fsc, path, mode)
elseif mode == "append" then elseif mode == "append" then
tx = "Append" tx = "Append"
end end
if fscrw or mode == false then
table.insert(n, {tx, function () table.insert(n, {tx, function ()
local rt, re = require("sys-filewrap").create(fsc, path, mode) local rt, re = require("sys-filewrap").create(fsc, path, mode)
if not rt then if not rt then
@ -144,17 +175,20 @@ getFsNode = function (fs, parent, fsc, path, mode)
return true, rt return true, rt
end}) end})
end end
end
table.insert(n, {"Copy", function () table.insert(n, {"Copy", function ()
local rt, re = require("sys-filewrap").create(fsc, path, false) local rt, re = require("sys-filewrap").create(fsc, path, false)
if not rt then if not rt then
return false, dialog("Open Error: " .. tostring(re), parent) return false, dialog("Open Error: " .. tostring(re), parent)
end end
return nil, setupCopyVirtualEnvironment(fs, parent, rt) return nil, setupCopyVirtualEnvironment(fs, parent, rt, path:match("[^/]*$") or "")
end}) end})
if fscrw then
table.insert(n, {"Delete", function () table.insert(n, {"Delete", function ()
fsc.remove(path) fsc.remove(path)
return nil, dialog("Done.", parent) return nil, dialog("Done.", parent)
end}) end})
end
return n return n
end, end,
unknownAvailable = false, unknownAvailable = false,
@ -169,32 +203,31 @@ function getRoot(fs, mode)
local l = {} local l = {}
for fsi in fs.list() do for fsi in fs.list() do
local id = fsi.getLabel() local id = fsi.getLabel()
if not id then
id = " Disk"
else
id = ":" .. id
end
if fsi == fs.primary then if fsi == fs.primary then
id = "NEO" .. id id = "NEO" .. ((id and (":" .. id)) or " Disk")
elseif fsi == fs.temporary then elseif fsi == fs.temporary then
id = "RAM" .. id id = "RAM" .. ((id and (" " .. id)) or "Disk")
else
id = id or "Disk"
end end
local used, total = fsi.spaceUsed(), fsi.spaceTotal() local used, total = fsi.spaceUsed(), fsi.spaceTotal()
local amount = string.format("%02i", math.ceil((used / total) * 100)) local amount = string.format("%02i", math.ceil((used / total) * 100))
local mb = math.floor(total / (1024 * 1024)) local mb = math.floor(total / (1024 * 1024))
if fsi.isReadOnly() then if fsi.isReadOnly() then
id = amount .. "% RO " .. mb .. "M " .. id id = "RO " .. amount .. "% " .. mb .. "M " .. id
else else
id = amount .. "% RW " .. mb .. "M " .. id id = "RW " .. amount .. "% " .. mb .. "M " .. id
end end
table.insert(l, {fsi.address:sub(1, 4) .. ": " .. id, function () table.insert(l, {fsi.address:sub(1, 4) .. " " .. id, function ()
return nil, getFsNode(fs, t, fsi, "/", mode) return nil, getFsNode(fs, t, fsi, "/", mode)
end}) end})
end end
return l return l
end, end,
unknownAvailable = false, unknownAvailable = false,
selectUnknown = function (text) end selectUnknown = function (text)
return false, dialog("Ow, that hurt...", t)
end
} }
return t return t
end end