Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cWrite(text)
- scrx, scry = term.getSize()
- xt = scrx/2
- xt = xt -#text/2
- x,y = term.getCursorPos()
- term.setCursorPos(xt,y)
- write(text)
- end
- function hitbox(hit, object)
- scrx, scry = term.getSize()
- xt = scrx/2
- xt2 = xt +#object/2
- xt = xt -#object/2
- if hit >= xt and hit <= xt2 then
- return true
- else
- return false
- end
- end
- function rWrite(text)
- scrx, scry = term.getSize()
- xt = scrx -#text
- x,y = term.getCursorPos()
- term.setCursorPos(xt,y)
- write(text)
- end
- function getList()
- list = http.get( "http://galatical.com/list" )
- if list then
- local tLines = {}
- local sLine = list.readLine()
- while sLine do
- table.insert(tLines, sLine)
- sLine = list.readLine()
- end
- list.close()
- return tLines
- else
- print("Failed to get programs list")
- end
- end
- function split(line)
- continue = 1
- counter = 0
- while continue == 1 do
- counter = counter+1
- sleep(0)
- if string.sub(line, counter, counter+1) == "||" then
- prgrm = string.sub(line, 1, counter-2)
- ver = string.sub(line, counter+3, #line)
- continue = 0
- end
- end
- if not prgrm then
- return nil
- end
- if not ver then
- return nil
- end
- return prgrm , ver
- end
- pglist = {}
- verlist = {}
- programs = getList()
- --print("Got data")
- for i = 1, #programs do
- --print("Splitting line "..i.."/"..#programs)
- pglist[i], verlist[i] = split(programs[i])
- if pglist[i] == nil or verlist[i] == nil then
- table.remove(pglist[i])
- table.remove(pglist[i])
- end
- end
- --[[for b = 1, #pglist do
- print(pglist[b].." version "..verlist[b])
- end]]
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setTextColor(colors.black)
- term.setCursorPos(1,1)
- cWrite("LPI")
- for c = 1, #pglist do
- term.setCursorPos(1,c+1)
- cWrite(pglist[c])
- rWrite("[v"..verlist[c].."]")
- end
- start = true
- while start do
- e,t,cx,cy = os.pullEvent("mouse_click")
- if pglist[cy-1] then
- if hitbox(cx, pglist[cy-1]) then
- response = http.get( "http://galatical.com/"..pglist[cy-1])
- if response then
- sR = response.readAll()
- response.close()
- if fs.exists(pglist[cy-1]) then
- fs.delete(pglist[cy-1])
- end
- file = fs.open(pglist[cy-1],"w")
- file.write( sR )
- file.close()
- scrx, scry = term.getSize()
- term.setCursorPos(1, scry)
- write(" ")
- term.setCursorPos(1, scry)
- cWrite("Downloaded "..pglist[cy-1])
- else
- scrx, scry = term.getSize()
- term.setCursorPos(1, scry)
- write(" ")
- term.setCursorPos(1, scry)
- cWrite("Failed.")
- end
- end
- end
- if cx == 1 and cy == scry then
- term.setCursorPos(1, scry-1)
- id = read()
- term.setCursorPos(1, scry-1)
- write(" ")
- response = http.get( "http://galatical.com/"..id)
- if response then
- sR = response.readAll()
- response.close()
- if fs.exists(id) then
- fs.delete(id)
- end
- file = fs.open(id,"w")
- file.write( sR )
- file.close()
- scrx, scry = term.getSize()
- term.setCursorPos(1, scry)
- write(" ")
- term.setCursorPos(1, scry)
- cWrite("Downloaded "..id)
- else
- scrx, scry = term.getSize()
- term.setCursorPos(1, scry)
- write(" ")
- term.setCursorPos(1, scry)
- cWrite("Failed.")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment