Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local cmd = table.remove(args, 1)
- local code = table.remove(args, 1)
- function string.starts(String,Start)
- return string.sub(String,1,string.len(Start))==Start
- end
- local apps = data.load("/.apps")
- local function update(code)
- local r = "/appdata/"..code
- local m = data.load(r..".manifest")
- local success,err = pastebin.get(code, r..".manifest", true)
- if not success then print(err) end
- local nm = data.load(r..".manifest")
- print("Checking for updates...")
- for k,v in pairs(nm.Files) do
- if not m.Files[k] or m.Files[k].Version ~= v.Version then
- local p = r.."/"..k
- print("Updating "..k.."...")
- local success,err = pastebin.get(v.Code, p, true)
- if not success then print(err) end
- end
- m.Files[k] = nil
- end
- for k,v in pairs(m.Files) do fs.delete(r.."/"..k) end
- print("Done updating.")
- return nm
- end
- local function execute(code, focus, ...)
- if not apps[code][3] or not multishell.setFocus(apps[code][3]) then
- local r = "/appdata/"..code
- local m = string.starts(code, "_") and data.load(r..".manifest") or update(code)
- local id = shell.openTab(r.."/"..m.Main, r, ...)
- multishell.setTitle(id, m.Name)
- if focus then multishell.setFocus(id) end
- apps[code][3] = id
- end
- end
- local function install(code)
- local r = "/appdata/"..code
- local success,err = pastebin.get(code, r..".manifest", true)
- if not success then print(err) end
- local m = data.load(r..".manifest")
- print("Installing Software...")
- for k,v in pairs(m.Files) do
- local p = r.."/"..k
- print("Downloading "..k.."...")
- local success,err = pastebin.get(v.Code, p, true)
- if not success then print(err) end
- end
- print("Finished Installing.")
- apps[code] = {1,2,-1}
- end
- local function uninstall(code)
- local r = "/appdata/"..code
- fs.delete(r)
- fs.delete(r..".manifest")
- apps[code] = nil
- os.queueEvent("uninstall_app", code)
- end
- local function setup(code)
- if code then
- if apps[code] then return end
- install(code)
- return
- end
- for i,code in ipairs(_G.Manifest.Apps) do setup(code) end
- end
- local function create(name)
- name = "_"..name
- local r = "/appdata/"..name
- local m = { Name = name, Main = ".main" }
- data.save(r..".manifest", m)
- local mainFile = fs.open(r.."/.main", "w")
- mainFile.write("local App = app.new()\nlocal Cursor = {1,1}\nApp.EventHandler:connect(\"mouse_drag\", function(btn,x,y)\nCursor = {x,y}\nend)\nfunction App:draw()\nterm.setBackgroundColor(colors.black)\nterm.setTextColor(colors.white)\nterm.clear()\nterm.setCursorPos(1,1)\npaintutils.drawFilledBox(Cursor[1],Cursor[2],Cursor[1],Cursor[2],colors.white)\nend\nApp:start()")
- mainFile.close()
- local nfp = fs.open(r.."/.nfp", "w")
- nfp.write("0f0\nf0f\n0f0")
- nfp.close()
- apps[name] = {1,2,-1}
- end
- local function show(code)
- local r = "/appdata/"..code
- shell.run("cd", r)
- end
- local function info(code)
- local r = "/appdata/"..code
- local m = data.load(r..".manifest")
- print(m.Name.." ["..r.."] ("..code.."): "..m.Main)
- end
- local function boot(code, ...)
- local boot = data.load("/.boot")
- if not code then
- for app,data in pairs(apps) do data[3] = -1 end
- for app,args in pairs(boot) do execute(app, false, table.unpack(args)) end
- else
- local r = "/appdata/"..code
- if not fs.exists(r..".manifest") then return end
- if boot[code] then
- boot[code] = nil
- else
- boot[code] = {...}
- end
- data.save("/.boot", boot)
- end
- end
- local function list()
- for code,d in pairs(apps) do
- info(code)
- end
- end
- local function rename(code, ...)
- if not string.starts(code, "_") then return end
- local r = "/appdata/"..code
- local m = data.load(r..".manifest")
- m.Name = table.concat({...}, " ")
- data.save(r..".manifest", m)
- end
- term.setTextColor(_G.TextColor)
- term.setBackgroundColor(_G.BackgroundColor)
- term.clear()
- term.setCursorPos(1,1)
- if cmd == "execute" then execute(code, true, table.unpack(args))
- elseif cmd == "install" then install(code)
- elseif cmd == "update" then update(code)
- elseif cmd == "uninstall" then uninstall(code)
- elseif cmd == "setup" then setup(code)
- elseif cmd == "create" then create(code)
- elseif cmd == "show" then show(code)
- elseif cmd == "list" then list()
- elseif cmd == "info" then info(code)
- elseif cmd == "boot" then boot(code, table.unpack(args))
- elseif cmd == "rename" then rename(code, table.unpack(args))
- end
- data.save("/.apps", apps)
- os.queueEvent("update_apps")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement