Advertisement
FFGFlash

.app

Sep 16th, 2021 (edited)
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.50 KB | None | 0 0
  1. local args = {...}
  2. local cmd = table.remove(args, 1)
  3. local code = table.remove(args, 1)
  4.  
  5. function string.starts(String,Start)
  6.    return string.sub(String,1,string.len(Start))==Start
  7. end
  8.  
  9. local apps = data.load("/.apps")
  10.  
  11. local function update(code)
  12.   local r = "/appdata/"..code
  13.   local m = data.load(r..".manifest")
  14.   local success,err = pastebin.get(code, r..".manifest", true)
  15.   if not success then print(err) end
  16.   local nm = data.load(r..".manifest")
  17.   print("Checking for updates...")
  18.   for k,v in pairs(nm.Files) do
  19.     if not m.Files[k] or m.Files[k].Version ~= v.Version then
  20.       local p = r.."/"..k
  21.       print("Updating "..k.."...")
  22.       local success,err = pastebin.get(v.Code, p, true)
  23.       if not success then print(err) end
  24.     end
  25.     m.Files[k] = nil
  26.   end
  27.   for k,v in pairs(m.Files) do fs.delete(r.."/"..k) end
  28.   print("Done updating.")
  29.   return nm
  30. end
  31.  
  32. local function execute(code, focus, ...)
  33.   if not apps[code][3] or not multishell.setFocus(apps[code][3]) then
  34.     local r = "/appdata/"..code
  35.     local m = string.starts(code, "_") and data.load(r..".manifest") or update(code)
  36.     local id = shell.openTab(r.."/"..m.Main, r, ...)
  37.     multishell.setTitle(id, m.Name)
  38.     if focus then multishell.setFocus(id) end
  39.     apps[code][3] = id
  40.   end
  41. end
  42.  
  43. local function install(code)
  44.   local r = "/appdata/"..code
  45.   local success,err = pastebin.get(code, r..".manifest", true)
  46.   if not success then print(err) end
  47.   local m = data.load(r..".manifest")
  48.   print("Installing Software...")
  49.   for k,v in pairs(m.Files) do
  50.     local p = r.."/"..k
  51.     print("Downloading "..k.."...")
  52.     local success,err = pastebin.get(v.Code, p, true)
  53.     if not success then print(err) end
  54.   end
  55.   print("Finished Installing.")
  56.   apps[code] = {1,2,-1}
  57. end
  58.  
  59. local function uninstall(code)
  60.   local r = "/appdata/"..code
  61.   fs.delete(r)
  62.   fs.delete(r..".manifest")
  63.   apps[code] = nil
  64.   os.queueEvent("uninstall_app", code)
  65. end
  66.  
  67. local function setup(code)
  68.   if code then
  69.     if apps[code] then return end
  70.     install(code)
  71.     return
  72.   end
  73.   for i,code in ipairs(_G.Manifest.Apps) do setup(code) end
  74. end
  75.  
  76. local function create(name)
  77.   name = "_"..name
  78.   local r = "/appdata/"..name
  79.   local m = { Name = name, Main = ".main" }
  80.   data.save(r..".manifest", m)
  81.  
  82.   local mainFile = fs.open(r.."/.main", "w")
  83.   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()")
  84.   mainFile.close()
  85.  
  86.   local nfp = fs.open(r.."/.nfp", "w")
  87.   nfp.write("0f0\nf0f\n0f0")
  88.   nfp.close()
  89.  
  90.   apps[name] = {1,2,-1}
  91. end
  92.  
  93. local function show(code)
  94.   local r = "/appdata/"..code
  95.   shell.run("cd", r)
  96. end
  97.  
  98. local function info(code)
  99.   local r = "/appdata/"..code
  100.   local m = data.load(r..".manifest")
  101.   print(m.Name.." ["..r.."] ("..code.."): "..m.Main)
  102. end
  103.  
  104. local function boot(code, ...)
  105.   local boot = data.load("/.boot")
  106.   if not code then
  107.     for app,data in pairs(apps) do data[3] = -1 end
  108.     for app,args in pairs(boot) do execute(app, false, table.unpack(args)) end
  109.   else
  110.     local r = "/appdata/"..code
  111.     if not fs.exists(r..".manifest") then return end
  112.  
  113.     if boot[code] then
  114.       boot[code] = nil
  115.     else
  116.       boot[code] = {...}
  117.     end
  118.  
  119.     data.save("/.boot", boot)
  120.   end
  121. end
  122.  
  123. local function list()
  124.   for code,d in pairs(apps) do
  125.     info(code)
  126.   end
  127. end
  128.  
  129. local function rename(code, ...)
  130.   if not string.starts(code, "_") then return end
  131.   local r = "/appdata/"..code
  132.   local m = data.load(r..".manifest")
  133.   m.Name = table.concat({...}, " ")
  134.   data.save(r..".manifest", m)
  135. end
  136.  
  137. term.setTextColor(_G.TextColor)
  138. term.setBackgroundColor(_G.BackgroundColor)
  139. term.clear()
  140. term.setCursorPos(1,1)
  141.  
  142. if cmd == "execute" then execute(code, true, table.unpack(args))
  143. elseif cmd == "install" then install(code)
  144. elseif cmd == "update" then update(code)
  145. elseif cmd == "uninstall" then uninstall(code)
  146. elseif cmd == "setup" then setup(code)
  147. elseif cmd == "create" then create(code)
  148. elseif cmd == "show" then show(code)
  149. elseif cmd == "list" then list()
  150. elseif cmd == "info" then info(code)
  151. elseif cmd == "boot" then boot(code, table.unpack(args))
  152. elseif cmd == "rename" then rename(code, table.unpack(args))
  153. end
  154.  
  155. data.save("/.apps", apps)
  156. os.queueEvent("update_apps")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement