Package org.gudy.azureus2.core3.torrent

Examples of org.gudy.azureus2.core3.torrent.TOTorrentFile


  }

  private TorrentInfo addTorrent(String sFileName,
      final String sOriginatingLocation) {
    TorrentInfo info = null;
    TOTorrent torrent = null;
    File torrentFile;
    boolean bDeleteFileOnCancel = false;

    // Make a copy if user wants that.  We'll delete it when we cancel, if we
    // actually made a copy.
    try {
      if (sFileName.startsWith("file://localhost/")) {
        sFileName = UrlUtils.decode(sFileName.substring(16));
      }

      final File fOriginal = new File(sFileName);

      if (!fOriginal.isFile() || !fOriginal.exists()) {
        Utils.execSWTThread(new AERunnable() {
          public void runSupport() {
            if (shell == null)
              new MessageSlideShell(Display.getCurrent(), SWT.ICON_ERROR,
                  "OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] {
                    UrlUtils.decode(sOriginatingLocation),
                    "Not a File"
                  }, -1 );
            else {
              MessageBoxShell mb = new MessageBoxShell(SWT.OK,
                  "OpenTorrentWindow.mb.openError", new String[] {
                    sOriginatingLocation,
                    "Not a File"
                  });
              mb.open(null);
            }
          }
        });
        return null;
      }

      if (fOriginal.length() > 20*1024*1024) {
        Utils.execSWTThread(new AERunnable() {
          public void runSupport() {
            if (shell == null)
              new MessageSlideShell(Display.getCurrent(), SWT.ICON_ERROR,
                  "OpenTorrentWindow.mb.openError", fOriginal.toString(), new String[] {
                    UrlUtils.decode(sOriginatingLocation),
                    "Too large to be a torrent"
                  }, -1 );
            else {
              MessageBoxShell mb = new MessageBoxShell(SWT.OK,
                  "OpenTorrentWindow.mb.openError", new String[] {
                    sOriginatingLocation,
                    "Too large to be a torrent"
                  });
              mb.open(null);
            }
          }
        });
        return null;
      }

      torrentFile = TorrentUtils.copyTorrentFileToSaveDir(fOriginal, true);
      bDeleteFileOnCancel = !fOriginal.equals(torrentFile);
      // TODO if the files are still equal, and it isn't in the save
      //       dir, we should copy it to a temp file in case something
      //       re-writes it.  No need to copy a torrent coming from the
      //       downloader though..
    } catch (IOException e1) {
      // Use torrent in wherever it is and hope for the best
      // XXX Should error instead?
      torrentFile = new File(sFileName);
    }

    VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
   
    VuzeFile vf = vfh.loadVuzeFile( torrentFile );
   
    if ( vf != null ){
     
        vfh.handleFiles( new VuzeFile[]{ vf }, VuzeFileComponent.COMP_TYPE_NONE );

        return null;
    }
   
    // Do a quick check to see if it's a torrent
    if (!TorrentUtil.isFileTorrent(torrentFile, shellForChildren,
        torrentFile.getName())) {
      if (bDeleteFileOnCancel) {
        torrentFile.delete();
      }
      return null;
    }

    // Load up the torrent, see it it's real
    try {
      torrent = TorrentUtils.readFromFile(torrentFile, false);
    } catch (final TOTorrentException e) {
     
      Utils.execSWTThread(new AERunnable() {
        public void runSupport() {
          if (shell == null)
            new MessageSlideShell(Display.getCurrent(), SWT.ICON_ERROR,
                "OpenTorrentWindow.mb.openError", Debug.getStackTrace(e),
                new String[] {
                  sOriginatingLocation,
                  e.getMessage()
                }, -1 );
          else {
            MessageBoxShell mb = new MessageBoxShell(SWT.OK,
                "OpenTorrentWindow.mb.openError", new String[] {
                  sOriginatingLocation,
                  e.getMessage()
                });
            mb.open(null);
          }
        }
      });

      if (bDeleteFileOnCancel)
        torrentFile.delete();

      return null;
    }

    String sExistingName = null;
    try {
      HashWrapper hash = torrent.getHashWrapper();
      if (hash != null) {
        for (int i = 0; i < torrentList.size(); i++) {
          try {
            TorrentInfo existing = (TorrentInfo) torrentList.get(i);
            if (existing.torrent.getHashWrapper().equals(hash)) {
View Full Code Here


        }
          };
 
          for (int i=0;i<res.length;i++){
 
              final TOTorrentFile torrent_file    = torrent_files[i];
 
              final int file_index = i;
 
              FileSkeleton info = new FileSkeleton() {
 
                private CacheFile   read_cache_file;
                // do not access this field directly, use lazyGetFile() instead
                private WeakReference dataFile = new WeakReference(null);
 
                public void
                setPriority(int b)
                {
                  priority    = b;
 
                  DiskManagerImpl.storeFilePriorities( download_manager, res );
 
                  listener.filePriorityChanged( this );
                }
 
                public void
                setSkipped(boolean _skipped)
                {
                  if ( !_skipped && getStorageType() == ST_COMPACT ){
                    if ( !setStorageType( ST_LINEAR )){
                      return;
                    }
                  }
 
                  if ( !_skipped && getStorageType() == ST_REORDER_COMPACT ){
                    if ( !setStorageType( ST_REORDER )){
                      return;
                    }
                  }

                  skipped = _skipped;
 
                  DiskManagerImpl.storeFilePriorities( download_manager, res );
                 
                  if(!_skipped)
                  {
                    boolean[] toCheck = new boolean[fileSetSkeleton.nbFiles()];
                    toCheck[file_index] = true;
                    doFileExistenceChecks(fileSetSkeleton, toCheck, download_manager, true);                     
                  }
                 
 
                  listener.filePriorityChanged( this );
                }
 
                public int
                getAccessMode()
                {
                  return( READ );
                }
 
                public long
                getDownloaded()
                {
                  return( downloaded );
                }
 
                public void
                setDownloaded(
                  long    l )
                {
                  downloaded  = l;
                }
 
                public String
                getExtension()
                {
                  String    ext   = lazyGetFile().getName();
                 
                      if ( incomplete_suffix != null && ext.endsWith( incomplete_suffix )){
                       
                        ext = ext.substring( 0, ext.length() - incomplete_suffix.length());
                      }

                  int separator = ext.lastIndexOf(".");
                  if (separator == -1)
                    separator = 0;
                  return ext.substring(separator);
                }
 
                public int
                getFirstPieceNumber()
                {
                  return( torrent_file.getFirstPieceNumber());
                }
 
                public int
                getLastPieceNumber()
                {
                  return( torrent_file.getLastPieceNumber());
                }
 
                public long
                getLength()
                {
                  return( torrent_file.getLength());
                }
 
                public int
                getIndex()
                {
                  return( file_index );
                }
 
                public int
                getNbPieces()
                {
                  return( torrent_file.getNumberOfPieces());
                }
 
                public int
                getPriority()
                {
                  return( priority );
                }
 
                public boolean
                isSkipped()
                {
                  return( skipped );
                }
 
                public DiskManager
                getDiskManager()
                {
                  return( null );
                }
 
                public DownloadManager
                getDownloadManager()
                {
                  return( download_manager );
                }
 
                public File
                getFile(
                  boolean follow_link )
                {
                  if ( follow_link ){
 
                    File link = getLink();
 
                    if ( link != null ){
 
                      return( link );
                    }
                  }
                  return lazyGetFile();
                }
 
                private File lazyGetFile()
                {
                  File toReturn = (File)dataFile.get();
                  if(toReturn != null)
                    return toReturn;
 
                  TOTorrent tor = download_manager.getTorrent();
 
                  String  path_str = root_dir;
                  File simpleFile = null;
 
                  // for a simple torrent the target file can be changed
 
                  if ( tor.isSimpleTorrent()){
 
                    simpleFile = download_manager.getAbsoluteSaveLocation();
 
                  }else{
                    byte[][]path_comps = torrent_file.getPathComponents();
 
                    for (int j=0;j<path_comps.length;j++){
 
                      String comp;
                      try
View Full Code Here

    TOTorrentFile[] files = torrent.getFiles();

    for (int i = 0; i < files.length; i++) {

      TOTorrentFile file = files[i];

      byte[][] comps = file.getPathComponents();

      for (int j = 0; j < comps.length; j++) {
        candidateDecoders = localeUtil.getCandidateDecoders(comps[j]);
        if (candidateDecoders.size() < lMinCandidates) {
          lMinCandidates = candidateDecoders.size();
View Full Code Here

    synchronized( DiskManagerChannelImpl.class ){
     
      channel_id = channel_id_next++;
    }
       
    TOTorrentFile  tf = core_file.getTorrentFile();
   
    TOTorrent   torrent = tf.getTorrent();
   
    TOTorrentFile[]  tfs = torrent.getFiles();

    rtas  = new long[torrent.getNumberOfPieces()];
   
    core_download.addPeerListener( this );
     
    for (int i=0;i<core_file.getIndex();i++){
       
      file_offset_in_torrent += tfs[i].getLength();
    }
     
    piece_size  = tf.getTorrent().getPieceLength();
   
    core_file.addListener( this );
   
    reportCreated( this );
  }
View Full Code Here

                   
                    PeerManagerRegistration reg_data = PeerManager.getSingleton().manualMatchLink( address, link );
                   
                    if ( reg_data != null ){

                      TOTorrentFile  file = reg_data.getLink( link );
                     
                      if ( file != null ){
                       
                        StringBuffer  target_url = new StringBuffer( 512 );
                       
                        target_url.append( "/files/" );
                       
                        target_url.append( URLEncoder.encodenew String( file.getTorrent().getHash(), "ISO-8859-1" ), "ISO-8859-1" ));
                       
                        byte[][]  bits = file.getPathComponents();
                       
                        for (int i=0;i<bits.length;i++){
                         
                          target_url.append( "/" );
                         
View Full Code Here

           
            file_offset  = 0;
           
            for (int j=0;j<files.length;j++){
             
              TOTorrentFile  torrent_file = files[j].getTorrentFile();
             
              byte[][]  comps = torrent_file.getPathComponents();
             
              if ( comps.length == bits.size()){
               
                boolean  match = true;
               
                for (int k=0;k<comps.length;k++){
                                                 
                  if ( !Arrays.equals( comps[k], (byte[])bits.get(k))){
                   
                    match  = false;
                   
                    break;
                  }
                }
               
                if ( match ){
                 
                  target_file   = files[j];
                                 
                  break;
                }
              }
             
              file_offset += torrent_file.getLength();
            }
          }
        }else{
         
          line = line.toLowerCase( MessageText.LOCALE_ENGLISH );
View Full Code Here

     
      base_url += "/" + URLEncoder.encode( new String( to_torrent.getName(), "ISO-8859-1" ), "ISO-8859-1" ).replaceAll("\\+", "%20");
     
      for (int i=0;i<files.length;i++ ){
       
        TOTorrentFile  file = files[i];
       
        long length = file.getLength();
         
        String  file_url_str = base_url;
       
        byte[][] bits = file.getPathComponents();
       
        for (int j=0;j<bits.length;j++){
         
          file_url_str += "/" + URLEncoder.encode( new String( bits[j], "ISO-8859-1" ), "ISO-8859-1" ).replaceAll("\\+", "%20");
        }
View Full Code Here

     
      int  read_access     = 0;
      int write_access    = 0;
      int  write_access_lax  = 0;
     
      TOTorrentFile  my_torrent_file = owner.getTorrentFile();
     
      String  users = "";
       
      for (Iterator it=owners.iterator();it.hasNext();){
       
        Object[]  entry = (Object[])it.next();
         
        FMFileOwner  this_owner = (FMFileOwner)entry[0];
       
        if (((Boolean)entry[1]).booleanValue()){
                   
          write_access++;
         
          TOTorrentFile this_tf = this_owner.getTorrentFile();
         
          if ( my_torrent_file != null && this_tf != null && my_torrent_file.getLength() == this_tf.getLength()){
           
            write_access_lax++;
          }
         
          users += (users.length()==0?"":",") + this_owner.getName() + " [write]";
View Full Code Here

     
      long  file_offset_in_torrent = 0;
     
      for (int i=0;i<torrent.getFiles().length;i++){
       
        TOTorrentFile  f = torrent.getFiles()[i];
       
        if ( f == torrent_file ){
         
          break;
        }
       
        file_offset_in_torrent  += f.getLength();
      }
     
      int piece_offset  = piece_size - (int)( file_offset_in_torrent % piece_size );
     
      if ( piece_offset == piece_size ){
View Full Code Here

  }
 
  protected void
  setControlFile()
  {
    TOTorrentFile  tf = owner.getOwner().getTorrentFile();
   
    if ( tf == null ){

      controlFileName = null;
      control_dir = null;
    }
   
    TOTorrent  torrent = tf.getTorrent();
   
    TOTorrentFile[]  files = torrent.getFiles();
   
    int  file_index = -1;
   
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.torrent.TOTorrentFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.