Advertisement
dannysmc95

App Store (Installer)

Feb 24th, 2015
1,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.29 KB | None | 0 0
  1. --[[
  2.     Name: App Store Installer
  3.     Creator: DannySMc (dannysm95)
  4.     Platform: Lua Virtual Machine
  5. ]]
  6.  
  7. -- Draw Functions
  8. draw = {}
  9. draw.__index = draw
  10.  
  11. -- Configurations Functions
  12. config = {}
  13. config.__index = config
  14.  
  15. -- Database Functions
  16. db = {}
  17. db.__index = db
  18.  
  19. -- Encryption, Decryption and Hashing Functions
  20. crypt = {}
  21. crypt.__index = crypt
  22.  
  23. -- Colour Functions
  24. col = {}
  25. col.__index = col
  26.  
  27. -- Misc Functions
  28. misc = {}
  29. misc.__index = misc
  30.  
  31. -- Data Manipulation Functions
  32. data = {}
  33. data.__index = data
  34.  
  35. -- Help Functions
  36. help = {}
  37. help.__index = help
  38.  
  39. -- Image Manipulation Functions
  40. image = {}
  41. image.__index = image
  42.  
  43. -- Install Functions
  44. install = {}
  45. install.__index = install
  46.  
  47. URL_Store = "http://ccsystems.dannysmc.com/update/appstore.lua"
  48. URL_Version = "https://ccsystems.dannysmc.com/update/appstoreupdate.lua"
  49. URL_Size = "https://ccsystems.dannysmc.com/update/appstoresize.lua"
  50.  
  51. -- Start Code:
  52.  
  53. function install.main()
  54.     col.screen("white", "white")
  55.     install.bar("Install")
  56.  
  57.     term.setCursorPos(1, 5)
  58.     col.set("grey", "white")
  59.     print("> Requesting file details, please wait...")
  60.     local filesize = http.get(URL_Size)
  61.     local filevers = http.get(URL_Version)
  62.     filevers = filevers.readAll()
  63.     filesize = filesize.readAll()
  64.     print("> Store Version : "..filevers)
  65.     print("> File Size     : "..filesize)
  66.     print(" ")
  67.     print("> Downloading please wait...")
  68.     local filedata = http.get(URL_Store)
  69.     filedata = filedata.readAll()
  70.     print("> Saving at 'store'...")
  71.     if fs.exists("store") == false then
  72.         local temp = fs.open("store", "w")
  73.         temp.write(filedata)
  74.         temp.close()
  75.     else
  76.         print("> File already exists.. Using 'store1234'...")
  77.         local temp = fs.open("store1234", "w")
  78.         temp.write(filedata)
  79.         temp.close()
  80.     end
  81.     print("> Completed...")
  82.     fs.delete(shell.getRunningProgram())
  83.     sleep(2)
  84.  
  85.     os.reboot()
  86.  
  87.     while true do
  88.         local args = { os.pullEvent() }
  89.         if args[1] == "timer" then
  90.             install.bar("Install")
  91.         end
  92.     end
  93. end
  94.  
  95. function install.bar(screenname)
  96.     draw.box(1, 51, 1, 3, false, "grey", "grey")
  97.     draw.box(1, 51, 2, 1, false, "grey", "grey")
  98.     draw.texta(misc.time(), 47, 1, false, "lime", "grey")
  99.     draw.texta("Store Installer", 1, 1, false, "cyan", "grey")
  100.     draw.textc(" "..screenname, 3, false, "white", "grey")
  101. end
  102.  
  103. -- End Code
  104.  
  105. function draw.cscreen()
  106.     term.clear()
  107.     term.setCursorPos(1,1)
  108.     return
  109. end
  110.  
  111. function draw.textc(Text, Line, NextLine, Color, BkgColor)
  112.     local x, y = term.getSize()
  113.     x = x/2 - #Text/2
  114.     term.setCursorPos(x, Line)
  115.     if Color then
  116.         col.set(Color, BkgColor)
  117.     end
  118.     term.write(Text)
  119.     if NextLine then
  120.         term.setCursorPos(1, NextLine)
  121.     end
  122.     if Color then
  123.         col.reset(Color, BkgColor)
  124.     end
  125.     return true  
  126. end
  127.  
  128. function draw.texta(Text, xx, yy, NextLine, Color, BkgColor)
  129.     term.setCursorPos(xx,yy)
  130.     if Color then
  131.         col.set(Color, BkgColor)
  132.     end
  133.     term.write(Text)
  134.     if NextLine then  
  135.         term.setCursorPos(1, NextLine)
  136.     end
  137.     if Color then
  138.         col.reset(Color, BkgColor)
  139.     end
  140.     return true  
  141. end
  142.  
  143. function draw.cline(Line, NextLine)
  144.     local x, y = term.getSize()
  145.     for i = 1, x do
  146.         term.setCursorPos(i, Line)
  147.         term.write(" ")
  148.     end  
  149.     if not NextLine then  
  150.         x, y = term.getCursorPos()
  151.         term.setCursorPos(1, y+1)
  152.     end
  153.     return true  
  154. end
  155.  
  156. function draw.popup(text)
  157.     draw.box(1, 51, 8, 1, " ", "lime", "red")
  158.     draw.textc(text, 8, false, "lime", "red")
  159.     sleep(1.5)
  160. end
  161.  
  162. function draw.box(StartX, lengthX, StartY, lengthY, Text, Color, BkgColor)
  163.     local x, y = term.getSize()
  164.     if Color then
  165.         col.set(Color, BkgColor)
  166.     end
  167.     if not Text then
  168.         Text = "*"
  169.     end
  170.     lengthX = lengthX - 1
  171.     lengthY = lengthY - 1
  172.     EndX = StartX + lengthX  
  173.     EndY = StartY + lengthY
  174.     term.setCursorPos(StartX, StartY)
  175.     term.write(string.rep(Text, lengthX))
  176.     term.setCursorPos(StartX, EndY)
  177.     term.write(string.rep(Text, lengthX))
  178.     for i = StartY, EndY do
  179.         term.setCursorPos(StartX, i)
  180.         term.write(Text)
  181.         term.setCursorPos(EndX, i)    
  182.         term.write(Text)
  183.     end
  184.     col.reset(Color, BkgColor)
  185.     return true  
  186. end
  187.  
  188. local MOD = 2^32
  189. local MODM = MOD-1
  190. local function memoize(f)
  191.     local mt = {}
  192.     local t = setmetatable({}, mt)
  193.     function mt:__index(k)
  194.         local v = f(k)
  195.         t[k] = v
  196.         return v
  197.     end
  198.     return t
  199. end
  200. local function make_bitop_uncached(t, m)
  201.     local function bitop(a, b)
  202.         local res,p = 0,1
  203.         while a ~= 0 and b ~= 0 do
  204.             local am, bm = a % m, b % m
  205.             res = res + t[am][bm] * p
  206.             a = (a - am) / m
  207.             b = (b - bm) / m
  208.             p = p*m
  209.         end
  210.         res = res + (a + b) * p
  211.         return res
  212.     end
  213.     return bitop
  214. end
  215. local function make_bitop(t)
  216.     local op1 = make_bitop_uncached(t,2^1)
  217.     local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)
  218.     return make_bitop_uncached(op2, 2 ^ (t.n or 1))
  219. end
  220. local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})
  221. local function bxor(a, b, c, ...)
  222.     local z = nil
  223.     if b then
  224.         a = a % MOD
  225.         b = b % MOD
  226.         z = bxor1(a, b)
  227.         if c then z = bxor(z, c, ...) end
  228.         return z
  229.     elseif a then return a % MOD
  230.     else return 0 end
  231. end
  232. local function band(a, b, c, ...)
  233.     local z
  234.     if b then
  235.         a = a % MOD
  236.         b = b % MOD
  237.         z = ((a + b) - bxor1(a,b)) / 2
  238.         if c then z = bit32_band(z, c, ...) end
  239.         return z
  240.     elseif a then return a % MOD
  241.     else return MODM end
  242. end
  243. local function bnot(x) return (-1 - x) % MOD end
  244. local function rshift1(a, disp)
  245.     if disp < 0 then return lshift(a,-disp) end
  246.     return math.floor(a % 2 ^ 32 / 2 ^ disp)
  247. end
  248. local function rshift(x, disp)
  249.     if disp > 31 or disp < -31 then return 0 end
  250.     return rshift1(x % MOD, disp)
  251. end
  252. local function lshift(a, disp)
  253.     if disp < 0 then return rshift(a,-disp) end
  254.     return (a * 2 ^ disp) % 2 ^ 32
  255. end
  256. local function rrotate(x, disp)
  257.     x = x % MOD
  258.     disp = disp % 32
  259.     local low = band(x, 2 ^ disp - 1)
  260.     return rshift(x, disp) + lshift(low, 32 - disp)
  261. end
  262. local k = {
  263.     0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  264.     0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  265.     0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  266.     0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  267.     0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  268.     0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  269.     0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  270.     0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  271.     0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  272.     0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  273.     0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  274.     0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  275.     0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  276.     0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  277.     0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  278.     0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
  279. }
  280. local function str2hexa(s)
  281.     return (string.gsub(s, ".", function(c) return string.format("%02x", string.byte(c)) end))
  282. end
  283. local function num2s(l, n)
  284.     local s = ""
  285.     for i = 1, n do
  286.         local rem = l % 256
  287.         s = string.char(rem) .. s
  288.         l = (l - rem) / 256
  289.     end
  290.     return s
  291. end
  292. local function s232num(s, i)
  293.     local n = 0
  294.     for i = i, i + 3 do n = n*256 + string.byte(s, i) end
  295.     return n
  296. end
  297. local function preproc(msg, len)
  298.     local extra = 64 - ((len + 9) % 64)
  299.     len = num2s(8 * len, 8)
  300.     msg = msg .. "\128" .. string.rep("\0", extra) .. len
  301.     assert(#msg % 64 == 0)
  302.     return msg
  303. end
  304. local function initH256(H)
  305.     H[1] = 0x6a09e667
  306.     H[2] = 0xbb67ae85
  307.     H[3] = 0x3c6ef372
  308.     H[4] = 0xa54ff53a
  309.     H[5] = 0x510e527f
  310.     H[6] = 0x9b05688c
  311.     H[7] = 0x1f83d9ab
  312.     H[8] = 0x5be0cd19
  313.     return H
  314. end
  315. local function digestblock(msg, i, H)
  316.     local w = {}
  317.     for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end
  318.     for j = 17, 64 do
  319.         local v = w[j - 15]
  320.         local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
  321.         v = w[j - 2]
  322.         w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
  323.     end
  324.     local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]
  325.     for i = 1, 64 do
  326.         local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
  327.         local maj = bxor(band(a, b), band(a, c), band(b, c))
  328.         local t2 = s0 + maj
  329.         local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
  330.         local ch = bxor (band(e, f), band(bnot(e), g))
  331.         local t1 = h + s1 + ch + k[i] + w[i]
  332.         h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
  333.     end
  334.     H[1] = band(H[1] + a)
  335.     H[2] = band(H[2] + b)
  336.     H[3] = band(H[3] + c)
  337.     H[4] = band(H[4] + d)
  338.     H[5] = band(H[5] + e)
  339.     H[6] = band(H[6] + f)
  340.     H[7] = band(H[7] + g)
  341.     H[8] = band(H[8] + h)
  342. end
  343. function crypt.sha256(msg)
  344.     msg = preproc(msg, #msg)
  345.     local H = initH256({})
  346.     for i = 1, #msg, 64 do digestblock(msg, i, H) end
  347.     return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
  348.         num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
  349. end
  350.  
  351. function col.set(textColour, backgroundColour)
  352.     if textColour and backgroundColour then
  353.         if term.isColour() then
  354.             term.setTextColour(colours[textColour])
  355.             term.setBackgroundColour(colours[backgroundColour])
  356.             return true
  357.         else
  358.             return false
  359.         end
  360.     else
  361.         return false
  362.     end
  363. end
  364.  
  365. function col.screen(txtCol, bkgCol)
  366.     intX = 1
  367.     intY = 1
  368.     col.set(txtCol, bkgCol)
  369.     repeat
  370.         intX = 1
  371.         repeat
  372.             term.setCursorPos(intX, intY)
  373.             write(" ")
  374.             intX = intX + 1
  375.         until intX == 52
  376.         intY = intY + 1
  377.     until intY == 20
  378. end
  379.  
  380. function col.reset()
  381.     if term.isColour then
  382.         term.setTextColour(colours.white)
  383.         term.setBackgroundColour(colours.black)
  384.         return true
  385.     else
  386.         return false
  387.     end
  388. end
  389.  
  390. function misc.time()
  391.     local nTime = textutils.formatTime(os.time(), true)
  392.     if string.len(nTime) == 4 then
  393.         nTime = "0"..nTime
  394.     end
  395.     os.startTimer(1)
  396.     return nTime
  397. end
  398.  
  399. function data.wordwrap(str, limit)
  400.   limit = limit or 72
  401.   local here = 1
  402.   local buf = ""
  403.   local t = {}
  404.   str:gsub("(%s*)()(%S+)()",
  405.   function(sp, st, word, fi)
  406.         if fi-here > limit then
  407.            --# Break the line
  408.            here = st
  409.            table.insert(t, buf)
  410.            buf = word
  411.         else
  412.            buf = buf..sp..word  --# Append
  413.         end
  414.   end)
  415.   --# Tack on any leftovers
  416.   if(buf ~= "") then
  417.         table.insert(t, buf)
  418.   end
  419.   return t
  420. end
  421.  
  422.  
  423. --[[
  424.     ################## Start AppStore Installer #######################
  425. ]]
  426.  
  427. if http then
  428.     if term.isColor() then
  429.         local status, err = pcall( function ()
  430.             install.main()
  431.         end)
  432.         if not status then
  433.             draw.popup("Error: "..err)
  434.             sleep(1.5)
  435.             os.reboot()
  436.         end
  437.     else
  438.         installstatus = false
  439.     end
  440. else
  441.     installstatus = false
  442. end
  443. install.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement