📄 coreupdatechecker.java
字号:
/*
* Created on 20-May-2004
* Created by Paul Gardner
* Copyright (C) 2004, 2005, 2006 Aelitis, All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* AELITIS, SAS au capital de 46,603.30 euros
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
*
*/
package org.gudy.azureus2.update;
/**
* @author parg
*
*/
import java.util.*;
import java.net.*;
import java.io.*;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.logging.Logger;
import org.gudy.azureus2.core3.config.*;
import org.gudy.azureus2.core3.html.*;
import org.gudy.azureus2.plugins.*;
import org.gudy.azureus2.plugins.logging.*;
import org.gudy.azureus2.plugins.update.*;
import org.gudy.azureus2.plugins.utils.resourcedownloader.*;
import com.aelitis.azureus.core.versioncheck.*;
public class
CoreUpdateChecker
implements Plugin, UpdatableComponent
{
public static final String LATEST_VERSION_PROPERTY = "latest_version";
public static final String MESSAGE_PROPERTY = "message";
public static final int RD_GET_DETAILS_RETRIES = 3;
public static final int RD_GET_MIRRORS_RETRIES = 3;
public static final int RD_SIZE_RETRIES = 3;
public static final int RD_SIZE_TIMEOUT = 10000;
protected static CoreUpdateChecker singleton;
protected PluginInterface plugin_interface;
protected ResourceDownloaderFactory rdf;
protected LoggerChannel log;
protected ResourceDownloaderListener rd_logger;
protected boolean first_check = true;
public static void
doUsageStats()
{
singleton.doUsageStatsSupport();
}
public
CoreUpdateChecker()
{
singleton = this;
}
protected void
doUsageStatsSupport()
{
try{
Map decoded = VersionCheckClient.getSingleton().getVersionCheckInfo(
first_check?VersionCheckClient.REASON_UPDATE_CHECK_START:VersionCheckClient.REASON_UPDATE_CHECK_PERIODIC);
displayUserMessage( decoded );
}finally{
first_check = false;
}
}
public void
initialize(
PluginInterface _plugin_interface )
{
plugin_interface = _plugin_interface;
plugin_interface.getPluginProperties().setProperty( "plugin.name", "Core Updater" );
log = plugin_interface.getLogger().getChannel("CoreUpdater");
rd_logger =
new ResourceDownloaderAdapter()
{
public void
reportActivity(
ResourceDownloader downloader,
String activity )
{
log.log( activity );
}
};
Properties props = plugin_interface.getPluginProperties();
props.setProperty( "plugin.version", plugin_interface.getAzureusVersion());
rdf = plugin_interface.getUtilities().getResourceDownloaderFactory();
plugin_interface.getUpdateManager().registerUpdatableComponent( this, true );
}
public String
getName()
{
return( "Azureus Core" );
}
public int
getMaximumCheckTime()
{
return( ( RD_SIZE_RETRIES * RD_SIZE_TIMEOUT )/1000);
}
public void
checkForUpdate(
final UpdateChecker checker )
{
try{
String current_version = plugin_interface.getAzureusVersion();
log.log( "Update check starts: current = " + current_version );
Map decoded = VersionCheckClient.getSingleton().getVersionCheckInfo(
first_check?VersionCheckClient.REASON_UPDATE_CHECK_START:VersionCheckClient.REASON_UPDATE_CHECK_PERIODIC);
displayUserMessage( decoded );
String latest_version;
String latest_file_name;
byte[] b_version = (byte[])decoded.get("version");
if ( b_version != null ){
latest_version = new String( b_version );
plugin_interface.getPluginProperties().setProperty( LATEST_VERSION_PROPERTY, latest_version );
}else{
throw( new Exception( "No version found in reply" ));
}
byte[] b_filename = (byte[]) decoded.get("filename");
if ( b_filename != null ){
latest_file_name = new String( b_filename );
}else{
throw( new Exception( "No update file details in reply" ));
}
//latest_version = "3.0.0.3";
//latest_file_name = "http://torrents.aelitis.com:88/torrents/Azureus2.5.0.0.jar.torrent";
//latest_file_name = "Azureus2.5.0.0.jar.torrent";
String msg = "Core: latest_version = '" + latest_version + "', file = '" + latest_file_name + "'";
URL full_download_url;
// since 2501 we support a full download URL, falling back to SF mirrors if this
// fails.
if ( latest_file_name.startsWith( "http" )){
try{
full_download_url = new URL( latest_file_name );
}catch( Throwable e ){
full_download_url = null;
log.log( e );
}
int pos = latest_file_name.lastIndexOf( '/' );
latest_file_name = latest_file_name.substring( pos+1 );
}else{
full_download_url = null;
}
checker.reportProgress( msg );
log.log( msg );
if ( !shouldUpdate( current_version, latest_version )){
return;
}
final String f_latest_version = latest_version;
final String f_latest_file_name = latest_file_name;
ResourceDownloader top_downloader;
if ( full_download_url == null ){
ResourceDownloader[] primary_mirrors;
primary_mirrors = getPrimaryDownloaders( latest_file_name );
// the download hierarchy is primary mirrors first (randomised alternate)
// then backup mirrors (randomised alternate)
// we don't want to load the backup mirrors until the primary mirrors fail
ResourceDownloader random_primary_mirrors = rdf.getRandomDownloader( primary_mirrors );
ResourceDownloader backup_downloader =
rdf.create(
new ResourceDownloaderDelayedFactory()
{
public ResourceDownloader
create()
{
ResourceDownloader[] backup_mirrors = getBackupDownloaders( f_latest_file_name );
return( rdf.getRandomDownloader( backup_mirrors ));
}
});
top_downloader =
rdf.getAlternateDownloader(
new ResourceDownloader[]
{
random_primary_mirrors,
backup_downloader,
});
}else{
ResourceDownloader full_rd = rdf.create( full_download_url );
full_rd = rdf.getSuffixBasedDownloader( full_rd );
ResourceDownloader primary_downloader =
rdf.create(
new ResourceDownloaderDelayedFactory()
{
public ResourceDownloader
create()
{
ResourceDownloader[] primary_mirrors = getPrimaryDownloaders( f_latest_file_name );
return( rdf.getRandomDownloader( primary_mirrors ));
}
});
ResourceDownloader backup_downloader =
rdf.create(
new ResourceDownloaderDelayedFactory()
{
public ResourceDownloader
create()
{
ResourceDownloader[] backup_mirrors = getBackupDownloaders( f_latest_file_name );
return( rdf.getRandomDownloader( backup_mirrors ));
}
});
top_downloader =
rdf.getAlternateDownloader(
new ResourceDownloader[]
{
full_rd,
primary_downloader,
backup_downloader,
});
}
top_downloader.addListener( rd_logger );
// get size so it is cached
top_downloader.getSize();
byte[] info_b = (byte[])decoded.get( "info" );
String info = null;
if ( info_b != null ){
try{
info = new String( info_b );
}catch( Throwable e ){
Debug.printStackTrace( e );
}
}
String[] desc;
if ( info == null ){
desc = new String[]{"Core Azureus Version" };
}else{
desc = new String[]{"Core Azureus Version", info };
}
final Update update =
checker.addUpdate(
"Core Azureus Version",
desc,
latest_version,
top_downloader,
Update.RESTART_REQUIRED_YES );
top_downloader.addListener(
new ResourceDownloaderAdapter()
{
public boolean
completed(
final ResourceDownloader downloader,
InputStream data )
{
installUpdate( checker, update, downloader, f_latest_version, data );
return( true );
}
});
}catch( Throwable e ){
log.log( e );
Debug.printStackTrace( e );
checker.failed();
}finally{
checker.completed();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -