Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Minecrosoft Paste--
- --Most of the upload/download code is from the pastebin program.--
- --Lead Programmer: Eric Bernard--
- if fs.exists("LimeFyre/APIs/fdialog") then
- os.loadAPI("LimeFyre/APIs/fdialog")
- end
- local dx, dy = term.getSize()
- local function dl(path,dest)
- local resp = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(path))
- if resp then
- f = fs.open(dest,"w")
- f.write(resp.readAll())
- f.close()
- return true
- else
- return false
- end
- end
- local function get(path)
- local resp = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(path))
- if resp then
- local sResponse = resp.readAll()
- resp.close()
- return sResponse
- else
- return false
- end
- end
- local function runProgram(code)
- local sCode = code
- local res = get(sCode)
- if res then
- local func, err = load(res, sCode, "t", _ENV)
- if not func then
- return false
- end
- local success, msg = pcall(func, table.unpack(tArgs, 3))
- if not success then
- printError( msg )
- end
- end
- end
- function clear(color)
- if color ~= nil then
- term.setBackgroundColor(color)
- end
- term.clear()
- term.setCursorPos(1,1)
- end
- cursor = term.setCursorPos
- bg = term.setBackgroundColor
- text = term.setTextColor
- line = paintutils.drawLine
- function centerPrint(text,y,distance)
- if text == nil then text = "Hello World!" end
- if y == nil then y = 1 end
- if distance == nil then distance = 0 end
- term.setCursorPos(dx/2-#tostring(text)/2-distance,y)
- print(" "..text)
- end
- function tile(txt,x,y,bgcolor,textcolor)
- if textcolor == bgcolor then
- if bgcolor == colors.black then
- textcolor = colors.white
- else
- textcolor = colors.black
- end
- end
- if x == "center" then
- x = dx/2-#txt/2
- end
- local width = #txt+x+1
- local height = y+2
- paintutils.drawFilledBox(x,y,width,height,bgcolor)
- bg(bgcolor)
- term.setCursorPos(x+1,y+1)
- text(textcolor)
- write(txt)
- return x,y,width,height
- end
- local loop = true
- while loop do
- clear(colors.gray)
- text(colors.yellow)
- centerPrint("Minecrosoft Paste",6)
- local newx,newy,neww,newh = tile(" Upload ",16,8,colors.green,colors.white)
- local getx,gety,getw,geth = tile(" Download ",28,8,colors.cyan,colors.white)
- local ex,ey,ew,eh = tile(" Exit ",28,12,colors.red,colors.white)
- --local runx,runy,runw,runh = tile(" Run ",23,8,colors.blue,colors.white)
- local lx,ly,lw,lh = tile("My Uploads",14,12,colors.magenta,colors.white)
- local event, button, x, y = os.pullEventRaw("mouse_click")
- --[=[if x >= runx and x <= runw and y >= runy and y <= runh then
- local runloop = true
- local input = ""
- while runloop do
- clear(colors.gray)
- text(colors.yellow)
- centerPrint("Pastebin ID",8)
- line(dx/2-4,9,dx/2+6,9,colors.white)
- cursor(dx/2-4,9)
- text(colors.black)
- write("> "..input:sub(1,8).."_")
- local bx, by, bw, bh = tile("Back",27,10,colors.red,colors.white)
- local yx, yy, yw, yh = tile("Run",15,10,colors.green,colors.white)
- local event, a,b,c = os.pullEventRaw()
- if event == "char" then
- input = input..a
- elseif event == "key" then
- if a == 14 then
- input = input:sub(1,#input-1)
- elseif a == 28 then
- clear(colors.gray)
- text(colors.white)
- centerPrint("Getting pastebin data",9)
- text(colors.lightGray)
- centerPrint("This may take a few seconds",11)
- local success = runProgram(input)
- if not success then
- clear(colors.gray)
- text(colors.red)
- centerPrint("An error occurred",8)
- text(colors.lightGray)
- centerPrint("This may be because of an invalid pastebin",10)
- centerPrint("ID or that the connection was interrupted.",11)
- sleep(2)
- centerPrint("Press any key to continue.",15)
- os.pullEvent("key_up")
- runloop = false
- break
- end
- end
- elseif event == "mouse_click" then
- local x,y = b,c
- if x >= bx and x <= bw and y >= by and y <= bh then
- runloop = false
- break
- elseif x >= yx and x <= yw and y >= yy and y <= yh then
- clear(colors.gray)
- text(colors.white)
- centerPrint("Getting pastebin data",9)
- text(colors.lightGray)
- centerPrint("This may take a few seconds",11)
- local success = runProgram(input)
- if not success then
- clear(colors.gray)
- text(colors.red)
- centerPrint("An error occurred",8)
- text(colors.lightGray)
- centerPrint("This may be because of an invalid pastebin",10)
- centerPrint("ID or that the connection was interrupted.",11)
- sleep(2)
- centerPrint("Press any key to continue.",15)
- os.pullEvent("key_up")
- runloop = false
- break
- end
- end
- end
- end]=]
- --[=[else]=]if x >= lx and x <= lw and y >= ly and y <= lh then
- local uloop = true
- local files = false
- while uloop do
- clear(colors.gray)
- text(colors.yellow)
- centerPrint("My Recent Paste Uploads",2)
- text(colors.white)
- if fs.exists("LimeFyre/User/Misc/paste") then
- local f = fs.open("LimeFyre/User/Misc/paste","r")
- pinfo = textutils.unserialize(f.readAll())
- f.close()
- files = true
- elseif fs.exists("pasteuploads") then
- local f = fs.open("pasteuploads","r")
- pinfo = textutils.unserialize(f.readAll())
- f.close()
- files = true
- end
- local cpos = 4
- if files then
- local istart = 1
- if #pinfo > 4 then istart = #pinfo-3 end
- for i=istart,#pinfo do
- term.setTextColor(colors.orange)
- centerPrint(pinfo[i].link,cpos)
- term.setTextColor(colors.lightGray)
- centerPrint("File: "..pinfo[i].name,cpos+1)
- cpos = cpos+3
- end
- else
- text(colors.white)
- centerPrint("No uploads!",3)
- end
- local bx, by, bw, bh = tile(" Back ","center",16,colors.blue,colors.white)
- local event, button, x, y = os.pullEventRaw("mouse_click")
- if x >= bx and x <= bw and y >= by and y <= bh then
- uloop = false
- break
- end
- end
- elseif x >= newx and x <= neww and y >= newy and y <= newh then
- local input = ""
- local uploop = true
- while uploop do
- clear(colors.gray)
- text(colors.yellow)
- centerPrint("Path to file",9)
- line(2,10,dx-2,10,colors.white)
- cursor(2,10)
- text(colors.black)
- local charlimit = dx-8
- disin = input
- if #input > charlimit then
- disin = disin:sub(#disin-charlimit,#disin)
- end
- write("> "..disin.."_")
- local ux,uy,uw,uh = tile("Upload",10,12,colors.green,colors.white)
- local bx,by,bw,bh = tile(" Back ",36,12,colors.red,colors.white)
- local fx,fy,fw,fh = 50
- if fs.exists("LimeFyre/APIs/fdialog") then
- fx,fy,fw,fh = tile(" Find ",23,12,colors.cyan,colors.white)
- end
- local event, a,b,c = os.pullEventRaw()
- if event == "char" then
- input = input..a
- elseif event == "key" then
- if a == 14 then
- input = input:sub(1,#input-1)
- elseif a == 28 then
- if fs.exists(input) and input ~= "" then
- local sName = fs.getName(input)
- local f = fs.open(input,"r")
- local content = f.readAll()
- f.close()
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(sName).."&"..
- "api_paste_code="..textutils.urlEncode(content)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local sCode = string.match( sResponse, "[^/]+$" )
- clear(colors.gray)
- text(colors.lime)
- centerPrint("Uploaded to "..sResponse,9)
- text(colors.green)
- if fs.exists("LimeFyre/User") then
- if fs.exists("LimeFyre/User/Misc/paste") then
- local f = fs.open("LimeFyre/User/Misc/paste","r")
- pinfo = textutils.unserialize(f.readAll())
- f.close()
- else
- pinfo = {}
- end
- local n = #pinfo+1
- pinfo[n] = {}
- pinfo[n].name = input
- pinfo[n].link = sCode
- local f = fs.open("LimeFyre/User/Misc/paste","w")
- f.write(textutils.serialize(pinfo))
- f.close()
- else
- if fs.exists("pasteuploads") then
- local f = fs.open("LimeFyre/User/Misc/paste","r")
- local pinfo = textutils.unserialize(f.readAll())
- f.close()
- else
- pinfo = {}
- end
- local n = #pinfo+1
- pinfo[n] = {}
- pinfo[n].name = input
- pinfo[n].link = sCode
- local f = fs.open("LimeFyre/User/Misc/paste","w")
- f.write(textutils.serialize(pinfo))
- f.close()
- end
- centerPrint("Use "..sCode.." to download it elsewhere.",11)
- centerPrint("The code has been saved in case you lose it.",12)
- centerPrint("Press any key to return",13)
- os.pullEvent("key_up")
- uploop = false
- else
- clear(colors.gray)
- text(colors.red)
- centerPrint("Something went wrong.",5)
- text(colors.lightGray)
- centerPrint("Connection with pastebin could not be",7)
- centerPrint("established or maintained long enough",8)
- centerPrint("to upload. Please try again later.",9)
- centerPrint("We apologize for the inconvenience.",10)
- centerPrint("Press any key to return.",15)
- os.pullEvent("key_up")
- uploop = false
- end
- end
- end
- elseif event == "mouse_click" then
- local button, x, y = a,b,c
- if x >= bx and x <= bw and y >= by and y <= bh then
- uploop = false
- break
- elseif x >= ux and x <= uw and y >= uy and y <= uh then
- if fs.exists(input) and input ~= "" then
- local sName = fs.getName(input)
- local f = fs.open(input,"r")
- local content = f.readAll()
- f.close()
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(sName).."&"..
- "api_paste_code="..textutils.urlEncode(content)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local sCode = string.match( sResponse, "[^/]+$" )
- clear(colors.gray)
- text(colors.lime)
- centerPrint("Uploaded to "..sResponse,9)
- text(colors.green)
- if fs.exists("LimeFyre/User") then
- if fs.exists("LimeFyre/User/Misc/paste") then
- local f = fs.open("LimeFyre/User/Misc/paste","r")
- pinfo = textutils.unserialize(f.readAll())
- f.close()
- else
- pinfo = {}
- end
- local n = #pinfo+1
- pinfo[n] = {}
- pinfo[n].name = input
- pinfo[n].link = sCode
- local f = fs.open("LimeFyre/User/Misc/paste","w")
- f.write(textutils.serialize(pinfo))
- f.close()
- else
- if fs.exists("pasteuploads") then
- local f = fs.open("LimeFyre/User/Misc/paste","r")
- local pinfo = textutils.unserialize(f.readAll())
- f.close()
- else
- pinfo = {}
- end
- local n = #pinfo+1
- pinfo[n] = {}
- pinfo[n].name = input
- pinfo[n].link = sCode
- local f = fs.open("LimeFyre/User/Misc/paste","w")
- f.write(textutils.serialize(pinfo))
- f.close()
- end
- centerPrint("Use "..sCode.." to download it elsewhere.",11)
- centerPrint("The code has been saved in case you lose it.",12)
- centerPrint("Press any key to return",13)
- os.pullEvent("key_up")
- uploop = false
- else
- clear(colors.gray)
- text(colors.red)
- centerPrint("Something went wrong.",5)
- text(colors.lightGray)
- centerPrint("Connection with pastebin could not be",7)
- centerPrint("established or maintained long enough",8)
- centerPrint("to upload. Please try again later.",9)
- centerPrint("We apologize for the inconvenience.",10)
- centerPrint("Press any key to return.",15)
- os.pullEvent("key_up")
- uploop = false
- end
- end
- elseif x >= fx and x <= fw and y >= fy and y <= fh then
- local file = fdialog.open("/")
- if file ~= nil then
- input = file
- end
- end
- end
- end
- elseif x >= getx and x <= getw and y >= gety and y <= geth then
- local pasteinput = ""
- local nameinput = ""
- local input = ""
- local selected = "paste"
- local pchar = "_"
- local nchar = ""
- local getloop = true
- while getloop do
- if selected == "paste" then
- if #pasteinput > 8 then
- input = input:sub(1,8)
- end
- pasteinput = input
- pchar = "_"
- nchar = ""
- else
- nameinput = input
- pchar = ""
- nchar = "_"
- end
- clear(colors.gray)
- text(colors.yellow)
- centerPrint("Pastebin code",3)
- centerPrint("Destination path",8)
- line(dx/2-4,4,dx/2+6,4,colors.white)
- line(2,9,dx-2,9,colors.white)
- text(colors.gray)
- term.setCursorPos(dx/2-4,4)
- write("> "..pasteinput..pchar)
- local charlimit = dx-8
- term.setCursorPos(2,9)
- if #nameinput >= charlimit then
- write("> "..nameinput:sub(#nameinput-charlimit,#nameinput)..nchar)
- else
- write("> "..nameinput..nchar)
- end
- local okx,oky,okw,okh = tile("Download","center",11,colors.green,colors.white)
- local bx,by,bw,bh = tile("Cancel","center",15,colors.red,colors.white)
- local event, p1, p2, p3 = os.pullEvent()
- if event == "char" then
- local character = p1
- input = input..character
- elseif event == "paste" then
- local pasted = p1
- input = input..pasted
- elseif event == "key" then
- local key = p1
- if key == 14 then
- input = input:sub(1,#input-1)
- elseif key == 28 then
- bg(colors.black)
- textColor(colors.white)
- clear()
- shell.run(input)
- local _,cy = term.getCursorPos()
- textColor(colors.white)
- centerPrint("Press any key to return to LimeFyre",cy)
- local event, key = os.pullEventRaw("key")
- runloop = false
- break
- end
- elseif event == "mouse_click" then
- local button = p1
- local x = p2
- local y = p3
- if y == 4 then
- if selected == "name" then
- nameinput = input
- end
- input = pasteinput
- selected = "paste"
- elseif y == 9 then
- if selected == "paste" then
- pasteinput = input
- end
- input = nameinput
- selected = "name"
- elseif x >= okx and x <= okw and y >= oky and y <= okh then
- if fs.exists(nameinput) then
- clear(colors.gray)
- text(colors.red)
- centerPrint("The file '"..nameinput:sub(1,20).."' already exists.",10)
- sleep(2)
- else
- local ok = dl(pasteinput,nameinput)
- if pasteinput == "" then ok = false end
- if ok then
- clear(colors.gray)
- text(colors.lime)
- centerPrint("The program was successfully downloaded!",9)
- text(colors.green)
- centerPrint("Press any key to return to the main screen.",11)
- os.pullEvent("key")
- getloop = false
- break
- else
- clear(colors.gray)
- text(colors.red)
- centerPrint("Something went wrong.",5)
- text(colors.lightGray)
- centerPrint("Either the pastebin ID entered "..'("'..pasteinput..'")',7)
- centerPrint("doesn't exist, or your connection to pastebin was",8)
- centerPrint("interrupted or not established. Please try again.",9)
- centerPrint("Press any key to continue.",15)
- os.pullEvent("key_up")
- end
- end
- elseif x >= bx and x <= bw and y >= by and y <= bh then
- getloop = false
- break
- end
- end
- end
- elseif x >= ex and x <= ew and y >= ey and y <= eh then
- loop = false
- clear(colors.black)
- text(colors.white)
- centerPrint("Thank you for using Minecrosoft Paste",2)
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement