Пример #1
0
fsize_t __dir_size_process( const char* path )
{
  if ( vfu_break_op() )
    return -1;
  
  DIR* dir;
  dirent* de;
  struct stat st;
  fsize_t size = 0;
  char new_name[MAX_PATH];
  
  dir = opendir( path );
  if ( !dir ) return 0;
  while( (de = readdir(dir)) )
    {
    if ( strcmp( de->d_name, "." ) == 0 ||
         strcmp( de->d_name, ".." ) == 0 ) continue;
    
    sprintf(new_name, "%s%s", path, de->d_name);
    lstat(new_name, &st);
    int is_link = int(S_ISLNK(st.st_mode));
    memset( &st, 0, sizeof(st) );
    #ifdef _TARGET_GO32_
      dosstat(dir, &st);
    #else
      stat(new_name, &st);
    #endif
    int is_dir = int(S_ISDIR(st.st_mode));
    
    if ( is_link ) continue; /* skip links */
    if ( is_dir )
      {
      strcat( new_name, "/" );
      fsize_t dir_size = __dir_size_process( new_name );
      if ( dir_size == -1 )
        {
        closedir(dir);
        return -1;
        }
      else
        {
        size += dir_size;
        size_cache_append( new_name, dir_size );
        }
      }
    else
      size += file_st_size( &st );
    
    }
  closedir(dir);
    
  /* show some progress :) */
  say2( str_dot_reduce( path, con_max_x()-1 ) );
  return size;
}
Пример #2
0
int con_full_box( int x, int y, const char *title, VArray *va, ConMenuInfo *menu_info )
{
  ScrollPos scroll;
  scroll.wrap = 0;
  scroll.set_min_max( 0, va->count()-1 );
  scroll.set_pagesize( con_max_y() - 3 ); /* one title and two status */
  scroll.go( 0 );

  char pos_str[32];

  con_xy( 1, 1 );
  con_puts( title, menu_info->ti );
  con_ce( menu_info->ti );
  while(4)
    {
    VString str;
    int z;
    for( z = 0; z < scroll.pagesize(); z++ )
      {
      if ( scroll.page() + z < va->count() )
        str = va->get( scroll.page() + z );
      else
        str = "~";
      str = str_dot_reduce( str, con_max_x()-1 );
      con_xy( 1, z + 2 );
      int c = ( scroll.page() + z == scroll.pos() ) ? menu_info->ch : menu_info->cn;
      con_puts( str, c );
      con_ce( c );
      }
    sprintf( pos_str, " %5d of %5d", scroll.pos()+1, scroll.max()+1 );
    con_out( con_max_x() - 15, 1, pos_str, menu_info->ti );
    int ch;
    switch( (ch = con_getch()) )
      {
      case 27 : menu_info->ec = 27; return -1; break;
      case  8 : menu_info->ec =  8; return -1; break;
      case KEY_BACKSPACE : menu_info->ec =  KEY_BACKSPACE; return -1; break;
      case 13 : menu_info->ec = 13; return scroll.pos(); break;
      case KEY_UP    : scroll.up(); break;
      case KEY_DOWN  : scroll.down(); break;
      case KEY_NPAGE : scroll.npage(); break;
      case KEY_PPAGE : scroll.ppage(); break;
      case KEY_HOME  : scroll.home(); break;
      case KEY_END   : scroll.end(); break;
      default:
        if ( tolower(ch) == tolower(menu_info->ac) )
          {
          menu_info->ec = menu_info->ac;
          return -2;
          }
          break;
      }
    }
}
Пример #3
0
void tree_draw_pos( ScrollPos &scroll, int opos )
{
  int z = scroll.pos() - scroll.page();
  if ( opos != -1 ) tree_draw_item( scroll.page(), opos );
  tree_draw_item( scroll.page(), z, 1 );
  VString str;
  str = dir_tree[scroll.pos()];
  str_tr( str,"\\", "/" );
  
  VString sz;
  sz.fi( size_cache_get( str ) );
  str_comma( sz );
  str_pad( sz, 14 );
  str = sz + " " + str;

  str = str_dot_reduce( str, con_max_x()-1 );
  
  say1( str, cINFO );
  say2( "         Help: R Rebuild, S Incremental search, Z Recalc directory size", cINFO );
  show_pos( scroll.pos()+1, scroll.max()+1 );
}
Пример #4
0
fsize_t __tree_rebuild_process( const char* path )
{
  if ( vfu_break_op() ) return -1;
  
  DIR* dir;
  dirent* de;
  struct stat st;
  fsize_t size = 0;
  char new_name[MAX_PATH];
  
  dir = opendir( path );
  if ( !dir ) return 0;
  while( (de = readdir(dir)) )
    {
    if ( strcmp( de->d_name, "." ) == 0 ||
         strcmp( de->d_name, ".." ) == 0 ) continue;

    sprintf(new_name, "%s%s", path, de->d_name);
    lstat(new_name, &st);
    int is_link = int(S_ISLNK(st.st_mode));
    
    if (is_link) continue;
    
    #ifdef _TARGET_GO32_
    dosstat(dir, &st);
    #else
    stat(new_name, &st);
    #endif
    
    int is_dir = S_ISDIR(st.st_mode);
    
    if ( is_dir )
      { /* directory */
      strcat( new_name, "/" );
      
      int z;
      int trim = 0;
      for ( z = 0; z < trim_tree.count(); z++ )
        {
        VString trim_temp = trim_tree[z];
        str_fix_path( trim_temp );
        if ( pathcmp(trim_temp, new_name) == 0 ) 
          { /* trim_tree item found */
          trim = 1;
          break;
          }
        }  
      if (trim) 
        continue; /* cut this branch */
      
      int pos = dir_tree.count();
      fsize_t dir_size = __tree_rebuild_process( new_name );
      if ( dir_size < 0 )
        { /* canceled */
        closedir(dir);
        return -1;
        }
      dir_tree.ins( pos, new_name );
      size_cache_set( new_name, dir_size );
      size += dir_size;
      }
    else
      { /* file */
      size += file_st_size( &st );
      }  
    
    }
  closedir(dir);
  
  /* show some progress :) */
  say2( str_dot_reduce( path, con_max_x()-1 ) );
  return size;
}
Пример #5
0
int con_menu_box( int x, int y, const char *title, VArray *va, int hotkeys, ConMenuInfo *menu_info  )
{
  ScrollPos scroll;
  int z;

  int w = -1;
  int h = -1;

  if (w == -1) w = va->max_len();
  if (h == -1) h = va->count();

  z = strlen(title);
  if (w < z) w = z;
  if (h > va->count()) h = va->count();
  if (h == 0) h = 1;

  // FIXME: those should be fixed!!!
  if (x + w > con_max_x()) w = con_max_x() - x - 4;
  if (y + h > con_max_y()-4) h = con_max_y() - y - 4;

  VString str;
  VString hots = "";
  if ( hotkeys > -1 )
    {
    for(z = 0; z < va->count(); z++)
      if (strncmp("--", va->get(z), 2))
        str_add_ch( hots, char(((const char*)(va->get(z)))[hotkeys]) );
      else
        str_add_ch( hots,' ' );
    str_up(hots);
    }
  con_xy(x,y);
  int ch = 0;

  str = " ";
  str += title;
  str += " ";
  str_pad( str,-(w), menu_info->bo ? '-' : ' ' );
  if (str_len(str) > w) str_sleft(str,w);
  if (menu_info->bo)
    str = ".-" + str + "-.";
  else
    str = "  " + str + "  ";
  con_out(x,y,str,menu_info->ti);
  y++;

  scroll.wrap = 1;
  scroll.set_min_max( 0, va->count()-1 );
  scroll.set_pagesize( h );
  scroll.go( 0 );

  while(1)
    {
    for( z = 0; z < scroll.pagesize(); z++ )
      {
      str = (scroll.page()+z >= va->count())? "~" : va->get(scroll.page()+z);

      if ( menu_info->hide_magic[0] )
        {
        int i = str_rfind( str, menu_info->hide_magic );
        if ( i != -1)
          str_sleft( str, i );
        }
 
      str_pad( str,-w , (strncmp("--", str, 2) == 0)?'-':' ');
      if (str_len(str) > w) 
        str = str_dot_reduce( str, w );
      if (menu_info->bo)
        str = "| " + str + " |";
      else
        str = "  " + str + "  ";
      con_out( x, y+z, str, ( scroll.page()+z != scroll.pos() ) ? menu_info->cn : menu_info->ch );
      }
    if (menu_info->bo)
      {
      str = "";
      str_pad( str, w+2, '-' );
      str = "`" + str + "'";
      con_out( x, y+scroll.pagesize(), str, menu_info->cn );
      }
    ch = con_getch();
    menu_info->ec = ch;

    if ( ch == KEY_UP    ) scroll.up();
    if ( ch == KEY_DOWN  ) scroll.down();
    if ( ch == KEY_NPAGE ) scroll.npage();
    if ( ch == KEY_PPAGE ) scroll.ppage();
    if ( ch == KEY_HOME  ) scroll.home();
    if ( ch == KEY_END   ) scroll.end();

    if ( ch < 0 || ch > 255 ) continue;
    if ( ch == 27 )
      {
      menu_info->ac = 0;
      return -1;
      }
    if ( ch == 13 )
      {
      if (strncmp("--", va->get(scroll.pos()), 2) != 0) // ako e "--" e separator
        {
        menu_info->ec = hots[scroll.pos()];
        menu_info->ac = -1;
        return scroll.pos();
        }
      }
    if ( menu_info->ac > -1 && ch == menu_info->ac )
      {
      if (strncmp("--", va->get(scroll.pos()), 2) != 0) // ako e "--" e separator
        {
        menu_info->ec = hots[scroll.pos()];
        menu_info->ac = -2;
        return scroll.pos();
        }
      }
    z = str_find( hots, toupper(ch) );
    if (z > -1)
      {
      menu_info->ec = hots[z];
      menu_info->ac = -1;
      return z;
      }
    }
  menu_info->ac = -1;
  return -1;
};
Пример #6
0
/*#######################################################################*/

