Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local title = "File manager v1.0"
- local w, h = term.getSize( )
- local color = { }
- local file = tArgs[1] or "files.conf"
- color[true] = colors.green
- color[false] = colors.red
- if not fs.exists( file ) then error( "config file doesnt exist" ) end
- local conf = fileapi.readConfig( file )
- if not conf then error( "something went wrong while reading the config" ) end
- local passw = fileapi.getConfigValue( conf, "acces-password" )
- local passa = fileapi.getConfigValue( conf, "filemanager-password" )
- local usepass = fileapi.getConfigValue( conf, "filemanager-usepass" )
- if not passw then error( "something went wrong while retreiving password" ) end
- local files = fileapi.getTable( passw )
- if not files then error( "wrong password" ) end
- if usepass == "1" then
- term.clear( )
- term.setCursorPos( 1, 1 )
- print "please enter password: "
- local inp = read( "*" )
- if inp ~= passa then
- term.clear( )
- term.setCursorPos( 1, 1 )
- print( "wrong password" )
- error( )
- end
- end
- function draw( t )
- term.setTextColor( colors.black )
- term.setBackgroundColor( colors.white )
- term.clear( )
- term.setCursorPos( 1, 1 )
- term.setBackgroundColor( colors.lightGray )
- term.clearLine( )
- term.write( title .. string.rep( " ", w - #title - 2 ) )
- term.setBackgroundColor( colors.green )
- term.write( " " )
- term.setBackgroundColor( colors.red )
- term.write( "X" )
- term.setBackgroundColor( colors.white )
- for i = 1, #t do
- if t[i] then
- term.setCursorPos( 3, i + 3 )
- term.write( t[i].name .. string.rep( " ", 10 - #t[i].name ) )
- term.setBackgroundColor( colors.red )
- term.write( " " )
- term.setBackgroundColor( color[t[i].conf.protect] )
- term.write( " " )
- term.setBackgroundColor( color[t[i].conf.hide] )
- term.write( " " )
- term.setBackgroundColor( colors.white )
- end
- end
- end
- draw( files )
- local running = true
- while running do
- local ev = { os.pullEvent( ) }
- if ev[1] == "mouse_click" then
- local x = ev[3]
- local y = ev[4] - 3
- if x == w and y == 1 - 3 then
- running = false
- end
- if x == w - 1 and y == 1 - 3 then
- term.setBackgroundColor( colors.white )
- term.setTextColor( colors.black )
- term.clear( )
- term.setCursorPos( 1, 1 )
- term.write( "file path: " )
- local filepath = read( )
- if fs.exists( filepath ) then
- fileapi.protect( filepath, { protect = false, hide = false } )
- end
- end
- if files[y] then
- if x == 13 then
- fileapi.unprotect( files[y].path )
- end
- if x == 14 then
- files[y].conf.protect = not files[y].conf.protect
- if files[y].conf.protect then
- files[y].data = fileapi.readFile( files[y].path )
- end
- end
- if x == 15 then
- files[y].conf.hide = not files[y].conf.hide
- if not files[y].conf.hide then
- files[y].conf.protect = true
- end
- end
- end
- end
- draw( files )
- end
- term.setBackgroundColor( colors.black )
- term.setTextColor( colors.white )
- term.clear( )
- term.setCursorPos( 1, 1 )
Advertisement
Add Comment
Please, Sign In to add comment