First commit
commit
03d7f71550
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"editor.quickSuggestions": {
|
||||||
|
"other": false,
|
||||||
|
"comments": false,
|
||||||
|
"strings": false
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
["zocke.min.filesystemapps"] = {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
["zocke.min.filesystem"]={
|
||||||
|
["commonName"]="Zocker's Mindows Filesystem",
|
||||||
|
["description"]="Handles multiple filesystems, supports mounting and adds properties and access control to common filesystems.",
|
||||||
|
["version"]="0.0.0.1",
|
||||||
|
["enabledState"]=1,
|
||||||
|
["installDate"]=0,
|
||||||
|
["apis"]={
|
||||||
|
["fs.lua"]={
|
||||||
|
["commonName"]="File System API",
|
||||||
|
["description"]="Handles access to the filesystem for system and applications.",
|
||||||
|
["handles"]={".api","common.filesystem"},
|
||||||
|
["requirements"]={"common.kernel","common.bios","*common.filesystem"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
["apps"]={
|
||||||
|
["explorer.lua"]={
|
||||||
|
["commonName"]="File System Explorer",
|
||||||
|
["description"]="Allows viewing and editing file systems accessable to the system.",
|
||||||
|
["command"]="explorer",
|
||||||
|
["requirements"]={"common.filesystem","common.graphics","common.input"},
|
||||||
|
},
|
||||||
|
["fsedit.lua"]={
|
||||||
|
["commonName"]="File System Editor",
|
||||||
|
["description"]="",
|
||||||
|
["command"]="fsedit",
|
||||||
|
["requirements"]={".api","common.graphics","common.input"},
|
||||||
|
["missingDisables"]=true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
["signals"]={
|
||||||
|
["component_added"]=".api",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
-- system extension
|
||||||
|
function table.copy(tab)
|
||||||
|
local ret = {}
|
||||||
|
for k,v in pairs(tab) do
|
||||||
|
if type(v) == "table" then
|
||||||
|
ret[k] = table.copy(v)
|
||||||
|
else
|
||||||
|
ret[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
function string.split(inputstr, sep)
|
||||||
|
if sep == nil then
|
||||||
|
sep = "%s"
|
||||||
|
end
|
||||||
|
local t={}
|
||||||
|
local i=1
|
||||||
|
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
|
||||||
|
t[i] = str
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
-- both following functions read and write on system drive
|
||||||
|
local function readFile(filename)
|
||||||
|
-- read file and create table
|
||||||
|
end
|
||||||
|
local function writeFile(filename,tab)
|
||||||
|
-- write table to file
|
||||||
|
end
|
||||||
|
local function loadFile()
|
||||||
|
|
||||||
|
local driverControl = {}
|
||||||
|
local signalControl = {}
|
||||||
|
|
||||||
|
for dev,evs in pairs(readFile("/apps/drivers.cfg")) do
|
||||||
|
for ev,pos in pairs(evs) do
|
||||||
|
driverControl[ev] = {dev,pos}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local defaultPackageRunning = {
|
||||||
|
enabled = false
|
||||||
|
neededFor = {}
|
||||||
|
}
|
||||||
|
for name,info in pairs(packList) do
|
||||||
|
info.running = table.copy(defaultPackageRunning)
|
||||||
|
end
|
||||||
|
|
||||||
|
local apiSet = {}
|
||||||
|
|
||||||
|
local shortcuts = {["fs"]="filesystem"}
|
||||||
|
|
||||||
|
-- internal runtime api
|
||||||
|
local running = {}
|
||||||
|
local runtime = {}
|
||||||
|
local metaAccess = function(hid,rights)
|
||||||
|
return (type(hid) == "table" and setmetatable({},{__index=function(t,k)
|
||||||
|
return metaAccess(hid[k],rights)
|
||||||
|
end})) or (type(hid) == "function" and function(...)
|
||||||
|
return hid(table.copy(rights),...)
|
||||||
|
end) or hid
|
||||||
|
end
|
||||||
|
function runtime.add(scriptFunction,dataTable,...)
|
||||||
|
local env = setmetatable({},{__index=function(t,k)
|
||||||
|
return metaAccess(apiSet[shortcuts[k] or k])
|
||||||
|
end})
|
||||||
|
local cor,err = coroutine.create(scriptFunction,env)
|
||||||
|
if not cor then
|
||||||
|
return nil,err
|
||||||
|
end
|
||||||
|
local ok,err = coroutine.resume(cor,...)
|
||||||
|
if not ok then
|
||||||
|
return nil,err
|
||||||
|
end
|
||||||
|
local pid = table.maxn(running) + 1
|
||||||
|
running[pid] = dataTable or {}
|
||||||
|
running[pid].thread = cor
|
||||||
|
return pid
|
||||||
|
end
|
||||||
|
function runtime.status(pid)
|
||||||
|
return coroutine.status(running[pid].thread)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- initialization sequence
|
||||||
|
|
||||||
|
print("Load packages ...")
|
||||||
|
for name,info in pairs(packList) do
|
||||||
|
if info.enabledState > 0 then
|
||||||
|
local ok,err = package.enable(name)
|
||||||
|
print(" "..name..((not ok and " could not be enabled: "..err) or " enabled"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local eD = {computer.pullSignal()}
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
["screen"]={
|
||||||
|
["screen_resized"]=1,
|
||||||
|
["touch"]=1,
|
||||||
|
["drag"]=1,
|
||||||
|
["drop"]=1,
|
||||||
|
["scroll"]=1,
|
||||||
|
["walk"]=1,
|
||||||
|
},
|
||||||
|
["keyboard"]={
|
||||||
|
["key_down"]=1,
|
||||||
|
["key_up"]=1,
|
||||||
|
["clipboard"]=1,
|
||||||
|
},
|
||||||
|
["redstone"]={
|
||||||
|
["redstone_changed"]=1,
|
||||||
|
},
|
||||||
|
["motion_sensor"]={
|
||||||
|
["motion"]=1,
|
||||||
|
},
|
||||||
|
["modem"]={
|
||||||
|
["modem_message"]=1,
|
||||||
|
},
|
||||||
|
["robot"]={
|
||||||
|
["inventory_changed"]=0,
|
||||||
|
},
|
||||||
|
["abstract_bus"]={
|
||||||
|
["bus_message"]=0,
|
||||||
|
},
|
||||||
|
}
|
@ -0,0 +1,160 @@
|
|||||||
|
local acc = {}
|
||||||
|
-- 0: for guest only asking, for else free
|
||||||
|
-- without asking : 1: user | 2: admin | 3:system
|
||||||
|
-- options : 4: with argument | 8: single asking
|
||||||
|
local perms = { -- "permName" , "permName#argument"
|
||||||
|
changePermissions = 3+4+8,
|
||||||
|
|
||||||
|
useMainComponent = 1+4,
|
||||||
|
useSystemComponent = 2+4,
|
||||||
|
bindComponent = 2+4,
|
||||||
|
releaseComponent = 3+4+8,
|
||||||
|
bindComponentType = 3+4,
|
||||||
|
releaseComponentType = 3+4+8,
|
||||||
|
|
||||||
|
changeFilesystem = 3+4,
|
||||||
|
releaseDefaultFilesystem = 2+4+8,
|
||||||
|
releaseMainFilesystem = 3+4+8,
|
||||||
|
|
||||||
|
createWindows = 1,
|
||||||
|
changeToWindow = 2,
|
||||||
|
|
||||||
|
useNetwork = 0,
|
||||||
|
bindDefaultPort = 2+4,
|
||||||
|
bindMainPort = 3+4,
|
||||||
|
releasePort = 3+4+8,
|
||||||
|
|
||||||
|
changePackages = 3+4+8,
|
||||||
|
}
|
||||||
|
local appPerms = {} -- "packageName" -> "permName" , "packageName#permName#argument"
|
||||||
|
local cfg = readFile("/apps/access.cfg")
|
||||||
|
|
||||||
|
local function splitPerm(name)
|
||||||
|
if type(name) ~= "string" or name:len() < 1 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local s = string.split(name,"#")
|
||||||
|
if not s[1] then return false end
|
||||||
|
if perms[s[1]] then
|
||||||
|
return true,nil,s[1],s[2]
|
||||||
|
end
|
||||||
|
if s[2] and appPerms[s[1]] and appPerms[s[1]][s[2]] then
|
||||||
|
return true,s[1],s[2],s[3]
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getLevel(perm)
|
||||||
|
local b,p,r,a = splitPerm(perm)
|
||||||
|
if not b then
|
||||||
|
return false,"Permission does not exist"
|
||||||
|
end
|
||||||
|
if p then
|
||||||
|
return appPerms[p][r] % 4
|
||||||
|
else
|
||||||
|
return perms[perm] % 4
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function hasArgument(perm)
|
||||||
|
local b,p,r,a = splitPerm(perm)
|
||||||
|
if not b then
|
||||||
|
return false,"Permission does not exist"
|
||||||
|
end
|
||||||
|
if p then
|
||||||
|
return appPerms[p][r] % 4
|
||||||
|
else
|
||||||
|
return perms[perm] % 4
|
||||||
|
end
|
||||||
|
return bit32.extract(perms[p],2) == 1
|
||||||
|
end
|
||||||
|
local function isSingleAsk(perm)
|
||||||
|
if not perms[perm] then
|
||||||
|
return false,"Permission does not exist"
|
||||||
|
end
|
||||||
|
return bit32.extract(perms[perm],3) == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function acc.giveAccessTo(pack,perm)
|
||||||
|
if not perms[perm] then
|
||||||
|
return false,"Permission does not exist"
|
||||||
|
end
|
||||||
|
if not package.isEnabled(pack) then
|
||||||
|
return false,"Package is not enabled"
|
||||||
|
end
|
||||||
|
if not cfg[pack] then
|
||||||
|
cfg[pack] = {}
|
||||||
|
end
|
||||||
|
cfg[pack][perm] = true
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
function acc.askAccessTo(pack,perm)
|
||||||
|
if not perms[perm] then
|
||||||
|
return false,"Permission does not exist"
|
||||||
|
end
|
||||||
|
if not package.isEnabled(pack) then
|
||||||
|
return false,"Package is not enabled"
|
||||||
|
end
|
||||||
|
if not cfg[pack] then
|
||||||
|
cfg[pack] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
function acc.hasAccessTo(pack,perm)
|
||||||
|
if not perms[perm] then
|
||||||
|
return false,"Permission does not exist"
|
||||||
|
end
|
||||||
|
if not package.isEnabled(pack) then
|
||||||
|
return false,"Package is not enabled"
|
||||||
|
end
|
||||||
|
if not cfg[pack] then
|
||||||
|
cfg[pack] = {}
|
||||||
|
end
|
||||||
|
local ok = cfg[pack][perm] ~= nil
|
||||||
|
if ok and
|
||||||
|
end
|
||||||
|
function acc.canHaveAccessTo(pack,perm)
|
||||||
|
if not perms[perm] then
|
||||||
|
return false,"Permission does not exist"
|
||||||
|
end
|
||||||
|
if not package.isEnabled(pack) then
|
||||||
|
return false,"Package is not enabled"
|
||||||
|
end
|
||||||
|
if not cfg[pack] then
|
||||||
|
cfg[pack] = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function acc.removeAccessTo(pack,perm)
|
||||||
|
if not perms[perm] then
|
||||||
|
return false,"Permission does not exist"
|
||||||
|
end
|
||||||
|
if not package.isEnabled(pack) then
|
||||||
|
return false,"Package is not enabled"
|
||||||
|
end
|
||||||
|
if not cfg[pack] then
|
||||||
|
cfg[pack] = {}
|
||||||
|
end
|
||||||
|
cfg[pack][perm] = false
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
function acc.save()
|
||||||
|
writeFile("/apps/access.cfg",cfg)
|
||||||
|
end
|
||||||
|
|
||||||
|
function acc.init()
|
||||||
|
for
|
||||||
|
end
|
||||||
|
function acc.runtime() -- also second init
|
||||||
|
local l = {}
|
||||||
|
for k,v in pairs(cfg) do
|
||||||
|
if not package.isInstalled(k) then
|
||||||
|
l[k] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for k,v in pairs(l) do
|
||||||
|
cfg[k] = nil
|
||||||
|
end
|
||||||
|
acc.save()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return acc
|
@ -0,0 +1,30 @@
|
|||||||
|
local com = {}
|
||||||
|
local devices = {}
|
||||||
|
|
||||||
|
function com.isAvailable(pid,devName)
|
||||||
|
|
||||||
|
end
|
||||||
|
function com.invoke(pid,devName,...)
|
||||||
|
|
||||||
|
end
|
||||||
|
function com.proxy(devName)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function com.init()
|
||||||
|
for k,v in components.list() do
|
||||||
|
devices[v] = {["type"] = components.type(v)} -- components type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function com.runtime()
|
||||||
|
while true do
|
||||||
|
local eD = {coroutine.yield()}
|
||||||
|
if eD[1] == "component_added" then -- component added
|
||||||
|
devices[eD[2]] = {["type"] = eD[3]}
|
||||||
|
elseif eD[1] == "component_removed" then -- component removed
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return com
|
@ -0,0 +1,105 @@
|
|||||||
|
local package = {}
|
||||||
|
local packList = readFile("/apps/installed.cfg")
|
||||||
|
local packageLoading = {}
|
||||||
|
|
||||||
|
function package.setEntry(name,info)
|
||||||
|
packList[name] = info
|
||||||
|
info.running = {}
|
||||||
|
info.running.enabled = false
|
||||||
|
end
|
||||||
|
local function packageEnableFor(info,forName)
|
||||||
|
info.running.enabled = true
|
||||||
|
if forName then
|
||||||
|
info.running.neededFor[forName] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function package.enableFor(name,forName)
|
||||||
|
local info = packList[name]
|
||||||
|
if not info then
|
||||||
|
return false,"Package is not installed"
|
||||||
|
end
|
||||||
|
if packageLoading[name] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if info.running.enabled then
|
||||||
|
return packageEnabledFor(info,forName)
|
||||||
|
end
|
||||||
|
if info.enabledState < 0 then
|
||||||
|
return false,"Package is disabled"
|
||||||
|
end
|
||||||
|
if not info.requirements then
|
||||||
|
return packageEnabledFor(info,forName)
|
||||||
|
end
|
||||||
|
packageLoading[name] = true
|
||||||
|
for _,v in pairs(info.requirements) do
|
||||||
|
if not package.enable(v,name) then
|
||||||
|
return false,"Requirements are missing"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return packageEnabledFor(info,forName)
|
||||||
|
end
|
||||||
|
function package.isInstalled(name)
|
||||||
|
return packList[name] ~= nil
|
||||||
|
end
|
||||||
|
function package.enable(name)
|
||||||
|
return package.enableFor(name,nil)
|
||||||
|
end
|
||||||
|
function package.isEnabled(name)
|
||||||
|
local info = packList[name]
|
||||||
|
if not info then
|
||||||
|
return false,"Package is not installed"
|
||||||
|
end
|
||||||
|
return info.running.enabled
|
||||||
|
end
|
||||||
|
function package.disable(name) do
|
||||||
|
local info = packList[name]
|
||||||
|
if not info then
|
||||||
|
return false,"Package is not installed"
|
||||||
|
end
|
||||||
|
if packageLoading[name] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
packageLoading[name] = true
|
||||||
|
for k,v in pairs(info.running.neededBy)
|
||||||
|
package.disable(name)
|
||||||
|
end
|
||||||
|
if info.requirements then
|
||||||
|
for k,v in pairs(info.requirements) do
|
||||||
|
package.disableUnneded(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for k,v in pairs(info.running.neededFor) do
|
||||||
|
package.disable(k)
|
||||||
|
end
|
||||||
|
info.running.neededFor = {}
|
||||||
|
info.running.enabled = false
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
function package.disableUnneeded(name)
|
||||||
|
local info = packList[name]
|
||||||
|
if not info then
|
||||||
|
return false,"Package is not installed"
|
||||||
|
end
|
||||||
|
if info.running.disabled then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if info.enabledState > 0 then
|
||||||
|
return false,"Package should be activated"
|
||||||
|
end
|
||||||
|
local needed = false
|
||||||
|
for k,v in pairs(info.running.neededFor)
|
||||||
|
if v then
|
||||||
|
return false,"Package is needed"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return package.disable(name)
|
||||||
|
end
|
||||||
|
function package.save()
|
||||||
|
local sav = table.copy(packList)
|
||||||
|
for name,info in pairs(sav)
|
||||||
|
info.running = nil
|
||||||
|
end
|
||||||
|
writeFile("/apps/installed.cfg",sav)
|
||||||
|
end
|
||||||
|
|
||||||
|
return package
|
Loading…
Reference in New Issue