1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-23 10:58:06 +11:00

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

View File

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