mirror of
https://github.com/kepler155c/opus
synced 2024-12-26 16:40:27 +00:00
web running os
This commit is contained in:
parent
00c96a096b
commit
64146f8625
@ -29,7 +29,7 @@ local function remoteCommand(node, msg)
|
|||||||
error('netfs: Connection failed', 2)
|
error('netfs: Connection failed', 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local methods = { 'delete', 'exists', 'getFreeSpace', 'getSize', 'makeDir' }
|
local methods = { 'delete', 'exists', 'getFreeSpace', 'makeDir' }
|
||||||
|
|
||||||
local function resolveDir(dir, node)
|
local function resolveDir(dir, node)
|
||||||
dir = dir:gsub(node.mountPoint, '', 1)
|
dir = dir:gsub(node.mountPoint, '', 1)
|
||||||
@ -101,6 +101,16 @@ function netfs.isReadOnly(node, dir)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function netfs.getSize(node, dir)
|
||||||
|
if dir == node.mountPoint and node.directory == '' then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return remoteCommand(node, {
|
||||||
|
fn = 'getSize',
|
||||||
|
args = { resolveDir(dir, node) },
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
function netfs.find(node, spec)
|
function netfs.find(node, spec)
|
||||||
spec = resolveDir(spec, node)
|
spec = resolveDir(spec, node)
|
||||||
local list = remoteCommand(node, {
|
local list = remoteCommand(node, {
|
||||||
|
@ -1,16 +1,40 @@
|
|||||||
local class = require('class')
|
local class = require('class')
|
||||||
local Logger = require('logger')
|
local Logger = require('logger')
|
||||||
|
local Peripheral = require('peripheral')
|
||||||
|
|
||||||
local MEProvider = class()
|
local MEProvider = class()
|
||||||
|
|
||||||
function MEProvider:init(args)
|
function MEProvider:init(args)
|
||||||
self.items = {}
|
local defaults = {
|
||||||
self.name = 'ME'
|
items = { },
|
||||||
|
name = 'ME',
|
||||||
|
}
|
||||||
|
Util.merge(self, defaults)
|
||||||
|
Util.merge(self, args)
|
||||||
|
|
||||||
|
if self.side then
|
||||||
|
local mep = peripheral.wrap('bottom')
|
||||||
|
if mep then
|
||||||
|
Util.merge(self, mep)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local mep = Peripheral.getByMethod('getAvailableItems')
|
||||||
|
if mep then
|
||||||
|
Util.merge(self, mep)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.side then
|
||||||
|
local sides = {
|
||||||
|
top = 'down',
|
||||||
|
bottom = 'up',
|
||||||
|
}
|
||||||
|
self.oside = sides[self.side]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function MEProvider:isValid()
|
function MEProvider:isValid()
|
||||||
local mep = peripheral.wrap('bottom')
|
return self.getAvailableItems and self.getAvailableItems()
|
||||||
return mep and mep.getAvailableItems and mep.getAvailableItems()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Strip off color prefix
|
-- Strip off color prefix
|
||||||
@ -32,14 +56,16 @@ local function safeString(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function MEProvider:refresh()
|
function MEProvider:refresh()
|
||||||
local mep = peripheral.wrap('bottom')
|
self.items = self.getAvailableItems('all')
|
||||||
if mep then
|
|
||||||
self.items = mep.getAvailableItems('all')
|
|
||||||
for _,v in pairs(self.items) do
|
for _,v in pairs(self.items) do
|
||||||
Util.merge(v, v.item)
|
Util.merge(v, v.item)
|
||||||
v.name = safeString(v.display_name)
|
v.name = safeString(v.display_name)
|
||||||
end
|
end
|
||||||
|
return self.items
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function MEProvider:listItems()
|
||||||
|
self:refresh()
|
||||||
return self.items
|
return self.items
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -60,21 +86,14 @@ function MEProvider:craft(id, dmg, qty)
|
|||||||
|
|
||||||
if item and item.is_craftable then
|
if item and item.is_craftable then
|
||||||
|
|
||||||
local mep = peripheral.wrap('bottom')
|
Logger.log('MEProvider', 'requested crafting for: ' .. id .. ':' .. dmg .. ' qty: ' .. qty)
|
||||||
if mep then
|
self.requestCrafting({ id = id, dmg = dmg }, qty)
|
||||||
Logger.log('meProvideer', 'requested crafting for: ' .. id .. ':' .. dmg .. ' qty: ' .. qty)
|
|
||||||
mep.requestCrafting({ id = id, dmg = dmg }, qty)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function MEProvider:craftItems(items)
|
function MEProvider:craftItems(items)
|
||||||
local mep = peripheral.wrap('bottom')
|
local cpus = self.getCraftingCPUs() or { }
|
||||||
|
|
||||||
local cpus = mep.getCraftingCPUs() or { }
|
|
||||||
local count = 0
|
local count = 0
|
||||||
|
|
||||||
for _,cpu in pairs(cpus) do
|
for _,cpu in pairs(cpus) do
|
||||||
@ -94,42 +113,29 @@ function MEProvider:craftItems(items)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function MEProvider:provide(item, qty, slot)
|
function MEProvider:provide(item, qty, slot)
|
||||||
local mep = peripheral.wrap('bottom')
|
|
||||||
if mep then
|
|
||||||
return pcall(function()
|
return pcall(function()
|
||||||
mep.exportItem({
|
self.exportItem({
|
||||||
id = item.id,
|
id = item.id,
|
||||||
dmg = item.dmg
|
dmg = item.dmg
|
||||||
},
|
}, self.oside, qty, slot)
|
||||||
'up',
|
|
||||||
qty,
|
|
||||||
slot)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--if item.qty then
|
|
||||||
-- item.qty = item.qty - extractedQty
|
|
||||||
--end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function MEProvider:insert(slot, qty)
|
function MEProvider:insert(slot, qty)
|
||||||
local mep = peripheral.wrap('bottom')
|
local s, m = pcall(function() self.pullItem(self.oside, slot, qty) end)
|
||||||
if mep then
|
|
||||||
local s, m = pcall(function() mep.pullItem('up', slot, qty) end)
|
|
||||||
if not s and m then
|
if not s and m then
|
||||||
print('meProvider:pullItem')
|
print('MEProvider:pullItem')
|
||||||
print(m)
|
print(m)
|
||||||
Logger.log('meProvider', 'Insert failed, trying again')
|
Logger.log('MEProvider', 'Insert failed, trying again')
|
||||||
sleep(1)
|
sleep(1)
|
||||||
s, m = pcall(function() mep.pullItem('up', slot, qty) end)
|
s, m = pcall(function() self.pullItem('up', slot, qty) end)
|
||||||
if not s and m then
|
if not s and m then
|
||||||
print('meProvider:pullItem')
|
print('MEProvider:pullItem')
|
||||||
print(m)
|
print(m)
|
||||||
Logger.log('meProvider', 'Insert failed again')
|
Logger.log('MEProvider', 'Insert failed again')
|
||||||
read()
|
read()
|
||||||
else
|
else
|
||||||
Logger.log('meProvider', 'Insert successful')
|
Logger.log('MEProvider', 'Insert successful')
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
require = requireInjector(getfenv(1))
|
require = requireInjector(getfenv(1))
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
local class = require('class')
|
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Event = require('event')
|
|
||||||
|
|
||||||
local sandboxEnv = Util.shallowCopy(getfenv(1))
|
local sandboxEnv = Util.shallowCopy(getfenv(1))
|
||||||
setmetatable(sandboxEnv, { __index = _G })
|
setmetatable(sandboxEnv, { __index = _G })
|
||||||
@ -10,12 +8,14 @@ setmetatable(sandboxEnv, { __index = _G })
|
|||||||
multishell.setTitle(multishell.getCurrent(), 'App Store')
|
multishell.setTitle(multishell.getCurrent(), 'App Store')
|
||||||
UI:configure('Appstore', ...)
|
UI:configure('Appstore', ...)
|
||||||
|
|
||||||
|
local APP_DIR = 'usr/apps'
|
||||||
|
|
||||||
local sources = {
|
local sources = {
|
||||||
|
|
||||||
{ text = "STD Default",
|
{ text = "STD Default",
|
||||||
event = 'source',
|
event = 'source',
|
||||||
url = "http://pastebin.com/raw/zVws7eLq" }, --stock
|
url = "http://pastebin.com/raw/zVws7eLq" }, --stock
|
||||||
|
--[[
|
||||||
{ text = "Discover",
|
{ text = "Discover",
|
||||||
event = 'source',
|
event = 'source',
|
||||||
generateName = true,
|
generateName = true,
|
||||||
@ -24,9 +24,10 @@ local sources = {
|
|||||||
{ text = "Opus",
|
{ text = "Opus",
|
||||||
event = 'source',
|
event = 'source',
|
||||||
url = "http://pastebin.com/raw/ajQ91Rmn" },
|
url = "http://pastebin.com/raw/ajQ91Rmn" },
|
||||||
|
]]
|
||||||
}
|
}
|
||||||
|
|
||||||
shell.setDir('/apps')
|
shell.setDir(APP_DIR)
|
||||||
|
|
||||||
function downloadApp(app)
|
function downloadApp(app)
|
||||||
local h
|
local h
|
||||||
@ -49,8 +50,8 @@ function runApp(app, checkExists, ...)
|
|||||||
local path, fn
|
local path, fn
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
|
|
||||||
if checkExists and fs.exists(fs.combine('/apps', app.name)) then
|
if checkExists and fs.exists(fs.combine(APP_DIR, app.name)) then
|
||||||
path = fs.combine('/apps', app.name)
|
path = fs.combine(APP_DIR, app.name)
|
||||||
else
|
else
|
||||||
local program = downloadApp(app)
|
local program = downloadApp(app)
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ local installApp = function(app)
|
|||||||
return false, "Failed to download"
|
return false, "Failed to download"
|
||||||
end
|
end
|
||||||
|
|
||||||
local fullPath = fs.combine('/apps', app.name)
|
local fullPath = fs.combine(APP_DIR, app.name)
|
||||||
Util.writeFile(fullPath, program)
|
Util.writeFile(fullPath, program)
|
||||||
return true, 'Installed as ' .. fullPath
|
return true, 'Installed as ' .. fullPath
|
||||||
end
|
end
|
||||||
@ -103,6 +104,7 @@ local viewApp = function(app)
|
|||||||
|
|
||||||
Util.writeFile('/.source', program)
|
Util.writeFile('/.source', program)
|
||||||
shell.openForegroundTab('edit /.source')
|
shell.openForegroundTab('edit /.source')
|
||||||
|
fs.delete('/.source')
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -190,7 +192,7 @@ function appPage:enable(source, app)
|
|||||||
UI.Page.enable(self)
|
UI.Page.enable(self)
|
||||||
|
|
||||||
self.container.viewport:setScrollPosition(0)
|
self.container.viewport:setScrollPosition(0)
|
||||||
if fs.exists(fs.combine('/apps', app.name)) then
|
if fs.exists(fs.combine(APP_DIR, app.name)) then
|
||||||
self.menuBar.removeButton:enable('Remove')
|
self.menuBar.removeButton:enable('Remove')
|
||||||
else
|
else
|
||||||
self.menuBar.removeButton:disable('Remove')
|
self.menuBar.removeButton:disable('Remove')
|
||||||
@ -215,13 +217,13 @@ function appPage:eventHandler(event)
|
|||||||
if self.app.runOnly then
|
if self.app.runOnly then
|
||||||
s,m = runApp(self.app, false, 'uninstall')
|
s,m = runApp(self.app, false, 'uninstall')
|
||||||
else
|
else
|
||||||
fs.delete(fs.combine('/apps', self.app.name))
|
fs.delete(fs.combine(APP_DIR, self.app.name))
|
||||||
self.notification:success("Uninstalled " .. self.app.name, 3)
|
self.notification:success("Uninstalled " .. self.app.name, 3)
|
||||||
self:focusFirst(self)
|
self:focusFirst(self)
|
||||||
self.menuBar.removeButton:disable('Remove')
|
self.menuBar.removeButton:disable('Remove')
|
||||||
self.menuBar:draw()
|
self.menuBar:draw()
|
||||||
|
|
||||||
os.unregisterApp(fs.combine('/apps', self.app.name))
|
os.unregisterApp(self.app.creator .. '.' .. self.app.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'install' then
|
elseif event.type == 'install' then
|
||||||
@ -246,11 +248,11 @@ function appPage:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
os.registerApp({
|
os.registerApp({
|
||||||
run = fs.combine('/apps', self.app.name),
|
run = fs.combine(APP_DIR, self.app.name),
|
||||||
title = self.app.title,
|
title = self.app.title,
|
||||||
category = category,
|
category = category,
|
||||||
icon = self.app.icon,
|
icon = self.app.icon,
|
||||||
})
|
}, self.app.creator .. '.' .. self.app.name)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self.notification:error(m, 3)
|
self.notification:error(m, 3)
|
||||||
@ -348,7 +350,7 @@ function categoryPage.grid:sortCompare(a, b)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function categoryPage.grid:getRowTextColor(row, selected)
|
function categoryPage.grid:getRowTextColor(row, selected)
|
||||||
if fs.exists(fs.combine('/apps', row.name)) then
|
if fs.exists(fs.combine(APP_DIR, row.name)) then
|
||||||
return colors.orange
|
return colors.orange
|
||||||
end
|
end
|
||||||
return UI.Grid:getRowTextColor(row, selected)
|
return UI.Grid:getRowTextColor(row, selected)
|
||||||
@ -370,7 +372,7 @@ function categoryPage:eventHandler(event)
|
|||||||
self:draw()
|
self:draw()
|
||||||
|
|
||||||
elseif event.type == 'quit' then
|
elseif event.type == 'quit' then
|
||||||
Event.exitPullEvents()
|
UI:exitPullEvents()
|
||||||
|
|
||||||
else
|
else
|
||||||
return UI.Page.eventHandler(self, event)
|
return UI.Page.eventHandler(self, event)
|
||||||
@ -382,5 +384,5 @@ print("Retrieving catalog list")
|
|||||||
categoryPage:setSource(sources[1])
|
categoryPage:setSource(sources[1])
|
||||||
|
|
||||||
UI:setPage(categoryPage)
|
UI:setPage(categoryPage)
|
||||||
Event.pullEvents()
|
UI:pullEvents()
|
||||||
UI.term:reset()
|
UI.term:reset()
|
||||||
|
@ -158,8 +158,8 @@ function page.container:setCategory(categoryName)
|
|||||||
filtered = { }
|
filtered = { }
|
||||||
|
|
||||||
for _,v in ipairs(config.Recent) do
|
for _,v in ipairs(config.Recent) do
|
||||||
local app = Util.find(applications, 'run', v)
|
local app = Util.find(applications, 'key', v)
|
||||||
if app and fs.exists(app.run) then
|
if app then -- and fs.exists(app.run) then
|
||||||
table.insert(filtered, app)
|
table.insert(filtered, app)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -273,12 +273,12 @@ function page:eventHandler(event)
|
|||||||
|
|
||||||
elseif event.type == 'button' then
|
elseif event.type == 'button' then
|
||||||
for k,v in ipairs(config.Recent) do
|
for k,v in ipairs(config.Recent) do
|
||||||
if v == event.button.app.run then
|
if v == event.button.app.key then
|
||||||
table.remove(config.Recent, k)
|
table.remove(config.Recent, k)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.insert(config.Recent, 1, event.button.app.run)
|
table.insert(config.Recent, 1, event.button.app.key)
|
||||||
if #config.Recent > maxRecent then
|
if #config.Recent > maxRecent then
|
||||||
table.remove(config.Recent, maxRecent + 1)
|
table.remove(config.Recent, maxRecent + 1)
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ local Socket = require('socket')
|
|||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
|
|
||||||
local GROUPS_PATH = 'usr/groups'
|
local GROUPS_PATH = 'usr/groups'
|
||||||
local SCRIPTS_PATH = 'usr/scripts'
|
local SCRIPTS_PATH = 'sys/etc/scripts'
|
||||||
|
|
||||||
multishell.setTitle(multishell.getCurrent(), 'Script')
|
multishell.setTitle(multishell.getCurrent(), 'Script')
|
||||||
UI:configure('script', ...)
|
UI:configure('script', ...)
|
||||||
|
@ -79,14 +79,11 @@ end
|
|||||||
|
|
||||||
function shell.resolveProgram( _sCommand )
|
function shell.resolveProgram( _sCommand )
|
||||||
|
|
||||||
local sPath = PATH or ''
|
|
||||||
|
|
||||||
if ALIASES[ _sCommand ] ~= nil then
|
if ALIASES[ _sCommand ] ~= nil then
|
||||||
_sCommand = ALIASES[ _sCommand ]
|
_sCommand = ALIASES[ _sCommand ]
|
||||||
end
|
end
|
||||||
|
|
||||||
local path = shell.resolve(_sCommand)
|
local path = shell.resolve(_sCommand)
|
||||||
|
|
||||||
if fs.exists(path) and not fs.isDir(path) then
|
if fs.exists(path) and not fs.isDir(path) then
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
@ -105,8 +102,8 @@ function shell.resolveProgram( _sCommand )
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Otherwise, look on the path variable
|
-- Otherwise, look on the path variable
|
||||||
for sPath in string.gmatch(sPath, "[^:]+") do
|
for sPath in string.gmatch(PATH or '', "[^:]+") do
|
||||||
sPath = fs.combine( shell.resolve(sPath), _sCommand )
|
sPath = fs.combine(sPath, _sCommand )
|
||||||
if fs.exists( sPath ) and not fs.isDir( sPath ) then
|
if fs.exists( sPath ) and not fs.isDir( sPath ) then
|
||||||
return sPath
|
return sPath
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
require = requireInjector(getfenv(1))
|
require = requireInjector(getfenv(1))
|
||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
|
local SHA1 = require('sha1')
|
||||||
|
|
||||||
|
local REGISTRY_DIR = 'usr/.registry'
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
enable = false,
|
enable = false,
|
||||||
@ -13,7 +16,6 @@ function lockScreen()
|
|||||||
require = requireInjector(getfenv(1))
|
require = requireInjector(getfenv(1))
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local SHA1 = require('sha1')
|
|
||||||
|
|
||||||
local center = math.floor(UI.term.width / 2)
|
local center = math.floor(UI.term.width / 2)
|
||||||
|
|
||||||
@ -153,45 +155,20 @@ end
|
|||||||
|
|
||||||
-- move completely into overview
|
-- move completely into overview
|
||||||
-- just post event from appstore
|
-- just post event from appstore
|
||||||
function os.registerApp(entry)
|
function os.registerApp(app, key)
|
||||||
local apps = { }
|
|
||||||
Config.load('apps', apps)
|
|
||||||
|
|
||||||
local run = fs.combine(entry.run, '')
|
|
||||||
|
|
||||||
for k,app in pairs(apps) do
|
|
||||||
if app.run == run then
|
|
||||||
table.remove(apps, k)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(apps, {
|
|
||||||
run = run,
|
|
||||||
title = entry.title,
|
|
||||||
args = entry.args,
|
|
||||||
category = entry.category,
|
|
||||||
icon = entry.icon,
|
|
||||||
})
|
|
||||||
|
|
||||||
Config.update('apps', apps)
|
|
||||||
|
|
||||||
|
app.key = SHA1.sha1(key)
|
||||||
|
debug(fs.combine(REGISTRY_DIR, app.key))
|
||||||
|
debug(app)
|
||||||
|
Util.writeTable(fs.combine(REGISTRY_DIR, app.key), app)
|
||||||
os.queueEvent('os_register_app')
|
os.queueEvent('os_register_app')
|
||||||
end
|
end
|
||||||
|
|
||||||
function os.unregisterApp(run)
|
function os.unregisterApp(key)
|
||||||
|
|
||||||
local apps = { }
|
local filename = fs.combine(REGISTRY_DIR, SHA1.sha1(key))
|
||||||
Config.load('apps', apps)
|
if fs.exists(filename) then
|
||||||
|
fs.delete(filename)
|
||||||
local run = fs.combine(run, '')
|
|
||||||
|
|
||||||
for k,app in pairs(apps) do
|
|
||||||
if app.run == run then
|
|
||||||
table.remove(apps, k)
|
|
||||||
Config.update('apps', apps)
|
|
||||||
os.queueEvent('os_register_app')
|
os.queueEvent('os_register_app')
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user