Package org.gudy.azureus2.core3.internat

Examples of org.gudy.azureus2.core3.internat.LocaleUtilDecoder


            setState( FAULTY );

            return;
        }

        LocaleUtilDecoder   locale_decoder = null;

        try{
            locale_decoder = LocaleTorrentUtil.getTorrentEncoding( torrent );

        }catch( TOTorrentException e ){
View Full Code Here


        String torrent_save_file )
    {
        try{
            int res = 0;

            LocaleUtilDecoder locale_decoder = LocaleTorrentUtil.getTorrentEncoding( torrent );

            TOTorrentFile[] files = torrent.getFiles();

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

                byte[][]path_comps = files[i].getPathComponents();

                String  path_str = torrent_save_dir + File.separator + torrent_save_file + File.separator;

                for (int j=0;j<path_comps.length;j++){

                    String comp = locale_decoder.decodeString( path_comps[j] );

                    comp = FileUtil.convertOSSpecificChars( comp, j != path_comps.length-1 );

                    path_str += (j==0?"":File.separator) + comp;
                }
View Full Code Here

        String     torrent_save_file,
        boolean    force_no_recycle )

            throws TOTorrentException, UnsupportedEncodingException, LocaleUtilEncodingException
    {
        LocaleUtilDecoder locale_decoder = LocaleTorrentUtil.getTorrentEncoding( torrent );

        TOTorrentFile[] files = torrent.getFiles();

        String  root_path = torrent_save_dir + File.separator + torrent_save_file + File.separator;
       
        boolean delete_if_not_in_dir = COConfigurationManager.getBooleanParameter("File.delete.include_files_outside_save_dir");

        // delete all files, then empty directories

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

            byte[][]path_comps = files[i].getPathComponents();

            String  path_str    = root_path;

            for (int j=0;j<path_comps.length;j++){

                try{

                    String comp = locale_decoder.decodeString( path_comps[j] );

                    comp = FileUtil.convertOSSpecificChars( comp, j != path_comps.length-1 );

                    path_str += (j==0?"":File.separator) + comp;
View Full Code Here

      tempRootDir    += File.separator;
     
      final String root_dir = StringInterner.intern(tempRootDir) ;
 
      try{
          final LocaleUtilDecoder locale_decoder = LocaleTorrentUtil.getTorrentEncoding( torrent );
 
          TOTorrentFile[] torrent_files = torrent.getFiles();
 
          final FileSkeleton[]   res = new FileSkeleton[ torrent_files.length ];
         
      final String incomplete_suffix = download_manager.getDownloadState().getAttribute( DownloadManagerState.AT_INCOMP_FILE_SUFFIX );

          final DiskManagerFileInfoSet fileSetSkeleton = new DiskManagerFileInfoSet() {
 
        public DiskManagerFileInfo[] getFiles() {
          return res;
        }
 
        public int nbFiles() {
          return res.length;
        }
 
        public void setPriority(int[] toChange) {
          if(toChange.length != res.length)
            throw new IllegalArgumentException("array length mismatches the number of files");
         
          for(int i=0;i<res.length;i++)
            res[i].priority = toChange[i];
         
          DiskManagerImpl.storeFilePriorities( download_manager, res);
         
         
         
          for(int i=0;i<res.length;i++)
            if(toChange[i] > 0 )
              listener.filePriorityChanged(res[i]);
        }
 
        public void setSkipped(boolean[] toChange, boolean setSkipped) {
          if(toChange.length != res.length)
            throw new IllegalArgumentException("array length mismatches the number of files");
         
              if (!setSkipped ){
              String[] types = DiskManagerImpl.getStorageTypes(download_manager);

              boolean[]  toLinear   = new boolean[toChange.length];
              boolean[]  toReorder   = new boolean[toChange.length];
             
              int  num_linear   = 0;
              int num_reorder  = 0;
             
              for ( int i=0;i<toChange.length;i++){
               
                if ( toChange[i] ){
                 
                  int old_type = DiskManagerUtil.convertDMStorageTypeFromString( types[i] );
                 
                  if ( old_type == DiskManagerFileInfo.ST_COMPACT ){
                   
                    toLinear[i] = true;
                   
                    num_linear++;
                   
                  }else if ( old_type == DiskManagerFileInfo.ST_REORDER_COMPACT ){
                   
                    toReorder[i] = true;
                   
                    num_reorder++;
                  }
                } 
              }
             
              if ( num_linear > 0 ){
               
                if (!Arrays.equals(toLinear, setStorageTypes(toLinear, DiskManagerFileInfo.ST_LINEAR))){
                 
                  return;
                }
              }
           
              if ( num_reorder > 0 ){
               
                if (!Arrays.equals(toReorder, setStorageTypes(toReorder, DiskManagerFileInfo.ST_REORDER ))){
                 
                  return;
                }
              }
              }
             
          for(int i=0;i<res.length;i++)
            if(toChange[i])
              res[i].skipped = setSkipped;
         
          if(!setSkipped)
            doFileExistenceChecks(this, toChange, download_manager, true);
         
          DiskManagerImpl.storeFilePriorities( download_manager, res);
         
          for(int i=0;i<res.length;i++)
            if(toChange[i])
              listener.filePriorityChanged(res[i]);
        }
 
        public boolean[] setStorageTypes(boolean[] toChange, int newStorageType) {
          if(toChange.length != res.length)
            throw new IllegalArgumentException("array length mismatches the number of files");
         
          String[] types = DiskManagerImpl.getStorageTypes(download_manager);
          boolean[] modified = new boolean[res.length];
          boolean[] toSkip = new boolean[res.length];
          int toSkipCount = 0;
          DownloadManagerState dmState = download_manager.getDownloadState();
         
          try {
            dmState.suppressStateSave(true);
 
            for(int i=0;i<res.length;i++)
            {
              if(!toChange[i])
                continue;
 
 
              final int idx = i;
 
              int old_type = DiskManagerUtil.convertDMStorageTypeFromString( types[i] );
 
              //System.out.println(old_type + " <> " + newStroageType);
 
              if ( newStorageType == old_type )
              {
                modified[i] = true;
                continue;
              }
 
              try{
                File    target_file = res[i].getFile( true );
 
                // if the file doesn't exist then this is the start-of-day, most likely
                // being called from the torrent-opener, so we don't need to do any
                // file fiddling (in fact, if we do, we end up leaving zero length
                // files for dnd files which then force a recheck when the download
                // starts for the first time)
 
                if ( target_file.exists()){
 
                  CacheFile cache_file =
                    CacheFileManagerFactory.getSingleton().createFile(
                      new CacheFileOwner()
                      {
                        public String
                        getCacheFileOwnerName()
                        {
                          return( download_manager.getInternalName());
                        }
 
                        public TOTorrentFile
                        getCacheFileTorrentFile()
                        {
                          return( res[idx].getTorrentFile() );
                        }
 
                        public File
                        getCacheFileControlFileDir()
                        {
                          return( download_manager.getDownloadState().getStateFile( ));
                        }
                        public int
                        getCacheMode()
                        {
                          return( CacheFileOwner.CACHE_MODE_NORMAL );
                        }
                      },
                      target_file,
                      DiskManagerUtil.convertDMStorageTypeToCache( newStorageType ));
 
                  cache_file.close();
 
                  toSkip[i] = ( newStorageType == FileSkeleton.ST_COMPACT || newStorageType == FileSkeleton.ST_REORDER_COMPACT )&& !res[i].isSkipped();
                  if(toSkip[i])
                    toSkipCount++;
                }
 
 
                modified[i] = true;
 
              }catch( Throwable e ){
 
                Debug.printStackTrace(e);
 
                Logger.log(
                  new LogAlert(download_manager,
                    LogAlert.REPEATABLE,
                    LogAlert.AT_ERROR,
                    "Failed to change storage type for '" + res[i].getFile(true) +"': " + Debug.getNestedExceptionMessage(e)));
 
                // download's not running - tag for recheck
 
                RDResumeHandler.recheckFile( download_manager, res[i] );
 
              }
 
              types[i] = DiskManagerUtil.convertDMStorageTypeToString( newStorageType );
            }
           
            /*
             * set storage type and skipped before we do piece clearing and file
             * clearing checks as those checks work better when skipped/stype is set
             * properly
             */
            dmState.setListAttribute( DownloadManagerState.AT_FILE_STORE_TYPES, types);
            if(toSkipCount > 0)
              setSkipped(toSkip, true);
           
           
            for(int i=0;i<res.length;i++)
            {
              if(!toChange[i])
                continue;
             
              // download's not running, update resume data as necessary
 
              int cleared = RDResumeHandler.storageTypeChanged( download_manager, res[i] );
 
              // try and maintain reasonable figures for downloaded. Note that because
              // we don't screw with the first and last pieces of the file during
              // storage type changes we don't have the problem of dealing with
              // the last piece being smaller than torrent piece size
 
              if (cleared > 0)
              {
                res[i].downloaded = res[i].downloaded - cleared * res[i].getTorrentFile().getTorrent().getPieceLength();
                if (res[i].downloaded < 0) res[i].downloaded = 0;
              }
            }
 
            DiskManagerImpl.storeFileDownloaded( download_manager, res, true );
 
            doFileExistenceChecks(this, toChange, download_manager, newStorageType == FileSkeleton.ST_LINEAR || newStorageType == FileSkeleton.ST_REORDER );
 
          } finally {
            dmState.suppressStateSave(false);
            dmState.save();
          }
         
          return modified;
        }
          };
 
          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
                      {
                        comp = locale_decoder.decodeString( path_comps[j] );
                      } catch (UnsupportedEncodingException e)
                      {
                        Debug.printStackTrace(e);
                        comp = "undecodableFileName"+file_index;
                      }
View Full Code Here

           throw( new NoStackException( "Download identity changed - please remove and re-add the download" ));
         }
        
         read_torrent_state  = null// no longer needed if we saved it
 
         LocaleUtilDecoder  locale_decoder = LocaleTorrentUtil.getTorrentEncoding( torrent );
            
           // if its a simple torrent and an explicit save file wasn't supplied, use
           // the torrent name itself

         display_name = FileUtil.convertOSSpecificChars(TorrentUtils.getLocalisedName(torrent),false);
        
         internal_name = ByteFormatter.nicePrint(torrent.getHash(),true);
 
           // now we know if its a simple torrent or not we can make some choices about
           // the save dir and file. On initial entry the save_dir will have the user-selected
           // save location and the save_file will be null
        
         File  save_dir_file  = new File( torrent_save_dir );
        
         // System.out.println( "before: " + torrent_save_dir + "/" + torrent_save_file );
        
           // if save file is non-null then things have already been sorted out
        
         if ( torrent_save_file == null ){
               
             // make sure we're working off a canonical save dir if possible
          
           try{
             if ( save_dir_file.exists()){
              
               save_dir_file = save_dir_file.getCanonicalFile();
             }
           }catch( Throwable e ){
              
             Debug.printStackTrace(e);
           }
   
           if ( torrent.isSimpleTorrent()){
            
               // if target save location is a directory then we use that as the save
               // dir and use the torrent display name as the target. Otherwise we
               // use the file name
            
             if ( save_dir_file.exists()){
              
               if ( save_dir_file.isDirectory()){
                
                 torrent_save_file  = display_name;
                
               }else{
                
                 torrent_save_dir  = save_dir_file.getParent().toString();
                
                 torrent_save_file  = save_dir_file.getName();
               }
             }else{
              
                 // doesn't exist, assume it refers directly to the file
              
               if ( save_dir_file.getParent() == null ){
                
                 throw( new NoStackException( "Data location '" + torrent_save_dir + "' is invalid" ));
 
               }
              
               torrent_save_dir  = save_dir_file.getParent().toString();
              
               torrent_save_file  = save_dir_file.getName();      
             }
            
           }else{
          
               // torrent is a folder. It is possible that the natural location
               // for the folder is X/Y and that in fact 'Y' already exists and
               // has been selected. If ths is the case the select X as the dir and Y
               // as the file name
            
             if ( save_dir_file.exists()){
              
               if ( !save_dir_file.isDirectory()){
                
                 throw( new NoStackException( "'" + torrent_save_dir + "' is not a directory" ));
               }
              
               if ( save_dir_file.getName().equals( display_name )){
                 torrent_save_dir  = save_dir_file.getParent().toString();
               }
             }
            
             torrent_save_file  = display_name;   
           }
         }
 
         torrent_save_location = new File( torrent_save_dir, torrent_save_file );
        
           // final validity test must be based of potentially linked target location as file
           // may have been re-targetted
 
         File  linked_target = getSaveLocation();
        
         if ( !linked_target.exists()){
          
             // if this isn't a new torrent then we treat the absence of the enclosing folder
             // as a fatal error. This is in particular to solve a problem with the use of
             // externally mounted torrent data on OSX, whereby a re-start with the drive unmounted
             // results in the creation of a local diretory in /Volumes that subsequently stuffs
             // up recovery when the volume is mounted
          
             // changed this to only report the error on non-windows platforms
          
           if ( !(new_torrent || Constants.isWindows )){
            
              // another exception here - if the torrent has never been started then we can
              // fairly safely continue as its in a stopped state
           
            if ( has_ever_been_started ){
            
              throw (new NoStackException(
                  MessageText.getString("DownloadManager.error.datamissing")
                      + " " + Debug.secretFileName(linked_target.toString())));
            }
           }
         } 
        
           // if this is a newly introduced torrent trash the tracker cache. We do this to
           // prevent, say, someone publishing a torrent with a load of invalid cache entries
           // in it and a bad tracker URL. This could be used as a DOS attack
 
         if ( new_torrent ){
          
          download_manager_state.setLongParameter( DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME, SystemTime.getCurrentTime());
          
             // propagate initial properties from torrent to download
          
          boolean  low_noise = TorrentUtils.getFlag( torrent, TorrentUtils.TORRENT_FLAG_LOW_NOISE );
         
          if ( low_noise ){
           
            download_manager_state.setFlag( DownloadManagerState.FLAG_LOW_NOISE, true );
          }
             
          Map peer_cache = TorrentUtils.getPeerCache( torrent );
         
          if ( peer_cache != null ){
           
            try{
              download_manager_state.setTrackerResponseCache( peer_cache );
             
            }catch( Throwable e ){
           
              Debug.out( e );
             
              download_manager_state.setTrackerResponseCache( new HashMap());
            }
          }else{
         
            download_manager_state.setTrackerResponseCache( new HashMap());
          }
          
             // also remove resume data incase someone's published a torrent with resume
             // data in it
          
           if ( for_seeding ){
            
             DiskManagerFactory.setTorrentResumeDataNearlyComplete(download_manager_state);
            
             // Prevent download being considered for on-completion moving - it's considered complete anyway.
             download_manager_state.setFlag(DownloadManagerState.FLAG_MOVE_ON_COMPLETION_DONE, true);
 
           }else{
            
             download_manager_state.clearResumeData();
           }
         }else{
          
           long  add_time = download_manager_state.getLongParameter( DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME );

           if ( add_time == 0 ){

             // grab an initial value from torrent file - migration only

             try{
               add_time = new File( torrentFileName ).lastModified();

             }catch( Throwable e ){
             }

             if ( add_time == 0 ){

               add_time = SystemTime.getCurrentTime();
             }

             download_manager_state.setLongParameter( DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME, add_time );
           }
         }
        
            
         //trackerUrl = torrent.getAnnounceURL().toString();
          
        torrent_comment = StringInterner.intern(locale_decoder.decodeString(torrent.getComment()));
          
        if ( torrent_comment == null ){
         
           torrent_comment  = "";
        }
       
        torrent_created_by = locale_decoder.decodeString(torrent.getCreatedBy());
          
        if ( torrent_created_by == null ){
         
          torrent_created_by  = "";
        }
View Full Code Here

    try{
      TOTorrent  torrent = lws.getTOTorrent( false );
     
      internal_name = ByteFormatter.nicePrint(torrent.getHash(),true);
     
      LocaleUtilDecoder  locale_decoder = LocaleTorrentUtil.getTorrentEncoding( torrent );
     
      piece_mapper = DMPieceMapperFactory.create( torrent );
     
      piece_mapper.construct( locale_decoder, save_file.getName());
     
View Full Code Here

 
        crypto_available  = true;
       
      }catch( Throwable e ){
       
        Logger.log(new LogAlert(LogAlert.UNREPEATABLE,
            "Unable to initialise cryptographic framework for magnet-based "
                + "torrent downloads, please re-install Java", e));
      }
    }
   
View Full Code Here

          try{
            SESecurityManager.createSelfSignedCertificate( alias, dn, strength );
           
            close(true );
           
            Logger.log(new LogAlert(LogAlert.UNREPEATABLE,
                LogAlert.AT_INFORMATION, MessageText
                    .getString("security.certcreate.createok")
                    + "\n" + alias + ":" + strength + "\n"
                    + dn + "\n" + SystemTime.getCurrentTime()));
           
          }catch( Throwable f ){
           
            Logger.log(new LogAlert(LogAlert.UNREPEATABLE, MessageText
                .getString("security.certcreate.createfail")
                + "\n" + SystemTime.getCurrentTime(), f));
          }
        }
      });
View Full Code Here

      try{
        ((ShareResource)shares[i]).delete();
       
      }catch( Throwable e ){
       
        Logger.log(new LogAlert(shares[i], false,
            "{globalmanager.download.remove.veto}", e));
      }
    }
  }
View Full Code Here

 
  protected void requestRecheck()
  {
    if (Logger.isEnabled()){
      Logger.log(new LogEvent(LOGID, "UpdateMonitor: recheck requested" ));
    }
   
    performCheck( false, true, true, null );
  }
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.internat.LocaleUtilDecoder

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.