Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- (C) 2014 Viktor alias Coronaxe. no rights reserved, but please mind the creator's credits anyways!
- local timezone = "utc"
- local timeoffset = "+1"
- local ver = 0.50
- local apiver = 0.36
- local screenAPI = "uRpaiUB3"
- local rvercode = "axgaywWj"
- local rexplorercode = "SCv9r7y7"
- local args = {...}
- --This code checks for my screen API
- if not fs.exists("/apis/screen") then
- if not http then
- error("Warning! Screen API not present and HTTP API not enabled! Please enable HTTP API in computercraft.cfg, or place the latest Version of the screen API as \"/apis/screen\"!")
- end
- print("Setting up apis for use, please stand by...")
- sleep(1)
- print("Getting API...")
- local response = http.get("http://pastebin.com/raw.php?i="..screenAPI)
- print("Saving API to disk...")
- local sResponse = response.readAll()
- fs.makeDir("/apis")
- local fh = fs.open("/apis/screen" ,"w")
- fh.write(tostring(sResponse))
- fh.close()
- print("Finished!")
- print("")
- print("This bit of code has been contributed by Thib0704! Thank you, Thib!")
- sleep(2)
- end
- --code has been contributed by Thib0704 @ computercraft.info!
- --following code checks if there are updates
- if http then
- print("checking for updates...")
- local rver = tonumber(http.get("http://pastebin.com/raw.php?i="..rvercode).readAll())
- if rver ~= nil and rver > ver then
- print("Found update! Beginning update process... Please do not terminate the program while updating!")
- sleep(1)
- fs.delete(shell.getRunningProgram())
- print("Getting new version "..rver.."...")
- local nv = http.get("http://pastebin.com/raw.php?i="..rexplorercode).readAll()
- local fh = fs.open(shell.getRunningProgram(),"w")
- fh.write(tostring(nv))
- fh.close()
- print("Done! Version Updated to "..rver..". The Computer will restart now")
- sleep(3)
- os.reboot()
- end
- else
- print("HTTP Not enabled. Weren't able to update!")
- sleep(0.5)
- end
- --eoc
- os.loadAPI("/apis/screen")
- local executing = false
- if clipboard == nil then
- clipboard = nil
- end
- if screen.version() < apiver then
- error("Your Version of the screen API is too old. Your Version: "..screen.version()..", Least Required Version: "..apiver..". Please restart this application to redownload the API")
- fs.delete("/apis/screen")
- end
- function quit()
- screen.cls()
- print("Thank you for using Explorer Version "..ver.."!")
- --os.unloadAPI("screen")
- error()
- end
- function resolve(path)
- if string.sub(path,1,1) == "/" then
- return path
- else
- return "/"..path
- end
- end
- function cd(path)
- local rPath = path
- if fs.exists(rPath) then
- local bPath = rPath
- shell.setDir(bPath)
- return true
- else
- return false
- end
- end
- function createFile(fPath)
- local fh = fs.open(fPath,"w")
- fh.close()
- end
- function exec(path,parameters)
- local rPath = path
- --print(rPath)
- if fs.exists(rPath) and not fs.isDir(rPath) then
- local cString = rPath.." "..parameters
- shell.run(cString)
- return true
- else
- return false
- end
- end
- function list(path)
- local rPath = path
- if fs.exists(rPath) then
- local fTable = fs.list(rPath)
- if fTable ~= nil then
- table.sort(fTable)
- local tFiles = {}
- local tFilesPath = {}
- local tDirs = {}
- local tDirsPath = {}
- local tDirAndFiles = {}
- for n, sItem in pairs( fTable ) do
- if string.sub( sItem, 1, 1 ) ~= "." then
- local sPath = fs.combine( rPath, sItem )
- sPath = "/"..sPath
- if fs.isDir( sPath ) then
- table.insert( tDirs, sItem )
- table.insert( tDirsPath, sPath )
- else
- table.insert( tFiles, sItem )
- table.insert( tFilesPath, sPath )
- end
- end
- end
- table.sort( tDirs )
- table.sort( tFiles )
- tDirAndFiles.directories = tDirs
- tDirAndFiles.dirpaths = tDirsPath
- tDirAndFiles.files = tFiles
- tDirAndFiles.filepaths = tFilesPath
- tDirAndFiles.all = {}
- tDirAndFiles.allpaths = {}
- for i=1, #tDirsPath do
- table.insert(tDirAndFiles.all,fs.getName(tDirsPath[i]))
- table.insert(tDirAndFiles.allpaths,tDirsPath[i])
- end
- for i=1, #tFilesPath do
- table.insert(tDirAndFiles.all,fs.getName(tFilesPath[i]))
- table.insert(tDirAndFiles.allpaths,tFilesPath[i])
- end
- return tDirAndFiles
- else
- print(shell.dir().." is not a directory!")
- return false
- end
- else
- print("invalid path!")
- return false
- end
- end
- function drawFiles(tDat,offset,highlight) --please only use absolute filepaths!
- local bckstr = ".."
- print("Currently in: "..resolve(shell.dir()))
- local x,y = term.getCursorPos()
- local btnBack = {x1 = 1, x2 = #bckstr, y1 = y, y2 = y, path = shell.resolve(".."), name = ".."}
- local drawnCoords = {}
- if resolve(shell.dir()) ~= "/" then
- table.insert(drawnCoords,btnBack)
- local tx,ty = term.getCursorPos()
- term.setBackgroundColor(colors.lime)
- write(bckstr)
- term.setCursorPos(tx,ty+1)
- else
- highlight = highlight + 1
- end
- for i=offset, #tDat do
- local tcpx, tcpy = term.getCursorPos()
- if fs.isDir(tDat[i]) then
- if i==highlight then
- term.setBackgroundColor(colors.purple)
- else
- term.setBackgroundColor(colors.blue)
- end
- else
- if i==highlight then
- term.setBackgroundColor(colors.orange)
- else
- term.setBackgroundColor(colors.red)
- end
- end
- write(fs.getName(tDat[i]))
- local temTable = {x1 = tcpx, x2 = tcpx + #fs.getName(tDat[i])-1, y1 = tcpy, y2 = tcpy, path = tDat[i], name = fs.getName(tDat[i])}
- table.insert(drawnCoords,temTable)
- term.setCursorPos(tcpx,tcpy+1)
- end
- return drawnCoords
- end
- function options()
- end
- function drawFileMenu(referrer,x,y,pd,nfm)
- local btnWidth = 7
- local fileBtn = {}
- local dirBtn = {}
- local tx,ty = term.getSize()
- local msgRun = "run "
- local msgEdit = "edit"
- local msgOpen = "open"
- local msgCopy = "copy"
- local msgPaste = "pste"
- local msgRename = "rnme"
- local msgDelete = "del "
- local btnRun = {x1 = x, x2 = x+btnWidth, y1 = y, y2 = y, text = msgRun, color = colors.blue, exec = function(referrer) if referrer.path~=resolve(shell.getRunningProgram()) then executing=true shell.run("clear") shell.run(referrer.path) executing=false sleep(1.5) end end}
- local btnEdit = {x1 = x, x2 = x+btnWidth, y1 = y, y2 = y, text = msgEdit, color = colors.blue, exec = function(referrer) executing=true shell.run("edit "..referrer.path) executing=false end}
- local btnOpen = {x1 = x, x2 = x+btnWidth, y1 = y, y2 = y, text = msgOpen, color = colors.blue, exec = function(referrer) cd(referrer.path) end}
- local btnCopy = {x1 = x, x2 = x+btnWidth, y1 = y, y2 = y, text = msgCopy, color = colors.blue, exec = function(referrer) if resolve(shell.getRunningProgram())~=referrer.path and resolve(referrer.path)~="/" then clipboard = referrer.path end end}
- local btnPaste = {x1 = x, x2 = x+btnWidth, y1 = y, y2 = y, text = msgPaste, color = colors.blue, exec = function(referrer) local clipboardto=clipboard local ex=true if clipboard~=nil and fs.exists(clipboard) then while ex do if fs.exists(shell.dir().."/"..fs.getName(clipboardto)) then clipboardto=clipboardto.."_copy" else ex=false end end fs.copy(clipboard,shell.dir().."/"..fs.getName(clipboardto)) else clipboard=nil end end}
- local btnRename = {x1 = x, x2 = x+btnWidth, y1 = y, y2 = y, text = msgRename, color = colors.blue, exec = function(referrer) local sx,sy = term.getSize() local evn,eparam,x,y local info = "New Name?" local arInput = {x1 = sx/2-14,x2 = sx/2+14,y1 = sy/2-3,y2 = sy/2,color = colors.lightBlue,pos = 1,data = {}} local btnCancel = {x1 = sx/2-14,x2 = sx/2-5,y1 = sy/2+1,y2 = sy/2+4,text = "Cancel",color = colors.red} local btnConfirm = {x1 = sx/2+5,x2 = sx/2+14,y1 = sy/2+1,y2 = sy/2+4,text = "Confirm",color = colors.lime} term.setCursorPos(sx/2-#info/2,sy/2-5) print(info) screen.drawBox(arInput) screen.drawButton(btnCancel,true) screen.drawButton(btnConfirm,true) screen.getFocus(arInput) term.setCursorBlink(true) for i=1,string.len(referrer.name) do arInput.data[i] = string.sub(referrer.name,i,i) arInput.pos = arInput.pos+1 end repeat screen.getFocus(arInput) for i=1,arInput.x2-arInput.x1-2 do term.setBackgroundColor(colors.black) write(" ") end screen.getFocus(arInput) for i=1,#arInput.data do term.setBackgroundColor(colors.black) write(arInput.data[i]) end evn,eparam,x,y = os.pullEvent() if evn == "char" and arInput.pos<=arInput.x2-arInput.x1-2 then arInput.data[arInput.pos] = eparam arInput.pos = arInput.pos+1 elseif evn == "key" and eparam == 14 and arInput.pos>1 then arInput.pos = arInput.pos-1 arInput.data[arInput.pos] = nil end until (evn == "mouse_click") or (evn == "key" and eparam == 28) local sFile = "" for i=1,#arInput.data do sFile = sFile..arInput.data[i] end if (sFile ~= nil) and (evn == "key" and eparam == 28) or (evn == "mouse_click" and screen.pressed(btnConfirm,x,y)) then if not fs.exists(shell.dir().."/"..sFile) and not fs.isReadOnly(shell.dir().."/"..sFile) then fs.move(referrer.path,shell.dir().."/"..sFile) else screen.cls() print("An Error Occurred. File Exists or Folder is Readonly.") sleep(1.5) end end term.setCursorBlink(false) end}
- local btnDelete = {x1 = x, x2 = x+btnWidth, y1 = y, y2 = y, text = msgDelete, color = colors.blue, exec = function(referrer) local warning="REALLY DELETE "..referrer.name.."?" local xt,yt = term.getSize() term.setCursorPos(xt/2-#warning/2,yt/2-6) term.write(warning) local yes={x1=xt/2-4,x2=xt/2+4,y1=yt/2-4,y2=yt/2-1,text="YES",color=colors.red} local no={x1=xt/2-4,x2=xt/2+4,y1=yt/2+1,y2=yt/2+4,text="NO",color=colors.red} local accessDenied={x1=xt/2-10,x2=xt/2+10,y1=yt/2-5,y2=yt/2+5,text="ACCESS DENIED",color=colors.red} screen.drawButton(yes,true) screen.drawButton(no,true) local evn,btn,px,py = os.pullEvent("mouse_click") if btn==1 and screen.pressed(yes,px,py) then if not fs.isReadOnly(referrer.path) and referrer.path ~= shell.getRunningProgram() then fs.delete(referrer.path) else screen.drawButton(accessDenied,true) sleep(1.5) end end end}
- if not pd and nfm then
- fileBtn = {}
- dirBtn = {btnCopy}
- elseif pd and nfm then
- fileBtn = {}
- dirBtn = {btnCopy,btnPaste}
- else
- if pd then
- --print("True")
- --sleep(3)
- fileBtn = {btnRun, btnEdit, btnCopy, btnPaste, btnRename, btnDelete}
- dirBtn = {btnOpen, btnCopy, btnPaste, btnRename, btnDelete}
- else
- --print("false")
- --sleep(3)
- fileBtn = {btnRun, btnEdit, btnCopy, btnRename, btnDelete}
- dirBtn = {btnOpen, btnCopy, btnRename, btnDelete}
- end
- end
- if (ty-#fileBtn<=y-2 and not fs.isDir(referrer.path)) or (ty-#dirBtn<=y-2 and fs.isDir(referrer.path)) then
- if not fs.isDir(referrer.path) then
- for i=1,#fileBtn do
- fileBtn[i].y1 = y-i+1
- fileBtn[i].y2 = y-i+1
- end
- else
- for i=1,#dirBtn do
- dirBtn[i].y1 = y-i+1
- dirBtn[i].y2 = y-i+1
- end
- end
- else
- if not fs.isDir(referrer.path) then
- for i=1,#fileBtn do
- fileBtn[i].y1 = y+i-1
- fileBtn[i].y2 = y+i-1
- end
- else
- for i=1,#dirBtn do
- dirBtn[i].y1 = y+i-1
- dirBtn[i].y2 = y+i-1
- end
- end
- end
- if fs.isDir(referrer.path) then
- for i=1,#dirBtn do
- screen.drawButton(dirBtn[i],true)
- end
- return dirBtn
- else
- for i=1,#fileBtn do
- screen.drawButton(fileBtn[i],true)
- end
- return fileBtn
- end
- end
- function drawTaskBar(deployed, dtype)
- local tx,ty = term.getSize()
- local allbtns = {}
- local menubtns = {}
- local newbtns = {}
- local switchbtns = {}
- local barBackground = {x1 = 1, x2 = 45, y1 = 1, y2 = 1, color = colors.gray}
- screen.drawButton(barBackground)
- local msgMenu = "^MENU^ "
- local msgQuit = " Quit "
- local msgShutdown = "Shutdwn"
- local msgRestart = "Restart"
- local msgOptions = "Options"
- local btnMenu = {x1 = 1, x2 = #msgMenu, y1 = 1, y2 = 1, text = msgMenu, color = colors.gray, textcolor = colors.yellow, altTextColor = colors.lime, altText = "vMENUv ", exec = function() return "MENU" end}
- local btnQuit = {x1 = 1, x2 = #msgQuit, y1 = 1, y2 = 1, text = msgQuit, color = colors.gray, textcolor = colors.lime, exec = function() screen.cls() quit() end}
- local btnShutdown = {x1 = 1, x2 = #msgShutdown, y1 = 1, y2 = 1, text = msgShutdown, color = colors.gray, textcolor = colors.lime, exec = function() os.shutdown() end}
- local btnRestart = {x1 = 1, x2 = #msgRestart, y1 = 1, y2 = 1, text = msgRestart, color = colors.gray, textcolor = colors.lime, exec = function() os.reboot() end}
- local btnOptions = {x1 = 1, x2 = #msgOptions, y1 = 1, y2 = 1, text = msgOptions, color = colors.gray, textcolor = colors.lime, exec = function() end}
- menubtns = {btnMenu, btnQuit, btnShutdown, btnRestart, btnOptions}
- for i=2,#menubtns do
- menubtns[i].y1 = i
- menubtns[i].y2 = i
- end
- local separator = {x1 = btnMenu.x2 + 1, x2 = btnMenu.x2 + 1, y1 = 1, y2 = 1, text = "|", color = colors.gray, textcolor = colors.orange}
- local msgNew = " ^NEW^ "
- local msgFile = " File "
- local msgFolder = " Folder"
- local btnNew = {x1 = btnMenu.x2 + 2, x2 = btnMenu.x2 + 2 + #msgNew, y1 = 1, y2 = 1, text = msgNew, color = colors.gray, textcolor = colors.yellow, altTextColor = colors.lime, altText = " vNEWv ", exec = function() return "NEW" end}
- local btnFile = {x1 = btnMenu.x2 + 2, x2 = btnMenu.x2 + 2 + #msgFolder, y1 = 1, y2 = 1, text = msgFile, color = colors.gray, textcolor = colors.lime, exec = function() local sx,sy = term.getSize() local evn,eparam,x,y local info = "New File" local arInput = {x1 = sx/2-14,x2 = sx/2+14,y1 = sy/2-3,y2 = sy/2,color = colors.lightBlue,pos = 1,data = {}} local btnCancel = {x1 = sx/2-14,x2 = sx/2-5,y1 = sy/2+1,y2 = sy/2+4,text = "Cancel",color = colors.red} local btnConfirm = {x1 = sx/2+5,x2 = sx/2+14,y1 = sy/2+1,y2 = sy/2+4,text = "Confirm",color = colors.lime} term.setCursorPos(sx/2-#info/2,sy/2-5) print(info) screen.drawBox(arInput) screen.drawButton(btnCancel,true) screen.drawButton(btnConfirm,true) screen.getFocus(arInput) term.setCursorBlink(true) repeat evn,eparam,x,y = os.pullEvent() if evn == "char" and arInput.pos<=arInput.x2-arInput.x1-2 then arInput.data[arInput.pos] = eparam arInput.pos = arInput.pos+1 elseif evn == "key" and eparam == 14 and arInput.pos>1 then arInput.pos = arInput.pos-1 arInput.data[arInput.pos] = nil end screen.getFocus(arInput) for i=1,arInput.x2-arInput.x1-2 do term.setBackgroundColor(colors.black) write(" ") end screen.getFocus(arInput) for i=1,#arInput.data do term.setBackgroundColor(colors.black) write(arInput.data[i]) end until (evn == "mouse_click") or (evn == "key" and eparam == 28) local sFile = "" for i=1,#arInput.data do sFile = sFile..arInput.data[i] end if (sFile ~= nil) and (evn == "key" and eparam == 28) or (evn == "mouse_click" and screen.pressed(btnConfirm,x,y)) then if not fs.exists(shell.dir().."/"..sFile) and not fs.isReadOnly(shell.dir().."/"..sFile) then createFile(shell.dir().."/"..sFile) else screen.cls() print("An Error Occurred. File Exists or Folder is Readonly.") sleep(1.5) end end term.setCursorBlink(false) end}
- local btnFolder = {x1 = btnMenu.x2 + 2, x2 = btnMenu.x2 + 2 + #msgFolder, y1 = 1, y2 = 1, text = msgFolder, color = colors.gray, textcolor = colors.lime, exec = function() local sx,sy = term.getSize() local evn,eparam,x,y local info = "New Directory" local arInput = {x1 = sx/2-14,x2 = sx/2+14,y1 = sy/2-3,y2 = sy/2,color = colors.lightBlue,pos = 1,data = {}} local btnCancel = {x1 = sx/2-14,x2 = sx/2-5,y1 = sy/2+1,y2 = sy/2+4,text = "Cancel",color = colors.red} local btnConfirm = {x1 = sx/2+5,x2 = sx/2+14,y1 = sy/2+1,y2 = sy/2+4,text = "Confirm",color = colors.lime} term.setCursorPos(sx/2-#info/2,sy/2-5) print(info) screen.drawBox(arInput) screen.drawButton(btnCancel,true) screen.drawButton(btnConfirm,true) screen.getFocus(arInput) term.setCursorBlink(true) repeat evn,eparam,x,y = os.pullEvent() if evn == "char" and arInput.pos<=arInput.x2-arInput.x1-2 then arInput.data[arInput.pos] = eparam arInput.pos = arInput.pos+1 elseif evn == "key" and eparam == 14 and arInput.pos>1 then arInput.pos = arInput.pos-1 arInput.data[arInput.pos] = nil end screen.getFocus(arInput) for i=1,arInput.x2-arInput.x1-2 do term.setBackgroundColor(colors.black) write(" ") end screen.getFocus(arInput) for i=1,#arInput.data do term.setBackgroundColor(colors.black) write(arInput.data[i]) end until (evn == "mouse_click") or (evn == "key" and eparam == 28) local sFolder = "" for i=1,#arInput.data do sFolder = sFolder..arInput.data[i] end if (sFolder ~= nil) and (evn == "key" and eparam == 28) or (evn == "mouse_click" and screen.pressed(btnConfirm,x,y)) then if not fs.exists(shell.dir().."/"..sFolder) and not fs.isReadOnly(shell.dir().."/"..sFolder) then fs.makeDir(shell.dir().."/"..sFolder) else screen.cls() print("An Error Occurred. File Exists or Folder is Readonly.") sleep(1.5) end end term.setCursorBlink(false) end}
- newbtns = {btnNew, btnFile, btnFolder}
- for i=2,#newbtns do
- newbtns[i].y1 = i
- newbtns[i].y2 = i
- end
- local separator2 = {x1 = btnNew.x2 + 1, x2 = btnNew.x2 + 1, y1 = 1, y2 = 1, text = "|", color = colors.gray, textcolor = colors.orange}
- switchbtns = {btnMenu,btnNew}
- local btnFS = {x1 = tx-11,x2 = 7,y1 = 1,y2 = 1,text = math.floor(fs.getFreeSpace(shell.dir())/1024).."KB",textcolor = colors.lime, color = colors.gray}
- if math.floor(fs.getFreeSpace(shell.dir())/1024)<500 then
- btnFS.textcolor = colors.blue
- end
- if math.floor(fs.getFreeSpace(shell.dir())/1024)<300 then
- btnFS.textcolor = colors.yellow
- end
- if math.floor(fs.getFreeSpace(shell.dir())/1024)<100 then
- btnFS.textcolor = colors.red
- end
- if clipboard~=nil then
- local btnClipboard = {x1 = separator2.x2+2, x2 = separator2.x2 + #fs.getName(clipboard) + 1, y1 = 1, y2 = 1, text = "CB: "..fs.getName(clipboard), textcolor = colors.red, color = colors.gray}
- allbtns = {separator, separator2, btnMenu, btnNew, btnFS, btnClipboard}
- else
- allbtns = {separator, separator2, btnMenu, btnNew, btnFS}
- end
- for i=1,#allbtns do
- screen.drawButton(allbtns[i])
- end
- if deployed and dtype == "MENU" then
- btnMenu.text = btnMenu.altText
- btnMenu.textcolor = btnMenu.altTextColor
- for i=1,#menubtns do
- screen.drawButton(menubtns[i])
- end
- return menubtns
- elseif deployed and dtype == "NEW" then
- btnNew.text = btnNew.altText
- btnNew.textcolor = btnNew.altTextColor
- for i=1,#newbtns do
- screen.drawButton(newbtns[i])
- end
- return newbtns
- else
- return switchbtns
- end
- end
- function init()
- screen.cls()
- print("Explorer Version "..ver..", Program written by Coronaxe!")
- print("")
- print("o) Leftklick a File (red) or Folder (blue) to highlight it")
- print("o) Rightklick a File (red) to open the context menu")
- print("o) Leftklick a highlighted Folder (purple) to switch to it")
- print("o) To Quit, please click on the \"x\" in the upper right!")
- print("")
- print("Please click anywhere to proceed.")
- os.pullEvent("mouse_click")
- end
- function usage()
- print("Use \""..fs.getName(shell.getRunningProgram()).."\", to start the Explorer!")
- print("Use \""..fs.getName(shell.getRunningProgram()).." help\", to print the Help Message!")
- end
- function bsod(ermsg)
- term.setBackgroundColor(colors.blue)
- term.clear()
- term.setCursorPos(1,1)
- local tx,ty = term.getSize()
- local tText = {
- "*!=#?!, an error has occurred!",
- "",
- "Detailed information:",
- ermsg,
- "If this is the first time",
- "you see this, ignore it.",
- "If this is not the first time",
- "you see this error,",
- "please wait for implementation",
- "of an error reporter!",
- }
- for i=1, #tText do
- term.setCursorPos(tx/2-#tText[i]/2,ty/2-7+i)
- print(tText[i])
- end
- end
- function showError(ermsg)
- local mx,my = term.getSize()
- local btnError = {
- x1 = 3,
- x2 = mx -3,
- y1 = 3,
- y2 = my -3,
- color = colors.red
- }
- screen.drawButton(btnError)
- local tText = {
- "*!=#?!, an error has occurred!",
- "",
- "Detailed information:",
- ermsg,
- "Please report this error!"
- }
- term.setBackgroundColor(colors.red)
- for i=1, #tText do
- term.setCursorPos(mx/2-#tText[i]/2,4+i)
- print(tText[i])
- end
- sleep(2.5)
- end
- function main()
- local soffset = 1
- local active = 0
- local pr = 0
- local ca = false -- Context Menu Active Variable
- local cx -- Context Menu last klicked X Coord
- local cy -- Context Menu last klicked y Coord
- local lItem -- last clicked Item
- local ci -- ContectMenu Items
- local dpb = false --draw the Paste Button
- local nfm = false -- Variable for klicking on no File
- local dtb = false --deploy taskbarbuttons
- local dt = "" --either menu type or new type
- local rv --returnvalue of the tb buttons
- local tbb = {} --Taskbar Buttons
- local dc = {} --Files Table
- local ci = {} --Context Items
- local mx,my = term.getSize()
- local btnQuit = {x1 = mx, x2 = mx, y1 = 1, y2 = 1, color = colors.red, text = "x"}
- term.setCursorBlink(false)
- shell.setDir(shell.dir())
- shell.setAlias(fs.getName(shell.getRunningProgram()),"/"..shell.getRunningProgram())
- screen.cls()
- while true do
- --screen.cls()
- screen.drawButton(btnQuit)
- term.setCursorPos(1,2)
- data = list(shell.dir())
- dc = drawFiles(data.allpaths,soffset,active-2)
- tbb = drawTaskBar(dtb,rv)
- if clipboard == nil then
- dpb = false
- else
- dpb = true
- end
- if ca then
- if lItem.name ~= ".." then
- ci = drawFileMenu(lItem,cx,cy,dpb,nfm)
- else
- ca = false
- end
- end
- local evn,misc,x,y = os.pullEvent()
- --print(evn)
- --sleep(3)
- if evn == "mouse_click" then
- if screen.pressed(btnQuit,x,y) then
- quit()
- end
- if misc == 1 then
- for i=1,#tbb do
- if screen.pressed(tbb[i],x,y) then
- pr = 1
- ca = false
- if dtb then
- rv = ""
- tbb[i].exec()
- dtb = false
- else
- rv = tbb[i].exec()
- dtb = true
- end
- end
- end
- end
- if ca and misc == 1 and pr ~= 1 then
- ca=false
- for i=1,#ci do
- if screen.pressed(ci[i],x,y) then
- ci[i].exec(lItem)
- pr = 1
- --ca = false
- end
- end
- end
- if pr~=1 then
- for i=1,#dc do
- if screen.pressed(dc[i],x,y) then
- pr = 1
- if misc == 2 then
- ca = true
- cx = x
- cy = y
- lItem = dc[i]
- else
- if not fs.isDir(dc[i].path) or not dc[i].name == ".." then
- if active == i + soffset then
- executing = true
- if dc[i].path ~= resolve(shell.getRunningProgram()) then
- screen.cls()
- shell.run(dc[i].path)
- sleep(1.5)
- end
- executing = false
- active = 0
- else
- active = i + soffset
- end
- else
- if active == i + soffset or dc[i].name == ".." then
- cd(dc[i].path)
- soffset = 1
- active = 0
- else
- active = i + soffset
- end
- end
- end
- end
- end
- end
- --Entry Point Mark for new File Menu (NEVERMIND!!!!! Taskbar!!!!)
- if pr == 0 then
- if evn == "mouse_click" and misc == 2 and y>2 then
- local tTable = {}
- tTable.path = shell.dir()
- tTable.name = fs.getName(shell.dir())
- active = 0
- ca = true
- nfm = true
- cx = x
- cy = y
- lItem = tTable
- pr = 0
- elseif evn == "mouse_click" and misc == 1 then
- dtb = false
- ca = false
- active = 0
- end
- elseif pr == 1 then
- nfm = false
- pr = 0
- else
- nfm = false
- active = 0
- ca = false
- end
- elseif evn == "mouse_scroll" then
- if misc <= 0 and soffset ~= 1 then
- ca = false
- soffset = soffset + misc
- elseif misc >= 0 and soffset <= #data.all-17 then
- ca = false
- soffset = soffset + misc
- end
- end
- if evn~="timer" and evn~="http_success" then
- screen.cls()
- end
- end
- end
- function showClock()
- local bstring = "before"
- local astring = "after"
- local tstring = ""
- if tonumber(timeoffset) > 0 then
- tstring = astring
- else
- tstring = bstring
- end
- if string.sub(timeoffset,1,1)=="+" then
- timeoffset = string.sub(timeoffset,2,2)
- elseif string.sub(timeoffset,1,1)=="-" then
- timeoffset = string.sub(timeoffset,2,2)
- end
- if tonumber(timeoffset) > 24 or tonumber(timeoffset) < -24 then
- error("Invalid Offset!")
- end
- while true do
- local stime = "http://www.timeapi.org/"..timezone.."/"..timeoffset.."+hours+"..tstring.."+now?format=%25H:%25M"
- local rtime = http.get(stime).readAll()
- local tupdate = os.startTimer(5)
- while true do
- local rx,ry = term.getCursorPos()
- term.setCursorPos(46,1)
- if not executing then
- term.setBackgroundColor(colors.gray)
- term.write(rtime)
- else
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,1)
- while executing do
- sleep(1)
- end
- break
- end
- term.setCursorPos(rx,ry)
- sleep(0.05)
- local tuevent = {os.pullEvent()}
- if tuevent[1] == "timer" and tuevent[2] == tupdate then
- break
- end
- end
- end
- end
- if #args > 0 then
- if args[1] == "help" then
- init()
- else
- usage()
- end
- else
- repeat
- local success, value = pcall(parallel.waitForAny,main,showClock)
- if not success then
- --screen.cls()
- --print(value)
- --sleep(3)
- showError(value)
- end
- until success
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement