Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This software is made by Xelostar.
- Please give me credit when showing someone this program.
- Links:
- -https://www.youtube.com/watch?v=8khhCTGfGzM
- -http://www.computercraft.info/forums2/index.php?/topic/27066-fileviewer/
- ]]--
- path = {}
- folderI = paintutils.loadImage("/FileViewer/folder.img")
- executeableI = paintutils.loadImage("/FileViewer/executeable.img")
- textI = paintutils.loadImage("/FileViewer/text.img")
- imageI = paintutils.loadImage("/FileViewer/image.img")
- blueprintI = paintutils.loadImage("/FileViewer/blueprint.img")
- clipboard = ""
- deleteOld = false
- screenWidth, screenHeight = term.getSize()
- page = 0
- files = {}
- function getPath()
- local pathT = "/"
- for k, v in pairs(path) do
- if k == 1 then
- pathT = pathT .. v
- else
- pathT = pathT .. "/" .. v
- end
- end
- return pathT
- end
- function getName(text)
- term.setBackgroundColor(colors.white)
- paintutils.drawLine(3, 9, 47, 9)
- paintutils.drawLine(3, 10, 47, 10)
- paintutils.drawLine(3, 11, 47, 11)
- term.setTextColor(colors.black)
- term.setCursorPos(4, 10)
- write(text)
- local name = read()
- return name
- end
- function up()
- local pathT = path
- path = {}
- for k, file in pairs(pathT) do
- if k ~= table.getn(pathT) then
- table.insert(path, file)
- end
- end
- end
- function getFile()
- local stop = false
- while not stop do
- local event, button, X, Y = os.pullEventRaw("mouse_click")
- for k, file in pairs(files) do
- if k >= (page * 10) and k <= (page * 10 + 10) then
- local pathT = getPath()
- if pathT == "/" then
- pathT = ""
- end
- local n = k - page * 10
- local add = 0
- local number = n
- while true do
- number = number - 5
- if number <= 0 then
- break
- end
- add = add + 1
- end
- if X >= (-7 + (n * 9) - add * 45) and X <= (-7 + (n * 9) - add * 45 + 6) and Y >= (3 + add * 8) and Y <= (3 + add * 8 + 6) then
- stop = true
- return file
- end
- end
- end
- end
- end
- function drawScreen()
- term.setBackgroundColor(colors.lightBlue)
- term.clear()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(2, 1)
- print("Up")
- term.setTextColor(colors.orange)
- term.setBackgroundColor(colors.yellow)
- term.setCursorPos(5, 1)
- print("+")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(6, 1)
- print("+")
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.purple)
- term.setCursorPos(7, 1)
- print("P")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(9, 1)
- print("CP")
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- term.setCursorPos(11, 1)
- print("C")
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- term.setCursorPos(13, 1)
- print("U")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(15, 1)
- print("Path: " .. getPath())
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- term.setCursorPos(screenWidth, 1)
- print("X")
- local rows = math.floor((screenHeight - 1) / 8)
- local columns = math.floor(screenWidth / 9)
- local filesPerPage = rows * columns
- for fileNr, file in pairs(files) do
- if fileNr >= (page * filesPerPage) and fileNr <= (page * filesPerPage + filesPerPage) then
- local pathT = getPath()
- if pathT == "/" then
- pathT = ""
- end
- local n = fileNr - page * filesPerPage
- local row = 0
- local number = n
- while true do
- number = number - columns
- if number <= 0 then
- break
- end
- row = row + 1
- end
- local fType = "executeable"
- if file:match"([^.]*).(.*)" ~= nil then
- a, extension = file:match"([^.]*).(.*)"
- if extension == "txt" then
- fType = "text"
- elseif extension == "img" then
- fType = "image"
- elseif extension == "bpr" then
- fType = "blueprint"
- end
- end
- if fs.isDir(pathT .. "/" .. file) then
- paintutils.drawImage(folderI, -7 + (n * 9) - row * (columns * 9), 3 + row * 8)
- else
- if fType == "text" then
- paintutils.drawImage(textI, -7 + (n * 9) - row * (columns * 9), 3 + row * 8)
- elseif fType == "image" then
- paintutils.drawImage(imageI, -7 + (n * 9) - row * (columns * 9), 3 + row * 8)
- elseif fType == "blueprint" then
- paintutils.drawImage(blueprintI, -7 + (n * 9) - row * (columns * 9), 3 + row * 8)
- else
- paintutils.drawImage(executeableI, -7 + (n * 9) - row * (columns * 9), 3 + row * 8)
- end
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(-7 + (n * 9) - row * (columns * 9), 8 + row * 8)
- local number = 0
- for character in file:gmatch"." do
- number = number + 1
- if number == 9 then
- term.setCursorPos(-7 + (n * 9) - row * (columns * 9), 9 + row * 8)
- end
- if number == 15 then
- write("..")
- break
- end
- write(character)
- end
- end
- end
- local xOfBar = screenWidth - 1
- local height = screenHeight - 4
- local start = 2
- local pointer = 1
- while pointer <= height do
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(xOfBar, start + pointer)
- if pointer == 1 then
- print("^")
- elseif pointer == start + height - 2 then
- print("V")
- else
- print("|")
- end
- pointer = pointer + 1
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(xOfBar - 1, math.floor(screenHeight / 2) + 1)
- print(page)
- end
- while true do
- files = {}
- for k, v in pairs(fs.list(getPath())) do
- table.insert(files, v)
- end
- drawScreen()
- local event, button, X, Y = os.pullEventRaw()
- if event == "mouse_click" then
- if button == 1 then
- if X == screenWidth and Y == 1 then
- break
- elseif X >= 2 and X <= 3 and Y == 1 then
- up()
- page = 0
- elseif X == screenWidth - 1 and Y == 3 then
- if page ~= 0 then
- page = page - 1
- end
- elseif X == screenWidth - 1 and Y == screenHeight - 2 then
- page = page + 1
- elseif X == 5 and Y == 1 then
- local mapName = getName("Map name: ")
- shell.run("mkdir", getPath() .. "/" .. mapName)
- elseif X == 6 and Y == 1 then
- local fileName = getName("File name: ")
- shell.run("edit", getPath() .. "/" .. fileName .. ".txt")
- elseif X == 7 and Y == 1 then
- local imageName = getName("Image name: ")
- shell.run("paint", getPath() .. "/" .. imageName .. ".img")
- elseif X == 9 and Y == 1 then
- clipboard = getPath() .. "/" .. getFile()
- deleteOld = false
- elseif X == 10 and Y == 1 then
- if deleteOld == false then
- shell.run("copy", clipboard, getPath())
- else
- shell.run("move", clipboard, getPath())
- end
- elseif X == 11 and Y == 1 then
- clipboard = getPath() .. "/" .. getFile()
- deleteOld = true
- elseif X == 13 and Y == 1 then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- paintutils.drawLine(3, 9, 49, 9)
- paintutils.drawLine(3, 10, 49, 10)
- paintutils.drawLine(3, 11, 49, 11)
- term.setCursorPos(13, 10)
- print("Click on a file to delete it.")
- sleep(1)
- drawScreen()
- local file = getFile()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- paintutils.drawLine(3, 9, 49, 9)
- paintutils.drawLine(3, 10, 49, 10)
- paintutils.drawLine(3, 11, 49, 11)
- term.setCursorPos(4, 10)
- print("Are you sure you want to delete " .. file .. "?")
- term.setBackgroundColor(colors.lime)
- term.setCursorPos(42, 10)
- print("Yes")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(46, 10)
- print("No ")
- local choice = false
- while true do
- local event, button, X, Y = os.pullEventRaw("mouse_click")
- if button == 1 then
- if Y == 10 then
- if X >= 42 and X <= 44 then
- choice = true
- break
- elseif X >= 46 and X <= 48 then
- break
- end
- end
- end
- end
- if choice == true then
- shell.run("delete", getPath() .. "/" .. file)
- end
- else
- local rows = math.floor((screenHeight - 1) / 8)
- local columns = math.floor(screenWidth / 9)
- local filesPerPage = rows * columns
- for k, file in pairs(files) do
- if k >= (page * filesPerPage) and k <= (page * filesPerPage + filesPerPage) then
- local pathT = getPath()
- if pathT == "/" then
- pathT = ""
- end
- local n = k - page * filesPerPage
- local row = 0
- local number = n
- while true do
- number = number - columns
- if number <= 0 then
- break
- end
- row = row + 1
- end
- if X >= -7 + (n * 9) - row * (columns * 9) and X <= -7 + (n * 9) - row * (columns * 9) + 6 and Y >= 3 + row * 8 and Y <= 3 + row * 8 + 6 then
- local fType = "executeable"
- if file:match"([^.]*).(.*)" then
- a, extension = file:match"([^.]*).(.*)"
- if extension == "txt" then
- fType = "text"
- elseif extension == "img" then
- fType = "image"
- elseif extension == "blueprint" then
- fType = "blueprint"
- end
- end
- if fs.isDir(pathT .. "/" .. file) then
- table.insert(path, file)
- page = 0
- else
- if fType == "text" then
- shell.run("edit", getPath() .. "/" .. file)
- elseif fType == "image" then
- shell.run("paint", getPath() .. "/" .. file)
- elseif fType == "blueprint" then
- shell.run("edit", getPath() .. "/" .. file)
- else
- shell.run(getPath() .. "/" .. file)
- end
- end
- end
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement