Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Programming by NEO
- -- Program Downloader v0.1
- -- http://computercraft.ru
- function pastebin(adress)
- pastebinPOST= " http://pastebin.com/raw.php?i="
- if (adress == nil) then error('Adrress is not exists') end
- pastebinPOSTE= pastebinPOST..adress
- h= http.post(pastebinPOSTE)
- lines= {}
- while true do
- q= h.readLine()
- if (q == nil) then break end
- lines[#lines+1]= q
- end
- return lines
- end
- function parseD(adress)
- lines= pastebin(adress)
- tokens= {}
- s= {}
- c= 0
- for i=1,#lines do
- for q=1,#lines[i] do
- c= c+1
- s[c]= string.sub(lines[i],q,q)
- end
- end
- temp= ''
- forS= false
- i= 0
- while i<#s do
- i= i+1
- forS= false
- if (s[i] == ';') then
- forS= true
- tokens[#tokens+1]= temp
- temp= ''
- end
- if (s[i] == '=') then
- forS= true
- tokens[#tokens+1]= temp
- tokens[#tokens+1]= '='
- temp= ''
- end
- if (forS~= true) then
- if (s[i+1] == nil) then
- temp= temp..s[i]
- tokens[#tokens+1]= temp
- end
- temp= temp..s[i]
- end
- end
- name_list= {}
- id_list= {}
- i= 0
- while i<#tokens do
- i= i+1
- if (tokens[i+1] == '=') then
- name_list[#name_list+1]= tokens[i]
- id_list[#id_list+1]= tokens[i+2]
- i= i+2
- end
- end
- return name_list,id_list
- end
- function drawA(arr)
- for i=1,#arr do
- print(arr[i])
- end
- end
- function download(index)
- lines= pastebin(PROGRAMS_ADRESS[index])
- path= fs.open(PROGRAMS_NAME[index],'w')
- for i=1,#lines do
- path.writeLine(lines[i])
- end
- path.close()
- while true do
- term.clear()
- term.setBackgroundColor(8192)
- term.setCursorPos(15,10)
- print('File '..PROGRAMS_NAME[index] ..' downloaded')
- term.setCursorPos(15,11)
- print('Press Space,to return')
- event,a= os.pullEvent()
- if (event == 'key' and a == 57) then break end
- end
- end
- function drawAll()
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(8)
- for i=min,max do
- if (i == count) then
- print(' <'..PROGRAMS_NAME[i]..'>')
- else
- --if (max-count>=2) then
- print(" "..PROGRAMS_NAME[i])
- end
- end
- end
- function load()
- PROGRAMS_NAME,PROGRAMS_ADRESS= parseD(ADRESS_LIST)
- table.insert(PROGRAMS_NAME,#PROGRAMS_NAME+1,"Update")
- table.insert(PROGRAMS_NAME,#PROGRAMS_NAME+1,"Re-list")
- table.insert(PROGRAMS_NAME,#PROGRAMS_NAME+1,"Exit")
- PROGRAMS_DESCRIPTION= pastebin(ADRESS_DISCRIPTION)
- table.insert(PROGRAMS_DESCRIPTION,#PROGRAMS_NAME-2,"Udpate Program")
- table.insert(PROGRAMS_DESCRIPTION,#PROGRAMS_NAME-1,"Reload Programs List")
- table.insert(PROGRAMS_DESCRIPTION,#PROGRAMS_NAME,"Exit Program")
- end
- function TextBox()
- X,Y= term.getSize()
- term.setCursorPos(1,Y-1)
- print("Loading...")
- sleep(1)
- end
- function description(index)
- while true do
- term.clear()
- term.setBackgroundColor(4096)
- term.setCursorPos(1,1)
- print(PROGRAMS_DESCRIPTION[index])
- print('Press Space,to return')
- event,a= os.pullEvent()
- if (event == 'key' and a == 57) then break end
- end
- end
- function update()
- fs.delete('pd')
- shell.run('pastebin','get','VhdQt94A','pd')
- shell.run('pd')
- error()
- end
- X,Y= term.getSize()
- ADRESS_LIST= "xZHMdRXP" -- не менять
- ADRESS_DISCRIPTION= "5Ha4HQXx"
- if (ADRESS_LIST == "") then error("Adrress = nil") end
- term.clear()
- term.setCursorPos(1,1)
- PROGRAMS_NAME= {}
- PROGRAMS_ADRESS= {}
- PROGRAMS_DESCRIPTION= {}
- load()
- count= 1
- if (Y>#PROGRAMS_NAME) then max= #PROGRAMS_NAME else max= Y end
- min= 1
- while true do
- drawAll()
- event,a= os.pullEvent()
- if (event == 'key') then
- if (a == 32) then description(count) end
- if (a == 200) then count= count-1 min= min-1 max= max-1 end
- if (a == 208) then count= count+1 max= max+1 max= max+1 end
- if (a == 28 and max-count>2) then download(count) end
- if (a == 28 and max-count == 2) then update() end
- if (a == 28 and max-count == 1) then load() TextBox() end
- if (a == 28 and max-count == 0) then
- term.clear()
- term.setCursorPos(1,1)
- error()
- end
- end
- if (min <= 1) then min= 1 end
- if (max > #PROGRAMS_NAME or max < #PROGRAMS_NAME) then max= #PROGRAMS_NAME end
- if (count< min) then count= min end
- if (count > max) then count= max end
- end
Add Comment
Please, Sign In to add comment