Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cmp = require('component')
- local event = require('event')
- local serialization = require('serialization')
- local gpu=cmp.gpu
- local term =require('term')
- local computer = require('computer')
- local filesystem=require('filesystem')
- local unicode = require('unicode')
- local sides = require("sides")
- local keyboard = require("keyboard")
- local thread = require('thread')
- --local tunnel = cmp.tunnel
- local draw = require('draw')
- local shell = require("shell")
- ----
- local oldBack=gpu.getBackground()
- local oldFore=gpu.getForeground()
- local pageDisk = 0
- sel=0
- ----
- function ob()
- while true do
- a,b,c,d,e,f = event.pull("modem_message")
- if unicode.sub(f,0,3)=="ls:" then
- path = unicode.sub(f,4,unicode.len(f))
- pathArr=serialization.unserialize(path)
- sel=0
- oldClickFile=nil
- clickFile=0
- drawFiles(1,72,getPath())
- tunnel.send(serialization.serialize(getFiles(getPath())))
- elseif unicode.sub(f,0,4)=="run:" then
- prog=unicode.sub(f,5,unicode.len(f))
- shell.execute(prog)
- elseif unicode.sub(f,0,3)=="cls" then
- term.clear()
- end
- os.sleep(0.00001)
- end
- end
- function exit()
- gpu.setBackground(oldBack)
- gpu.setForeground(oldFore)
- term.clear()
- os.exit()
- end
- function checkEvent()
- key,_,x,y,clickMouse,name=event.pull()
- return key , x , y , clickMouse
- end
- function getPath()
- path=''
- for i=1,#pathArr do
- path=path..pathArr[i]
- end
- return path
- end
- function drawMenu()
- draw.field(1,1,80,25,' ',0x222222,0xFFFFFF) -- <frame>
- draw.field(1,2,18,24,' ',0xAAAAAA,0xFFFFFF)
- draw.field(19,2,62,24,' ',0xFFFFFF,0xFFFFFF)
- draw.field(39,2,1,24,"¦",0xFFFFFF,0x00FF00)
- draw.field(60,2,1,24,"¦",0xFFFFFF,0x00FF00)
- draw.field(3,1,3,1,' ',0x0000FF,0xFFFFFF)
- draw.field(4,1,1,1,'<',0x0000FF,0xFFFFFF)
- draw.field(8,1,3,1,' ',0x0000FF,0xFFFFFF)
- draw.field(9,1,1,1,'>',0x0000FF,0xFFFFFF)
- draw.field(1,1,1,1,'X',0xFF0000,0xFFFFFF)
- end
- function getFiles(path)
- arr={} arr2={}
- for val,val2 in filesystem.list(path) do if val~= nil then arr[#arr+1]=val end end
- for i=1,#arr do if unicode.sub(arr[i],unicode.len(arr[i]),unicode.len(arr[i])) == '/' then arr2[#arr2+1]=arr[i] end end
- for i=1,#arr do if unicode.sub(arr[i],unicode.len(arr[i]),unicode.len(arr[i])) ~= '/' then arr2[#arr2+1]=arr[i] end end
- arr=arr2
- return arr
- end
- function drawName(x,arr,i,deb)
- j=i-deb
- if unicode.sub(arr[i],unicode.len(arr[i]),unicode.len(arr[i])) == '/' then
- gpu.setForeground(0xBBBB00)
- gpu.set(x,1+j,arr[i])
- else
- gpu.setForeground(0)
- gpu.set(x,1+j,arr[i])
- end
- gpu.setForeground(0)
- gpu.setBackground(0xFFFFFF)
- end
- function drawSelect(x,arr,sel,deb)
- j=sel-deb
- if oldClickFile ~= nil and oldSelect ~= nil then
- l=oldSelect[3]-oldSelect[4]
- if oldClickFile ~= sel and arr[oldClickFile]~= nil then
- if unicode.sub(arr[oldClickFile],unicode.len(arr[oldClickFile]),unicode.len(arr[oldClickFile])) == '/' then
- gpu.setForeground(0xBBBB00)
- gpu.setBackground(0xFFFFFF)
- gpu.fill(oldSelect[1],1+l,20,1,' ')
- gpu.set(oldSelect[1],1+l,arr[oldClickFile])
- else
- gpu.setBackground(0xFFFFFF)
- gpu.fill(oldSelect[1],1+l,20,1,' ')
- gpu.setForeground(0)
- gpu.set(oldSelect[1],1+l,arr[oldClickFile])
- end
- end
- end
- if unicode.sub(arr[sel],unicode.len(arr[sel]),unicode.len(arr[sel])) == '/' then
- gpu.setForeground(0xBBBB00)
- gpu.setBackground(0x55AAEE)
- gpu.fill(x,1+j,20,1,' ')
- gpu.set(x,1+j,arr[sel])
- else
- gpu.setBackground(0x55AAEE)
- gpu.fill(x,1+j,20,1,' ')
- gpu.setForeground(0)
- gpu.set(x,1+j,arr[sel])
- end
- gpu.setForeground(0)
- gpu.setBackground(0xFFFFFF)
- oldSelect={x,arr,sel,deb}
- end
- function getMyDisks(mode)
- local disks={}
- local fromAddress = filesystem.get(os.getenv("_")).address
- local candidates = {}
- for address in cmp.list("filesystem", true) do
- local dev = cmp.proxy(address)
- if --[[not dev.isReadOnly() and]] dev.address ~= computer.tmpAddress() then
- table.insert(candidates, dev)
- end
- end
- if mode==2 then
- for i = 1, #candidates do
- local label = candidates[i].getLabel()
- if label and label ~= 'raid' then
- label = label
- else
- label = candidates[i].address
- end
- disks[#disks+1]={label,candidates[i].address}
- end
- return disks
- elseif mode == 1 then
- for i = 1, #candidates do
- local label = candidates[i].getLabel()
- if label and label ~= 'raid' then
- label = label
- else
- label = candidates[i].address
- end
- disks[#disks+1]=label
- end
- return disks
- end
- end
- function drawDisks()
- local disks=getMyDisks(1)
- draw.fileList(0xAAAAAA,0,1,2,18,6,'[Filesystem]',disks,1,disks[posDisk],pageDisk,0xFF00FF,0x55AAEE)
- end
- function drawFiles(k,v,path)
- drawPath()
- draw.field(19,2,62,24,' ',0xFFFFFF,0xFFFFFF)
- draw.field(39,2,1,24,"¦",0xFFFFFF,0x00FF00)
- draw.field(60,2,1,24,"¦",0xFFFFFF,0x00FF00)
- arr=getFiles(path)
- for i=k,v do
- if i < 25 then
- if arr[i] ~= nil then
- drawName(19,arr,i,0)
- end
- elseif i >24 and i < 49 then
- if arr[i] ~= nil then
- drawName(40,arr,i,24)
- end
- elseif i > 48 and i < 73 then
- if arr[i] ~= nil then
- drawName(61,arr,i,48)
- end
- end
- end
- gpu.setForeground(0)
- gpu.setBackground(0xFFFFFF)
- end
- --55AAEE
- function run(f)
- shell.execute(tostring(f))
- end
- function delete()
- draw.field(20,10,40,5,' ',0xAAAAAA,0xFFFFFF)
- draw.clound('┌','┐','└','┘','│','─',20,10,40,5,0xAAAAAA,0)
- draw.text(21,12,38,'Вы точно хотите удалить файл?[Y/n]: ',0xAAAAAA,0)
- while not choice do
- _,_,_,per = event.pull('key_up')
- if per == 21 then
- shell.execute('del '..getPath()..arr[clickFile])
- sel=0
- oldClickFile=nil
- clickFile=0
- drawMenu()
- drawPath()
- drawDisks()
- drawFiles(1,72,getPath())
- choice=per
- elseif per == 49 then
- drawMenu()
- drawPath()
- drawDisks()
- drawFiles(1,72,getPath())
- choice=per
- end
- end
- choice=nil
- end
- function drawPath()
- draw.field(20,1,40,1,' ',0x222222,0xFFFFFF)
- path=getPath()
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x222222)
- if unicode.len(path) > 40 then
- path2=unicode.sub(path,unicode.len(path)-40,unicode.len(path))
- else
- path2=path
- end
- gpu.set(20,1,path2)
- gpu.setForeground(0)
- gpu.setBackground(0xFFFFFF)
- end
- function startDisk()
- local disks=getMyDisks(2)
- arrMyDiskAddress=filesystem.get(os.getenv("_"))
- for i=1,#disks do
- if arrMyDiskAddress.address:sub(1,8) == disks[i][1]:sub(1,8) or arrMyDiskAddress.getLabel():sub(1,8) == disks[i][1]:sub(1,8) then
- posDisk=i
- break
- end
- end
- return 'mnt/'..tostring(arrMyDiskAddress.address:sub(1,3))..'/' , posDisk
- end
- function enter(x,y,w,h,color_back,color_fore)
- got=nil
- function drawTextInPass(x,y,w,h,txt,col)
- if unicode.len(txt) > w-3 then
- txt=unicode.sub(txt,unicode.len(txt)-(w-3),unicode.len(txt))
- end
- draw.field(x+1,y+1,w-2,1,' ',color_back,color_fore)
- oldB=gpu.getBackground()
- oldF=gpu.getForeground()
- gpu.setBackground(color_back)
- gpu.setForeground(col)
- gpu.set(x+1,y+1,txt)
- gpu.setBackground(oldB)
- gpu.setForeground(oldF)
- end
- draw.field(x,y,w,h,' ',color_back,color_fore)
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,0xAA0000)
- local function getKey(s)
- local key, _, x1 , code, _ = event.pull()
- if key == 'key_up' or key == 'touch' then
- return code , x1 , key
- end
- end
- local function enterPass(x,y,w,h)
- try = ""
- ex=true
- while ex do
- local err, f , x1 , key = pcall(getKey)
- if not err then
- return err, try
- end
- if f ~= nil and key == 'key_up' then --
- if keyboard.keys[f] == 'grave' then ex=false end
- if f < 60 and f > 0 then
- if keyboard.keys[f] == 'enter' then
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- return err, try , 's'
- end
- if keyboard.keys[f] == 'back' then
- if unicode.len(try) > 0 then
- try=unicode.sub(try,0,unicode.len(try)-1)
- drawTextInPass(x,y,w,h,try,color_fore)
- else
- try = 'cancel'
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- return err , try , 'f'
- end
- end
- if unicode.len(keyboard.keys[f]) == 1 then
- try = try..keyboard.keys[f]
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'space' then
- try = try..'_'
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'minus' then
- try = try..'-'
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'period' then
- try = try..'.'
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'comma' then
- try = try..','
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'slash' then
- try = try..'/'
- drawTextInPass(x,y,w,h,try,color_fore)
- end
- end
- elseif key == 'touch' and f ~= nil then
- if x1 > x-1 and x1 < x+w and f > y-1 and f < y+h then
- --
- else
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- return err, try , 's'
- end
- end
- end
- end --
- while true do
- err, try , got = enterPass(x,y,w,h)
- if got == 's' then -- success
- break
- elseif got == 'f' then
- try = nil
- break
- end
- end
- return try
- end
- local function drawButtonAddMenu(arr,i)
- draw.field(arr[i][1],arr[i][2],arr[i][3],1,'▄',arr[i][4],arr[i][5])
- draw.field(arr[i][1],arr[i][2]+1,arr[i][3],1,' ',arr[i][5],arr[i][5])
- draw.field(arr[i][1],arr[i][2]+2,arr[i][3],1,'▄',arr[i][5],arr[i][4])
- end
- function drawFrame(txt)
- arrDrawFrame={
- {25,12,12,0xAAAAAA,0xBBBB00,0,'Отмена'},
- {43,12,12,0xAAAAAA,0xBBBB00,0,'Готово'}
- }
- draw.field(20,8,40,8,' ',0xAAAAAA,0xFFFFFF) -- frame
- draw.clound('┌','┐','└','┘','│','─',20,8,40,8,0xAAAAAA,0)
- draw.text(20,8,38,txt,0xAAAAAA,0) -- /frame
- draw.field(25,9,30,3,' ',0xAAAAAA,0xFFFFFF) -- nameFrame
- draw.clound('┌','┐','└','┘','│','─',25,9,30,3,0xAAAAAA,0) -- nameFrame
- for i=1,#arrDrawFrame do
- drawButtonAddMenu(arrDrawFrame,i)
- draw.text(arrDrawFrame[i][1],arrDrawFrame[i][2]+1,arrDrawFrame[i][3],arrDrawFrame[i][7],arrDrawFrame[i][5],arrDrawFrame[i][6])
- end
- while true do
- local key,_,x,y,_,_ = event.pull('touch')
- if x > 20 and x < 40 and y >8 and y < 12 then
- name=enter(25,9,30,3,0xAAAAAA,0)
- elseif x > 24 and x < 36 and y > 12 and y < 16 then
- name = nil
- break
- elseif x > 42 and x < 55 and y > 12 and y < 16 then
- if name ~= nil and unicode.len(name) > 0 then
- break
- end
- end
- end
- print(name)
- return name
- end
- function renameFile()
- oldName=getPath()..tostring(arr[clickFile])
- nn=drawFrame('[Переименование]')
- if nn ~= nil then
- newName=getPath()..nn
- end
- n=1
- if oldName ~= newName and nn~=nil then
- while true do
- if filesystem.exists(getPath()..newName) == false then
- filesystem.rename(oldName,newName)
- break
- elseif filesystem.exists(getPath()..newName..'('..n..')') == false and filesystem.exists(getPath()..newName) == true then
- filesystem.rename(oldName,newName..'('..n..')')
- break
- end
- n=n+1
- end
- end
- end
- function copyFile()
- print(copyFilePath,copyF)
- if arr[clickFile] ~= nil then
- copyFilePath=getPath()
- copyF=tostring(arr[clickFile])
- end
- end
- function pasteFile()
- pasteFilePath=getPath()
- n=1
- if copyFilePath ~= pasteFilePatha and copyF ~= nil then
- while true do
- if filesystem.exists(pasteFilePath..copyF) == false then
- shell.execute('cp '..copyFilePath..copyF..' '..pasteFilePath..copyF)
- break
- elseif filesystem.exists(getPath()..copyF..'('..n..')') == false and filesystem.exists(pasteFilePath..copyF) == true then
- shell.execute('cp '..copyFilePath..copyF..' '..pasteFilePath..copyF..'('..n..')')
- break
- end
- n=n+1
- end
- end
- end
- function addFile()
- newFileName=drawFrame('[Создание файла/директории]')
- if newFileName ~= nil then
- if unicode.sub(newFileName,unicode.len(newFileName),unicode.len(newFileName)) == '/' then
- shell.execute('mkdir '..newFileName)
- else
- nf=io.open(newFileName,'w')
- nf:close()
- end
- end
- end
- function menu()
- drawMenu()
- drawDisks()
- drawFiles(1,72,getPath())
- while true do
- key , x , y , clickMouse = checkEvent()
- if key == 'touch' then
- if x > 18 and x < 39 then
- if arr[y-1] ~= nil then
- clickFile=y-1
- N=1
- end
- elseif x > 39 and x < 60 then
- if arr[(y-1)+24] ~= nil then
- clickFile=(y-1)+24
- N=1
- end
- elseif x > 60 and x < 81 then
- if arr[(y-1)+48] ~= nil then
- clickFile=(y-1)+48
- N=1
- end
- elseif x > 2 and x < 7 and y == 1 then
- if #pathArr > 1 then
- pathArr2={}
- for i=1,#pathArr-1 do
- pathArr2[#pathArr2+1]=pathArr[i]
- end
- pathArr=pathArr2
- sel=0
- oldClickFile=nil
- clickFile=0
- drawFiles(1,72,getPath())
- N=1
- end
- elseif x>1 and x < 18 and y > 2 and y < 7 then
- ldr=getMyDisks(2)
- if ldr[y-2+pageDisk] ~= nil then
- posDisk=y-2+pageDisk
- pathArr={}
- pathArr[1]=tostring('mnt/'..ldr[posDisk][2]:sub(1,3)..'/')
- sel=0
- oldClickFile=nil
- clickFile=0
- drawFiles(1,72,getPath())
- drawDisks()
- end
- elseif x==1 and y==1 then
- exit()
- end
- if oldClickFile ~= clickFile and N ~= nil then
- sel=clickFile
- if sel < 25 then
- if arr[sel] ~= nil then
- drawSelect(19,arr,sel,0)
- end
- elseif sel >24 and sel < 49 then
- if arr[sel] ~= nil then
- drawSelect(40,arr,sel,24)
- end
- elseif sel > 48 and sel < 73 then
- if arr[sel] ~= nil then
- drawSelect(61,arr,sel,48)
- end
- end
- elseif oldClickFile == clickFile and N~= nil then
- if arr[clickFile] ~= nil and unicode.sub(arr[clickFile],unicode.len(arr[clickFile]),unicode.len(arr[clickFile])) == '/' then
- pathArr[#pathArr+1]=tostring(arr[clickFile])
- sel=0
- oldClickFile=nil
- clickFile=0
- drawFiles(1,72,getPath())
- else
- if clickMouse == 0 and N~= nil then
- if arr[clickFile] ~= nil then
- gpu.setBackground(oldBack)
- gpu.setForeground(oldFore)
- term.clear()
- run(getPath()..arr[clickFile])
- end
- sel=0
- oldClickFile=nil
- clickFile=0
- event.pull('touch')
- drawMenu()
- drawPath()
- drawDisks()
- drawFiles(1,72,getPath())
- elseif clickMouse == 1 and arr[clickFile] ~= nil and N~= nil then
- gpu.setBackground(oldBack)
- gpu.setForeground(oldFore)
- term.clear()
- shell.execute('edit '..getPath()..arr[clickFile])
- sel=0
- oldClickFile=nil
- clickFile=0
- drawMenu()
- drawPath()
- drawDisks()
- drawFiles(1,72,getPath())
- end
- end
- end
- oldClickFile=clickFile
- elseif key == 'key_up' then
- if y == 211 and clickFile ~= nil and clickFile ~= 0 then
- delete()
- elseif y == 19 and clickFile ~= nil and clickFile ~= 0 then
- renameFile()
- sel=0
- oldClickFile=nil
- clickFile=0
- drawMenu()
- drawPath()
- drawDisks()
- drawFiles(1,72,getPath())
- elseif y == 46 and clickFile ~= nil and clickFile ~= 0 then
- copyFile()
- elseif y == 47 then
- pasteFile()
- sel=0
- oldClickFile=nil
- clickFile=0
- drawMenu()
- drawPath()
- drawDisks()
- drawFiles(1,72,getPath())
- elseif y == 49 then
- addFile()
- drawMenu()
- drawPath()
- drawDisks()
- drawFiles(1,72,getPath())
- end
- elseif key == 'scroll' then
- if x>1 and x < 18 and y > 2 and y < 7 then
- pageDisk=pageDisk-(clickMouse)
- if pageDisk < 0 then pageDisk=0 end
- gmd=getMyDisks(1)
- if pageDisk > math.ceil(#gmd/4) then pageDisk = math.ceil(#gmd/4) end
- drawDisks()
- end
- end
- os.sleep(0.0001)
- N=nil
- end
- end
- --
- local pa,posDisk= startDisk()
- pathArr={tostring(pa)}
- --
- thread.init()
- thread.create(ob)
- menu()
- thread.waitForAll()
- --drawFrame('test')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement