Guest User

startup

a guest
Dec 14th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.09 KB | None | 0 0
  1. function getList()
  2.      local list = {}
  3.      local conts = ''
  4.      local worked = false
  5.      if http then
  6.          worked = true
  7.          local response = http.get("https://raw.githubusercontent.com/TheJogMan/JogProgs/master/progList")
  8.          local str = response.readAll()
  9.          conts = str
  10.          local inItem = false
  11.          local gotName = false
  12.          local gotCode = false
  13.          local gotID = false
  14.          local gotVer = false
  15.          local gotDesc = false
  16.          local objStart = 0
  17.          local curName = ''
  18.          local curCode = ''
  19.          local curID = ''
  20.          local curVer = ''
  21.          local curDesc = ''
  22.          for i = 1, string.len(str) do
  23.              local c = string.sub(str,i,i)
  24.              if inItem == false then
  25.                  if c == '{' then
  26.                      inItem = true
  27.                     end
  28.                 else
  29.                  if c == '}' then
  30.                      inItem = false
  31.                      gotName = false
  32.                      gotCode = false
  33.                      gotID = false
  34.                      gotVer = false
  35.                      gotDesc = false
  36.                      curName = ''
  37.                      curCode = ''
  38.                      curID = ''
  39.                      curVer = ''
  40.                      curDesc = ''
  41.                      objStart = 0
  42.                     else
  43.                      if gotName == false then
  44.                          if objStart == 0 then
  45.                              if c == '[' then
  46.                                  objStart = i + 1
  47.                                 end
  48.                             else
  49.                              if c == ']' then
  50.                                  local conv = string.sub(str,objStart,i - 1)
  51.                                  local conv2 = ''
  52.                                  for i = 1, string.len(conv) do
  53.                                      local c = string.sub(conv,i,i)
  54.                                      if c == '(' then
  55.                                          local n = string.sub(conv,i + 1,i + 1)
  56.                                          local r = ''
  57.                                          if n == 1 then
  58.                                              r = '('
  59.                                             elseif n == 2 then
  60.                                              r = ')'
  61.                                             elseif n == 3 then
  62.                                              r = '['
  63.                                             elseif n == 4 then
  64.                                              r = ']'
  65.                                             elseif n == 5 then
  66.                                              r = '{'
  67.                                             elseif n == 6 then
  68.                                              r = '}'
  69.                                             end
  70.                                          conv2 = conv2 .. r
  71.                                          i = i + 2
  72.                                         else
  73.                                          conv2 = conv2 .. c
  74.                                         end
  75.                                     end
  76.                                  curName = conv2
  77.                                  gotName = true
  78.                                  objStart = 0
  79.                                 end
  80.                             end
  81.                         elseif gotCode == false then
  82.                          if objStart == 0 then
  83.                              if c == '[' then
  84.                                  objStart = i + 1
  85.                                 end
  86.                             else
  87.                              if c == ']' then
  88.                                  local conv = string.sub(str,objStart,i - 1)
  89.                                  local conv2 = ''
  90.                                  for i = 1, string.len(conv) do
  91.                                      local c = string.sub(conv,i,i)
  92.                                      if c == '(' then
  93.                                          local n = string.sub(conv,i + 1,i + 1)
  94.                                          local r = ''
  95.                                          if n == 1 then
  96.                                              r = '('
  97.                                             elseif n == 2 then
  98.                                              r = ')'
  99.                                             elseif n == 3 then
  100.                                              r = '['
  101.                                             elseif n == 4 then
  102.                                              r = ']'
  103.                                             elseif n == 5 then
  104.                                              r = '{'
  105.                                             elseif n == 6 then
  106.                                              r = '}'
  107.                                             end
  108.                                          conv2 = conv2 .. r
  109.                                          i = i + 2
  110.                                         else
  111.                                          conv2 = conv2 .. c
  112.                                         end
  113.                                     end
  114.                                  curCode = conv2
  115.                                  gotCode = true
  116.                                  objStart = 0
  117.                                 end
  118.                             end
  119.                         elseif gotID == false then
  120.                          if objStart == 0 then
  121.                              if c == '[' then
  122.                                  objStart = i + 1
  123.                                 end
  124.                             else
  125.                              if c == ']' then
  126.                                  local conv = string.sub(str,objStart,i - 1)
  127.                                  local conv2 = ''
  128.                                  for i = 1, string.len(conv) do
  129.                                      local c = string.sub(conv,i,i)
  130.                                      if c == '(' then
  131.                                          local n = string.sub(conv,i + 1,i + 1)
  132.                                          local r = ''
  133.                                          if n == 1 then
  134.                                              r = '('
  135.                                             elseif n == 2 then
  136.                                              r = ')'
  137.                                             elseif n == 3 then
  138.                                              r = '['
  139.                                             elseif n == 4 then
  140.                                              r = ']'
  141.                                             elseif n == 5 then
  142.                                              r = '{'
  143.                                             elseif n == 6 then
  144.                                              r = '}'
  145.                                             end
  146.                                          conv2 = conv2 .. r
  147.                                          i = i + 2
  148.                                         else
  149.                                          conv2 = conv2 .. c
  150.                                         end
  151.                                     end
  152.                                  curID = conv2
  153.                                  gotID = true
  154.                                  objStart = 0
  155.                                 end
  156.                             end
  157.                         elseif gotDesc == false then
  158.                          if objStart == 0 then
  159.                              if c == '[' then
  160.                                  objStart = i + 1
  161.                                 end
  162.                             else
  163.                              if c == ']' then
  164.                                  local conv = string.sub(str,objStart,i - 1)
  165.                                  local conv2 = ''
  166.                                  for i = 1, string.len(conv) do
  167.                                      local c = string.sub(conv,i,i)
  168.                                      if c == '(' then
  169.                                          local n = string.sub(conv,i + 1,i + 1)
  170.                                          local r = ''
  171.                                          if n == 1 then
  172.                                              r = '('
  173.                                             elseif n == 2 then
  174.                                              r = ')'
  175.                                             elseif n == 3 then
  176.                                              r = '['
  177.                                             elseif n == 4 then
  178.                                              r = ']'
  179.                                             elseif n == 5 then
  180.                                              r = '{'
  181.                                             elseif n == 6 then
  182.                                              r = '}'
  183.                                             end
  184.                                          conv2 = conv2 .. r
  185.                                          i = i + 2
  186.                                         else
  187.                                          conv2 = conv2 .. c
  188.                                         end
  189.                                     end
  190.                                  curDesc = conv2
  191.                                  gotDesc = true
  192.                                  objStart = 0
  193.                                 end
  194.                             end
  195.                         elseif gotVer == false then
  196.                          if objStart == 0 then
  197.                              if c == '[' then
  198.                                  objStart = i + 1
  199.                                 end
  200.                             else
  201.                              if c == ']' then
  202.                                  local conv = string.sub(str,objStart,i - 1)
  203.                                  local conv2 = ''
  204.                                  for i = 1, string.len(conv) do
  205.                                      local c = string.sub(conv,i,i)
  206.                                      if c == '(' then
  207.                                          local n = string.sub(conv,i + 1,i + 1)
  208.                                          local r = ''
  209.                                          if n == 1 then
  210.                                              r = '('
  211.                                             elseif n == 2 then
  212.                                              r = ')'
  213.                                             elseif n == 3 then
  214.                                              r = '['
  215.                                             elseif n == 4 then
  216.                                              r = ']'
  217.                                             elseif n == 5 then
  218.                                              r = '{'
  219.                                             elseif n == 6 then
  220.                                              r = '}'
  221.                                             end
  222.                                          conv2 = conv2 .. r
  223.                                          i = i + 2
  224.                                         else
  225.                                          conv2 = conv2 .. c
  226.                                         end
  227.                                     end
  228.                                  curVer = conv2
  229.                                  gotVer = true
  230.                                  objStart = 0
  231.                                  local obj = {}
  232.                                  obj.name = curName
  233.                                  obj.code = curCode
  234.                                  obj.ID = curID
  235.                                  obj.ver = curVer
  236.                                  obj.desc = curDesc
  237.                                  list[#list + 1] = obj
  238.                                 end
  239.                             end
  240.                         end
  241.                     end
  242.                 end
  243.             end
  244.          response.close()
  245.         end
  246.      return list, conts, worked
  247.     end
  248.  
  249. function getListItem(id)
  250.      local obj = nil
  251.      local worked = false
  252.      for i = 1, #list do
  253.          local prog = list[i]
  254.          if prog.ID == id then
  255.              obj = prog
  256.              i = #list
  257.             end
  258.         end
  259.      return obj, worked
  260.     end
  261.  
  262. function convertInf2(inf)
  263.      local nInf = ''
  264.      for i = 1, string.len(inf) do
  265.          local c = string.sub(inf,i,i)
  266.          if c == '(' then
  267.              nInf = nInf .. '(1)'
  268.             elseif c == ')' then
  269.              nInf = nInf .. '(2)'
  270.             elseif c == '[' then
  271.              nInf = nInf .. '(3)'
  272.             elseif c == ']' then
  273.              nInf = nInf .. '(4)'
  274.             elseif c == '{' then
  275.              nInf = nInf .. '(5)'
  276.             elseif c == '}' then
  277.              nInf = nInf .. '(6)'
  278.             else
  279.              nInf = nInf .. c
  280.             end
  281.         end
  282.      return(nInf)
  283.     end
  284.  
  285. function saveChangeLog(clog)
  286.      local str = '['.. convertInf2(clog.version) ..']['.. convertInf2(clog.label) ..']'
  287.      for i = 1, #clog.changes do
  288.          str = str .. '['.. convertInf2(clog.changes[i]) ..']'
  289.         end
  290.      local file = fs.open('disk/changeLog','w')
  291.      file.write(str)
  292.      file.close()
  293.     end
  294.  
  295. function getDiskSide(label)
  296.      local peris = peripheral.getNames()
  297.      local side = nil
  298.      for i = 1, #peris do
  299.          if peripheral.getType(peris[i]) == 'drive' then
  300.              if disk.hasData(peris[i]) then
  301.                  if disk.getLabel(peris[i]) == label then
  302.                      side = peris[i]
  303.                      i = #peris
  304.                     end
  305.                 end
  306.             end
  307.         end
  308.      return(side)
  309.     end
  310. ------------------------------------------------------------------------------------------------------------------------------------------------------
  311. id = '2'
  312. ver = '1'
  313. list, conts, worked = getList()
  314. if worked then
  315.      local prog, got = getListItem(id)
  316.      if not prog.ver == ver then
  317.          term.setBackgroundColor(colors.black)
  318.          term.setTextColor(colors.white)
  319.          term.clear()
  320.          term.setCursorPos(1,1)
  321.          print('Detected an update for the installation program')
  322.          print('it will now be installed')
  323.          shell.run('pastebin run '.. prog.code)
  324.          print('rebooting')
  325.          os.reboot()
  326.         end
  327.     end
  328. changeLog = {}
  329. changeLog.version = '1'
  330. changeLog.label = 'Initial Release!'
  331. changeLog.changes = {}
  332. ------------------------------------------------------------------------------------------------------------------------------------------------------
  333. changeLog.changes[#changeLog.changes + 1] = 'Initial Release!'
  334. ------------------------------------------------------------------------------------------------------------------------------------------------------
  335. saveChangeLog(changeLog)
  336. W, H = term.getSize()
  337. if W == 51 and H == 19 then
  338.      shell.run('disk/computer/compMain')
  339.     elseif W == 39 and H == 13 then
  340.      shell.run('disk/turtle/turtleMain')
  341.     elseif W == 1 and H == 1 then
  342.      shell.run('disk/tablet/tabMain')
  343.     else
  344.      term.setBackgroundColor(colors.black)
  345.      term.setTextColor(colors.white)
  346.      term.clear()
  347.      term.setCursorPos(1,1)
  348.      print('This program is not able to run on this display')
  349.      print('The disk will be ejected and the computer will reboot')
  350.      sleep(2)
  351.     end
  352. if getDiskSide('Jog Installer') then
  353.      disk.eject(getDiskSide('Jog Installer'))
  354.     end
  355. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment