Advertisement
Guest User

plastic

a guest
Oct 20th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 38.84 KB | None | 0 0
  1. -- Plastic Beta v0.12
  2. -- [0.12] Bug fixes
  3. -- [0.11] Support for latest version of OpenPeripheral
  4. -- A Google Glass like OS/Programs/Whatever you want to call it
  5. -- That runs on Terminal Glasses in OpenPeripheral
  6. -- Just stick in a computer with a Terminal Glass Peripheral and run it!
  7. -- Have fun using it!
  8. -- Feel free to use my code in anyway you want!
  9. -- HOWEVER as stated by the policies of the APIs I used
  10. -- Please do not use my API keys. Just register for them
  11. -- Yourself! It's free and World Weather Online is instant!
  12.  
  13. local tArgs = {...}
  14.  
  15. local function searchArgs(text)
  16.     for k,v in pairs(tArgs) do
  17.         if v == text then return true end
  18.     end
  19.     return false
  20. end
  21.  
  22. if not http then print("Sorry, Plastic requires HTTP to run!") return end
  23.  
  24. local plasticInstallation = shell.getRunningProgram()
  25.  
  26. -- Find glass bridge
  27. local plastic = false
  28. local worldSensor = false
  29.  
  30. if fs.exists("/ocs/apis/sensor") then
  31.     os.loadAPI("ocs/apis/sensor")
  32. end
  33.  
  34. for k,v in pairs(rs.getSides()) do
  35.     if (peripheral.getType(v) == "openperipheral_glassesbridge") then
  36.         plastic = peripheral.wrap(v)
  37.         break
  38.     elseif (peripheral.getType(v) == "sensor") and (not worldSensor) then
  39.         worldSensor = sensor.wrap(v)
  40.         if not (worldSensor.getSensorName() == "worldCard") then
  41.             worldSensor = false
  42.         end
  43.     end
  44. end
  45.  
  46. if not plastic then print("Could not find Glass Bridge!") error() end
  47.  
  48. local rootApps = nil
  49.  
  50. if searchArgs("root") then
  51.     rootApps = {}
  52.     if term.isColor() then
  53.         term.setTextColor(colors.red)
  54.     end
  55.     print("-- [[ ROOT MODE ENABLED ]] --")
  56.     print("PLASTIC MAY BECOME UNSTABLE AND")
  57.     print("MAY CRASH. USE AT YOUR OWN RISK!")
  58.     if fs.isDir("/plasticApps") then
  59.  
  60.     else
  61.         print("Creating /plasticApps folder")
  62.         fs.delete("/plasticApps")
  63.         fs.makeDir("/plasticApps")
  64.     end
  65.     -- Example plastic root app
  66.     --   --[[Plastic Root App]]--
  67.     --   --NAME: Example App
  68.     --   if cmd == "hello" then
  69.     --   print("HELLO!")
  70.     --   end
  71.  
  72.     print("Searching for apps in /plasticApps")
  73.     print("")
  74.     for k,v in pairs(fs.list("/plasticApps")) do
  75.         if not(fs.isDir("/plasticApps/"..v)) then
  76.             local f = io.open("/plasticApps/"..v, "r")
  77.             if f:read("*l") == "--[[Plastic Root App]]--" then
  78.                 local name = f:read("*l"):match("%-%-NAME%: (.+)")
  79.                 dofile("/plasticApps/"..v)
  80.                 print("-- Application registered: ", name, " --")
  81.                 local data = f:read("*a")
  82.                 rootApps[name] = data
  83.             end
  84.             f:close()
  85.         end
  86.     end
  87.     print("")
  88.     print("Search completed!")
  89.     print("Starting Plastic...")
  90. end
  91.  
  92. if not(searchArgs("nodaemon")) and not(searchArgs("root")) then
  93.     term.clear()
  94.     term.setCursorPos(1,1)
  95.  
  96.     print("Plastic daemon now running. Use exit to exit")
  97. end
  98.  
  99. local function reliableSleep(time)
  100.     sleep(time)
  101. end
  102.  
  103.  
  104. -- Setup the actual "plastic"
  105. local gColors = {}
  106. gColors.red = 0xff3333
  107. gColors.blue = 0x7dd2e4
  108. gColors.yellow = 0xffff4d
  109. gColors.green = 0x4dff4d
  110. gColors.gray = 0xe0e0e0
  111. gColors.textGray = 0x818181
  112. gColors.text = 0x5a5a5a
  113. gColors.rain = 0x2e679f
  114.  
  115. plastic.clear()
  116. local mainBox = plastic.addBox(20, 20, 1, 48, gColors.gray, 0.7)
  117. local outlineT = plastic.addBox(18,18,2,2,gColors.blue,0.7)
  118. local outlineB = plastic.addBox(18,68,2,2,gColors.blue,0.7)
  119. --Startup Animation
  120. if not(searchArgs("lite")) then
  121.     -- 120, Edge is 140, Center is 80
  122.     for i = 0, 17 do
  123.         mainBox.setWidth(i*8)
  124.         outlineT.setWidth(i*8+4)
  125.         outlineB.setWidth(i*8+4)
  126.         reliableSleep(0.01)
  127.     end
  128. else
  129.     mainBox.setWidth(136)
  130.     outlineT.setWidth(140)
  131.     outlineB.setWidth(140)
  132.     mainBox.setHeight(48)
  133. end
  134. local header = plastic.addText(75, 25, "", gColors.textGray)
  135. local secondText = plastic.addText(50, 40, "", gColors.blue)
  136. local thirdText = plastic.addText(40, 55, "", gColors.blue)
  137. local mainText = plastic.addText(40, 27, "", gColors.blue)
  138. local forthText = plastic.addText(40, 55, "", gColors.text)
  139. local tempText = plastic.addText(40, 70, "", gColors.text)
  140. header.setZ(5)
  141. mainText.setZ(5)
  142. secondText.setZ(5)
  143. thirdText.setZ(5)
  144. tempText.setZ(5)
  145. forthText.setZ(5)
  146.  
  147. local function closeAnimation()
  148.     if mainBox then
  149.         pcall(mainText.delete)
  150.         pcall(secondText.delete)
  151.         pcall(header.delete)
  152.         pcall(thirdText.delete)
  153.         pcall(tempText.delete)
  154.         pcall(forthText.delete)
  155.         os.queueEvent("plastic_clock_manager", "kill")
  156.         reliableSleep(0.1)
  157.         if not(searchArgs("lite")) then
  158.             pcall(function()
  159.             for i = 17, 0, -1 do
  160.                 mainBox.setWidth(i*8)
  161.                 outlineT.setWidth(i*8+2)
  162.                 outlineB.setWidth(i*8+2)
  163.                 reliableSleep(0.01)
  164.             end
  165.             end)
  166.         end
  167.         pcall(outlineT.delete)
  168.         pcall(outlineB.delete)
  169.         pcall(mainBox.delete)
  170.     end
  171. end
  172.  
  173. local oldShutdown = os.shutdown
  174. local oldReboot = os.reboot
  175.  
  176. function os.shutdown()
  177.     closeAnimation()
  178.     return oldShutdown()
  179. end
  180.  
  181. function os.reboot()
  182.     closeAnimation()
  183.     return oldReboot()
  184. end
  185.  
  186. local function runPlastic()
  187.     -- Variables & Stuff
  188.     local corruption = false
  189.     local firstTime = true
  190.     local showClock = false
  191.  
  192.     -- Fancy functions
  193.     local gWidth = 24
  194.     local extraSupport = 0
  195.  
  196.     local function trimText(s)
  197.         return s:match("^%s*(.-)%s*$")
  198.     end
  199.  
  200.     local function plasticGet(url, noCancel)
  201.         http.request(url)
  202.         while true do
  203.             local e, rUrl, rmsg = os.pullEvent()
  204.             if (e == "http_success") and (rUrl == url) then
  205.                 if rmsg then
  206.                     local data = rmsg.readAll()
  207.                     rmsg.close()
  208.                     if data then
  209.                         return "success", data
  210.                     else
  211.                         sleep(1)
  212.                         http.request(url)
  213.                     end
  214.                 else
  215.                     sleep(1)
  216.                     http.request(url)
  217.                 end
  218.             elseif (e == "http_failure") and (rUrl == url) then
  219.                 return "failure"
  220.             elseif (e == "chat_command") and ((trimText(rUrl:lower()) == "cancel") or (trimText(rUrl:lower()) == "home")) and not(noCancel) then
  221.                 return "cancel"
  222.             end
  223.         end
  224.     end
  225.  
  226.     local function slowText(text, object)
  227.         if not(searchArgs("lite")) then
  228.             object.setText("")
  229.             for i = 1, #text do
  230.                 object.setText(string.sub(text, 1, i))
  231.                 reliableSleep(0.01)
  232.             end
  233.         else
  234.             object.setText(text)
  235.         end
  236.     end
  237.  
  238.     local function getCenter(text)
  239.         return math.ceil(((136/2)-(plastic.getStringWidth(text)*(0.65)/2))+20-0.5)
  240.     end
  241.  
  242.     local function centerText(text, object)
  243.         object.setText("")
  244.         object.setX(getCenter(text))
  245.         slowText(text, object)
  246.     end
  247.  
  248.     local function copyTable(tb)
  249.         local newTable = {}
  250.         for k,v in pairs(tb) do
  251.             newTable[k] = v
  252.         end
  253.         return newTable
  254.     end
  255.  
  256.     -- Load settings
  257.     local settings = {}
  258.     if fs.exists("/plasticOptions") and not(fs.isDir("/plasticOptions")) then
  259.         local f = io.open("/plasticOptions", "r")
  260.         local data = f:read("*a")
  261.         settings = textutils.unserialize(data)
  262.         f:close()
  263.         firstTime = false
  264.     end
  265.  
  266.     if not(settings) or not((type(settings["name"]) == "string") and (type(settings["use12hour"]) == "boolean") and
  267.         (type(settings["city"]) == "string") and (type(settings["showtime"]) == "string") and
  268.         ((settings["temperature"] == "c") or (settings["temperature"] == "f"))) and not(firstTime) then
  269.         corruption = true
  270.         header.setY(25)
  271.         header.setColor(gColors.red)
  272.         centerText("Error: Corruption", header)
  273.         mainText.setY(37)
  274.         mainText.setColor(gColors.yellow)
  275.         centerText("Options data is", mainText)
  276.         secondText.setY(47)
  277.         secondText.setColor(gColors.yellow)
  278.         centerText("corrupted.", secondText)
  279.         thirdText.setY(57)
  280.         thirdText.setColor(gColors.yellow)
  281.         thirdText.setX(40)
  282.         slowText("Resetting Plastic...", thirdText)
  283.         reliableSleep(2)
  284.         fs.delete("/plasticOptions")
  285.         closeAnimation()
  286.         reliableSleep(1)
  287.         shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  288.         error()
  289.     end
  290.  
  291.     local function getWT(city, canceller)
  292.         local function getRawWT(city, canceller) --f or c for unit
  293.             local unit = settings["temperature"]
  294.             local use12hour = settings["use12hour"]
  295.             local months = {"Jan", "Feb", "March", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"}
  296.             local resp, webData = nil
  297.             if canceller then
  298.                 resp, webData = plasticGet("http://api.worldweatheronline.com/free/v1/weather.ashx?q="..textutils.urlEncode(city).."&format=xml&extra=localObsTime&num_of_days=1&includelocation=yes&key=uyp4r5ekjns64pmpvv3qkynj", true)
  299.             else
  300.                 resp, webData = plasticGet("http://api.worldweatheronline.com/free/v1/weather.ashx?q="..textutils.urlEncode(city).."&format=xml&extra=localObsTime&num_of_days=1&includelocation=yes&key=uyp4r5ekjns64pmpvv3qkynj")
  301.             end
  302.             if resp == "cancel" then
  303.                 return "cancel"
  304.             elseif resp == "success" then
  305.             else
  306.                 error()
  307.             end
  308.             if webData:find("<error>") then
  309.                 return "invalid"
  310.             end
  311.             local city, country = webData:match([[<areaName><!%[CDATA%[([^>]+)%]%]></areaName><country><!%[CDATA%[([^>]+)%]%]></country>]])
  312.             if trimText(country) == "United States Of America" then
  313.                 country = "USA"
  314.             end
  315.             city = trimText(city):gsub(" City", "")
  316.             local resolvedLocation = city .. ", " .. country
  317.  
  318.             local currentTemp = nil
  319.             if unit == "c" then
  320.                 currentTemp = webData:match([[<current_condition>.+<temp_C>([^<]+)</temp_C>.+</current_condition>]])
  321.             elseif unit == "f" then
  322.                 currentTemp = webData:match([[<current_condition>.+<temp_F>([^<]+)</temp_F>.+</current_condition>]])
  323.             end
  324.             local currentHumidity = webData:match([[<current_condition>.+<humidity>([^<]+)</humidity>.+</current_condition>]])
  325.             local currentWeather = trimText(webData:match([[<current_condition>.+<weatherDesc><!%[CDATA%[([^>]+)%]%]></weatherDesc>.+</current_condition>]]))
  326.             local lowTemp, highTemp = nil
  327.             if unit == "c" then
  328.                 highTemp = webData:match([[<weather>.+<tempMaxC>([^<]+)</tempMaxC>.+</weather>]])
  329.                 lowTemp = webData:match([[<weather>.+<tempMinC>([^<]+)</tempMinC>.+</weather>]])
  330.             elseif unit == "f" then
  331.                 highTemp = webData:match([[<weather>.+<tempMaxF>([^<]+)</tempMaxF>.+</weather>]])
  332.                 lowTemp = webData:match([[<weather>.+<tempMinF>([^<]+)</tempMinF>.+</weather>]])
  333.             end
  334.             dayWeather = trimText(webData:match([[<weather>.+<weatherDesc><!%[CDATA%[([^<]+)%]%]></weatherDesc>.+</weather>]]))
  335.  
  336.             local time = nil
  337.             local year, month, day, rawTime, timeFormat = webData:match("<localObsDateTime>(%d+)%-(%d+)%-(%d+) (%d+:%d+) (%u+)</localObsDateTime>")
  338.             local resolvedDate = day .. " " .. months[tonumber(month)] .. " " .. year
  339.             if not use12hour then
  340.                 if timeFormat == "AM" then
  341.                     if rawTime:sub(1,2) == "12" then
  342.                         time = "0" .. rawTime:sub(3,-1)
  343.                     else
  344.                         time = rawTime
  345.                     end
  346.                 elseif timeFormat == "PM" then
  347.                     if rawTime:sub(1,2) == "12" then
  348.                         time = rawTime
  349.                     else
  350.                         time = tostring(tonumber(rawTime:sub(1,2))+12) .. rawTime:sub(3,-1)
  351.                     end
  352.                 else
  353.                     error()
  354.                 end
  355.             else
  356.                 time = rawTime .. " " .. timeFormat
  357.             end
  358.             if time:sub(1,1) == "0" then time = time:sub(2,-1) end
  359.             local current = {}
  360.             current["temp"] = currentTemp
  361.             current["weather"] = currentWeather
  362.             current["humidity"] = currentHumidity
  363.             current["time"] = time
  364.             current["date"] = resolvedDate
  365.             current["url"] = timeURL
  366.             current["location"] = resolvedLocation
  367.  
  368.             local day = {}
  369.             day["high"] = highTemp
  370.             day["low"] = lowTemp
  371.             day["weather"] = dayWeather
  372.  
  373.             return "success", current, day
  374.         end
  375.         local result = nil
  376.         result = {pcall(getRawWT, city, canceller)}
  377.         if result[1] then
  378.             table.remove(result, 1)
  379.         end
  380.         if result[1] then
  381.             return unpack(result)
  382.         else
  383.             return "failure"
  384.         end
  385.     end
  386.  
  387.     -- Get the time and weather!
  388.     local function getTime(city)
  389.         --local resp, time = getTime(settings["city"])
  390.         local resp, cur, today = getWT(city)
  391.         if resp == "success" then
  392.             return "success", cur["time"]
  393.         else return "failure" end
  394.     end
  395.  
  396.     local function displayTime(time)
  397.         if time then
  398.             if #time == 4 then
  399.                 mainText.setX(60)
  400.             elseif #time == 5 then
  401.                 mainText.setX(50)
  402.             elseif #time == 7 then
  403.                 mainText.setX(36)
  404.             elseif #time == 8 then
  405.                 mainText.setX(27)
  406.             end
  407.             mainText.setText(time)
  408.         end
  409.     end
  410.  
  411.     local function resetScreen()
  412.         thirdText.setText("")
  413.         header.setText("")
  414.         forthText.setText("")
  415.         tempText.setText("")
  416.         mainText.setText("")
  417.         mainText.setColor(gColors.text)
  418.         mainText.setScale(3)
  419.         mainText.setY(32)
  420.         secondText.setText("")
  421.         secondText.setColor(gColors.blue)
  422.         secondText.setY(57)
  423.         os.queueEvent("plastic_clock_manager", "show")
  424.         centerText("Welcome, " .. settings["name"], secondText)
  425.     end
  426.  
  427.     local function textScreen()
  428.         thirdText.setText("")
  429.         header.setText("")
  430.         mainText.setText("")
  431.         secondText.setText("")
  432.         os.queueEvent("plastic_clock_manager", "hide")
  433.         reliableSleep(0.05)
  434.         header.setScale(1)
  435.         mainText.setScale(1)
  436.         secondText.setScale(1)
  437.         thirdText.setScale(1)
  438.         header.setColor(gColors.text)
  439.         mainText.setColor(gColors.text)
  440.         secondText.setColor(gColors.text)
  441.         thirdText.setColor(gColors.text)
  442.         header.setY(25)
  443.         mainText.setY(37)
  444.         secondText.setY(47)
  445.         thirdText.setY(57)
  446.         reliableSleep(0.1)
  447.     end
  448.  
  449.     local function squeezeScreen()
  450.         thirdText.setText("")
  451.         header.setText("")
  452.         mainText.setText("")
  453.         secondText.setText("")
  454.         forthText.setText("")
  455.         os.queueEvent("plastic_clock_manager", "hide")
  456.         reliableSleep(0.05)
  457.         header.setScale(1)
  458.         mainText.setScale(1)
  459.         secondText.setScale(1)
  460.         thirdText.setScale(1)
  461.         forthText.setScale(1)
  462.         header.setColor(gColors.text)
  463.         mainText.setColor(gColors.text)
  464.         secondText.setColor(gColors.text)
  465.         thirdText.setColor(gColors.text)
  466.         forthText.setColor(gColors.text)
  467.         header.setY(22)
  468.         mainText.setY(31)
  469.         secondText.setY(40)
  470.         thirdText.setY(49)
  471.         forthText.setY(58)
  472.         reliableSleep(0.1)
  473.     end
  474.  
  475.     -- Setup functions
  476.     local function setupName()
  477.         thirdText.setY(57)
  478.         secondText.setText("")
  479.         mainText.setText("")
  480.         thirdText.setText("")
  481.         centerText("What's your name?", mainText)
  482.         secondText.setY(47)
  483.         secondText.setScale(1)
  484.         secondText.setColor(gColors.text)
  485.         centerText("Ex: $$John", secondText)
  486.         local e, msg = os.pullEvent("chat_command")
  487.         local name = msg
  488.         secondText.setText("")
  489.         centerText("Your name is", mainText)
  490.         centerText(name .. "?", secondText)
  491.         thirdText.setColor(gColors.blue)
  492.         centerText("Options: $$y/n", thirdText)
  493.         while true do
  494.             local e, msg = os.pullEvent("chat_command")
  495.             msg = trimText(msg:lower())
  496.             if msg:find("y") then
  497.                 return name
  498.             elseif msg:find("n") then
  499.                 return setupName()
  500.             end
  501.         end
  502.     end
  503.  
  504.  
  505.     local function setupTime()
  506.         thirdText.setY(57)
  507.         secondText.setText("")
  508.         thirdText.setText("")
  509.         centerText("Use 12h Time Format?", mainText)
  510.         secondText.setColor(gColors.blue)
  511.         centerText("Options: $$y/n", secondText)
  512.         while true do
  513.             local e, msg = os.pullEvent("chat_command")
  514.             msg = trimText(msg:lower())
  515.             if msg:find("y") then
  516.                 return true
  517.             elseif msg:find("n") then
  518.                 return false
  519.             end
  520.         end
  521.     end
  522.  
  523.     local function setupTemperature()
  524.         thirdText.setY(57)
  525.         secondText.setText("")
  526.         thirdText.setText("")
  527.         centerText("Celsius or Farenheit?", mainText)
  528.         secondText.setColor(gColors.blue)
  529.         centerText("Options: $$c/f", secondText)
  530.         while true do
  531.             local e, msg = os.pullEvent("chat_command")
  532.             msg = trimText(msg:lower())
  533.             if msg:find("c") then
  534.                 return "c"
  535.             elseif msg:find("f") then
  536.                 return "f"
  537.             end
  538.         end
  539.     end
  540.  
  541.     local function setupLocation()
  542.         thirdText.setY(57)
  543.         secondText.setText("")
  544.         thirdText.setText("")
  545.         secondText.setColor(gColors.text)
  546.         thirdText.setColor(gColors.text)
  547.         centerText("What's your city?", mainText)
  548.         centerText("(To get time/weather)", secondText)
  549.         centerText("Ex: $$New York", thirdText)
  550.         while true do
  551.             local e, city = os.pullEvent("chat_command")
  552.             thirdText.setColor(gColors.yellow)
  553.             centerText("Connecting...", thirdText)
  554.             local resp, cur = getWT(city)
  555.             if resp == "success" then
  556.                 mainText.setText("")
  557.                 secondText.setText("")
  558.                 thirdText.setText("")
  559.                 centerText("You're in", mainText)
  560.                 centerText(cur["location"] .. "?", secondText)
  561.                 thirdText.setColor(gColors.blue)
  562.                 centerText("Options: $$y/n", thirdText)
  563.                 while true do
  564.                     local e, msg = os.pullEvent("chat_command")
  565.                     msg = trimText(msg:lower())
  566.                     if msg:find("y") then
  567.                         return city
  568.                     elseif msg:find("n") then
  569.                         return setupLocation()
  570.                     end
  571.                 end
  572.             else
  573.                 thirdText.setColor(gColors.red)
  574.                 centerText("Invalid city!", thirdText)
  575.     return city
  576.             end
  577.         end
  578.     end
  579.  
  580.     local function mainThread()
  581.         local function start()
  582.             local function welcome()
  583.                 centerText("Welcome to", mainText)
  584.                 secondText.setScale(3)
  585.                 secondText.setX(40)
  586.                 slowText("Plastic", secondText)
  587.                 reliableSleep(2)
  588.                 secondText.setText("")
  589.                 mainText.setText("")
  590.                 centerText("Setup", header)
  591.                 mainText.setText("")
  592.                 mainText.setColor(gColors.text)
  593.                 mainText.setY(37)
  594.                 thirdText.setY(57)
  595.                 return setupName()
  596.             end
  597.  
  598.             if firstTime then
  599.                 settings["name"] = welcome()
  600.                 settings["use12hour"] = setupTime()
  601.                 settings["city"] = setupLocation()
  602.                 settings["temperature"] = setupTemperature()
  603.                 settings["showtime"] = "ingame"
  604.  
  605.                 local f = io.open("/plasticOptions", "w")
  606.                 f:write(textutils.serialize(settings))
  607.                 f:close()
  608.                 closeAnimation()
  609.                 reliableSleep(1)
  610.                 shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  611.                 error()
  612.             else
  613.                 return
  614.             end
  615.         end
  616.  
  617.         local function convert(query)
  618.             secondText.setX(25)
  619.             slowText("Powered by STANDS4 APIs", secondText)
  620.             --reliableSleep(1)
  621.             --secondText.setX(35)
  622.             --slowText("Converting... | cancel", secondText)
  623.             local resp, msg = plasticGet("http://www.stands4.com/services/v2/conv.php?uid=2464&tokenid=lQAygI15b9x34e2L&expression=" .. textutils.urlEncode(query))
  624.             if resp == "success" then
  625.                 if tonumber(msg:match("<errorCode>(%d+)")) > 0 then
  626.                     centerText(trimText(msg:match("<errorMessage>([^<]+)</errorMessage>")), secondText)
  627.                     return
  628.                 else
  629.                     local response = msg:match("<result>([^<]+)</result>")
  630.                     local replaceable = {["kilogram"] = "kg", ["nautical mile"] = "nmile" , ["megabyte"] = "mb", ["gigabyte"] = "gb", ["kilobyte"] = "kb"
  631.                         ,["millimeter"] = "mm", ["centimeter"] = "cm", ["micrometer"] = "Um", ["nanometer"] = "nm", ["terrabyte"] = "tb", ["exabyte"] = "eb",
  632.                         ["British"] = "gb", ["kilometer"] = "km", ["hour"] = "h", [" / "] = "/", ["&amp;"] = "", ["deg;"] = ""}
  633.                     for k,v in pairs(replaceable) do
  634.                         response = response:lower():gsub(k,v)
  635.                         response = response:lower():gsub(k .. "s",v)
  636.                     end
  637.                     if #response >24 then
  638.                         local startSearch = response:find("%=")
  639.                         local trim = response:find("%.", startSearch)
  640.                         local units = response:find("%s", trim)
  641.                         local nresponse = response:sub(1, trim+3) .. response:sub(units,-1)
  642.                         response = trimText(nresponse)
  643.                     end
  644.                     secondText.setX(25)
  645.                     if #response > 22 then
  646.                         slowText(response, secondText)
  647.                     else
  648.                         centerText(response, secondText)
  649.                     end
  650.                     return
  651.                 end
  652.             elseif resp == "failure" then
  653.                 centerText("Service not available", secondText)
  654.                 return
  655.             elseif resp == "cancel" then
  656.                 centerText("Request Cancelled", secondText)
  657.                 return
  658.             end
  659.         end
  660.  
  661.         local function renderWeather(city)
  662.             local resp, cur, day = nil
  663.             centerText("Src: World Weather Online",secondText)
  664.             if not city then
  665.                 resp, cur, day = getWT(settings["city"], true)
  666.             else
  667.                 resp, cur, day = getWT(city, true)
  668.             end
  669.             if resp == "success" then
  670.                     squeezeScreen()
  671.                     header.setColor(gColors.blue)
  672.                     centerText(cur["location"], header)
  673.                     mainText.setColor(gColors.textGray)
  674.                     centerText(cur["weather"], mainText)
  675.                     tempText.setX(97)
  676.                     tempText.setScale(3)
  677.                     tempText.setY(43)
  678.                     tempText.setColor(gColors.blue)
  679.                     slowText(cur["temp"]..settings["temperature"]:upper(), tempText)
  680.                     secondText.setX(23)
  681.                     slowText("Humidity: " .. cur["humidity"] .. "%", secondText)
  682.                     thirdText.setX(23)
  683.                     slowText("Current", thirdText)
  684.                     forthText.setX(23)
  685.                     slowText("$$back/day", forthText)
  686.                 local function loadCurrent()
  687.                     centerText(cur["weather"], mainText)
  688.                     slowText(cur["temp"]..settings["temperature"]:upper(), tempText)
  689.                     slowText("Current", thirdText)
  690.                     slowText("$$back/day", forthText)
  691.                     while true do
  692.                         local e, msg = os.pullEvent("chat_command")
  693.                         msg = trimText(msg:lower())
  694.                         if (msg == "back") or msg == "home" then
  695.                             return resetScreen()
  696.                         elseif (msg == "day") then
  697.                             return loadDay()
  698.                         end
  699.                     end
  700.                 end
  701.                 local function loadDay()
  702.                     centerText(day["weather"], mainText)
  703.                     slowText(day["high"]..settings["temperature"]:upper(), tempText)
  704.                     slowText("Low: " .. day["low"] .. (settings["temperature"]:upper()), thirdText)
  705.                     slowText("$$back/cur", forthText)
  706.                     while true do
  707.                         local e, msg = os.pullEvent("chat_command")
  708.                         msg = trimText(msg:lower())
  709.                         if (msg == "back") or msg == "home" then
  710.                             return resetScreen()
  711.                         elseif (msg:find("cur")) then
  712.                             return loadCurrent()
  713.                         end
  714.                     end
  715.                 end
  716.                 while true do
  717.                     local e, msg = os.pullEvent("chat_command")
  718.                     msg = trimText(msg:lower())
  719.                     if (msg == "back") or msg == "home" then
  720.                         return resetScreen()
  721.                     elseif (msg == "day") then
  722.                         return loadDay()
  723.                     end
  724.                 end
  725.             elseif resp == "cancel" then
  726.                 centerText("Request Cancelled", secondText)
  727.                 return
  728.             elseif resp == "invalid" then
  729.                 centerText("Invalid location!", secondText)
  730.                 return
  731.             else
  732.                 centerText("Service not available", secondText)
  733.                 return
  734.             end
  735.         end
  736.  
  737.         local function renderDate(city)
  738.             centerText("Src: World Weather Online",secondText)
  739.             local resp, cur = getWT(city, true)
  740.             if resp == "success" then
  741.                 textScreen()
  742.                 header.setColor(gColors.blue)
  743.                 centerText("Current Time/Date", header)
  744.                 centerText(cur["location"], mainText)
  745.                 centerText(cur["date"] .. " - " .. cur["time"], secondText)
  746.                 centerText("$$back", thirdText)
  747.                 while true do
  748.                     local e, msg = os.pullEvent("chat_command")
  749.                     msg = trimText(msg:lower())
  750.                     if (msg == "back") or (msg == "home") then
  751.                         resetScreen()
  752.                         return
  753.                     end
  754.                 end
  755.             elseif resp == "cancel" then
  756.                 centerText("Request Cancelled", secondText)
  757.                 return
  758.             elseif resp == "invalid" then
  759.                 centerText("Invalid location!", secondText)
  760.                 return
  761.             else
  762.                 centerText("Service not available", secondText)
  763.                 return
  764.             end
  765.         end
  766.  
  767.         local function getEnvs()
  768.             local newEnv = getfenv(0)
  769.             newEnv.secondText = secondText
  770.             newEnv.thirdText = thirdText
  771.             newEnv.forthText = forthText
  772.             newEnv.tempText = tempText
  773.             newEnv.mainText = mainText
  774.             newEnv.resetScreen = resetScreen
  775.             newEnv.squeezeScreen = squeezeScreen
  776.             newEnv.textScreen = textScreen
  777.             newEnv.slowText = slowText
  778.             newEnv.centerText = centerText
  779.             newEnv.plasticGet = plasticGet
  780.             newEnv.trimText = trimText
  781.             newEnv.header = header
  782.             newEnv.plastic = plastic
  783.             return newEnv
  784.         end
  785.  
  786.         local function home()
  787.             local function resetSecond()
  788.                 secondText.setText("")
  789.                 secondText.setColor(gColors.blue)
  790.                 secondText.setY(57)
  791.                 secondText.setScale(1)
  792.             end
  793.             thirdText.setText("")
  794.             header.setText("")
  795.             mainText.setText("")
  796.             mainText.setColor(gColors.text)
  797.             mainText.setScale(3)
  798.             mainText.setY(32)
  799.             secondText.setText("")
  800.             secondText.setColor(gColors.blue)
  801.             secondText.setY(57)
  802.             displayTime("00:00 --")
  803.             os.queueEvent("plastic_clock_manager", "show")
  804.             centerText("Welcome, " .. settings["name"], secondText)
  805.             while true do
  806.                 local skipAll = false
  807.                 local e, msg = os.pullEvent()
  808.                 if e == "chat_command" then
  809.                     msg = trimText(msg:lower())
  810.                     if searchArgs("root") then
  811.                         for k,v in pairs(rootApps) do
  812.                             local a = loadstring("local cmd = [[" .. msg .. "]]\n" .. v)
  813.                             if a then
  814.                                 local env = getEnvs()
  815.                                 setfenv(a, env)
  816.                                 if a() then
  817.                                     skipAll = true
  818.                                 end
  819.                             else
  820.                                 print("Failed to run application: ", k)
  821.                             end
  822.                         end
  823.                     end
  824.                     if not(skipAll) then
  825.                         if (msg:sub(1,1) == "=") then
  826.                             local banned = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
  827.                             "p", "q", "r", "s", "t", "u", "v", "w", "x","y", "z"}
  828.                             local formula = msg:sub(2, -1):lower()
  829.                             for k,v in pairs(banned) do
  830.                                 formula = formula:gsub(v, "")
  831.                             end
  832.                             local func = loadstring("return " .. formula)
  833.                             local e, resp = pcall(func)
  834.                             if e and ((type(resp) == "number") or (type(resp) == "string")) then
  835.                                 centerText("=" .. resp, secondText)
  836.                             else
  837.                                 centerText("Syntax Error", secondText)
  838.                             end
  839.                         elseif msg == "help" then
  840.                             squeezeScreen()
  841.                             header.setColor(gColors.blue)
  842.                             centerText("Help, Try: $$", header)
  843.                             centerText("=12*3, home, irl, restart,", mainText)
  844.                             centerText("igl, quit, update, weather,", secondText)
  845.                             centerText("time/weather for city,", thirdText)
  846.                             centerText("convert x to y (back)", forthText)
  847.                             while true do
  848.                                 local _, msg = os.pullEvent("chat_command")
  849.                                 msg = trimText(msg:lower())
  850.                                 if (msg == "back") or (msg == "home") then
  851.                                     resetScreen()
  852.                                     break
  853.                                 end
  854.                             end
  855.                         elseif msg == "about" then
  856.                             secondText.setX(32)
  857.                             slowText("Plastic B v0.11 by 1lann", secondText)
  858.                         elseif (msg:sub(1,8) == "weather ") or msg == "weather" then
  859.                             local location = nil
  860.                             if msg:sub(1,12) == "weather for " then
  861.                                 location = trimText(msg:sub(13, -1))
  862.                             elseif msg:sub(1,11) == "weather in " then
  863.                                 location = trimText(msg:sub(12, -1))
  864.                             elseif msg == "weather" then
  865.                                 location = ""
  866.                             else
  867.                                 location = trimText(msg:sub(9, -1))
  868.                             end
  869.                             if location == "" then
  870.                                 renderWeather()
  871.                             else
  872.                                 renderWeather(location)
  873.                             end
  874.                         elseif (msg:sub(1,8) == "time in ") or (msg:sub(1,9) == "time for ") or (msg:sub(1,9) == "date for ") then
  875.                             local location = nil
  876.                             if (msg:sub(1,8) == "time in ") then
  877.                                 location = msg:sub(9,-1)
  878.                             else
  879.                                 location = msg:sub(10, -1)
  880.                             end
  881.                             if location == "" then
  882.                                 centerText("No city speicifed!", secondText)
  883.                             else
  884.                                 renderDate(location)
  885.                             end
  886.                         elseif msg == "settings" then
  887.                             local exit = false
  888.                             while true do
  889.                                 local noSave = false
  890.                                 textScreen()
  891.                                 header.setColor(gColors.blue)
  892.                                 centerText("Change Settings", header)
  893.                                 centerText("Options: temperature,", mainText)
  894.                                 centerText("time format, name,", secondText)
  895.                                 centerText("location, back", thirdText)
  896.                                 while true do
  897.                                     local _, msg = os.pullEvent("chat_command")
  898.                                     msg = trimText(msg:lower())
  899.                                     if (msg == "back") or (msg == "home") then
  900.                                         resetScreen()
  901.                                         exit = true
  902.                                         break
  903.                                     elseif (msg == "temperature") then
  904.                                         mainText.setText("")
  905.                                         secondText.setText("")
  906.                                         thirdText.setText("")
  907.                                         header.setText("")
  908.                                         header.setColor(gColors.textGray)
  909.                                         centerText("Setup", header)
  910.                                         settings["temperature"] = setupTemperature()
  911.                                         noSave = false
  912.                                     elseif (msg == "time format") then
  913.                                         mainText.setText("")
  914.                                         secondText.setText("")
  915.                                         thirdText.setText("")
  916.                                         header.setText("")
  917.                                         header.setColor(gColors.textGray)
  918.                                         centerText("Setup", header)
  919.                                         settings["use12hour"] = setupTime()
  920.                                         noSave = false
  921.                                     elseif (msg == "name") then
  922.                                         mainText.setText("")
  923.                                         secondText.setText("")
  924.                                         thirdText.setText("")
  925.                                         header.setText("")
  926.                                         header.setColor(gColors.textGray)
  927.                                         centerText("Setup", header)
  928.                                         settings["name"] = setupName()
  929.                                         noSave = false
  930.                                     elseif (msg == "location") then
  931.                                         mainText.setText("")
  932.                                         secondText.setText("")
  933.                                         thirdText.setText("")
  934.                                         header.setText("")
  935.                                         header.setColor(gColors.textGray)
  936.                                         centerText("Setup", header)
  937.                                         settings["city"] = setupLocation()
  938.                                         noSave = false
  939.                                     else
  940.                                         noSave = true
  941.                                     end
  942.                                     if not(noSave) then
  943.                                         local f = io.open("/plasticOptions", "w")
  944.                                         f:write(textutils.serialize(settings))
  945.                                         f:close()
  946.                                         mainText.setText("")
  947.                                         secondText.setText("")
  948.                                         thirdText.setText("")
  949.                                         header.setText("")
  950.                                         mainText.setColor(gColors.green)
  951.                                         centerText("Settings saved!", mainText)
  952.                                         sleep(2)
  953.                                         break
  954.                                     end
  955.                                 end
  956.                                 if exit then break end
  957.                             end
  958.                         elseif (msg:sub(1,8) == "convert ") then
  959.                             os.queueEvent("plastic_clock_manager", "show")
  960.                             resetSecond()
  961.                             convert(msg)
  962.                         elseif msg == "irl" then
  963.                             if not(settings["showtime"] == "irl") then
  964.                                 secondText.setX(30)
  965.                                 slowText("Changing time... | cancel", secondText)
  966.                                 local resp, time = getTime(settings["city"])
  967.                                 if resp == "success" then
  968.                                     settings["showtime"] = "irl"
  969.                                     os.queueEvent("plastic_clock_manager", "force", time)
  970.                                     os.queueEvent("plastic_clock_manager", "show")
  971.                                     os.queueEvent("plastic_clock_manager", "irl")
  972.                                     displayTime(time)
  973.                                     local f = io.open("/plasticOptions", "w")
  974.                                     f:write(textutils.serialize(settings))
  975.                                     f:close()
  976.                                     centerText("Time is now IRL", secondText)
  977.                                 else
  978.                                     centerText("Could not get IRL time!", secondText)
  979.                                 end
  980.                             else
  981.                                 centerText("Time is already IRL!", secondText)
  982.                             end
  983.                         elseif msg == "ingame" or (msg == "igl") then
  984.                             if not(settings["showtime"] == "ingame") then
  985.                                 settings["showtime"] = "ingame"
  986.                                 os.queueEvent("plastic_clock_manager", "force", textutils.formatTime(os.time(), not(settings["use12hour"])))
  987.                                 os.queueEvent("plastic_clock_manager", "show")
  988.                                 os.queueEvent("plastic_clock_manager", "ingame")
  989.                                 local f = io.open("/plasticOptions", "w")
  990.                                 f:write(textutils.serialize(settings))
  991.                                 f:close()
  992.                                 centerText("Time is now in-game", secondText)
  993.                             else
  994.                                 secondText.setX(30)
  995.                                 slowText("Time is already in-game!", secondText)
  996.                             end
  997.                         elseif msg == "update" then
  998.                             secondText.setX(35)
  999.                             centerText("Updating... | cancel", secondText)
  1000.                             local resp, data = plasticGet("http://pastebin.com/raw.php?i=43nHyKXU")
  1001.                             if resp == "success" then
  1002.                                 local f = io.open(plasticInstallation, "w")
  1003.                                 f:write(data)
  1004.                                 f:close()
  1005.                                 closeAnimation()
  1006.                                 reliableSleep(1)
  1007.                                 shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  1008.                                 error()
  1009.                             elseif resp == "failure" then
  1010.                                 centerText("Failed to update!", secondText)
  1011.                             elseif resp == "cancel" then
  1012.                                 centerText("Request Cancelled", secondText)
  1013.                             end
  1014.                         elseif (msg == "home") or (msg == "clock") or (msg == "time") then
  1015.                             resetScreen()
  1016.                         elseif (msg == "restart") then
  1017.                             closeAnimation()
  1018.                             reliableSleep(1)
  1019.                             shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  1020.                             error()
  1021.                         elseif (msg == "exit") or (msg == "quit") or (msg == "stop") then
  1022.                             closeAnimation()
  1023.                             error()
  1024.                         else
  1025.                             centerText("Unknown Command!", secondText)
  1026.                         end
  1027.                     end
  1028.                 end
  1029.             end
  1030.         end
  1031.  
  1032.         start()
  1033.         home()
  1034.     end
  1035.  
  1036.     local function updateWeather()
  1037.         if sensor then
  1038.             if worldSensor then
  1039.                 header.setY(22)
  1040.                 local data = worldSensor.getTargets()["CURRENT"]
  1041.                 if data["Thundering"] then
  1042.                     header.setColor(gColors.textGray)
  1043.                     header.setX(53)
  1044.                     header.setText("Thunderstorm")
  1045.                 elseif data["Raining"] then
  1046.                     header.setColor(gColors.rain)
  1047.                     header.setX(80)
  1048.                     header.setText("Rain")
  1049.                 elseif data["Daytime"] then
  1050.                     header.setColor(gColors.yellow)
  1051.                     header.setX(75)
  1052.                     header.setText("Sunny")
  1053.                 else
  1054.                     header.setColor(gColors.rain)
  1055.                     header.setX(59)
  1056.                     header.setText("Clear Night")
  1057.                 end
  1058.             else
  1059.                 header.setColor(gColors.textGray)
  1060.                 header.setX(35)
  1061.                 header.setText("Missing world sensor!")
  1062.             end
  1063.         end
  1064.     end
  1065.  
  1066.     local function weatherThread()
  1067.         local timer = os.startTimer(5)
  1068.         while true do
  1069.             local e, id = os.pullEvent()
  1070.             if e == "plastic_clock_manager" then
  1071.                 if id == "hide" then
  1072.                     showClock = false
  1073.                 elseif id == "show" then
  1074.                     updateWeather()
  1075.                     timer = os.startTimer(5)
  1076.                     showClock = true
  1077.                 end
  1078.             elseif (e == "timer") and (timer == id) and showClock then
  1079.                 updateWeather()
  1080.                 timer = os.startTimer(5)
  1081.             end
  1082.         end
  1083.     end
  1084.  
  1085.     local function backgroundThread()
  1086.         local webUpdate = 0
  1087.         local resp, time = nil
  1088.         local lastTimeUpdate = os.clock()
  1089.         local function updateTime(prevTime, city)
  1090.             if os.clock() >= lastTimeUpdate+60 then
  1091.                 webUpdate  = webUpdate + 1
  1092.                 if webUpdate < 60 then
  1093.                     if prevTime then
  1094.                         local hour,minute,ampm = prevTime:match("^(%d+):(%d+)(.-)$")
  1095.                         if ampm == " AM" then
  1096.                             if settings["use12hour"] == false then
  1097.                                 return getTime(city)
  1098.                             end
  1099.                             lastTimeUpdate = os.clock()
  1100.                             if minute == "59" then
  1101.                                 if hour == "11" then
  1102.                                     return "success","12:00 PM"
  1103.                                 elseif hour == "12" then
  1104.                                     return "success","1:00 AM"
  1105.                                 else
  1106.                                     return "success",tostring(tonumber(hour)+1)..":00 AM"
  1107.                                 end
  1108.                             else
  1109.                                 if #tostring(tonumber(minute)+1) > 1 then
  1110.                                     return "success",hour..":"..tostring(tonumber(minute)+1).." AM"
  1111.                                 else
  1112.                                     return "success",hour..":0"..tostring(tonumber(minute)+1).." AM"
  1113.                                 end
  1114.                             end
  1115.                         elseif ampm == " PM" then
  1116.                             if settings["use12hour"] == false then
  1117.                                 return getTime(city)
  1118.                             end
  1119.                             lastTimeUpdate = os.clock()
  1120.                             if minute == "59" then
  1121.                                 if hour == "11" then
  1122.                                     return "success","12:00 AM"
  1123.                                 elseif hour == "12" then
  1124.                                     return "success","1:00 PM"
  1125.                                 else
  1126.                                     return "success",tostring(tonumber(hour)+1)..":00 PM"
  1127.                                 end
  1128.                             else
  1129.                                 if #tostring(tonumber(minute)+1) > 1 then
  1130.                                     return "success",hour..":"..tostring(tonumber(minute)+1).." PM"
  1131.                                 else
  1132.                                     return "success",hour..":0"..tostring(tonumber(minute)+1).." PM"
  1133.                                 end
  1134.                             end
  1135.                         else
  1136.                             if settings["use12hour"] == true then
  1137.                                 return getTime(city)
  1138.                             end
  1139.                             lastTimeUpdate = os.clock()
  1140.                             if minute == "59" then
  1141.                                 if hour == "23" then
  1142.                                     return "success", "0:00"
  1143.                                 else
  1144.                                     return "success", tostring(tonumber(hour)+1)..":".."00"
  1145.                                 end
  1146.                             else
  1147.                                 if #tostring(tonumber(minute)+1) > 1 then
  1148.                                     return "success",hour..":"..tostring(tonumber(minute)+1)
  1149.                                 else
  1150.                                     return "success",hour..":0"..tostring(tonumber(minute)+1)
  1151.                                 end
  1152.                             end
  1153.                         end
  1154.                     else
  1155.                         return "failure"
  1156.                     end
  1157.                 else
  1158.                     return getTime(city)
  1159.                 end
  1160.             else
  1161.                 return "success",prevTime
  1162.             end
  1163.         end
  1164.         local clockType = settings["showtime"]
  1165.         local timerID = nil
  1166.         local updateTimer = nil
  1167.         local previousClock = nil
  1168.         local dynamicSleep = nil
  1169.         local resp = nil
  1170.         if settings["showtime"] == "irl" then
  1171.             resp, time = getTime(settings["city"])
  1172.             if resp == "success" then
  1173.                 settings["showtime"] = "irl"
  1174.                 os.queueEvent("plastic_clock_manager", "force", time)
  1175.                 os.queueEvent("plastic_clock_manager", "show")
  1176.                 os.queueEvent("plastic_clock_manager", "irl")
  1177.                 displayTime(time)
  1178.                 local f = io.open("/plasticOptions", "w")
  1179.                 f:write(textutils.serialize(settings))
  1180.                 f:close()
  1181.  
  1182.             else
  1183.  
  1184.             end
  1185.         end
  1186.         if clockType == "ingame" then
  1187.             dynamicSleep = 0.83
  1188.         else
  1189.             dynamicSleep = 60
  1190.         end
  1191.         timerID = os.clock() + dynamicSleep
  1192.         os.startTimer(0.83)
  1193.         updateTimer = 0.83+os.clock()
  1194.         while true do
  1195.             if os.clock() >= updateTimer then
  1196.                     os.startTimer(0.83)
  1197.                     updateTimer = 0.83+os.clock()
  1198.             end
  1199.             local e, command, param =  os.pullEvent()
  1200.             if e == "plastic_clock_manager" then
  1201.                 if command == "show" then
  1202.                     if time then
  1203.                         displayTime(time)
  1204.                     end
  1205.                     mainText.setColor(gColors.text)
  1206.                     mainText.setScale(3)
  1207.                     mainText.setY(32)
  1208.                     header.setText("")
  1209.                     showClock = true
  1210.                     timerID = os.clock()
  1211.                 elseif command == "hide" then
  1212.                     header.setText("")
  1213.                     mainText.setText("")
  1214.                     timerID = os.clock()+2
  1215.                     showClock = false
  1216.                 elseif command == "irl" then
  1217.                     clockType = "irl"
  1218.                     dynamicSleep = 60
  1219.                     timerID = os.clock() + dynamicSleep
  1220.                 elseif command == "ingame" then
  1221.                     clockType = "ingame"
  1222.                     dynamicSleep = 0.83
  1223.                     timerID = os.clock() + dynamicSleep
  1224.                 elseif command == "force" then
  1225.                     if param then
  1226.                         time = param
  1227.                     end
  1228.                 elseif command == "kill" then
  1229.                     sleep(100)
  1230.                 end
  1231.             elseif os.clock() >= timerID then
  1232.                 if showClock then
  1233.                     if clockType == "irl" then
  1234.                         resp, time = updateTime(time,settings["city"])
  1235.                         if resp ~= "success" then
  1236.                             displayTime("ERROR")
  1237.                             webUpdate = 60
  1238.                         else
  1239.                             displayTime(time)
  1240.                         end
  1241.                     elseif clockType == "ingame" then
  1242.                         time = textutils.formatTime(os.time(), not(settings["use12hour"]))
  1243.                         displayTime(time)
  1244.                     end
  1245.                 end
  1246.                 timerID = os.clock() + dynamicSleep
  1247.             end
  1248.         end
  1249.     end
  1250.  
  1251.     local eError, eResp = pcall(function() parallel.waitForAny(mainThread,backgroundThread,weatherThread) end)
  1252.     if eError then
  1253.         return
  1254.     elseif eResp then
  1255.         if not(fs.exists("/plasticLog")) then
  1256.             local f = io.open("/plasticLog", "w") f:write("-- Plastic Error Logs --\n") f:close()
  1257.         end
  1258.         local f = io.open("/plasticLog", "a")
  1259.         f:write(eResp .. "\n")
  1260.         f:close()
  1261.         mainText.setText("")
  1262.         secondText.setText("")
  1263.         thirdText.setText("")
  1264.         forthText.setText("")
  1265.         tempText.setText("")
  1266.         header.setText("")
  1267.         header.setY(25)
  1268.         header.setColor(gColors.red)
  1269.         centerText("Plastic has crashed", header)
  1270.         mainText.setY(37)
  1271.         mainText.setColor(gColors.yellow)
  1272.         secondText.setColor(gColors.yellow)
  1273.         thirdText.setColor(gColors.yellow)
  1274.         mainText.setScale(1)
  1275.         secondText.setScale(1)
  1276.         thirdText.setScale(1)
  1277.         centerText("and will now restart.", mainText)
  1278.         secondText.setY(47)
  1279.         centerText("See /plasticLog for", secondText)
  1280.         thirdText.setY(57)
  1281.         centerText("more information.", thirdText)
  1282.         reliableSleep(3)
  1283.         closeAnimation()
  1284.         reliableSleep(1)
  1285.         shell.run(plasticInstallation, "nodaemon", unpack(tArgs))
  1286.         error()
  1287.     end
  1288. end
  1289.  
  1290. local function plasticWrapper()
  1291.     pcall(runPlastic)
  1292. end
  1293.  
  1294. --[[function os.pullEvent(lookfor)
  1295.     local data = {os.pullEventRaw()}
  1296.     --if not(data[1] == "timer") and not(data[1] == "ocs_success") then
  1297.         print(os.clock(), data[1], tostring(data[2]))
  1298.     --end
  1299.     if not lookfor then
  1300.         return unpack(data)
  1301.     elseif data[1] == lookfor then
  1302.         return unpack(data)
  1303.     end
  1304. end]]
  1305.  
  1306. if not(searchArgs("nodaemon")) then
  1307.     parallel.waitForAny(plasticWrapper, function() shell.run("/rom/programs/shell") end)
  1308.     closeAnimation()
  1309.     term.clear()
  1310.     term.setCursorPos(1,1)
  1311.     print("Thank you for using Plastic Beta v0.11 by 1lann")
  1312. else
  1313.     runPlastic()
  1314.     closeAnimation()
  1315.     term.clear()
  1316.     term.setCursorPos(1,1)
  1317.     print("Thank you for using Plastic Beta v0.11 by 1lann")
  1318. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement