Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Minif OS File Core
- local start = 0
- osFileRoot = ""
- fileAction = ""
- fileName = ""
- function edit(file)
- fileAction = "edit"
- fileName = file
- end
- function paint(file)
- fileAction = "paint"
- fileName = file
- end
- function drawFile()
- paintutils.drawFilledBox(3,6,mos.osScreenSizeX-2,mos.osScreenSizeY-2,colors.white)
- term.setCursorPos(mos.osScreenSizeX-6,mos.osScreenSizeY-3)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.green)
- term.write("New")
- term.setBackgroundColor(colors.white)
- end
- function runThing(file)
- if fs.isDir(file) then
- mos.osDrawWindow("Open File")
- osListFiles(file.."/")
- else
- paintutils.drawFilledBox(3,6,mos.osScreenSizeX-2,mos.osScreenSizeY-2,colors.white)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(4,7)
- term.write(file)
- term.setCursorPos(4,8)
- term.write("Open this file using...")
- term.setCursorPos(4,10)
- term.setBackgroundColor(colors.lightBlue)
- term.write("Text")
- term.setCursorPos(9,10)
- term.write("Draw")
- term.setCursorPos(4,12)
- term.write("Copy")
- term.setCursorPos(9,12)
- term.write("Rename")
- term.setCursorPos(16,12)
- term.write("Delete")
- while true do
- osPEvent, osPB, osPX, osPY = os.pullEvent()
- if osPEvent == "mouse_click" then
- if osPY == 10 and osPX >= 4 and osPX <= 7 then
- edit(file)
- return
- else if osPY == 10 and osPX >= 9 and osPY <= 12 then
- paint(file)
- return
- else if osPY == 12 and osPX >= 4 and osPX <= 7 then
- term.setCursorPos(4,mos.osScreenSizeY-4)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- local fname = read()
- if fs.exists(osFileRoot..fname) then
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.setTextColor(colors.red)
- term.write("File Exists")
- sleep(2)
- else
- fs.copy(file, osFileRoot..fname)
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.setTextColor(colors.black)
- term.write("Copied to "..osFileRoot..fname)
- sleep(2)
- end
- return
- else if osPY == 12 and osPX >= 9 and osPX <= 14 then
- term.setCursorPos(4,mos.osScreenSizeY-4)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- local fname = read()
- if fs.exists(osFileRoot..fname) then
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.setTextColor(colors.red)
- term.write("File Exists")
- sleep(2)
- else
- fs.move(file, osFileRoot..fname)
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.setTextColor(colors.black)
- term.write("Renamed to "..osFileRoot..fname)
- sleep(2)
- end
- return
- else if osPY == 12 and osPX >= 16 and osPX <= 21 then
- fs.delete(file)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.setTextColor(colors.black)
- term.write("Deleted "..file)
- sleep(2)
- return
- else
- return
- end
- end
- end
- end
- end
- else
- if osPEvent == "key" then
- if osPB == keys.t then
- shell.run('edit "'..file..'"')
- end
- if osPB == keys.d then
- shell.run('paint "'..file..'"')
- end
- return
- end
- end
- end
- return
- end
- end
- function newFile(loc)
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.green)
- term.write("New: ")
- local newFile = read()
- if fs.exists(loc..newFile) then
- term.setCursorPos(4,mos.osScreenSizeY-2)
- term.setTextColor(colors.red)
- print("File Exists!")
- sleep(2)
- else
- run = false
- runThing(loc..newFile)
- end
- term.setTextColor(colors.black)
- end
- function osListFiles(location)
- local run = true
- local start = 0
- local list = fs.list(location)
- drawFile()
- while run do
- for i, file in ipairs(list) do
- if i>mos.osScreenSizeY-4-7+start then
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.write("Next>")
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPX>=3 and osPX<=(mos.osScreenSizeX-2) and osPY>=7 and osPY<=(mos.osScreenSizeY-5) then
- for e, file in ipairs(list) do
- if e == osPY + start-6 then
- if run then
- runThing(location..file)
- run = false
- end
- end
- end
- return
- else
- if osPY == mos.osScreenSizeY-3 and osPX >= mos.osScreenSizeX-6 and osPX <= mos.osScreenSizeX-3 then
- newFile(location)
- return
- else
- drawFile()
- start = i-1
- end
- end
- end
- term.setCursorPos(4,i+6-start)
- if fs.isDir(location..file) then
- term.setTextColor(colors.green)
- else
- term.setTextColor(colors.black)
- end
- print(i.." "..file)
- end
- if run then
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPX>=3 and osPX<=(mos.osScreenSizeX-2) and osPY>=7 and osPY<=(mos.osScreenSizeY-4) then
- for e, file in ipairs(list) do
- if e == osPY + start-6 then
- if run then
- runThing(location..file)
- run = false
- end
- end
- end
- return
- else
- if osPY == mos.osScreenSizeY-3 and osPX >= mos.osScreenSizeX-6 and osPX <= mos.osScreenSizeX-3 then
- newFile(location)
- return
- else
- return
- end
- end
- end
- end
- end
- function osListFilesAtRoot(root)
- osFileRoot = root
- osListFiles(root)
- return fileAction, fileName
- end
Advertisement
Add Comment
Please, Sign In to add comment