⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cc

📁 类似GetRight的下载工具
💻 CC
📖 第 1 页 / 共 3 页
字号:
    } // if the size is less then minimum -> delete the file    else if ( e->size < ProtocolManager::self()->getMinimumKeepSize() ) {	ftp.ftpDelete( udest.path() );    }  }  ftp.ftpDisconnect();  // We have done our job => finish  finished();  m_cmd = CMD_NONE;}void FtpProtocol::slotDel( const char *_url ){  list<string> lst;  lst.push_back( _url );    slotDel( lst );}void FtpProtocol::slotDel( list<string>& _source ){  // Check wether the URLs are wellformed  list<string>::iterator soit = _source.begin();  for( ; soit != _source.end(); ++soit )  {        debug( "kio_ftp : Checking %s", soit->c_str() );    K2URL usrc( *soit );    if ( usrc.isMalformed() ) {      error( ERR_MALFORMED_URL, soit->c_str() );      m_cmd = CMD_NONE;      return;    }    if ( strcmp( usrc.protocol(), "ftp" ) != 0L ) {      error(ERR_INTERNAL,"kio_ftp got non ftp file for delete command" );      error( ERR_INTERNAL, "kio_file got non local file as source in copy command" );      m_cmd = CMD_NONE;      return;    }  }  debug( "kio_ftp : All URLs ok" );  // Get a list of all source files and directories  list<Copy> fs;  list<CopyDir> ds;  int size = 0;  debug( "kio_ftp : Iterating" );  soit = _source.begin();  debug( "kio_ftp : Looping" );  for( ; soit != _source.end(); ++soit )  {        debug( "kio_ftp : Executing %s", soit->c_str() );    K2URL usrc( *soit );    debug( "kio_ftp : Parsed URL" );    // Did an error occur ?    int s;//     if ( ( s = listRecursive( usrc.path(), fs, ds, false ) ) == -1 )//       {// 	// Error message is already sent// 	ftp.ftpDisconnect();// 	m_cmd = CMD_NONE;// 	return;//       }    // Sum up the total amount of bytes we have to copy    size += s;  }  debug( "kio_ftp : Recursive ok" );  if ( fs.size() == 1 )    m_cmd = CMD_DEL;  else    m_cmd = CMD_MDEL;  // Tell our client what we 'r' gonna do  totalSize( size );  totalFiles( fs.size() );  totalDirs( ds.size() );  /*****   * Delete files   *****/  list<Copy>::iterator fit = fs.begin();  for( ; fit != fs.end(); fit++ ) {     string filename = fit->m_strAbsSource;    debug( "kio_ftp : Deleting file %s", filename.c_str() );    deletingFile( filename.c_str() );    if ( !ftp.ftpDelete( filename.c_str() ) ) // !!! use unlink ?      {	error( ERR_CANNOT_DELETE, filename.c_str() );	ftp.ftpDisconnect();	m_cmd = CMD_NONE;	return;      }  }  /*****   * Delete empty directories   *****/  list<CopyDir>::iterator dit = ds.begin();  for( ; dit != ds.end(); dit++ ) {     string dirname = dit->m_strAbsSource;    debug( "kio_ftp : Deleting directory %s", dirname.c_str() );    deletingFile( dirname.c_str() );    if ( !ftp.ftpRmdir( dirname.c_str() ) ) {      error( ERR_COULD_NOT_RMDIR, dirname.c_str() );      ftp.ftpDisconnect();      m_cmd = CMD_NONE;      return;    }  }    finished();    m_cmd = CMD_NONE;}void FtpProtocol::slotData( void *_p, int _len ){  switch( m_cmd )    {    case CMD_PUT:      ftp.write( _p, _len );      break;    }}void FtpProtocol::slotDataEnd(){  switch( m_cmd )    {    case CMD_PUT:      m_cmd = CMD_NONE;    }}long FtpProtocol::listRecursive( const char *_path, list<Copy>& _files, list<CopyDir>& _dirs, bool _rename ){  m_bAutoSkip = false;    // Check wether we have to copy the complete directory tree beginning by its root.  int len = strlen( _path );  while( len >= 1 && _path[ len - 1 ] == '/' )    len--;  if ( len == 0 )  {    CopyDir c;    c.m_strAbsSource = _path;    if ( _rename )      c.m_strRelDest = "";    else      c.m_strRelDest = "";    c.m_access = S_IRWXU | S_IRWXO | S_IRWXG;    c.m_type = S_IFDIR;    _dirs.push_back( c );        return listRecursive2( "/", c.m_strRelDest.c_str(), _files, _dirs );  }    string p;  p.assign( _path, len );  debug( "kio_ftp : ########## RECURSIVE LISTING %s", p.c_str() );    K2URL tmpurl( "ftp:/" );  tmpurl.setPath( p.c_str() );  FtpEntry* e = ftp.ftpStat( tmpurl );  if ( !e )  {    error( ERR_DOES_NOT_EXIST, p.c_str() );    return -1;  }    K2URL u( p.c_str() );  // Should be checked before, but who knows  if ( u.isMalformed() )    assert( 0 );  // Is the source not a directory ? => so just copy it and we are done.  if ( !S_ISDIR( e->type ) )  {    debug( "kio_ftp : not a dir" );    string fname;    if ( _rename )      fname = "";    else    {      fname = u.filename();      // Should be impossible, but who knows ...      if ( fname.empty() )	assert( 0 );    }    Copy c;    c.m_strAbsSource = p;    c.m_strRelDest = fname;    c.m_access = e->access;    c.m_type = e->type;    c.m_size = e->size;    _files.push_back( c );    return e->size;  }  // The source is a directory. So we have to go into recursion here.  string tmp1;  if ( _rename )    tmp1 = u.path( 0 );  else  {        tmp1 = u.directory( true );    tmp1 += "/";  }  string tmp2;  if ( _rename )    tmp2 = "";  else    tmp2 = u.filename();  CopyDir c;  c.m_strAbsSource = p;  c.m_strRelDest = tmp2;  c.m_access = e->access;  c.m_type = e->type;  _dirs.push_back( c );  debug( "kio_ftp : ########### STARTING RECURSION with %s and %s",tmp1.c_str(), tmp2.c_str() );    return listRecursive2( tmp1.c_str(), tmp2.c_str(), _files, _dirs );}long FtpProtocol::listRecursive2( const char *_abs_path, const char *_rel_path,				  list<Copy>& _files, list<CopyDir>& _dirs ){  long size = 0;    cerr << "listRecursive2 " << _abs_path << "  " << _rel_path << endl;  string p = _abs_path;  p += _rel_path;  scanningDir( p.c_str() );    K2URL tmpurl( "ftp:/" );  tmpurl.setPath( p.c_str() );  if ( !ftp.ftpOpenDir( tmpurl ) )  {    if ( m_bAutoSkip )      return 0;    SkipDlg_Result result = open_SkipDlg( p.c_str(), true );    if ( result == S_CANCEL )    {      // error( ERR_CANNOT_ENTER_DIRECTORY, p.c_str() );      return -1;    }    else if ( result == S_AUTO_SKIP )      m_bAutoSkip = true;    return 0;  }  list<string> recursion;  debug( "kio_ftp : ##Listing" );    FtpEntry *e;  while ( ( e = ftp.readdir() ) != 0L )  {    debug( "kio_ftp : #%s", e->name.c_str() );        if ( e->name == "." || e->name == ".." )      continue;        string p2 = p;    p2 += "/";    p2 += e->name;      string tmp = _rel_path;    tmp += "/";    tmp += e->name;      if ( !S_ISDIR( e->type ) )    {      debug( "kio_ftp : Appending '%s' '%s'", p2.c_str(), tmp.c_str() );      Copy c;      c.m_strAbsSource = p2;      c.m_strRelDest = tmp;      c.m_access = e->access;      c.m_type = e->type;      c.m_size = e->size;      _files.push_back( c );      size += e->size;    }    else    {      CopyDir c;      c.m_strAbsSource = p2;      c.m_strRelDest = tmp;      c.m_access = e->access;      c.m_type = e->type;      _dirs.push_back( c );      recursion.push_back( tmp );    }  }  if ( !ftp.ftpCloseDir() )  {    // error( ERR_COULD_NOT_CLOSEDIR, p.c_str() );    return -1;  }    list<string>::iterator it = recursion.begin();  for( ; it != recursion.end(); ++it )  {        long s;    if ( ( s = listRecursive2( _abs_path, it->c_str(), _files, _dirs ) ) == -1 )      return -1;    size += s;  }    return size;}void FtpProtocol::slotListDir( const char *_url ){  debug( "kio_ftp : =============== LIST %s ===============", _url  );    string url = _url;    K2URL usrc( _url );  if ( usrc.isMalformed() )  {    error( ERR_MALFORMED_URL, url.c_str() );    m_cmd = CMD_NONE;    return;  }  if ( strcmp( usrc.protocol(), "ftp" ) != 0L )  {    error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" );    m_cmd = CMD_NONE;    return;  }  /*  struct stat buff;  if ( stat( usrc.path(), &buff ) == -1 )  {    error( ERR_DOES_NOT_EXIST, url.c_str() );    m_cmd = CMD_NONE;    return;  }  if ( !S_ISDIR( buff.st_mode ) )  {    error( ERR_IS_FILE, url.c_str() );    m_cmd = CMD_NONE;    return;  } */  m_cmd = CMD_LIST;    if ( !ftp.opendir( usrc ) )  {    error( ERR_CANNOT_ENTER_DIRECTORY, url.c_str() );    m_cmd = CMD_NONE;    return;  }  FtpEntry* e;  while ( ( e = ftp.readdir() ) )  {    if ( e->name == "." || e->name == ".." )      continue;    debug( "kio_ftp : Listing %s", e->name.c_str() );    UDSEntry entry;    UDSAtom atom;    atom.m_uds = UDS_NAME;    atom.m_str = e->name;    entry.push_back( atom );          atom.m_uds = UDS_FILE_TYPE;    atom.m_long = e->type;    entry.push_back( atom );    atom.m_uds = UDS_SIZE;    atom.m_long = e->size;    entry.push_back( atom );    /* atom.m_uds = UDS_MODIFICATION_TIME;    atom.m_long = buff.st_mtime;    entry.push_back( atom ); */    atom.m_uds = UDS_ACCESS;    atom.m_long = e->access;    entry.push_back( atom );    atom.m_uds = UDS_USER;    atom.m_str = e->owner;    entry.push_back( atom );    atom.m_uds = UDS_GROUP;    atom.m_str = e->group;    entry.push_back( atom );    atom.m_uds = UDS_LINK_DEST;    atom.m_str = e->link;    entry.push_back( atom );    /* atom.m_uds = UDS_ACCESS_TIME;    atom.m_long = buff.st_atime;    entry.push_back( atom );        atom.m_uds = UDS_CREATION_TIME;    atom.m_long = buff.st_ctime;    entry.push_back( atom ); */    listEntry( entry );  }  debug( "kio_ftp : ============= COMPLETED LIST ============" );   ftp.closedir();    debug( "kio_ftp : ============= COMPLETED LIST 2 ============" );  m_cmd = CMD_NONE;  finished();  debug( "kio_ftp : =============== BYE ===========" );}void FtpProtocol::slotTestDir( const char *_url ){  string url = _url;    K2URL usrc( _url );  if ( usrc.isMalformed() )  {    error( ERR_MALFORMED_URL, url.c_str() );    m_cmd = CMD_NONE;    return;  }      if ( strcmp( usrc.protocol(), "ftp" ) != 0L )  {    error( ERR_INTERNAL, "kio_ftp got non ftp file as source in copy command" );    m_cmd = CMD_NONE;    return;  }  debug( "kio_ftp : =============== slotTestDir ==============" );  FtpEntry* e;  if ( !( e = ftp.stat( usrc ) ) )  {    debug( "kio_ftp : =========== ERROR ========" );    error( ERR_DOES_NOT_EXIST, url.c_str() );    m_cmd = CMD_NONE;    return;  }    if ( S_ISDIR( e->type ) )  {    debug( "kio_ftp : ========== DONE DIR ========= %s", _url );        isDirectory();  }  else  {    debug( "kio_ftp : ========== DONE FILE ========= %s", _url );    isFile();  }  finished();}void FtpProtocol::jobError( int _errid, const char *_txt ){  if ( !m_bIgnoreJobErrors )    error( _errid, _txt );}/************************************* * * FtpIOJob * *************************************/FtpIOJob::FtpIOJob( Connection *_conn, FtpProtocol *_Ftp ) : IOJob( _conn ){  m_pFtp = _Ftp;}  void FtpIOJob::slotError( int _errid, const char *_txt ){  IOJob::slotError( _errid, _txt );  m_pFtp->jobError( _errid, _txt );}/************************************* * * Utilities * *************************************/int check( Connection *_con ){  int err;  struct timeval tv;  tv.tv_sec = 0;  tv.tv_usec = 0;  fd_set rfds;  FD_ZERO( &rfds );  FD_SET( _con->inFD(), &rfds );  again:  if ( ( err = select( _con->inFD(), &rfds, 0L, 0L, &tv ) ) == -1 && errno == EINTR )    goto again;  // No error and something to read ?  if ( err != -1 && err != 0 )    return 1;    return 0;}void openFileManagerWindow( const char * ){  assert( 0 );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -