coreupdatechecker.java
来自「Azureus is a powerful, full-featured, cr」· Java 代码 · 共 767 行 · 第 1/2 页
JAVA
767 行
String java_version = System.getProperty("java.version");
if ( java_version == null ){ java_version = "unknown"; }
message.put( "java", java_version );
String java_vendor = System.getProperty( "java.vm.vendor" );
if ( java_vendor == null ){ java_vendor = "unknown"; }
message.put( "javavendor", java_vendor );
long max_mem = Runtime.getRuntime().maxMemory()/(1024*1024);
message.put( "javamx", new Long( max_mem ) );
//installed plugin IDs
PluginInterface[] plugins = plugin_interface.getPluginManager().getPluginInterfaces();
List pids = new ArrayList();
for (int i=0;i<plugins.length;i++){
String pid = plugins[i].getPluginID();
// filter out built-in and core ones
if ( !pid.startsWith( "<" ) &&
!pid.startsWith( "azupdater" ) &&
!pid.startsWith( "azplatform" ) &&
!pids.contains( pid )){
pids.add( pid );
}
}
message.put( "plugins", pids );
}
return message;
}
/**
* Log and display a user message if contained within reply.
* @param reply from server
*/
private void displayUserMessage( Map reply ) {
// pick up any user message in the reply
try{
byte[] message = (byte[])reply.get( "message" );
if ( message != null ){
String s_message = new String(message);
String last = COConfigurationManager.getStringParameter( "CoreUpdateChecker.lastmessage", "" );
if ( !s_message.equals( last )){
int alert_type = LGLogger.AT_WARNING;
String alert_text = s_message;
if ( alert_text.startsWith("i:" )){
alert_type = LGLogger.AT_COMMENT;
alert_text = alert_text.substring(2);
}
LGLogger.logUnrepeatableAlert( alert_type, alert_text );
COConfigurationManager.setParameter( "CoreUpdateChecker.lastmessage", s_message );
COConfigurationManager.save();
}
}
}catch( Throwable e ){
Debug.printStackTrace( e );
}
}
/*
protected Map
doHTTPVersionDownload()
throws Exception
{
URL url = getVersionURL();
ResourceDownloader rd = rdf.create( url );
rd = rdf.getRetryDownloader( rd, RD_GET_DETAILS_RETRIES );
if ( rd_logger != null ){
rd.addListener( rd_logger );
}
BufferedInputStream data = new BufferedInputStream(rd.download());
Map decoded = BDecoder.decode(data);
data.close();
displayUserMessage( decoded );
return( decoded );
}
protected URL
getVersionURL()
throws MalformedURLException, UnsupportedEncodingException
{
String url_str = Constants.AELITIS_WEB_SITE + "version.php";
String id = COConfigurationManager.getStringParameter("ID",null);
if ( id != null && COConfigurationManager.getBooleanParameter("Send Version Info")){
String java_version = System.getProperty("java.version");
if ( java_version == null ){
java_version = "unknown";
}
String java_vendor = System.getProperty( "java.vm.vendor" );
if ( java_vendor == null ){
java_vendor = "unknown";
}
long max_mem = Runtime.getRuntime().maxMemory()/(1024*1024);
PluginInterface[] plugins = plugin_interface.getPluginManager().getPluginInterfaces();
List pids = new ArrayList();
for (int i=0;i<plugins.length;i++){
String pid = plugins[i].getPluginID();
// filter out built-in and core ones
if ( !pid.startsWith( "<" ) &&
!pid.startsWith( "azupdater" ) &&
!pid.startsWith( "azplatform" ) &&
!pids.contains( pid )){
pids.add( pid );
}
}
String plugins_str = "";
for (int i=0;i<pids.size();i++){
String pid = (String)pids.get(i);
plugins_str += ( plugins_str.length()==0?"":";")+pid ;
}
url_str += "?id=" + id +
"&version=" + Constants.AZUREUS_VERSION +
"&os=" + URLEncoder.encode( Constants.OSName, Constants.BYTE_ENCODING).replaceAll("\\+", "%20") +
"&java=" + URLEncoder.encode( java_version, Constants.BYTE_ENCODING).replaceAll("\\+", "%20") +
"&javavendor=" + URLEncoder.encode( java_vendor, Constants.BYTE_ENCODING).replaceAll("\\+", "%20") +
"&javamx=" + max_mem +
"&plugins=" + URLEncoder.encode( plugins_str, Constants.BYTE_ENCODING).replaceAll("\\+", "%20");
}
return( new URL( url_str ));
}
*/
protected ResourceDownloader[]
getPrimaryDownloaders(
String latest_file_name )
{
log.log( "Downloading primary mirrors" );
List res = new ArrayList();
try{
if ( latest_file_name == null ){
// very old method, non-mirror based
res.add( new URL( Constants.SF_WEB_SITE + "Azureus2.jar" ));
}else{
URL mirrors_url = new URL("http://prdownloads.sourceforge.net/azureus/" + latest_file_name + "?download");
ResourceDownloader rd = rdf.create( mirrors_url );
rd = rdf.getRetryDownloader( rd, RD_GET_MIRRORS_RETRIES );
rd.addListener( rd_logger );
String page = HTMLPageFactory.loadPage( rd.download()).getContent();
String pattern = "/azureus/" + latest_file_name + "?use_mirror=";
int position = page.indexOf(pattern);
while ( position > 0 ){
int end = page.indexOf(">", position);
if (end < 0) {
position = -1;
}else{
String mirror = page.substring(position, end);
try{
res.add( new URL( "http://prdownloads.sourceforge.net" + mirror ));
}catch( Throwable e ){
log.log( "Invalid URL read:" + mirror, e );
}
position = page.indexOf(pattern, position + 1);
}
}
}
}catch( Throwable e ){
log.log( "Failed to read primary mirror list", e );
}
ResourceDownloader[] dls = new ResourceDownloader[res.size()];
for (int i=0;i<res.size();i++){
URL url =(URL)res.get(i);
log.log( " Primary mirror:" +url.toString());
ResourceDownloader dl = rdf.create( url );
dl = rdf.getMetaRefreshDownloader( dl );
// add in a layer to do torrent based downloads if url ends with .torrent
dl = rdf.getSuffixBasedDownloader( dl );
dls[i] = dl;
}
return( dls );
}
protected ResourceDownloader[]
getBackupDownloaders(
String latest_file_name )
{
List res = new ArrayList();
try{
if ( latest_file_name != null ){
log.log( "Downloading backup mirrors" );
URL mirrors_url = new URL("http://azureus.sourceforge.net/mirrors.php");
ResourceDownloader rd = rdf.create( mirrors_url );
rd = rdf.getRetryDownloader( rd, RD_GET_MIRRORS_RETRIES );
rd.addListener( rd_logger );
BufferedInputStream data = new BufferedInputStream(rd.download());
Map decoded = BDecoder.decode(data);
data.close();
List mirrors = (List)decoded.get("mirrors");
for (int i=0;i<mirrors.size();i++){
String mirror = new String( (byte[])mirrors.get(i));
try{
res.add( new URL( mirror + latest_file_name ));
}catch(Throwable e){
log.log( "Invalid URL read:" + mirror, e );
}
}
}
}catch( Throwable e ){
log.log( "Failed to read backup mirror list", e );
}
ResourceDownloader[] dls = new ResourceDownloader[res.size()];
for (int i=0;i<res.size();i++){
URL url =(URL)res.get(i);
log.log( " Primary mirror:" +url.toString());
ResourceDownloader dl = rdf.create( url );
// add in .torrent decoder if appropriate
dl = rdf.getSuffixBasedDownloader( dl );
dls[i] = dl;
}
return( dls );
}
protected ResourceDownloader[]
getTestMirrors()
{
try{
ResourceDownloader[] dls = new ResourceDownloader[1];
ResourceDownloader rd = rdf.create( new URL("http://66.90.75.92/suprnova//torrents/1822/DivX511-exe.torrent" ));
rd = rdf.getSuffixBasedDownloader( rd );
dls[0] = rd;
return( dls );
}catch( Throwable e ){
Debug.printStackTrace( e );
return( new ResourceDownloader[0]);
}
}
protected void
installUpdate(
UpdateChecker checker,
ResourceDownloader rd,
String version,
InputStream data )
{
try{
String temp_jar_name = "Azureus2_" + version + ".jar";
String target_jar_name = "Azureus2.jar";
UpdateInstaller installer = checker.createInstaller();
installer.addResource( temp_jar_name, data );
if ( Constants.isOSX ){
installer.addMoveAction(
temp_jar_name,
installer.getInstallDir() + "/Azureus.app/Contents/Resources/Java/" + target_jar_name );
}else{
installer.addMoveAction(
temp_jar_name,
installer.getInstallDir() + File.separator + target_jar_name );
}
}catch( Throwable e ){
rd.reportActivity("Update install failed:" + e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?