Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- **************************************************************** --
- -- local variables
- -- **************************************************************** --
- local w,h = term.getSize() -- 51, 19
- local select = 1
- local verNum = 1.01
- local m,s, timeUpdated = "00","00", false
- local logs = {}
- local firstTime = not fs.exists('STARGATE')
- local gates = { }
- -- **************************************************************** --
- -- Download and load apis, files, and directories
- -- **************************************************************** --
- if not http then
- print("Stargate DHD requires http API")
- print("Set enableAPI_http to true in ComputerCraft.cfg")
- return
- end
- function Initialize()
- if not fs.exists("dropbox") then
- shell.run('pastebin get L9iRRjg6 dropbox')
- term.clear() -- **** need to fix GUI prob **** --
- table.insert(logs, 'Downloaded Dropbox Downloader')
- rollingLogs()
- end
- if not fs.exists('STARGATE') then
- fs.makeDir('STARGATE')
- table.insert(logs, 'Creating directory STARGATE')
- rollingLogs()
- end
- if not fs.exists('STARGATE/apis') then
- fs.makeDir('STARGATE/apis')
- table.insert(logs, 'Creating directory apis')
- rollingLogs()
- end
- if not fs.exists('STARGATE/Settings') then
- fs.makeDir('STARGATE/Settings')
- table.insert(logs, 'Creating directory Settings')
- rollingLogs()
- end
- if not fs.exists("STARGATE/apis/wrap") then
- shell.run("dropbox Simple%20Wrap.lua CC%20Porgrams 126735377 STARGATE/apis/wrap")
- table.insert(logs, 'Downloading api: Simple Wrap.lua from dropbox')
- rollingLogs()
- end
- if not fs.exists("STARGATE/apis/Downloader") then
- shell.run("dropbox Downloader.lua CC%20Porgrams 126735377 STARGATE/apis/Downloader")
- table.insert(logs, 'Downloading api: Downloader.lua from dropbox')
- rollingLogs()
- end
- os.loadAPI("STARGATE/apis/wrap")
- table.insert(logs, 'Loading api: wrap')
- rollingLogs()
- os.loadAPI("STARGATE/apis/Downloader")
- table.insert(logs, 'Loading api: Downloader')
- rollingLogs()
- if not fs.exists('STARGATE/Settings/Timing') then
- local f = fs.open('STARGATE/Settings/Timing', 'w')
- f.writeLine(14)
- f.close()
- table.insert(logs, 'Setting cumulative update time to 15 min')
- rollingLogs()
- end
- if not fs.exists('STARGATE/Settings/onlineInfo') then
- local f = fs.open('STARGATE/Settings/onlineInfo', 'w')
- f.writeLine("Dropbox or Pastebin")
- f.writeLine("link or code")
- f.close()
- table.insert(logs, 'Setting online cumulative update location')
- rollingLogs()
- end
- if not fs.exists('STARGATE/Settings/AddressList') then
- local f = fs.open('STARGATE/Settings/AddressList', 'w')
- f.writeLine("Stargate_Address_List = {")
- f.writeLine("}")
- f.close()
- table.insert(logs, 'Making blank Address List')
- rollingLogs()
- end
- end
- -- **************************************************************** --
- -- Some Functions
- -- **************************************************************** --
- function dial(address)
- local gate = wrap.attach("Abstract Bus Adapter")
- if gate then
- gate.sendPacket("FFFF", "action: dial", "address: "..address)
- end
- end
- function disconnect()
- local gate = wrap.attach("Abstract Bus Adapter")
- if gate then
- gate.sendPacket("FFFF", "action: disconnect")
- end
- end
- function settings_Timing(newTime)
- if newTime then
- local f = fs.open('STARGATE/Settings/Timing', 'w')
- f.writeLine(newTime)
- f.close()
- m, s, timeUpdated = newTime, "00", true
- else
- local f = fs.open('STARGATE/Settings/Timing', 'r')
- local Time = f.readLine()
- f.close()
- return math.floor(Time)
- end
- end
- function settings_OnlineInfo(Dropbox_Pastebin, info)
- if info then
- local f = fs.open('STARGATE/Settings/onlineInfo', 'w')
- if Dropbox_Pastebin == "Dropbox" and string.find(info,"www.") then
- local str = strsplit("www.", info)
- info = str[1].."dl."..str[2]
- end
- f.writeLine(Dropbox_Pastebin)
- f.writeLine(info)
- f.close()
- else
- local f = fs.open('STARGATE/Settings/onlineInfo', 'r')
- local Paste_Drop = f.readLine()
- local location = f.readLine()
- f.close()
- return Paste_Drop, location
- end
- end
- function updateAdressList()
- os.unloadAPI("STARGATE/Settings/AddressList")
- local name, info = settings_OnlineInfo()
- Downloader.get(name, info)
- os.loadAPI("STARGATE/Settings/AddressList")
- if AddressList.Stargate_Address_List then
- gates = AddressList.Stargate_Address_List
- end
- updateGateMenu()
- end
- function updateSG_DHD()
- local file = http.get("https://dl.dropboxusercontent.com/u/126735377/CC%20Porgrams/Stargate%20DHD.lua")
- local program = file.readAll()
- file.close()
- if not string.find(program,"local verNum = "..verNum) then
- term.clear()
- drawHeaderFooter()
- printCentered("O----------------O", 7, 1)
- printCentered("O----------------O", 9, 1)
- local update = {". ",".. ","... ","...."}
- for i=1,#update do
- printCentered("| updating"..update[i].." |", 8, 1)
- sleep(1)
- end
- local dir = shell.getRunningProgram()
- fs.delete(dir)
- local f = fs.open(dir, "w")
- f.write(program)
- f.close()
- shell.run(dir)
- end
- end
- function strsplit( pat, str )
- local t = {}
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function rollingLogs()
- if firstTime then
- term.clear()
- drawHeaderFooter()
- printCentered("Doing some things...",8, 1)
- printCentered("O"..string.rep("-", w-6).."O",9, 1)
- for i=1, 3 do
- printCentered("|"..string.rep(" ", w-6).."|",9+i, 1)
- end
- printCentered("O"..string.rep("-", w-6).."O",13, 1)
- while #logs > 3 do
- table.remove(logs, 1)
- end
- for i=1, #logs do
- printCentered(logs[i], 9+i, 1)
- end
- sleep(1)
- end
- end
- -- **************************************************************** --
- -- GUI
- -- **************************************************************** --
- --Some draw functions to get us started
- function printCentered(str, ypos, offset)
- if not offset then offset = 0 end
- term.setCursorPos(w/2 - #str/2+offset, ypos)
- term.write(str)
- end
- function printRight(str, ypos)
- term.setCursorPos(w - #str, ypos)
- term.write(str)
- end
- function printCollumRow(str, ypos, num, offset)
- if num == 1 then
- term.setCursorPos(1+offset,ypos)
- term.write(str)
- elseif num == 2 then
- term.setCursorPos(w/2 - #str/2, ypos)
- term.write(str)
- elseif num == 3 then
- term.setCursorPos((w - #str)-offset+1, ypos)
- term.write(str)
- end
- end
- --draw menu functions
- function drawHeaderFooter()
- printCentered("O"..string.rep("-", w-2).."O", 1, 1)
- printCentered("O Stargate D.H.D. O", 1)
- printCentered("| Cumulative Update |", 2)
- printCentered("O-----< "..m..":"..s.." >-----O", 3)
- printCentered("O"..string.rep("-", w-2).."O", h-1, 1)
- for i=2, h-2 do
- term.setCursorPos(1,i)
- term.write("|")
- term.setCursorPos(w,i)
- term.write("|")
- end
- term.setCursorPos(2,h)
- term.write("By: PaintPauller")
- printRight("Version: "..verNum, h)
- end
- function drawMain()
- local toPrint = { "Dial Stargate", "Disconnect Stargate", "Settings", "Force Update"}
- local num = 1
- for i=6, #toPrint*4, 3 do
- printCentered(toPrint[num], i)
- if select == num then
- printCentered("O"..string.rep("-", #toPrint[num]).."O", i+1)
- end
- num = num + 1
- end
- printRight("Quit", h-2)
- if select == #toPrint+1 then
- printRight("> Quit <", h-2)
- end
- end
- function drawDiall()
- local collum = 1
- local row = 5
- for i=1, #gates do
- if i>18 then break end
- printCollumRow(gates[i].name, row, collum, 2)
- if select == i then
- printCollumRow("O"..string.rep("-", #gates[i].name).."O", row+1, collum, 1)
- end
- row = row + 2
- if row >= 16 then
- row = 5
- collum = collum + 1
- end
- end
- printRight("Back", h-2)
- if select == #gates+1 or select == 19 then
- printRight("> Back <", h-2)
- end
- end
- function drawSettingsEditor()
- printCentered("O"..string.rep("-", 42).."O", h-6, 1)
- printCentered("|"..string.rep(" ", 42).."|", h-5, 1)
- printCentered("O"..string.rep("-", 42).."O", h-4, 1)
- end
- function drawSettings()
- local name, location = settings_OnlineInfo()
- if #location > 31 then
- location = string.sub(location, 1, 30).."..."
- end
- printCollumRow("Change Cumulative Update Timing", 5, 1, 3)
- printCollumRow("Change Online Location", 8, 1, 3)
- printCollumRow("Minutes: "..settings_Timing()+1, 6, 1, 5)
- printCollumRow(name, 9, 1, 5)
- printCollumRow("Location: "..location, 10, 1, 5)
- printRight("Back", h-2)
- settings_OnlineInfo(Dropbox_Pastebin, info)
- if select == 1 then
- printCollumRow("> Minutes: "..settings_Timing()+1, 6, 1, 3)
- elseif select == 2 then
- printCollumRow("> "..name, 9, 1, 3)
- elseif select == 3 then
- printCollumRow("> Location: "..location, 10, 1, 3)
- elseif select == 4 then
- printRight("> Back <", h-2)
- end
- end
- -- Menu state
- local menustate = "Main"
- local menuOpt = {
- ['Main'] = {
- options = { "Dial a Stargate", "Disconnect Stargate", "Settings", "Force Update", "Quit" },
- draw = drawMain
- },
- ["Dial a Stargate"] = {
- options = { }, --filled in later
- draw = drawDiall
- },
- ['Settings'] = {
- options = { "Minute", "DropBox_Pastebin", "Online Location", "Main" },
- draw = drawSettings
- },
- }
- function updateGateMenu()
- menuOpt["Dial a Stargate"].options = { }
- for i=1, #gates do
- if i>18 then break end
- table.insert(menuOpt["Dial a Stargate"].options, gates[i].name)
- end
- table.insert(menuOpt["Dial a Stargate"].options, 'Main')
- end
- updateGateMenu()
- -- Run
- function timer()
- while true do
- updateAdressList()
- for mc=settings_Timing(), 0, -1 do
- for sc =60, 0, -1 do
- m = mc
- s = sc
- if s < 10 then s = tostring("0"..s) end
- if m < 10 then m = tostring("0"..m) end
- local old_x, old_y = term.getCursorPos()
- printCentered("O-----< "..m..":"..s.." >-----O", 3)
- term.setCursorPos(old_x, old_y)
- if not timeUpdated then sleep(1) end
- end
- if timeUpdated then sleep(.00001) end
- end
- timeUpdated = false
- end
- end
- function runMenu()
- while true do
- local acted = false
- term.clear()
- drawHeaderFooter()
- menuOpt[menustate].draw()
- --[[ -- Debug Start --
- term.setCursorPos(1,h)
- term.clearLine()
- printRight(menustate, h)
- term.setCursorPos(2,h)
- term.write(tostring(menuOpt[menustate].options[select])..": "..select)
- --]] -- Debug End --
- local id, key = os.pullEvent("key")
- -- 203: left, 205: right, 200: up, 208: down, 28: enter
- if key == 200 and select > 1 then
- select = select-1
- elseif key == 200 and select == 1 then
- select = #menuOpt[menustate].options
- elseif key == 208 and select < #menuOpt[menustate].options then
- select = select+1
- elseif key == 208 and select == #menuOpt[menustate].options then
- select = 1
- elseif key == 203 and select == 19 and menustate == "Dial a Stargate" then
- select = 1
- elseif key == 203 and select < 7 and menustate == "Dial a Stargate" then
- select = select+12
- if select > #menuOpt[menustate].options then select = #menuOpt[menustate].options end
- elseif key == 203 and select > 6 and menustate == "Dial a Stargate" then
- select = select-6
- elseif key == 205 and select == 19 and menustate == "Dial a Stargate" then
- select = 1
- elseif key == 205 and select < 13 and menustate == "Dial a Stargate" then
- select = select+6
- if select > #menuOpt[menustate].options then select = #menuOpt[menustate].options end
- elseif key == 205 and select > 12 and menustate == "Dial a Stargate" then
- select = select-12
- elseif key == 28 then
- if menuOpt[menustate].options[select] == "Quit" then break end
- if menuOpt[menustate].options[select] == "Force Update" then
- updateAdressList()
- acted = true
- end disconnect()
- if menuOpt[menustate].options[select] == "Disconnect Stargate" and not acted then
- disconnect()
- acted = true
- end
- for name, info in pairs(menuOpt) do
- if menuOpt[menustate].options[select] == name and not acted then
- menustate = menuOpt[menustate].options[select]
- select = 1
- acted = true
- end
- end
- if menustate == "Dial a Stargate" and not acted then
- dial(gates[select].address)
- sleep(1)
- menustate = "Main"
- acted = true
- end
- if menustate == "Settings" and not acted then
- if select == 1 then
- drawSettingsEditor()
- term.setCursorPos(5,h-5)
- local command = tostring(read())
- local Ncommand = tonumber(command)
- if type(Ncommand) == 'number' and Ncommand <= 99 and Ncommand >= 1 then
- term.setCursorPos(5,h-5)
- term.write('Updateing...')
- settings_Timing(math.floor(Ncommand-1))
- while timeUpdated do sleep(.00001) end
- else
- term.setCursorPos(5,h-5)
- term.write('Invalid number!')
- sleep(1)
- end
- acted = true
- elseif select == 2 then
- local name, location = settings_OnlineInfo()
- if name == "Dropbox" then
- settings_OnlineInfo("Pastebin", location)
- else
- settings_OnlineInfo("Dropbox", location)
- end
- acted = true
- elseif select == 3 then
- local name, location = settings_OnlineInfo()
- drawSettingsEditor()
- term.setCursorPos(5,h-7)
- if name == "Dropbox" then
- term.write("Paste the Dropbox link below.")
- elseif name == "Pastebin" then
- term.write("Paste the Pastebin code below.")
- end
- term.setCursorPos(5,h-5)
- local command = tostring(read())
- drawSettings()
- drawSettingsEditor()
- term.setCursorPos(5,h-5)
- term.write('Updateing...')
- settings_OnlineInfo(name, command)
- sleep(1)
- updateAdressList()
- acted = true
- end
- end
- end
- end
- end
- Initialize()
- updateSG_DHD()
- if settings_OnlineInfo() == "Dropbox or Pastebin" then
- menustate = "Settings"
- select = 2
- end
- parallel.waitForAny( timer, runMenu )
- term.clear()
- term.setCursorPos(1,1)
Add Comment
Please, Sign In to add comment