Xslymaster

ZoSOS

Oct 12th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.00 KB | None | 0 0
  1. --[[
  2.  
  3.     ZoS was created by Zachary Knoblauch
  4.  
  5. --]]
  6.  
  7. -- API
  8.  
  9. os.loadAPI("ZROOT/API/GUIAPI")
  10.  
  11.  
  12. -- Error Handling
  13.  
  14. if not http then
  15.     print("You must have HTTP enabled in the config")
  16. end
  17.  
  18. if not term.isColor() then
  19.     print("You must be using an Advanced Computer")
  20. end
  21.  
  22. if not fs.exists("ZROOT/API/GUIAPI") then
  23.     shell.run("pastebin get qz7KGw3R ZROOT/API/GUIAPI")
  24.     os.reboot()
  25. end
  26.  
  27. -- Variables
  28.  
  29. -- os variables
  30. version = "0.1"
  31.  
  32. -- api bars and logo image loading
  33. fileCheck = GUIAPI.createBar( "bar" )
  34. skipfileCheck = GUIAPI.createDialogueBox("ZoS", {"Would you like to", "skip file checking?"}, "yn")
  35. dtopWallpaper = paintutils.loadImage("ZROOT/ICONS/.dtopWallpaper")
  36. tetrisLogo = paintutils.loadImage("ZROOT/ICONS/.tetrisLogo")
  37. sketchLogo = paintutils.loadImage("ZROOT/ICONS/.sketchLogo")
  38. firewolfLogo = paintutils.loadImage("ZROOT/ICONS/.firewolfLogo")
  39.  
  40. -- Cordinates and context menus
  41. slc = 0
  42. contextX = 0
  43. contextY = 0
  44.  
  45. -- Color Variables
  46. White = 1
  47. Orange = 2
  48. Magenta = 4
  49. LightBlue = 8
  50. Yellow = 16
  51. Lime = 32
  52. Pink = 64
  53. Gray = 128
  54. Grey = 128
  55. LightGray = 256
  56. LightGrey = 256
  57. Cyan = 512
  58. Purple = 1024
  59. Blue = 2048
  60. Brown = 4096
  61. Green = 8192
  62. Red = 16384
  63. Black = 32768
  64.  
  65. -- Tables
  66.  
  67.  
  68.  
  69. -- Functions
  70.  
  71. function main()
  72.     skipfileCheckingYN()
  73. end
  74.  
  75. function accountCreation()
  76.     print("Please select a username")
  77.     username = read()
  78.     print("Please select a password")
  79.     password = read("*")
  80.     userFile = fs.open("ZROOT/USER/.list", "w")
  81.     userFile.write(""..username)
  82.     userFile.write("\n{login="..textutils.serialize(username)..", password="..textutils.serialize(password).."}")
  83.     userFile.close()   
  84.     shell.run("mkdir ZROOT/USER/"..username)
  85.     shell.run("rm firsttime")
  86. end
  87.  
  88. function cl()
  89.     term.clear()
  90.     term.setCursorPos(1,1)
  91. end
  92.  
  93. function fatalError()
  94.     print("Please re-install ZoS, a fatal error has occurred.\nZoS will now shutdown to prevent any harm to your computer")
  95. end
  96.  
  97. function missingFileorFolder()
  98.     cl()
  99.     fatalError()
  100.     sleep(4)
  101.     os.reboot()
  102. end
  103.  
  104. function skipfileCheckingYN()
  105.     cl()
  106.     results = skipfileCheck:draw( 9, 11, 7, colors.gray, colors.lightBlue, colors.white )
  107.     if results == true then
  108.         bootUpFs()
  109.     elseif results == false then
  110.         term.setBackgroundColor(Black)
  111.         bootUp()
  112.     end
  113. end
  114.  
  115. function dlContextMenu1()
  116.     term.setTextColor(Orange)
  117.     term.setBackgroundColor(Gray)
  118.     term.setCursorPos(1, 2)
  119.     print("=-=-=-=-=-=-")
  120.     term.setCursorPos(1, 3)
  121.     term.setTextColor(Red)
  122.     print("  shutdown  ")
  123.     term.setTextColor(Orange)
  124.     term.setCursorPos(1, 4)
  125.     print("=-=-=-=-=-=-")
  126.     term.setCursorPos(1, 5)
  127.     print("  restart   ")
  128.     term.setCursorPos(1, 6)
  129.     print("=-=-=-=-=-=-")
  130.     term.setCursorPos(1, 7)
  131.     print(" Quit2Shell ")
  132.     term.setCursorPos(1, 8)
  133.     print("=-=-=-=-=-=-")
  134.     print(" =-=File=-= ")
  135. end
  136.  
  137. function dlContextMenu2()
  138.     term.setTextColor(Orange)
  139.     term.setBackgroundColor(Gray)
  140.     term.setCursorPos(contextX, contextY)
  141.     print("          ")
  142.     term.setCursorPos(contextX, contextY+1)
  143.     print("  Ink     ")
  144.     term.setCursorPos(contextX, contextY+2)
  145.     print("  Paint   ")
  146.     term.setCursorPos(contextX, contextY+3)
  147.     print("          ")
  148.  
  149. end
  150.  
  151. function fileChecking()
  152.     cl()
  153.     term.setCursorPos(19, 9)
  154.     print("Loading ZoS")
  155.     sleep(1.5)
  156.     cl()
  157.     term.setCursorPos(1, 1)
  158.     print(version)
  159.     term.setCursorPos(1, 1)
  160.     fileCheck:draw( 9,11,30,colors.white,colors.green,true,colors.black,colors.white )
  161.     sleep(1)
  162.     if not fs.exists("ZROOT") then
  163.         missingFileorFolder()
  164.     else
  165.         fileCheck:update(20)
  166.         sleep(1)
  167.     if not fs.exists("ZROOT/API") then
  168.         missingFileorFolder()
  169.     else
  170.         fileCheck:update(40)
  171.         sleep(1)
  172.     if not fs.exists("ZROOT/DOC") then
  173.         missingFileorFolder()
  174.     else
  175.         fileCheck:update(60)
  176.         sleep(1)
  177.     if not fs.exists("ZROOT/PROGRAMS") then
  178.         missingFileorFolder()
  179.     else
  180.         fileCheck:update(80)
  181.         sleep(1)
  182.     if not fs.exists("ZROOT/USER") then
  183.         missingFileorFolder()
  184.     else
  185.         fileCheck:update(90)
  186.         sleep(1)
  187.     if not fs.exists("ZROOT/ICONS") then
  188.         missingFileorFolder()
  189.     else
  190.         fileCheck:update(100)
  191.         sleep(1)
  192. end
  193.     end
  194.         end
  195.     end
  196.         end
  197.     end
  198. end
  199.  
  200. function drawDesktop()
  201.     term.clear()
  202.     term.setBackgroundColor(Blue)
  203.     term.setCursorPos(1, 1)
  204.     term.clearLine()
  205.     term.setCursorPos(1, 1)
  206.     term.setTextColor(Black)
  207.     print("[Start]")
  208.     paintutils.drawImage(dtopWallpaper, 1, 2)
  209.     paintutils.drawImage(tetrisLogo, 3, 3)
  210.     paintutils.drawImage(sketchLogo, 3, 8)
  211.     paintutils.drawImage(firewolfLogo, 11, 3)
  212.     term.setCursorPos(3, 6)
  213.     term.setBackgroundColor(Cyan)
  214.     print("Tetris")
  215.     term.setCursorPos(3, 12)
  216.     print("Sketch")
  217.     term.setCursorPos(11, 8)
  218.     print("Firewolf")
  219. end
  220.  
  221. function Desktop()
  222.     drawDesktop()
  223. while true do
  224. local event, button, X, Y = os.pullEventRaw()
  225.   if slc == 0 then
  226.     if event == "mouse_click" then
  227.       if X >=2 and X <=6 and Y>=4 and Y<=6 and button == 1 then
  228.         shell.run("ZROOT/PROGRAMS/bbtetris")
  229.         drawDesktop()
  230.       elseif X >=2 and X <=6 and Y>=8 and Y<=11 and button ==1 then
  231.         shell.run("ZROOT/PROGRAMS/Sketch")
  232.         drawDesktop()
  233.       elseif X >=11 and X <=14 and Y>=4 and Y<=6 and button ==1 then
  234.         shell.run("ZROOT/PROGRAMS/Firewolf")
  235.         drawDesktop()
  236.       elseif X >=2 and X <=8 and Y==1 and button ==1 then
  237.       dlContextMenu1()
  238.       slc = 1
  239.           elseif X >= 1 and Y >=2 and button == 2 then slc = 2
  240.             if X >=38 then
  241.             contextX = 38
  242.             end
  243.             if Y >=14 then
  244.             contextY = 14
  245.             end
  246.             if X <= 38 then
  247.             contextX = X
  248.             end
  249.             if Y <= 14 then
  250.             contextY = Y
  251.             end
  252.             dlContextMenu2()
  253.         else
  254.         drawDesktop()
  255.       end
  256.     end
  257.    elseif slc == 1 then
  258.      if X >=1 and X <=11 and button == 1 and Y== 3 then slc = 0
  259.        os.shutdown()
  260.        elseif X>=1 and X<=11 and Y==5 and button ==1 then slc = 0
  261.        os.reboot()
  262.        elseif X>=1 and X<=11 and Y==7 and button == 1 then slc = 0
  263.        term.setBackgroundColor(Black)
  264.        cl()
  265.        write("CraftOS 1.5")
  266.        break
  267.        elseif X>=1 and X<=11 and Y==9 and button == 1 then slc = 0
  268.        shell.run("ZROOT/PROGRAMS/ice-browser")
  269.        else
  270.        slc = 0
  271.        drawDesktop()
  272.      end
  273.   elseif slc == 2 then
  274.         if X >= contextX and X <= contextX+13 and Y==contextY+1 and button == 1 then slc = 0
  275.         shell.run("ZROOT/PROGRAMS/ink")
  276.         drawDesktop()
  277.           elseif X>= contextX and X <=contextX+13 and Y==contextY+2 and button == 1 then slc = 0
  278.             cl()
  279.             print("What would you like to paint?")
  280.             object = read()
  281.             shell.run("paint ZROOT/USER/"..object)
  282.             drawDesktop()
  283.               else slc = 0
  284.               drawDesktop()
  285.       end
  286.     end
  287.   end
  288. end
  289.  
  290. function bootUpFs()
  291.     shell.run("ZROOT/PROGRAMS/LoginGUI")
  292.     Desktop()
  293. end
  294.  
  295. function bootUp()
  296.     fileChecking()
  297.     shell.run("ZROOT/PROGRAMS/LoginGUI")
  298.     Desktop()
  299. end
  300.  
  301. if not fs.exists("firsttime") then
  302.     main()
  303.     elseif fs.exists("firsttime") then
  304.         print("We are now running the account creation process")
  305.         accountCreation()
  306.         os.reboot()
  307. end
  308.  
  309. -- Main
  310. main()
Advertisement
Add Comment
Please, Sign In to add comment