extern const char *FTIMETYPE[]; /* in vfuopt.cpp */
void vfu_redraw() /* redraw file list and header */
{
  char t[MAX_PATH];
  VString str;

  str  = "Mask: ";
  str += files_mask;
  con_out(1,1,str,cINFO);
  con_ce(cINFO);
  if ( work_mode == WM_ARCHIVE )
    con_out( con_max_x()-34, 1, " [-ARCHIVE-] ", cWARNING );
  con_out(con_max_x()-17,1,"Press H for help",cINFO);
  con_out(con_max_x()-20,1,"VFU " VFU_VERSION " <H> for help",cINFO);

  str = "Path: ";
  str += work_path;
  if ( work_mode == WM_ARCHIVE )
    {
    str += "[";
    str += archive_name;
    str += "]/"; /* NOTE: to simulate root dir visually */
    str += archive_path;
    }
  str = str_dot_reduce( str, con_max_x()-1 );
  con_out(1,2,str,cINFO);
  con_ce(cINFO);

  str = "";

  if ( opt.sort_order == 'N' ) str = "NAME";
  if ( opt.sort_order == 'M' ) str = "NAME#";
  if ( opt.sort_order == 'E' ) str = "EXT";
  if ( opt.sort_order == 'A' ) str = "MODE";
  if ( opt.sort_order == 'O' ) str = "OWNER";
  if ( opt.sort_order == 'G' ) str = "GROUP";
  if ( opt.sort_order == 'T' ) str = "MTIME";
  if ( opt.sort_order == 'H' ) str = "CTIME";
  if ( opt.sort_order == 'C' ) str = "ATIME";
  if ( opt.sort_order == 'S' ) str = "SIZE";
  if ( opt.sort_order == 'Y' ) str = "TYPE";
  str += opt.sort_direction == 'A' ? "+" : "-";
  str = "(SORT:" + str + ")";
  con_out( con_max_x() - str_len( str ) + 1, 2, str, cHEADER );

  str = "";

  t[0] = 0;
  char *spos = t;
  if (opt.sort_order == 'D') opt.sort_order = 'T'; /* hack anyway */
  if (!opt.long_name_view)
    {
    if (opt.f_mode  ) spos += sprintf( spos, "%10s ", MODE_STRING );
    if (opt.f_owner ) spos += sprintf( spos, "   OWNER " );
    if (opt.f_group ) spos += sprintf( spos, "   GROUP " );
    if (opt.f_time  ) spos += sprintf( spos, "%s  TiME ", FTIMETYPE[opt.f_time_type] );
    if (opt.f_size  ) spos += sprintf( spos, filesize_fmt, "SiZE" );
    };
  if ( opt.f_mode + opt.f_owner + opt.f_group + opt.f_time + opt.f_size + opt.f_type == 0 )
    opt.f_type = 1; /* a hack really :) if all fields are off -- turn on type one */
  if (opt.f_type || opt.long_name_view) spos += sprintf( spos, "TP" );
  tag_mark_pos = strlen( t );
  sel_mark_pos = tag_mark_pos + 2;

  spos += sprintf( spos, "  #NAME    %s",
                   opt.long_name_view ? "( long name view )" : "" );

  str_pad( t, - con_max_x() );
  str_sleft( t, con_max_x() );

  con_out(1,3, t, cHEADER );
  show_pos( FLI+1, files_count );

  int z;

  for ( z = 0; z < PS; z++ )
    {
    ASSERT( FLP + z >= 0 );
    if ( FLP + z >= files_count )
      {
      con_out( 1, z+4, "~", cPLAIN );
      con_ce( cPLAIN );
      }
    else if ( files_list[FLP+z] == NULL )  /* FIXME: if NULL?! */
      {
      con_out( 1, z+4, "~", cPLAIN );
      con_ce( cPLAIN );
      }
    else
      vfu_draw( FLP + z );
    }
  if ( files_count <= 0 )
    con_out( ( con_max_x() - 20 ) / 2, 10, " *** No files found *** ", cHEADER);

}