Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vers="2.00pr2"
- --ShockBrowser V1.10
- --By Skullblade/Skullblade213
- --A Basic GUI File Browser In Beta
- --Credits!
- --Special Thanks to BigSHinyToys for permission to use his GUI setup:D
- --Lua-users.org rounding function (http://lua-users.org/wiki/SimpleRound)
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function Scrolling(msg)
- term.setBackgroundColor(ButtonBack)
- y=4
- for i=1,15 do
- term.setCursorPos(51,y)
- print(" ")
- if i==1 then
- term.setCursorPos(51,y)
- print("-")
- end
- if i==15 then
- term.setCursorPos(51,y)
- print("+")
- end
- y=y+1
- i=i+1
- end
- FileList = fs.list(direct)
- nume=1
- while FileList[nume] ~= nil do
- nume=nume+1
- end
- term.setCursorPos(1,1)
- Current=round(CursorChange/nume*15, 0)
- if Current>15 then
- Current=15
- end
- term.setBackgroundColor(colors.gray)
- if Current+4>18 then
- Current=18-4
- end
- term.setCursorPos(51,Current+4)
- print(" ")
- end
- function ColorCheck()
- if fs.exists("SB-Config") == false then
- file=fs.open("SB-Config", "w")
- file.writeLine("--Colors")
- file.writeLine(" ")
- file.writeLine("HeaderBack=2048")
- file.writeLine("HeaderText=colors.purple")
- file.writeLine("ButtonBack=256")
- file.writeLine("ButtonText=1")
- file.writeLine("Background=8")
- file.writeLine("Text=32768")
- file.writeLine(" ")
- file.writeLine("--Use any computercraft color code format")
- file.writeLine("--Defult Color Codes")
- file.writeLine(" ")
- file.writeLine("--HeaderBack=2048")
- file.writeLine("--HeaderText=colors.purple")
- file.writeLine("--ButtonBack=1")
- file.writeLine("--ButtonText=256")
- file.writeLine("--Background=8")
- file.writeLine("--Text=32768")
- file.writeLine(" ")
- file.writeLine("--Auto Check For Updates")
- file.writeLine(" ")
- file.writeLine("AutoCheck=true")
- file.writeLine(" ")
- file.writeLine("--'Icons'")
- file.writeLine(" ")
- file.writeLine('DirIcon="[D]"')
- file.writeLine('DirColor=colors.red')
- file.writeLine('DiskIcon="[E]"')
- file.writeLine('DiskColor=colors.pink')
- file.writeLine('RecyIcon="[R]"')
- file.writeLine('RecyColor=colors.yellow')
- file.writeLine('FileIcon="[F]"')
- file.writeLine('FileColor=colors.lime')
- file.close()
- end
- end
- function Updater()
- runningProg=shell.getRunningProgram()
- if fs.exists(".temp") == true then
- fs.delete(".temp")
- end
- if ForceU==true and http then
- print("Force Update")
- sleep(.5)
- file=fs.open(".temp", "w")
- file.writeLine('fs.delete(runningProg) shell.run("pastebin get pcaVwGY8 "..runningProg) fs.delete(".temp") term.clear() term.setCursorPos(1,1) print("Downloaded to "..runningProg)')
- file.close()
- shell.run(".temp")
- elseif AutoCheck==true and http and ForceU==false then
- action="No"
- term.setTextColor(colors.black)
- shell.run("pastebin get byX1Gv6a .temp")
- term.setTextColor(colors.white)
- shell.run(".temp")
- fs.delete(".temp")
- if version~=vers then
- term.clear()
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(10,5)
- write("Update? ")
- term.setBackgroundColor(colors.red)
- print("X")
- term.setCursorPos(10,6)
- term.setBackgroundColor(colors.lightGray)
- print(" ")
- term.setCursorPos(10,7)
- print(" ")
- term.setCursorPos(10,8)
- print(" ")
- term.setCursorPos(10,9)
- print(" ")
- term.setCursorPos(10,10)
- print(" ")
- term.setCursorPos(10,11)
- print(" ")
- term.setCursorPos(10,6)
- term.setTextColor(colors.black)
- print(" Update ShockBrowser?")
- term.setTextColor(colors.white)
- term.setCursorPos(10,7)
- print(" Current Version="..version)
- term.setCursorPos(10,8)
- print(" Your Version="..vers)
- term.setTextColor(colors.red)
- term.setCursorPos(10,10)
- print(" [Yes] [No]")
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- while true do
- action="none"
- event, button,x, y = os.pullEvent("mouse_click")
- if x>14 and x<20 and y==10 then
- action="Yes"
- break
- end
- if (x>29 and x<34 and y==10) or (y==5 and x==42) then
- action="No"
- break
- end
- end
- if action=="Yes" then
- file=fs.open(".temp", "a")
- file.writeLine('fs.delete(runningProg) shell.run("pastebin get pcaVwGY8 "..runningProg) term.clear() term.setCursorPos(1,1) print("Downloaded to "..runningProg)')
- file.close()
- shell.run(".temp")
- end
- end
- end
- if fs.exists(".temp") == true then
- fs.delete(".temp")
- end
- end
- function yInc()
- if yChange=="Up" then
- y1=y1-1
- end
- if yChange=="Down" then
- y1=y1+1
- end
- end
- function Run(types)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- shell.run(Direct.."/"..FileList[y-3+CursorChange],ar)
- term.setCursorPos(9,17)
- print("Finished Running : "..FileList[y-3+CursorChange])
- term.setCursorPos(9,18)
- print("Click anywere to continue")
- event, buttonb, xx, yy = os.pullEvent("mouse_click")
- end
- function Draw()
- ColorCheck()
- shell.run("SB-Config")
- term.setTextColor(Text)
- term.setBackgroundColor(Background)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(HeaderBack)
- term.setTextColor(HeaderText)
- term.clearLine()
- print("ShockBrowser")
- term.setCursorPos(51, 1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- print("X")
- term.setCursorPos(1,2)
- term.setBackgroundColor(ButtonBack)
- term.setTextColor(ButtonText)
- term.clearLine()
- dir = Direct
- if Direct == "" then
- dir = "/"
- end
- print(dir)
- term.setCursorPos(1,3)
- term.setBackgroundColor(HeaderBack)
- term.setTextColor(HeaderText)
- write(" < ")
- term.setBackgroundColor(Background)
- term.setTextColor(Text)
- print("Back")
- end
- function message(msg)
- term.setCursorPos(15,7)
- term.setBackgroundColor(HeaderBack)
- term.setTextColor(HeaderText)
- write(" ")
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- print("X")
- term.setCursorPos(15,7)
- term.setBackgroundColor(HeaderBack)
- term.setTextColor(HeaderText)
- print(msg[1])
- term.setBackgroundColor(ButtonBack)
- term.setTextColor(ButtonText)
- term.setCursorPos(15,8)
- print(" ")
- term.setCursorPos(15,9)
- print(" ")
- term.setCursorPos(15,10)
- print(" ")
- term.setCursorPos(15,11)
- print(" OK ")
- if msg[2]~=nil then
- term.setCursorPos(15,8)
- print(msg[2])
- end
- term.setBackgroundColor(ButtonText)
- term.setTextColor(ButtonBack)
- term.setCursorPos(16,10)
- print("/ ")
- input=""
- while true do
- event,param1,param2,param3=os.pullEvent()
- if event=="mouse_click" then
- if param2==39 and param3==7 then
- break
- end
- if (param2>15 and param2<39) and param3==10 then
- term.setBackgroundColor(ButtonText)
- term.setTextColor(ButtonBack)
- term.setCursorPos(16,10)
- print("/ ")
- term.setCursorPos(17,10)
- input=read()
- end
- if input~="" and (param2==37 or param2==38) and param3==11 then
- return input
- end
- end
- if event=="key" then
- if param1==28 and input~="" then
- return input
- end
- end
- end
- end
- function DrawMenu(cords,msg,act)
- if cords[3]~=nil and cords[3]=="calc" and yChange=="Up" then
- cords[2]=yarc-(cords[2]-yarc)
- elseif cords[3]==nil then
- if cords[2]>18 then
- cords[2]=18
- end
- yarc=cords[2]
- y1=cords[2]
- x1=cords[1]
- yChange="Down"
- if y1+msg[1]>18 then
- yChange="Up"
- end
- end
- yarc=cords[2]
- y1=cords[2]
- x1=cords[1]
- term.setBackgroundColor(HeaderBack)
- term.setTextColor(HeaderText)
- term.setCursorPos(x1,y1)
- print(msg[2])
- yInc()
- term.setBackgroundColor(ButtonBack)
- term.setTextColor(ButtonText)
- for h=3,#msg do
- term.setCursorPos(x1,y1)
- print(msg[h])
- yInc()
- h=h+1
- end
- event, button, xx, yy = os.pullEvent("mouse_click")
- if yChange=="Down" and act[yy-cords[2]]~=nil then
- if xx>cords[1]-1 and string.len(msg[yy-cords[2]+2])+cords[1]>xx then
- act[yy-cords[2]]()
- end
- elseif yChange=="Up" and act[cords[2]-yy]~=nil then
- if xx>cords[1]-1 and string.len(msg[cords[2]-yy+2])+cords[1]>xx then
- act[cords[2]-yy]()
- end
- end
- end
- function FileL(direct)
- CursorChange=0
- while true do
- Direct = direct
- Draw()
- Scrolling(direct)
- term.setBackgroundColor(Background)
- term.setTextColor(Text)
- if recents[1] == direct then
- table.remove(recents, 1)
- end
- table.insert(recents, 1, direct)
- if direct == "" then
- recents = {}
- end
- FileList = fs.list(direct)
- num=1
- nume=#FileList+1
- y=4
- while FileList[num+CursorChange] ~= nil do
- if num == 16 then
- break
- end
- isDir = fs.isDir(direct.."/"..FileList[num+CursorChange])
- if isDir == true then
- term.setCursorPos(1,y)
- term.setTextColor(DirColor)
- write(DirIcon)
- if FileList[num+CursorChange] == "disk" or FileList[num+CursorChange] == "disk2" or FileList[num+CursorChange] == "disk3" or FileList[num+CursorChange] == "disk4" or FileList[num+CursorChange] == "disk5" or FileList[num+CursorChange] == "disk6" then
- term.setCursorPos(1,y)
- term.setTextColor(DiskColor)
- write(DiskIcon)
- end
- if FileList[num+CursorChange] == "RecycleBin" then
- term.setCursorPos(1,y)
- term.setTextColor(RecyColor)
- write(RecyIcon)
- end
- else
- term.setCursorPos(1,y)
- term.setTextColor(FileColor)
- write(FileIcon)
- end
- term.setTextColor(Text)
- print(FileList[num+CursorChange])
- num=num+1
- y=y+1
- end
- Mouse()
- if broke == "true" then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(colors.yellow)
- term.setCursorPos(1,1)
- print("Thanks For Using ShockBrowser")
- term.setTextColor(colors.white)
- return
- end
- end
- end
- function Mouse()
- event, button, x, y = os.pullEvent()
- if event=="mouse_click" then
- OldClick = "False"
- broke = "false"
- if y>4 and y<18 and x==51 then
- CursorChange=round(((y-4)/15)*nume, 0)
- OldClick="True"
- end
- if y == 1 and x == 51 and OldClick ~= "True" then
- broke = "true"
- OldClick = "True"
- end
- FileLen=0
- if FileList[y-3+CursorChange] ~= nil then
- FileLen = string.len(FileList[y-3+CursorChange])
- end
- if (x==51 and y==4) and OldClick ~= "True" then
- if CursorChange~=0 then
- CursorChange=CursorChange-1
- end
- OldClick = "True"
- end
- if (x==51 and y==18) and OldClick ~= "True" then
- if CursorChange ~= nume-2 then
- CursorChange=CursorChange+1
- end
- OldClick = "True"
- end
- if OldClick ~= "True" and broke=="false" then
- if ((x==1 or x==2 or x==3) and y > 3 and y < num+3) or (x < FileLen+4 and x > 3 and y > 3 and y < num+3 and button == 2) then
- isDir = fs.isDir(Direct.."/"..FileList[y-3+CursorChange])
- Old="False"
- if isDir == true and ((FileList[y-3+CursorChange] == "disk") or (FileList[y-3+CursorChange] == "disk2") or (FileList[y-3+CursorChange] == "disk3") or (FileList[y-3+CursorChange] == "disk4") or (FileList[y-3+CursorChange] == "disk5") or (FileList[y-3+CursorChange] == "disk6")) then
- Old="True"
- DrawMenu({x,y},{4,"Disk ","Open ","Label ","Eject "},
- {function() direct = tostring(Direct.."/"..FileList[y-3+CursorChange]) FileL(direct);end,
- function() dn=message({"Disk Side"}) if dn~=nil then ld=message({"Disk Label"}) if ld~=nil then S={"left","right","front","back","top","bottom"}realSide=false for i=1,#S do if S[i]==dn then realSide=true end i=i+1 sleep(0) end if realSide==true and disk.getMountPath(dn)==FileList[y-3+CursorChange] then disk.setLabel(dn,ld) end end end;end,
- function() dn=message({"Disk Side"}) if dn~=nil then S={"left","right","front","back","top","bottom"}realSide=false for i=1,#S do if S[i]==dn then realSide=true end i=i+1 sleep(0) end if realSide==true and disk.getMountPath(dn)==FileList[y-3+CursorChange] then disk.eject(dn)end end;end})
- end
- if string.lower(shell.resolve(Direct.."/"..FileList[y-3+CursorChange]))=="recyclebin" then
- Old="True"
- DrawMenu({x,y},{3,"Recycle ","Open ","Dump "},
- {function() direct = tostring(Direct.."/"..FileList[y-3+CursorChange]) FileL(direct);end,
- function()
- dlist=fs.list(FileList[y-3+CursorChange])
- for i=1,#dlist do
- fs.delete("RecycleBin/"..dlist[i])
- i=i+1
- end
- ;end})
- end
- if isDir == true and Old=="False" then
- Old="True"
- DrawMenu({x,y},{7,"Folder ","Open ","Copy ","Cut ","Delete ","Rename ","Move "},
- {function() direct = tostring(Direct.."/"..FileList[y-3+CursorChange]) FileL(direct);end,
- function() ClipBoard={Direct.."/"..FileList[y-3+CursorChange],"Copy",FileList[y-3+CursorChange]};end,
- function() if not fs.isReadOnly(Direct.."/"..FileList[y-3+CursorChange]) then ClipBoard={Direct.."/"..FileList[y-3+CursorChange],"Cut",FileList[y-3+CursorChange]}end;end,
- function() if string.lower(shell.resolve(Direct))~="recyclebin" and fs.exists("RecycleBin/"..FileList[y-3+CursorChange]) and not fs.isReadOnly(Direct.."/"..FileList[y-3+CursorChange]) then fs.delete("RecycleBin/"..FileList[y-3+CursorChange]) fs.move(Direct.."/"..FileList[y-3+CursorChange],"RecycleBin/"..FileList[y-3+CursorChange]) end if string.lower(shell.resolve(Direct))~="recyclebin" and not fs.exists("RecycleBin/"..FileList[y-3+CursorChange]) and not fs.isReadOnly(Direct.."/"..FileList[y-3+CursorChange]) then fs.move(Direct.."/"..FileList[y-3+CursorChange],"RecycleBin/"..FileList[y-3+CursorChange]) end if string.lower(shell.resolve(Direct))=="recyclebin" and not fs.isReadOnly(Direct.."/"..FileList[y-3+CursorChange]) then fs.delete(Direct.."/"..FileList[y-3+CursorChange]) end ;end,
- function() if not fs.isReadOnly(Direct.."/"..FileList[y-3+CursorChange]) then rn=message({"Rename Folder"}) if rn~=nil and not fs.exists(rn) then fs.move(Direct.."/"..FileList[y-3+CursorChange],Direct.."/"..rn)end end;end,
- function() if not fs.isReadOnly(Direct.."/"..FileList[y-3+CursorChange]) then mv=message({"Move Folder"}) if mv~=nil and not fs.exists(mv) then fs.move(Direct.."/"..FileList[y-3+CursorChange],mv)end end;end
- })
- end
- if fs.exists(Direct.."/"..FileList[y-3+CursorChange]) == true and Old=="False" then
- Old="True"
- DrawMenu({x,y},{8,"File ","Run ","Edit ","Copy ","Cut ","Delete ","Rename ","Move "},
- {function()
- if shell.getRunningProgram()~=(Direct.."/"..FileList[y-3+CursorChange]) then
- DrawMenu({x+11,yarc+1,"calc"},{3,"Run ","Norm ","Args "},{function() ar="" Run() ;end,function() ar=message({"Run With Args"}) if ar~=nil then Run() end;end})
- end;end,
- function() shell.run("/rom/programs/edit",Direct.."/"..FileList[y-3+CursorChange]) ;end,
- function() ClipBoard={Direct.."/"..FileList[y-3+CursorChange],"Copy",FileList[y-3+CursorChange]};end,
- function() ClipBoard={Direct.."/"..FileList[y-3+CursorChange],"Cut",FileList[y-3+CursorChange]};end,
- function() if string.lower(shell.resolve(Direct))~="recyclebin" and fs.exists("RecycleBin/"..FileList[y-3+CursorChange]) then fs.delete("RecycleBin/"..FileList[y-3+CursorChange]) fs.move(Direct.."/"..FileList[y-3+CursorChange],"RecycleBin/"..FileList[y-3+CursorChange]) end if string.lower(shell.resolve(Direct))~="recyclebin" and not fs.exists("RecycleBin/"..FileList[y-3+CursorChange]) then fs.move(Direct.."/"..FileList[y-3+CursorChange],"RecycleBin/"..FileList[y-3+CursorChange]) end if string.lower(shell.resolve(Direct))=="recyclebin" then fs.delete("RecycleBin/"..FileList[y-3+CursorChange]) end ;end,
- function() rn=message({"Rename File"}) if rn~=nil and not fs.exists(rn) then fs.move(Direct.."/"..FileList[y-3+CursorChange],Direct.."/"..rn)end;end,
- function() mv=message({"Move File"}) if mv~=nil and not fs.exists(mv) then fs.move(Direct.."/"..FileList[y-3+CursorChange],mv)end;end
- })
- end
- OldClick = "True"
- end
- end
- if OldClick ~= "True" then
- if x < FileLen+4 and x > 3 and y > 3 and y < num+3 and button == 1 and OldClick ~= "True" then
- dire = tostring(FileList[y-3+CursorChange])
- isDir = fs.isDir(Direct.."/"..dire)
- if isDir == true then
- direct = tostring(Direct.."/"..FileList[y-3+CursorChange])
- FileL(direct)
- end
- if isDir == false and broke ~= "true" then
- Run()
- end
- OldClick = "True"
- end
- end
- if (x == 1 or x == 2 or x == 3) and y == 3 and button == 1 and OldClick ~= "True" then
- direr = recents[2]
- if recents[2] == nil then
- direr = ""
- end
- table.remove(recents, 1)
- table.remove(recents, 1)
- FileL(direr)
- OldClick = "True"
- end
- if y == 2 and button == 1 and OldClick ~= "True" then
- term.setCursorPos(1,2)
- term.setBackgroundColor(ButtonBack)
- term.clearLine()
- write("/")
- jumpto = read()
- f = fs.isDir(jumpto)
- jumpto = "/"..jumpto
- jumpto=string.lower(jumpto)
- if f == true then
- FileL(jumpto)
- end
- OldClick = "True"
- elseif y>3 and button == 2 and OldClick ~= "True" then
- nf=""
- DrawMenu({x,y},
- {4,"Options ","New ","CPULabel ","Paste "},
- {function() DrawMenu({x+11,yarc+1,"calc"},{3,"New ","File ","Folder "},{function() nf=message({"New File"}) if nf~=nil and not fs.exists("nf") then f=fs.open(Direct.."/"..nf,"w") f.write("") f.close() end ;end,function() nf=message({"New Folder"}) if nf~=nil and not fs.exists("nf") then fs.makeDir(Direct.."/"..nf) end;end});end,function() label=message({"Label Computer"}) if label~=nil then os.setComputerLabel(label) end;end,function() if ClipBoard[1]~=nil and ClipBoard[2]~=nil and ClipBoard[3]~=nil then if not fs.exists(Direct.."/"..ClipBoard[3]) and fs.exists(ClipBoard[1]) then if ClipBoard[2]=="Copy" then fs.copy(ClipBoard[1], Direct.."/"..ClipBoard[3]) end if ClipBoard[2]=="Cut" then fs.move(ClipBoard[1], Direct.."/"..ClipBoard[3]) end end end;end})
- end
- end
- if event=="mouse_scroll" then
- broke = "false"
- if button==-1 then --Up
- if CursorChange~=0 then
- CursorChange=CursorChange-1
- end
- end
- if button==1 then --Down
- if CursorChange ~= nume-2 then
- CursorChange=CursorChange+1
- end
- end
- end
- if event=="mouse_drag" then
- if y>4 and y<18 and x==51 then
- CursorChange=round(((y-4)/15)*nume, 0)
- OldClick="True"
- end
- end
- end
- if not fs.exists("RecycleBin") then
- fs.makeDir("RecycleBin")
- end
- ForceU=false
- tArgs = (...)
- shell.run("SB-Config")
- if tArgs=="-u" then
- AutoCheck=true
- end
- if tArgs=="-f" then
- ForceU=true
- end
- Updater()
- if action ~="Yes" then
- ColorCheck()
- ClipBoard={"","",""}
- term.clear()
- direct = ""
- recents = {""}
- FileL("")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement