FileDocCategorySizeDatePackage
SWTVersionGetter.javaAPI DocAzureus 3.0.3.45452Mon Jul 16 20:53:12 BST 2007org.gudy.azureus2.ui.swt.updater2

SWTVersionGetter

public class SWTVersionGetter extends Object
author
Olivier Chalouhi

Fields Summary
private static final LogIDs
LOGID
private String
platform
private int
currentVersion
private int
latestVersion
private org.gudy.azureus2.plugins.update.UpdateChecker
checker
private String[]
mirrors
private String
infoURL
Constructors Summary
public SWTVersionGetter(org.gudy.azureus2.plugins.update.UpdateChecker _checker)

  
   
  
  			  
  
    this.platform 		= SWT.getPlatform();
    this.currentVersion = SWT.getVersion();
    

    /**
     * Hack to make users re-download swt package which is hacked to include
     * our osx platform jnilib. 
     */
    if (currentVersion == 3232 && Constants.isOSX) {
			PlatformManager p_man = PlatformManagerFactory.getPlatformManager();
			if (p_man != null
					&& !p_man.hasCapability(PlatformManagerCapabilities.GetVersion)) {
				currentVersion = 3231;
			}
		}
    
    /* hack no longer needed as most (all?) CVS users will have rolled back by now and
     * we're shipping with 3.1.1
     
    if ( currentVersion == 3206 ){
    	
    		// problem here with 3.2M2 that we rolled out to CVS users - it doesn't work
    		// on windows 98 (hangs the app). We therefore decided to fall back to 3.1.1
    		// which does work. However, to rollback the CVS users we need to make it appear
    		// that 3206 is < 3.1.1. We do this by hacking the version here
    	
    	System.out.println( "Rolling back SWT version 3.2M2 to 3.1.1" );
    	
    	currentVersion = 3138;	// 3.1.1 is 3139
    }
    */
    
    this.latestVersion = 0;
    checker	= _checker;
  
Methods Summary
private voiddownloadLatestVersion()

  	if (Logger.isEnabled())
			Logger.log(new LogEvent(LOGID, "Requesting latest SWT version "
					+ "and url from version check client."));
    
    Map reply = VersionCheckClient.getSingleton().getVersionCheckInfo(VersionCheckClient.REASON_CHECK_SWT);
    
    String msg = "SWT version check received:";
    
    byte[] version_bytes = (byte[])reply.get( "swt_version" );
    if( version_bytes != null ) {
      latestVersion = Integer.parseInt( new String( version_bytes ) );
      msg += " version=" + latestVersion;
    }
    
    byte[] url_bytes = (byte[])reply.get( "swt_url" );
    if( url_bytes != null ) {
      mirrors = new String[] { new String( url_bytes ) };
      msg += " url=" + mirrors[0];
    }
    
    byte[] info_bytes = (byte[])reply.get( "swt_info_url" );
    
    if ( info_bytes != null ){
    	
    	byte[] sig = (byte[])reply.get( "swt_info_sig" );

		if ( sig == null ){
			
			Logger.log( new LogEvent( LogIDs.LOGGER, "swt info signature check failed - missing signature" ));

		}else{
			
		  	try{
	    		infoURL = new String( info_bytes );
	    		
	    		try{
					AEVerifier.verifyData( infoURL, sig );
					
				}catch( Throwable e ){

					Logger.log( new LogEvent( LogIDs.LOGGER, "swt info signature check failed", e  ));
					
					infoURL = null;
				}
	    	}catch ( Exception e ){
	    		
	    		Logger.log(new LogEvent(LOGID, "swt info_url", e));
	    	}
		}
    }

    if (Logger.isEnabled())
			Logger.log(new LogEvent(LOGID, msg));
  
public intgetCurrentVersion()

	    return currentVersion;
  
public java.lang.StringgetInfoURL()

		return infoURL;
	
public intgetLatestVersion()

return
Returns the latestVersion.

    return latestVersion;
  
public java.lang.String[]getMirrors()

return
Returns the mirrors.

    return mirrors;
  
public java.lang.StringgetPlatform()

return
Returns the platform.

    return platform;
  
public booleanneedsUpdate()

    try {
      downloadLatestVersion();

      String msg = "SWT: current version = " + currentVersion + ", latest version = " + latestVersion;
      
      checker.reportProgress( msg );
      
      if (Logger.isEnabled())
				Logger.log(new LogEvent(LOGID, msg));
      
      return latestVersion > currentVersion;
    } catch(Exception e) {
      e.printStackTrace();
      return false;
    }