Advertisement
thegreatstudio

kreosstartup

May 2nd, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.11 KB | None | 0 0
  1. if not load then
  2.     os.loadAPI("/kreos/api/load")
  3. end
  4.  
  5. if not term.isColor and not term.isColor() then
  6.     if os.getVersion() == "CraftOS 1.3" then
  7.         print("Sorry, this OS can only run on Computers with CraftOS 1.4 and above.")
  8.         error()
  9.     end
  10.    
  11.     print("Sorry, this OS can only run on Advanced Computers")
  12.     error()
  13. end
  14.  
  15. if not http then
  16.     print("Sorry, This OS requires the HTTP API to be enabled, please enable it.")
  17.     error()
  18. end
  19.  
  20. -- local kreosLogo = {
  21.     -- " 7    7 77777   7777   7777   777 ",
  22.     -- " 7    7 7    7 7      7    7 7    ",
  23.     -- " 7   7  7    7 7      7    7 7    ",
  24.     -- " 7   7  7    7 7      7    7  77  ",
  25.     -- " 7777   77777   7777  7    7    7 ",
  26.     -- " 7   7  7    7 7      7    7    7 ",
  27.     -- " 7   7  7    7 7       7777  777  ",
  28.     -- " 7    7 7    7 7                  ",
  29.     -- " 7    7 7    7  77777777777777777 ",
  30. -- }
  31.  
  32. local kreosLogo = {
  33.     "3   3 3333  3333  777   777             bbb    ",
  34.     "3   3 3   3 3    7   7 7                  b    ",
  35.     "3  3  3   3 3    7   7 7    333  3  b     b bbb",
  36.     "3  3  3   3 3    7   7  77  3 3  3   3  bbb b b",
  37.     "333   3333  333  7   7    7 3 3bb333b33 b   b b",
  38.     "3  3  3   3 3    7   7    7 3 3b 3 3b3  b   b b",
  39.     "3  3  3   3 3     777  777  333b 333b33 bbb3bbb",
  40.     "3   3 3   3 3                                  ",
  41.     "3   3 3   3 33333333333333333333333333333333333",
  42. }
  43.  
  44. local bar = load.init(load.LOGO_IS_LOAD, kreosLogo, 5, nil, 18, colors.red, "Starting KREOS...", "KREOS Orbit V2.1", "(c) 2012 - 2013 kornichen. All rights reserved.")
  45.  
  46. local w, h = term.getSize()
  47.  
  48. function fileDownload(path, url)
  49.     local text = http.get( url ).readAll()
  50.     local file = assert( io.open( path, "w" ) )
  51.     file:write( text )
  52.     file:close()
  53. end
  54.  
  55. local function startup()
  56.     bar:triggerUpdate("Loading API's...")
  57.     sleep(0.5)
  58.     if not kapi20 then
  59.         os.loadAPI("/kreos/api/kapi20")
  60.     end
  61.     bar:triggerUpdate("Loading API's...")
  62.     sleep(0.5)
  63.     if not config then
  64.         os.loadAPI("/kreos/api/config")
  65.     end
  66.     if not esl then
  67.         os.loadAPI("/kreos/api/esl")
  68.     end
  69.     bar:triggerUpdate("Loading Files...")
  70.     sleep(0.5)
  71.     kreConfig = config.new("/kreos/config/config.kre")
  72.     kreConfig:load()
  73.     kreUsers = config.new("/kreos/config/users.kre")
  74.     kreUsers:load()
  75.     bar:triggerUpdate("Preparing KREOS...")
  76.     sleep(0.5)
  77.     firstStart = kreConfig:getBoolean("firstStart", true)
  78.     kreConfig:addCommentForKey("firstStart", "Do not change this or KREOS will not work right anymore!")
  79.     version = kreConfig:getNumber("version", 2.0)
  80.     kreConfig:addCommentForKey("version", "Do not change this or KREOS will not work right anymore!")
  81.     if fs.exists("/kreos/temp") then fs.delete("/kreos/temp") end
  82.     fs.makeDir("/kreos/temp")
  83.     if firstStart == true then
  84.         users = kreUsers:getNumber("users", 1)
  85.         kreUsers:addCommentForKey("users", "Number of users")
  86.     end
  87.     bar:triggerUpdate("Welcome to KREOS!")
  88.     sleep(0.5)
  89.     kreConfig:save()
  90.     kreUsers:save()
  91. end
  92.  
  93. local function startupbar()
  94.     bar:run(true)
  95. end
  96.  
  97. parallel.waitForAll(startupbar, startup)
  98.  
  99. -- ==============
  100. --  Login Screen
  101. -- ==============
  102.  
  103. function login()
  104.     if firstStart == true then
  105.        
  106.         kapi20.createWindow("FirstStart", "First Start of KREOS", 1, 1, w, h, false, false, true, false, true)
  107.         kapi20.addLabel("label1", "Thank you for downloading KREOS!", math.ceil(w/2)-math.ceil(string.len("Thank you for downloading KREOS!")/2), 3, true)
  108.         kapi20.addButton("button1", "Continue", math.ceil(w/2)-math.ceil(string.len("Continue")/2), 5, true, function(button)
  109.             kapi20.removeButton("button1")
  110.             kapi20.removeLabel("label1")
  111.             kapi20.createWindow("FirstStart2", "First Start of KREOS", 1, 1, w, h, false, false, true, false, true)
  112.             kapi20.addLabel("label2", "Please enter your Name and a passwort", math.ceil(w/2)-math.ceil(string.len("Please enter your Name and a passwort")/2), 3, true)
  113.             kapi20.addLabel("label3", "below this text.", math.ceil(w/2)-math.ceil(string.len("below this text.")/2), 4, true)
  114.             kapi20.addLabel("label4", "Username:", math.ceil(w/2)-math.ceil(string.len("Username:")/2), 6, true)
  115.             kapi20.addInputBox("username", 11, math.ceil(w/2)-math.ceil(11/2), 7, true, "text", nil)
  116.             kapi20.addLabel("label5", "Password:", math.ceil(w/2)-math.ceil(string.len("Password:")/2), 9, true)
  117.             kapi20.addInputBox("password", 11, math.ceil(w/2)-math.ceil(11/2), 10, true, "password", nil)
  118.             kapi20.addButton("button2", "Continue", math.ceil(w/2)-math.ceil(string.len("Continue")/2), 12, true, function(button)
  119.                
  120.                 username = kapi20.inputBoxGetValue("username")
  121.                 password = kapi20.inputBoxGetValue("password")
  122.                
  123.                 if username == nil then
  124.                     -- ...
  125.                 end
  126.                 if password == nil then
  127.                     -- ...
  128.                 end
  129.                 if username ~= nil and password ~= nil then
  130.                     tempUsername = kreUsers:getString("user1.username", username)
  131.                     kreUsers:addCommentForKey("user1.username", "Username of User 1")
  132.                     tempPassword = kreUsers:getString("user1.password", password)
  133.                     kreUsers:addCommentForKey("user1.password", "Password of User 1 (Hashed)")
  134.                
  135.                     kreUsers:save()
  136.                 end
  137.                
  138.                 kapi20.removeButton("button2")
  139.                 kapi20.removeInputBox("username")
  140.                 kapi20.removeInputBox("password")
  141.                 kapi20.removeLabel("label2")
  142.                 kapi20.removeLabel("label3")
  143.                 kapi20.removeLabel("label4")
  144.                 kapi20.removeLabel("label5")
  145.                 kapi20.createWindow("FirstStart3", "First Start of KREOS", 1, 1, w, h, false, false, true, false, true)
  146.                 kapi20.addLabel("label1", "Your done with configuration.", math.ceil(w/2)-math.ceil(string.len("Your done with configuration!")/2), 3, true)
  147.                 kapi20.addLabel("label1", "Have fun with KREOS!", math.ceil(w/2)-math.ceil(string.len("Have fun with KREOS!")/2), 4, true)
  148.                 kapi20.addLabel("label1", "~kornichen", math.ceil(w/2)-math.ceil(string.len("~kornichen")/2), 6, true)
  149.                
  150.                 kapi20.addButton("button3", "Continue", math.ceil(w/2)-math.ceil(string.len("Continue")/2), 8, true, function(button)
  151.                    
  152.                     kapi20.removeButton("button3")
  153.                    
  154.                    
  155.                     kreConfig:getBoolean("firstStart", false)
  156.                     kreConfig:reset("firstStart")
  157.                     kreConfig:save()
  158.                    
  159.                     shell.run("/kreos/sys")
  160.                    
  161.                 end)
  162.             end)
  163.         end)
  164.        
  165.         while true do
  166.             local eventType, button, x, y, i1, i2, i3 = kapi20.pullEvent()
  167.            
  168.             sleep(0.1)
  169.         end
  170.        
  171.     elseif firstStart == false then
  172.        
  173.         kapi20.createWindow("LoginScreen", "Login", 1, 1, w, h, false, false, true, false, true)
  174.         kapi20.addLabel("label1", "Username:", math.ceil(w/2)-math.ceil(string.len("Username:")/2), 4, true)
  175.         kapi20.addInputBox("username", 11, math.ceil(w/2)-math.ceil(11/2), 5, true, "text", nil)
  176.         kapi20.addLabel("label2", "Password:", math.ceil(w/2)-math.ceil(string.len("Password:")/2), 7, true)
  177.         kapi20.addInputBox("password", 11, math.ceil(w/2)-math.ceil(11/2), 8, true, "password", nil)
  178.         kapi20.addButton("button1", "Login", math.ceil(w/2)-math.ceil(string.len("Login")/2), 10, true, function(button)
  179.        
  180.             for i=1, kreUsers:getNumber("users", 1) do
  181.                 if kreUsers:getString("user" ..i.. ".username", nil) == kapi20.inputBoxGetValue("username") then
  182.                     if kreUsers:getNumber("user" ..i.. ".password", nil) == kapi20.inputBoxGetValue("password") then
  183.                         shell.run("/kreos/sys")
  184.                     end
  185.                 end
  186.             end
  187.             os.reboot()
  188.         end)
  189.        
  190.         while true do
  191.             local eventType, button, x, y, i1, i2, i3 = kapi20.pullEvent()
  192.            
  193.             sleep(0.1)
  194.         end
  195.     end
  196. end
  197.  
  198. if fs.exists("/kreos/temp/version.kre") then fs.delete("/kreos/temp/version.kre") end
  199. fileDownload("/kreos/temp/version.kre", "http://bitnut.de/kreos20/version.kre")
  200. verFile = assert(fs.open("/kreos/temp/version.kre", "r"))
  201. newestversion = verFile.readLine()
  202. if tonumber(version) < tonumber(newestversion) then
  203.     kapi20.createWindow("Update", "Update available", 1, 1, w, h, false, false, true, false, true)
  204.     kapi20.addLabel("updateLabel1", "There is a new version of KREOS available!", math.ceil(w/2)-math.ceil(string.len("There is a new version of KREOS available!")/2), 3, true)
  205.     kapi20.addLabel("updateLabel2", "Click on update to update now.", math.ceil(w/2)-math.ceil(string.len("Click on update to update now.")/2), 5, true)
  206.     kapi20.addLabel("updateLabel3", "Click on update to update later.", math.ceil(w/2)-math.ceil(string.len("Click on update to update later.")/2), 6, true)
  207.     kapi20.addButton("updateButton1", "Update", math.ceil(w/2)-string.len("Update")-1, 8, true, function(button)
  208.         if fs.exists("/kreos/temp/updatefiles.kre") then fs.delete("/kreos/temp/updatefiles.kre") end
  209.         fileDownload("/kreos/temp/updatefiles.kre", "http://bitnut.de/kreos20/updatefiles.kre")
  210.         term.clear()
  211.         print("Updating... Please wait a moment.")
  212.         for line in io.lines("/kreos/temp/updatefiles.kre") do
  213.             print("Downloading..." ..line)
  214.             if fs.exists(line) then fs.delete(line) end
  215.             fileDownload(line, "http://bitnut.de/kreos20/sysfiles/" ..line)
  216.         end
  217.         kreConfig:reset("version")
  218.         kreConfig:getNumber("version", newestversion)
  219.         kreConfig:save()
  220.         print("All files are downloaded!")
  221.         print("System will reboot now.")
  222.         sleep(1)
  223.         os.reboot()
  224.     end)
  225.     kapi20.addButton("updateButton2", "Later", math.ceil(w/2)+1, 8, true, function(button)
  226.         login()
  227.     end)
  228.    
  229.     while true do
  230.         local eventType, button, x, y, i1, i2, i3 = kapi20.pullEvent()
  231.            
  232.         sleep(0.1)
  233.     end
  234. end
  235.  
  236. login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement