Guest User

filemanager

a guest
Mar 1st, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.16 KB | None | 0 0
  1. local tArgs = { ... }
  2. local title = "File manager v1.0"
  3. local w, h = term.getSize( )
  4. local color = { }
  5. local file = tArgs[1] or "files.conf"
  6. color[true] = colors.green
  7. color[false] = colors.red
  8.  
  9. if not fs.exists( file ) then error( "config file doesnt exist" ) end
  10. local conf = fileapi.readConfig( file )
  11. if not conf then error( "something went wrong while reading the config" ) end
  12. local passw = fileapi.getConfigValue( conf, "acces-password" )
  13. local passa = fileapi.getConfigValue( conf, "filemanager-password" )
  14. local usepass = fileapi.getConfigValue( conf, "filemanager-usepass" )
  15. if not passw then error( "something went wrong while retreiving password" ) end
  16. local files = fileapi.getTable( passw )
  17. if not files then error( "wrong password" ) end
  18.  
  19. if usepass == "1" then
  20.   term.clear( )
  21.   term.setCursorPos( 1, 1 )
  22.   print "please enter password: "
  23.   local inp = read( "*" )
  24.   if inp ~= passa then
  25.     term.clear( )
  26.     term.setCursorPos( 1, 1 )
  27.     print( "wrong password" )
  28.     error( )
  29.   end
  30. end
  31.  
  32. function draw( t )
  33.   term.setTextColor( colors.black )
  34.   term.setBackgroundColor( colors.white )
  35.   term.clear( )
  36.   term.setCursorPos( 1, 1 )
  37.  
  38.   term.setBackgroundColor( colors.lightGray )
  39.   term.clearLine( )
  40.   term.write( title .. string.rep( " ", w - #title - 2 ) )
  41.  
  42.   term.setBackgroundColor( colors.green )
  43.   term.write( " " )
  44.   term.setBackgroundColor( colors.red )
  45.   term.write( "X" )
  46.  
  47.   term.setBackgroundColor( colors.white )
  48.  
  49.   for i = 1, #t do
  50.     if t[i] then
  51.       term.setCursorPos( 3, i + 3 )
  52.       term.write( t[i].name .. string.rep( " ", 10 - #t[i].name ) )
  53.    
  54.       term.setBackgroundColor( colors.red )
  55.       term.write( " " )
  56.    
  57.       term.setBackgroundColor( color[t[i].conf.protect] )
  58.       term.write( " " )
  59.    
  60.       term.setBackgroundColor( color[t[i].conf.hide] )
  61.       term.write( " " )
  62.      
  63.       term.setBackgroundColor( colors.white )
  64.     end
  65.   end
  66. end
  67.  
  68. draw( files )
  69.  
  70. local running = true
  71. while running do
  72.   local ev = { os.pullEvent( ) }
  73.   if ev[1] == "mouse_click" then
  74.     local x = ev[3]
  75.     local y = ev[4] - 3
  76.     if x == w and y == 1 - 3 then
  77.       running = false
  78.     end
  79.     if x == w - 1 and y == 1 - 3 then
  80.       term.setBackgroundColor( colors.white )
  81.       term.setTextColor( colors.black )
  82.       term.clear( )
  83.       term.setCursorPos( 1, 1 )
  84.       term.write( "file path: " )
  85.       local filepath = read( )
  86.       if fs.exists( filepath ) then
  87.         fileapi.protect( filepath, { protect = false, hide = false } )
  88.       end
  89.     end
  90.     if files[y] then
  91.       if x == 13 then
  92.         fileapi.unprotect( files[y].path )
  93.       end
  94.       if x == 14 then
  95.         files[y].conf.protect = not files[y].conf.protect
  96.         if files[y].conf.protect then
  97.           files[y].data = fileapi.readFile( files[y].path )
  98.         end
  99.       end
  100.       if x == 15 then
  101.         files[y].conf.hide = not files[y].conf.hide
  102.         if not files[y].conf.hide then
  103.           files[y].conf.protect = true
  104.         end
  105.       end
  106.     end
  107.   end
  108.   draw( files )
  109. end
  110.  
  111. term.setBackgroundColor( colors.black )
  112. term.setTextColor( colors.white )
  113. term.clear( )
  114. term.setCursorPos( 1, 1 )
Advertisement
Add Comment
Please, Sign In to add comment