Advertisement
HydrantHunter

DHD/Gate Installer

Dec 25th, 2013
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.06 KB | None | 0 0
  1. --[[ DHD/Gate Installer ]]--
  2. --[[   version 1.1.00   ]]--
  3. --[[  by HydrantHunter  ]]--
  4. --[[      aka Dog       ]]--
  5. --[[ pastebin  A6uxKyCy ]]--
  6. local iVer = "1.1"
  7. --[[
  8. Tested with/Requires:
  9.   - Minecraft 1.6.4
  10.   - HTTP API enabled (for this installer only)
  11.   - LanteaCraft (snapshot 82+ and RC1_15+)
  12.   - ComputerCraft 1.57+ for MC 1.6.4
  13.     - ccDHD: Advanced Computer (color, mouse), 4 optional Advanced Monitors (color, touch), optional Biolock
  14.     - gateLiaison: Advanced Computer (color, mouse), 3 optional Advanced Monitors (color)
  15. ]]--
  16. local startup = 0
  17.  
  18. local function downloadFile(fileToken, fileName)
  19.   local fileURL = http.get("http://pastebin.com/raw.php?i=" .. textutils.urlEncode(fileToken))
  20.   if fileURL then
  21.     local fileContents = fileURL.readAll()
  22.     fileURL.close()
  23.     local newFile = fs.open(fileName, "w")
  24.     newFile.write(fileContents)
  25.     newFile.close()
  26.   end
  27. end
  28.  
  29. local function drawHeader()
  30.   term.setBackgroundColor(colors.black)
  31.   term.clear()
  32.   term.setBackgroundColor(colors.lightBlue)
  33.   term.setTextColor(colors.black)
  34.   term.setCursorPos(2,1)
  35.   term.write(string.rep(" ",19))
  36.   term.setCursorPos(2,2)
  37.   term.write(" DHD Installer " .. iVer .. " ")
  38.   term.setCursorPos(2,3)
  39.   term.write(string.rep(" ",19))
  40. end
  41.  
  42. local function drawCLI()
  43.   term.setBackgroundColor(colors.black)
  44.   term.setCursorPos(1,6)
  45.   if startup == 1 or startup == 2 then
  46.     term.setTextColor(colors.lime)
  47.     term.write(" [                 ] ")
  48.     term.setCursorPos(4,6)
  49.     term.setTextColor(colors.lightGray)
  50.     term.write("ccDHD Installed")
  51.   else
  52.     term.setTextColor(colors.white)
  53.     term.write(" [  Install ccDHD  ] ")
  54.   end
  55.   term.setCursorPos(1,8)
  56.   if startup == 3 or startup == 4 then
  57.     term.setTextColor(colors.lime)
  58.     term.write(" [                 ] ")
  59.     term.setCursorPos(4,8)
  60.     term.setTextColor(colors.lightGray)
  61.     term.write("Gate  Installed")
  62.   else
  63.     term.setTextColor(colors.white)
  64.     term.write(" [  Install  Gate  ] ")
  65.   end
  66.   term.setTextColor(colors.orange)
  67.   term.setCursorPos(1,10)
  68.   term.write(" [                 ] ")
  69.   term.setTextColor(colors.white)
  70.   term.setCursorPos(9,10)
  71.   term.write("Reboot")
  72.   term.setTextColor(colors.red)
  73.   term.setCursorPos(1,12)
  74.   term.write(" [                 ] ")
  75.   term.setTextColor(colors.white)
  76.   term.setCursorPos(10,12)
  77.   term.write("Quit")
  78. end
  79.  
  80. local function setCCLabel(whichType)
  81.   local currentCCLabel = os.getComputerLabel()
  82.   if tostring(currentCCLabel) == "" or currentCCLabel == nil then
  83.     os.setComputerLabel(whichType)
  84.   end
  85. end
  86.  
  87. local function cleanUp()
  88.   if fs.exists("/logs/DHDlast") then
  89.     fs.move("/logs/DHDlast","/data/DHDlast")
  90.   end
  91.   if fs.exists("/logs/DHDhistory") then
  92.     fs.move("/logs/DHDhistory","/data/DHDhistory")
  93.   end
  94.   if fs.exists("/logs") then fs.delete("/logs") end
  95. end
  96.  
  97. if fs.exists("/data/gateSettings") then startup = 4 end -- gateLiaison installed?
  98. if fs.exists("/gateLiaison") then startup = 3 end       -- gateLiaison installed as gateLiason (otherwise installed as startup)
  99. if fs.exists("/data/DHDconfig") then startup = 2 end    -- ccDHD installed?
  100. if fs.exists("/DHD") then startup = 1 end               -- ccDHD installed as DHD (otherwise installed as startup)
  101. if startup == 0 then                                    -- neither is installed
  102.   if fs.exists("/startup") then startup = 5 end         -- startup exists, install by name (otherwise install as startup)
  103. end
  104.  
  105. drawHeader()
  106. drawCLI()
  107.  
  108. while true do
  109.   userInput = { os.pullEvent("mouse_click") }
  110.   if userInput[3] > 1 and userInput[3] < 21 then
  111.     if userInput[4] == 6 then
  112.       setCCLabel("DHD")
  113.       if fs.exists("/logs") and fs.exists("/data/DHDSettings") then fs.delete("/data/DHDsettings") end
  114.       if fs.exists("/data/DHDSettings") then fs.delete("/data/DHDsettings") end
  115.       if not fs.exists("/data") then
  116.         fs.makeDir("/data")
  117.       end
  118.       cleanUp()
  119.       if startup == 1 or startup == 5 then
  120.         if fs.exists("/DHD") then fs.delete("/DHD") end
  121.         downloadFile("vMtcSz2e","/DHD")
  122.         startup = 1
  123.       elseif startup == 0 or startup == 2 then
  124.         if fs.exists("/startup") then fs.delete("/startup") end
  125.         downloadFile("vMtcSz2e","/startup")
  126.         startup = 2
  127.       end
  128.       drawCLI()
  129.     elseif userInput[4] == 8 then
  130.       setCCLabel("Gate")
  131.       if fs.exists("/logs") and fs.exists("/data/gateSettings") then fs.delete("/data/gateSettings") end
  132.       if not fs.exists("/data") then
  133.         fs.makeDir("/data")
  134.       end
  135.       cleanUp()
  136.       if startup == 3 or startup == 5 then
  137.         if fs.exists("/gateLiaison") then fs.delete("/gateLiaison") end
  138.         downloadFile("xSHHqL0h","/gateLiaison")
  139.         startup = 3
  140.       elseif startup == 0 or startup == 4 then
  141.         if fs.exists("/startup") then fs.delete("/startup") end
  142.         downloadFile("xSHHqL0h","/startup")
  143.         startup = 4
  144.       end
  145.       drawCLI()
  146.     elseif userInput[4] == 10 then
  147.       os.reboot()
  148.     elseif userInput[4] == 12 then
  149.       term.clear()
  150.       term.setCursorPos(1,1)
  151.       break
  152.     end
  153.   end
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement