Advertisement
Redxone

RedOS: wip

Jul 15th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.87 KB | None | 0 0
  1.  
  2.  
  3. -- Life Easier Commands --
  4. local w, h = term.getSize()
  5. local scp = term.setCursorPos
  6. local sbc = term.setBackgroundColor
  7. local stc = term.setTextColor
  8. local sp = textutils.slowPrint
  9. local cl = term.clear
  10. local needUpdate = false
  11. local iconContent = {}
  12. local clk = function(btext,x,y,color,time) sbc(color) scp(x,y) write(btext) sleep(time) end
  13. shell.setDir("")
  14.  
  15. function checkUpdate()
  16.     local res = http.get("http://www.pastebin.com/raw.php?i=mZi6TjgU")
  17.  
  18.     if res then
  19.         con = res.readAll()
  20.         res.close()
  21.  
  22.         f = fs.open(shell.getRunningProgram(),"r")
  23.         compare = f.readAll()
  24.         f.close()
  25.  
  26.         if(con ~= compare)then
  27.             needUpdate = true
  28.         else
  29.             needUpdate = false
  30.         end
  31.  
  32.     end
  33.  
  34. end
  35.  
  36. function UncodeColor(code)
  37.  
  38.     local code_colors = {
  39.  
  40.         ["0"] = colors.white,
  41.         ["1"] = colors.orange,
  42.         ["2"] = colors.magenta,
  43.         ["3"] = colors.lightBlue,
  44.         ["4"] = colors.yellow,
  45.         ["5"] = colors.lime,
  46.         ["6"] = colors.pink,
  47.         ["7"] = colors.gray,
  48.         ["8"] = colors.lightGray,
  49.         ["9"] = colors.cyan,
  50.         ["a"] = colors.purple,
  51.         ["b"] = colors.blue,
  52.         ["c"] = colors.brown,
  53.         ["d"] = colors.green,
  54.         ["e"] = colors.red,
  55.         ["f"] = colors.black,
  56.  
  57.     }
  58.  
  59.  
  60.     for k, v in pairs(code_colors) do
  61.         if(code == k)then return v end
  62.     end
  63.  
  64. end
  65.  
  66.  
  67. function drawIcon(file,x,y)
  68.  
  69.     x = x - 1
  70.     y = y - 1
  71.  
  72.     file = "tut/lol"
  73.     -- get file and content from a 5x5 pixel area --
  74.     f = fs.open(file,"r")
  75.     for i = 1, 5 do
  76.         table.insert(iconContent,f.readLine():sub(1,5))
  77.     end
  78.     f.close()
  79.  
  80.     -- now to draw the contents grabed from the icon
  81.     for i = 1, #iconContent do
  82.         -- how do i set the color?
  83.         for cf = 1, 5 do
  84.             scp(x+cf,y+i)
  85.             sbc(UncodeColor(iconContent[i]:sub(cf,cf)))
  86.             write(" ")
  87.         end
  88.     end
  89.  
  90. end
  91.  
  92.  
  93. function fadeScr()
  94.     local fadecolors = {colors.black,colors.gray,colors.lightGray,colors.white}
  95.         for i = 1, #fadecolors do
  96.          term.setBackgroundColor(fadecolors[i])
  97.          term.clear()
  98.          sleep(rate)
  99.        end
  100. end
  101.  
  102. function fadeout_complete(rate,text)
  103.     local fadecolors = {colors.white,colors.lightGray,colors.gray,colors.black}
  104.     local txtfcolors = {colors.black,colors.gray,colors.lightGray,colors.black}
  105.         for i = 1, #fadecolors do
  106.          term.setBackgroundColor(fadecolors[i])
  107.          term.clear()
  108.          term.setTextColor(txtfcolors[i])
  109.          center_complete(text)
  110.          sleep(rate)
  111.        end
  112. end
  113.  
  114. function center_x(text,y)
  115.     term.setCursorPos((w/2) - (#text/2), y)
  116.     print(text)
  117. end
  118.  
  119. function center_y(text,x)
  120.     term.setCursorPos(x, (h/2))
  121.     print(text)
  122. end
  123.  
  124. function center_complete(text,optional_yoffset)
  125.     if(not optional_yoffset)then term.setCursorPos((w/2) - (#text/2), (h/2) ) end
  126.     if(optional_yoffset)then term.setCursorPos((w/2) - (#text/2), (h/2)+optional_yoffset) end
  127.     write(text)
  128. end
  129. -----------------------------
  130.  
  131.  
  132. -- Program Enviorment
  133. local programs = {
  134.      prgs = {},
  135.      progpath = ".RedOS/docs/",
  136.      selected=false,
  137.      inMenu = false,
  138.      menutype = '',
  139.      selID = 1,
  140.  
  141.     shortAddMenu = {
  142.  
  143.         {g="                                          "};
  144.         {g="               Add Shortcut?              "};
  145.         {g="                                          "};
  146.         {g="                                          "};
  147.         {g="           [Accept]  -  [Cancel]          "};
  148.  
  149.     },
  150.  
  151.     remMenu = {
  152.  
  153.         {g="                                          "};
  154.         {g="              Delete Program?             "};
  155.         {g="                                          "};
  156.         {g="                                          "};
  157.         {g="           [Accept]  -  [Cancel]          "};
  158.  
  159.     },
  160.  
  161.     shortRemMenu = {
  162.  
  163.         {g="                                          "};
  164.         {g="              Remove Shortcut?            "};
  165.         {g="                                          "};
  166.         {g="                                          "};
  167.         {g="           [Accept]  -  [Cancel]          "};
  168.  
  169.     },
  170.  
  171.      draw_short = function(self, state)
  172.         if(state)then shm = self.shortRemMenu else shm = self.shortAddMenu end
  173.         scp(1,(h/2) - (#shm)/2)
  174.         for i = 1, #shm do
  175.             sbc(colors.orange)
  176.             stc(colors.white)
  177.             scp(5,((h/2) - ((#shm)/2))+i)
  178.             print(shm[i].g)
  179.             sleep(0.01)
  180.         end
  181.     end,
  182.  
  183.     draw_del = function(self)
  184.         shm = self.remMenu
  185.         scp(1,(h/2) - (#shm)/2)
  186.         for i = 1, #shm do
  187.             sbc(colors.orange)
  188.             stc(colors.white)
  189.             scp(5,((h/2) - ((#shm)/2))+i)
  190.             print(shm[i].g)
  191.             sleep(0.01)
  192.         end
  193.     end,
  194.  
  195.  
  196.  
  197.      checkShort = function(self,name)
  198.         return fs.isDir(".RedOS/desktop/"..name)
  199.      end,
  200.  
  201.      deleteShort = function(self,name)
  202.          fs.delete(".RedOS/desktop/"..name)
  203.      end,
  204.  
  205.     makeShortcut = function(self,name,mkLoc)
  206.          fs.makeDir(".RedOS/desktop/"..name)
  207.          fs.copy(mkLoc, ".RedOS/desktop/"..name.."/"..name)
  208.          
  209.          shell.run("paint",".RedOS/desktop/"..name.."/icon")
  210.      end,
  211.  
  212.     getprogs = function(self)
  213.         self.prgs = {}
  214.         for k, v in pairs(fs.list(self.progpath)) do
  215.             self.prgs[k] = {sel=false,file=v,off=k,dir = fs.isDir(self.progpath..v)}
  216.         end
  217.     end,
  218.  
  219.  
  220.  
  221.     clear = function(self)
  222.         sbc(colors.white)
  223.         cl()
  224.  
  225.         sbc(colors.red)
  226.         scp(1,1)
  227.         term.clearLine()
  228.         scp(1,1)
  229.         stc(colors.white)
  230.         write("Programs")
  231.         sbc(colors.orange)
  232.         scp(w,1)
  233.         write("X")
  234.         scp((w)-9,2)
  235.         sbc(colors.red)
  236.         stc(colors.white)
  237.         self:getprogs()
  238.         for i = 2, h do
  239.             scp(w-9,i)
  240.             write(string.rep(" ",10))
  241.         end
  242.     end,
  243.  
  244.     draw = function(self)
  245.         self:clear()
  246.     end,
  247.  
  248.     update = function(self)
  249.  
  250.         sbc(colors.orange)
  251.         stc(colors.white)
  252.         center_x("Downloaded Programs",3)
  253.  
  254.  
  255.         stc(colors.black)
  256.         sbc(colors.red)
  257.         scp(w-8,3)
  258.         write("Shortcut")
  259.         scp(w-8,4)
  260.         write("Delete")
  261.         sbc(colors.white)
  262.         -- print out programs--
  263.  
  264.         -- draw programs --
  265.        
  266.  
  267.         for i = 1, #self.prgs do
  268.             if(not self.prgs[i].dir)then
  269.                 scp(1,i+3)
  270.                 stc(colors.black)
  271.                 if(self.prgs[i].sel)then sbc(colors.lightBlue) else sbc(colors.white) end
  272.                 if(self:checkShort(self.prgs[i].file))then stc(colors.green) else stc(colors.black) end
  273.                 print(self.prgs[i].file)
  274.             end
  275.         end
  276.  
  277.         a = {os.pullEvent()}
  278.  
  279.         if( (a[1] == "mouse_drag" or a[1] == "mouse_click") and a[2] == 1)then
  280.                 if(a[3] >= w and a[4] == 1)then
  281.                     clk("X",w,1,colors.red,0.2)
  282.                     self.selected=false
  283.                     setState('desktop')
  284.                 end
  285.             scp(1,2)
  286.             stc(colors.black)
  287.             --print(a[3].." | "..a[4])
  288.  
  289.             -- Button Clicks --
  290.             if(a[3] >= w-10 and a[4] == 4 and self.selected)then -- Remove File
  291.                 self:draw_del()
  292.                 self.inMenu = true
  293.                 menutype = 'remove'
  294.             end
  295.  
  296.             if(a[3] >= w-10 and a[4] == 3 and self.selected)then -- Manage Shortcut File
  297.                
  298.                 if(self:checkShort(self.prgs[self.selID].file))then
  299.                     self:draw_short(true)
  300.                     self.inMenu = true
  301.                     menutype = 'shortcut-'
  302.                 else
  303.                     self:draw_short(false)
  304.                     self.inMenu = true
  305.                     menutype = 'shortcut+'
  306.                 end
  307.             end
  308.  
  309.             -- cancel button --
  310.  
  311.             if(a[3] >= 29 and a[3] <= 36 and a[4] == 12 and self.inMenu == true)then
  312.                 self.selected=false
  313.                 self.inMenu=false
  314.                 self:clear()
  315.             end
  316.  
  317.             -- accept button --
  318.             if(a[3] >= 16 and a[3] <= 23 and a[4] == 12 and self.inMenu == true)then
  319.                 if(menutype == 'remove')then
  320.                     fs.delete(self.progpath..self.prgs[self.selID].file)
  321.                     if(self:checkShort(self.prgs[self.selID].file))then self:deleteShort(self.prgs[self.selID].file) end
  322.                     self:clear()
  323.                     self:update()
  324.                     self.inMenu = false
  325.                     self.selected=false
  326.                 elseif(menutype=='shortcut+')then
  327.                     self:makeShortcut(self.prgs[self.selID].file,self.progpath..self.prgs[self.selID].file)
  328.                     self.inMenu = false
  329.                     self.selected=false
  330.                     setState('desktop')
  331.                 elseif(menutype=='shortcut-')then
  332.                     self:deleteShort(self.prgs[self.selID].file)
  333.                     self:clear()
  334.                     self:update()
  335.                     self.inMenu = false
  336.                     self.selected=false
  337.                 end
  338.             end
  339.  
  340.                 -- program selection / management --
  341.             for i = 1, #self.prgs do
  342.                 if(not self.prgs[i].dir)then
  343.  
  344.                     if(a[3] >= 1 and a[3] <= #self.prgs[i].file and a[4] == i+3)then
  345.                         if(self.selected)then
  346.                             if(self.prgs[i].sel)then self.prgs[i].sel=false self.selected=false end
  347.                         else
  348.                             self.prgs[i].sel = true
  349.                             self.selected=true
  350.                             self.selID = i
  351.                         end
  352.                         self:update()
  353.                     end
  354.                 end
  355.             end
  356.         end
  357.     end,
  358. }
  359.  
  360.  
  361. -- Downloader Enviorment
  362. local downloader = {
  363.        
  364.     downloading=false,
  365.  
  366.     dwnFiles = {
  367.         {text="Kosy Mail",url="Tsjq5eVa",locdir = ".RedOS/docs/cozymail",down=false,install=true,has=false};
  368.         {text="Kosy Chat",url="cj8SKTMj", locdir = ".RedOS/docs/cozychat",down=false,install=false,has=true};
  369.     },
  370.  
  371.  
  372.     draw = function(self)
  373.         sbc(colors.white)
  374.         cl()
  375.         sbc(colors.red)
  376.         scp(1,1)
  377.         term.clearLine()
  378.         scp(1,1)
  379.         stc(colors.white)
  380.         write("Downloader")
  381.         sbc(colors.orange)
  382.         scp(w,1)
  383.         write("X")
  384.     end,
  385.     download = function(self)
  386.  
  387.         if(not http)then setState('desktop') end
  388.         self.downloading=true
  389.  
  390.         sleep(1)
  391.         for i = 1, #self.dwnFiles do
  392.             if(self.dwnFiles[i].down)then
  393.                  local res = http.get("http://www.pastebin.com/raw.php?i="..textutils.urlEncode(self.dwnFiles[i].url) )
  394.  
  395.                 if res then
  396.                      con = res.readAll()
  397.                     res.close()
  398.                 else
  399.                     changeState('desktop')
  400.                 end
  401.  
  402.                 if(self.dwnFiles[i].install)then
  403.                     f = fs.open(".temp","w")
  404.                     f.write(con)
  405.                     f.close()
  406.                     shell.run(".temp")
  407.                     fs.delete(".temp")
  408.                     self.dwnFiles[i].down = false
  409.                     self.downloading=false
  410.                 else
  411.                     f = fs.open(self.dwnFiles[i].locdir,"w")
  412.                     f.write(con)
  413.                     f.close()
  414.                     self.dwnFiles[i].down = false
  415.                     self.downloading=false
  416.                 end
  417.             end
  418.         end
  419.        
  420.     end,
  421.     update = function(self)
  422.  
  423.  
  424.         if(self.downloading)then sbc(colors.red) else sbc(colors.green) end
  425.         stc(colors.white)
  426.         scp(1,h-1)
  427.         write(string.rep(" ",w))
  428.         center_x("Download",h-1)
  429.  
  430.         sbc(colors.orange)
  431.         stc(colors.white)
  432.         center_x("Available RedOS Software",3)
  433.  
  434.         sbc(colors.white)
  435.         stc(colors.black)
  436.  
  437.         -- print out downloadablez --
  438.         for i = 1, #self.dwnFiles do
  439.             if(fs.exists(self.dwnFiles[i].locdir))then self.dwnFiles[i].has = true else self.dwnFiles[i].has = false end
  440.             if(not self.dwnFiles[i].has)then stc(colors.black) else stc(colors.red) end
  441.             if(self.dwnFiles[i].down)then sbc(colors.lightBlue) else sbc(colors.white) end
  442.             scp(1,i+4)
  443.             write(self.dwnFiles[i].text)
  444.             scp(30,i+4)
  445.             stc(colors.lightGray)
  446.             sbc(colors.white)
  447.             write(self.dwnFiles[i].url)
  448.         end
  449.  
  450.         a = {os.pullEvent()}
  451.  
  452.         if( (a[1] == "mouse_drag" or a[1] == "mouse_click") and a[2] == 1)then
  453.                 if(a[3] >= w and a[4] == 1)then
  454.                     clk("X",w,1,colors.red,0.2)
  455.                     setState('desktop')
  456.                 end
  457.  
  458.                 --Download--
  459.                 if(a[4] == 18)then
  460.                     self:download()
  461.                 end
  462.  
  463.                 for i = 1, #self.dwnFiles do
  464.                         if(a[3] >= 1 and a[3] <= #self.dwnFiles[i].text
  465.                             and a[4] == i+4 and not self.dwnFiles[i].has)then
  466.                             if(not self.dwnFiles[i].down)then self.dwnFiles[i].down = true
  467.                             else self.dwnFiles[i].down = false end
  468.                         end
  469.                 end
  470.         end
  471.     end,
  472.     clear = function(self)
  473.         sbc(colors.white)
  474.         cl()
  475.         sbc(colors.red)
  476.         scp(1,1)
  477.         term.clearLine()
  478.         scp(1,1)
  479.         stc(colors.white)
  480.         write("Downloader")
  481.         sbc(colors.orange)
  482.         scp(w,1)
  483.         write("X")
  484.     end,
  485.  
  486. }
  487.  
  488.  
  489. -- Desktop Enviorment
  490. local desktop = {
  491.    
  492.     sMenuWidth = 10,
  493.     inMenu = false,
  494.     deskLoc = ".RedOS/desktop/",
  495.     deskProgs = {};
  496.     ficons = {},
  497.     icon_width = 4,
  498.     icon_height = 5,
  499.     needUpdateInstance=false,
  500.  
  501.  
  502.     get_desk = function(self)
  503.         self.deskProgs = {}
  504.         for k, v in pairs(fs.list(self.deskLoc)) do
  505.             if(fs.isDir(self.deskLoc..v))then
  506.                 self.deskProgs[k] = {name=v,file=self.deskLoc..v.."/"..v,icon=self.deskLoc..v.."/icon"}
  507.             end
  508.         end
  509.     end,
  510.  
  511.     loadBack = function(self)
  512.         if(fs.exists(".RedOS/graphics/background"))then
  513.             paintutils.drawImage(paintutils.loadImage(".RedOS/graphics/background"), 2, 1)
  514.         end
  515.     end,
  516.  
  517.     draw_desk = function(self)
  518.        
  519.         self.ficons = {}
  520.  
  521.         local c_tab = 0
  522.         local sp_count = 0
  523.         local mx_tab = 2
  524.         local x_degree = 10
  525.         local y_degree = 7
  526.  
  527.         for i = 1, #self.deskProgs do
  528.             -- get current files icon
  529.             if(c_tab == 2)then sp_count = sp_count + 1 c_tab = 0 end
  530.             c_tab = c_tab + 1
  531.             self.ficons[i] = {icon = self.deskProgs[i].icon, x = 2, y = i+((i-1)*y_degree)}
  532.             local fileico = paintutils.loadImage(self.ficons[i].icon)
  533.             local calc_x = sp_count*x_degree
  534.             local calc_y = (c_tab-1)*y_degree
  535.             self.ficons[i].x = self.ficons[i].x + calc_x
  536.             self.ficons[i].y = calc_y + 2
  537.             paintutils.drawImage(fileico, self.ficons[i].x, self.ficons[i].y)
  538.             scp( self.ficons[i].x - 1, 1 + self.ficons[i].y + 3 )
  539.             sbc(colors.white)
  540.             stc(colors.black)
  541.             print(self.deskProgs[i].name)
  542.  
  543.         end
  544.        
  545.     end,
  546.  
  547.     draw_avaupdate = function(self)
  548.         scp(1,(h/2) - (#self.updateMenu)/2)
  549.         for i = 1, #self.updateMenu do
  550.             sbc(colors.red)
  551.             stc(colors.white)
  552.             scp(5,((h/2) - ((#self.updateMenu)/2))+i)
  553.             print(self.updateMenu[i].g)
  554.             sleep(0.01)
  555.         end
  556.     end,
  557.  
  558.     reboot = function(self)
  559.         sbc(colors.white)
  560.         cl()
  561.         stc(colors.black)
  562.         print()
  563.         fadeout_complete(0.2,"Rebooting...")
  564.         sleep(0.4)
  565.         os.reboot()
  566.     end,
  567.     shutdown = function(self)
  568.         sbc(colors.white)
  569.         cl()
  570.         stc(colors.black)
  571.         print()
  572.         fadeout_complete(0.2,"Shutting Down...")
  573.         sleep(0.4)
  574.         os.shutdown()
  575.     end,
  576.  
  577.     startMenu = {
  578.  
  579.         {text="           ",run = function() end};
  580.         {text=" Settings> ",run = function(self)  self.inMenu = false shell.run("paint", ".RedOS/graphics/background") self:draw() end};
  581.         {text=" Download> ",run = function() changeState('downloader') end};
  582.         {text=" Explorer> ",run = function(self) shell.run(".RedOS/startmenu/apps/cozyfile") self.inMenu = false self:draw() end};
  583.         {text=" Programs> ",run = function(self) changeState('programs') end};
  584.         {text=" Shell     ",run = function() sbc(colors.black) stc(colors.white) scp(1,1) cl() shell.run("shell") end};
  585.         {text=" Reboot    ",run = function(self) self:reboot() end};
  586.         {text=" Shutdown  ",run = function(self) self:shutdown() end};
  587.         {text=" Update    ",run = function(self) checkUpdate() self.inMenu =false self:draw() end};
  588.         {text="           ",run = function() end};
  589.     },
  590.  
  591.  
  592.     updateMenu = {
  593.  
  594.         {g="                                          "};
  595.         {g="             Update Available             "};
  596.         {g="                                          "};
  597.         {g="                                          "};
  598.         {g="         [Download]  -  [Not Now]         "};
  599.  
  600.     },
  601.  
  602.     clear = function(self)
  603.         fadeScr(0.08)
  604.         self:loadBack()
  605.         sbc(colors.red)
  606.         scp(1,19)
  607.         sleep(0.1)
  608.         write(string.rep(" ",w))
  609.         stc(colors.white)
  610.         scp(1,19)
  611.         checkUpdate()
  612.         self.needUpdateInstance = needUpdate
  613.         write("RedOS")
  614.         if(not self.needUpdateInstance)then
  615.             write("              Up to Date!")
  616.         else
  617.             write("             Needs Update!")
  618.         end
  619.         sbc(colors.black)
  620.         self:get_desk()
  621.         self:draw_desk()
  622.     end,
  623.     draw = function(self)
  624.         sbc(colors.white)
  625.         cl()
  626.         self:loadBack()
  627.         sbc(colors.red)
  628.         scp(1,19)
  629.         write(string.rep(" ",w))
  630.         stc(colors.white)
  631.         scp(1,19)
  632.         write("RedOS")
  633.         if(not self.needUpdateInstance)then
  634.             write("              Up to Date!") 
  635.         else
  636.             write("             Needs Update!")
  637.         end
  638.         sbc(colors.black)
  639.         self:get_desk()    
  640.     end,
  641.     update = function(self)
  642.        
  643.  
  644.         --Events--
  645.         self:draw_desk()
  646.  
  647.  
  648.         --- Check if a update is needed --
  649.         if(needUpdate)then
  650.             self:draw_avaupdate()
  651.         end
  652.  
  653.         if(self.inMenu)then
  654.             -- Drawing Da Menu --
  655.              
  656.              for i =1, #self.startMenu do
  657.                 sbc(colors.gray)
  658.                 stc(colors.white)
  659.                 scp(1,18-#self.startMenu+i)
  660.                 write(self.startMenu[i].text)
  661.              end
  662.  
  663.         end
  664.  
  665.         e = {os.pullEvent()}
  666.        
  667.         if(e[1] == "mouse_click" and not self.inMenu)then
  668.                     -- desktop item clicks brah --
  669.             for i = 1, #self.deskProgs do
  670.  
  671.                 -- Click detection --
  672.                 if(e[3] >= self.ficons[i].x and
  673.                     e[3] <= self.icon_width+self.ficons[i].x and
  674.                     e[4] >= self.ficons[i].y and
  675.                     e[4] <= self.icon_height+self.ficons[i].y ) then
  676.  
  677.                     -- run program --
  678.                     sbc(colors.black)
  679.                     stc(colors.white)
  680.                     term.clear()
  681.                     if(e[2] == 1)then
  682.                         os.run({},self.deskProgs[i].file)
  683.                         center_complete("Press Any Key To Return to RedOS")
  684.                         center_complete("Program Ran: "..self.deskProgs[i].file,1)
  685.                         os.pullEvent("key")
  686.                     elseif(e[2] == 2)then
  687.                        
  688.                         shell.run("paint ",self.deskProgs[i].icon)
  689.                     end
  690.  
  691.                     self:draw()
  692.                 end
  693.             end
  694.         end
  695.  
  696.         if(e[1] == "mouse_click" and e[2] == 1)then
  697.  
  698.             -- Start Menu Clicked --
  699.             -- e[2] == mouse_button e[3] == mouse_x, e[4] == mouse_y,
  700.             --scp(1,1)
  701.             --print("X: "..e[3].."Y: "..e[4])
  702.             if(needUpdate)then
  703.                 if(e[3] >= 14 and e[3] <= 23 and e[4] == 12)then
  704.                     -- download update --
  705.                     sbc(colors.white)
  706.                     cl()
  707.                     stc(colors.black)
  708.                     center_x("Downloading Update....",2)
  709.                     scp(1,4)
  710.                     stc(colors.lightGray)
  711.                     print("Pinging RedOS File...")
  712.                     local redRes = http.get("http://www.pastebin.com/raw.php?i=mZi6TjgU")
  713.                     if(redRes)then
  714.                         local con = redRes.readAll()
  715.                         redRes.close()
  716.                         stc(colors.green)
  717.                         print("Success!.")
  718.                         stc(colors.gray)
  719.                         print("Replaceing File...")
  720.                         fs.delete(shell.getRunningProgram())
  721.                         f = fs.open(shell.getRunningProgram(),"w")
  722.                         f.write(con)
  723.                         stc(colors.black)
  724.                         center_x("Press Any Key To Reboot",7)
  725.                         os.pullEvent("key")
  726.                         os.reboot()
  727.                     else
  728.                         stc(colors.red)
  729.                         print("Failed.")
  730.                         stc(colors.gray)
  731.                         print("Please check your connection to the internet")
  732.                         stc(colors.black)
  733.                         center_x("Press Any Key",7)
  734.                         os.pullEvent("key")
  735.                         self:draw()
  736.                     end
  737.                 end
  738.  
  739.                 if(e[3] >= 29 and e[3] <= 37 and e[4] == 12)then
  740.                     -- not now
  741.                     needUpdate=false
  742.                     self:draw()
  743.                 end
  744.             end
  745.  
  746.             if(e[3] >= 1 and e[3] <= 5 and e[4] == 19)then
  747.  
  748.                 if(not self.inMenu) then self.inMenu = true;
  749.                 elseif(self.inMenu) then self.inMenu=false end
  750.  
  751.                 sbc(colors.gray)
  752.                 scp(1,h)
  753.                 write("RedOS")
  754.                 sleep(0.1)
  755.  
  756.                 self:draw()
  757.                 self:update()
  758.  
  759.             end
  760.  
  761.  
  762.  
  763.             -- Menu Button Clicks --
  764.                 for i = 1, #self.startMenu do
  765.                     if(e[3] >= 1 and e[3] <= self.sMenuWidth and e[4] >= h-#self.startMenu and e[4] <= h and self.inMenu)then
  766.                         if(self.inMenu and e[4] == i+((h-1) - #self.startMenu))then self.startMenu[i].run(self) end
  767.                     elseif(self.inMenu)then self.inMenu = false self:draw()  end
  768.                 end
  769.             end
  770.  
  771.     end,
  772.  
  773. }
  774.  
  775. --- Without transition --
  776. function setState(s)
  777.     if(s == 'desktop')then desktop:draw() state = 'desktop' end
  778.     if(s == 'downloader')then downloader:draw() state = 'downloader' end
  779.     if(s == 'programs')then programs:draw() state = 'programs' end
  780.     ros()
  781. end
  782.  
  783. -- With Transition --
  784. function changeState(s)
  785.     if(s == 'desktop')then desktop:clear() state = 'desktop' end
  786.     if(s == 'downloader')then downloader:clear() state = 'downloader' end
  787.     if(s == 'programs')then programs:clear() state = 'programs' end
  788.     ros()
  789. end
  790.  
  791. function ros()
  792. while true do
  793.     sleep(0.001)
  794.     if(state == 'desktop')then desktop:update() end
  795.     if(state == 'downloader')then downloader:update() end
  796.     if(state == 'programs')then programs:update() end
  797. end
  798. end
  799.  
  800. changeState('desktop')
  801. ros()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement