2
* Created on 20-May-2004
3
* Created by Paul Gardner
4
* Copyright (C) 2004, 2005, 2006 Aelitis, All Rights Reserved.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
* AELITIS, SAS au capital de 46,603.30 euros
19
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
23
package org.gudy.azureus2.update;
34
import org.gudy.azureus2.core3.util.*;
35
import org.gudy.azureus2.core3.logging.*;
36
import org.gudy.azureus2.core3.logging.Logger;
37
import org.gudy.azureus2.core3.config.*;
38
import org.gudy.azureus2.core3.html.*;
40
import org.gudy.azureus2.plugins.*;
41
import org.gudy.azureus2.plugins.logging.*;
42
import org.gudy.azureus2.plugins.update.*;
43
import org.gudy.azureus2.plugins.utils.resourcedownloader.*;
45
import com.aelitis.azureus.core.versioncheck.*;
50
implements Plugin, UpdatableComponent
52
public static final String LATEST_VERSION_PROPERTY = "latest_version";
53
public static final String MESSAGE_PROPERTY = "message";
55
public static final int RD_GET_DETAILS_RETRIES = 3;
56
public static final int RD_GET_MIRRORS_RETRIES = 3;
58
public static final int RD_SIZE_RETRIES = 3;
59
public static final int RD_SIZE_TIMEOUT = 10000;
61
protected static CoreUpdateChecker singleton;
63
protected PluginInterface plugin_interface;
64
protected ResourceDownloaderFactory rdf;
65
protected LoggerChannel log;
66
protected ResourceDownloaderListener rd_logger;
68
protected boolean first_check = true;
73
singleton.doUsageStatsSupport();
86
Map decoded = VersionCheckClient.getSingleton().getVersionCheckInfo(
87
first_check?VersionCheckClient.REASON_UPDATE_CHECK_START:VersionCheckClient.REASON_UPDATE_CHECK_PERIODIC);
89
displayUserMessage( decoded );
100
PluginInterface _plugin_interface )
102
plugin_interface = _plugin_interface;
104
plugin_interface.getPluginProperties().setProperty( "plugin.name", "Core Updater" );
106
log = plugin_interface.getLogger().getChannel("CoreUpdater");
109
new ResourceDownloaderAdapter()
113
ResourceDownloader downloader,
120
Properties props = plugin_interface.getPluginProperties();
122
props.setProperty( "plugin.version", plugin_interface.getAzureusVersion());
124
rdf = plugin_interface.getUtilities().getResourceDownloaderFactory();
126
plugin_interface.getUpdateManager().registerUpdatableComponent( this, true );
132
return( "Azureus Core" );
136
getMaximumCheckTime()
138
return( ( RD_SIZE_RETRIES * RD_SIZE_TIMEOUT )/1000);
143
final UpdateChecker checker )
146
String current_version = plugin_interface.getAzureusVersion();
148
log.log( "Update check starts: current = " + current_version );
150
Map decoded = VersionCheckClient.getSingleton().getVersionCheckInfo(
151
first_check?VersionCheckClient.REASON_UPDATE_CHECK_START:VersionCheckClient.REASON_UPDATE_CHECK_PERIODIC);
154
displayUserMessage( decoded );
156
String latest_version;
157
String latest_file_name;
159
byte[] b_version = (byte[])decoded.get("version");
161
if ( b_version != null ){
163
latest_version = new String( b_version );
165
plugin_interface.getPluginProperties().setProperty( LATEST_VERSION_PROPERTY, latest_version );
169
throw( new Exception( "No version found in reply" ));
172
byte[] b_filename = (byte[]) decoded.get("filename");
174
if ( b_filename != null ){
176
latest_file_name = new String( b_filename );
180
throw( new Exception( "No update file details in reply" ));
183
//latest_version = "3.0.0.3";
184
//latest_file_name = "http://torrents.aelitis.com:88/torrents/Azureus2.5.0.0.jar.torrent";
185
//latest_file_name = "Azureus2.5.0.0.jar.torrent";
187
String msg = "Core: latest_version = '" + latest_version + "', file = '" + latest_file_name + "'";
189
URL full_download_url;
191
// since 2501 we support a full download URL, falling back to SF mirrors if this
194
if ( latest_file_name.startsWith( "http" )){
197
full_download_url = new URL( latest_file_name );
199
}catch( Throwable e ){
201
full_download_url = null;
206
int pos = latest_file_name.lastIndexOf( '/' );
208
latest_file_name = latest_file_name.substring( pos+1 );
212
full_download_url = null;
215
checker.reportProgress( msg );
219
if ( !shouldUpdate( current_version, latest_version )){
224
final String f_latest_version = latest_version;
225
final String f_latest_file_name = latest_file_name;
227
ResourceDownloader top_downloader;
229
if ( full_download_url == null ){
231
ResourceDownloader[] primary_mirrors;
233
primary_mirrors = getPrimaryDownloaders( latest_file_name );
235
// the download hierarchy is primary mirrors first (randomised alternate)
236
// then backup mirrors (randomised alternate)
238
// we don't want to load the backup mirrors until the primary mirrors fail
240
ResourceDownloader random_primary_mirrors = rdf.getRandomDownloader( primary_mirrors );
242
ResourceDownloader backup_downloader =
244
new ResourceDownloaderDelayedFactory()
246
public ResourceDownloader
249
ResourceDownloader[] backup_mirrors = getBackupDownloaders( f_latest_file_name );
251
return( rdf.getRandomDownloader( backup_mirrors ));
256
rdf.getAlternateDownloader(
257
new ResourceDownloader[]
259
random_primary_mirrors,
265
ResourceDownloader full_rd = rdf.create( full_download_url );
267
full_rd = rdf.getSuffixBasedDownloader( full_rd );
269
ResourceDownloader primary_downloader =
271
new ResourceDownloaderDelayedFactory()
273
public ResourceDownloader
276
ResourceDownloader[] primary_mirrors = getPrimaryDownloaders( f_latest_file_name );
278
return( rdf.getRandomDownloader( primary_mirrors ));
282
ResourceDownloader backup_downloader =
284
new ResourceDownloaderDelayedFactory()
286
public ResourceDownloader
289
ResourceDownloader[] backup_mirrors = getBackupDownloaders( f_latest_file_name );
291
return( rdf.getRandomDownloader( backup_mirrors ));
297
rdf.getAlternateDownloader(
298
new ResourceDownloader[]
306
top_downloader.addListener( rd_logger );
308
// get size so it is cached
310
top_downloader.getSize();
313
byte[] info_b = (byte[])decoded.get( "info" );
317
if ( info_b != null ){
320
info = new String( info_b );
322
}catch( Throwable e ){
324
Debug.printStackTrace( e );
332
desc = new String[]{"Core Azureus Version" };
336
desc = new String[]{"Core Azureus Version", info };
339
final Update update =
341
"Core Azureus Version",
345
Update.RESTART_REQUIRED_YES );
347
top_downloader.addListener(
348
new ResourceDownloaderAdapter()
352
final ResourceDownloader downloader,
355
installUpdate( checker, update, downloader, f_latest_version, data );
360
}catch( Throwable e ){
364
Debug.printStackTrace( e );
380
* Log and display a user message if contained within reply.
381
* @param reply from server
383
private void displayUserMessage( Map reply ) {
384
// pick up any user message in the reply
387
byte[] message = (byte[])reply.get( "message" );
389
if ( message != null && message.length > 0 ){
391
String s_message = new String(message);
393
String last = COConfigurationManager.getStringParameter( "CoreUpdateChecker.lastmessage", "" );
395
if ( !s_message.equals( last )){
397
byte[] signature = (byte[])reply.get( "message_sig" );
399
if ( signature == null ){
401
Logger.log( new LogEvent( LogIDs.LOGGER, "Signature missing from message" ));
407
AEVerifier.verifyData( s_message, signature );
409
}catch( Throwable e ){
411
Logger.log( new LogEvent( LogIDs.LOGGER, "Message signature check failed", e ));
416
int alert_type = LogAlert.AT_WARNING;
417
String alert_text = s_message;
419
if ( alert_text.startsWith("i:" )){
421
alert_type = LogAlert.AT_INFORMATION;
423
alert_text = alert_text.substring(2);
426
plugin_interface.getPluginProperties().setProperty( MESSAGE_PROPERTY, alert_text );
429
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, alert_type, alert_text));
431
COConfigurationManager.setParameter( "CoreUpdateChecker.lastmessage", s_message );
433
COConfigurationManager.save();
436
}catch( Throwable e ){
438
Debug.printStackTrace( e );
442
protected ResourceDownloader[]
443
getPrimaryDownloaders(
444
String latest_file_name )
446
log.log( "Downloading primary mirrors" );
448
List res = new ArrayList();
451
if ( latest_file_name == null ){
453
// very old method, non-mirror based
455
res.add( new URL( Constants.SF_WEB_SITE + "Azureus2.jar" ));
459
URL mirrors_url = new URL("http://prdownloads.sourceforge.net/azureus/" + latest_file_name + "?download");
461
ResourceDownloader rd = rdf.create( mirrors_url );
463
rd = rdf.getRetryDownloader( rd, RD_GET_MIRRORS_RETRIES );
465
rd.addListener( rd_logger );
467
String page = HTMLPageFactory.loadPage( rd.download()).getContent();
469
String pattern = "/azureus/" + latest_file_name + "?use_mirror=";
471
int position = page.indexOf(pattern);
473
while ( position > 0 ){
475
int end = page.indexOf(">", position);
483
String mirror = page.substring(position, end);
485
if ( mirror.endsWith("\"")){
487
mirror = mirror.substring(0,mirror.length()-1);
491
res.add( new URL( "http://prdownloads.sourceforge.net" + mirror ));
493
}catch( Throwable e ){
495
log.log( "Invalid URL read:" + mirror, e );
498
position = page.indexOf(pattern, position + 1);
502
}catch( Throwable e ){
504
log.log( "Failed to read primary mirror list", e );
507
ResourceDownloader[] dls = new ResourceDownloader[res.size()];
509
for (int i=0;i<res.size();i++){
511
URL url =(URL)res.get(i);
513
log.log( " Primary mirror:" +url.toString());
515
ResourceDownloader dl = rdf.create( url );
517
dl = rdf.getMetaRefreshDownloader( dl );
519
// add in a layer to do torrent based downloads if url ends with .torrent
521
dl = rdf.getSuffixBasedDownloader( dl );
529
protected ResourceDownloader[]
530
getBackupDownloaders(
531
String latest_file_name )
533
List res = new ArrayList();
536
if ( latest_file_name != null ){
538
log.log( "Downloading backup mirrors" );
540
URL mirrors_url = new URL("http://azureus.sourceforge.net/mirrors.php");
542
ResourceDownloader rd = rdf.create( mirrors_url );
544
rd = rdf.getRetryDownloader( rd, RD_GET_MIRRORS_RETRIES );
546
rd.addListener( rd_logger );
548
BufferedInputStream data = new BufferedInputStream(rd.download());
550
Map decoded = BDecoder.decode(data);
554
List mirrors = (List)decoded.get("mirrors");
556
for (int i=0;i<mirrors.size();i++){
558
String mirror = new String( (byte[])mirrors.get(i));
562
res.add( new URL( mirror + latest_file_name ));
563
// res.add( new URL( "http://torrents.aelitis.com:88/torrents/Azureus2.4.0.2_signed.jar.torrent" ));
567
log.log( "Invalid URL read:" + mirror, e );
571
}catch( Throwable e ){
573
log.log( "Failed to read backup mirror list", e );
576
ResourceDownloader[] dls = new ResourceDownloader[res.size()];
578
for (int i=0;i<res.size();i++){
580
URL url =(URL)res.get(i);
582
log.log( " Backup mirror:" +url.toString());
584
ResourceDownloader dl = rdf.create( url );
586
// add in .torrent decoder if appropriate
588
dl = rdf.getSuffixBasedDownloader( dl );
598
UpdateChecker checker,
600
ResourceDownloader rd,
605
data = update.verifyData( data, true );
607
rd.reportActivity( "Data verified successfully" );
609
String temp_jar_name = "Azureus2_" + version + ".jar";
610
String target_jar_name = "Azureus2.jar";
612
UpdateInstaller installer = checker.createInstaller();
614
installer.addResource( temp_jar_name, data );
616
if ( Constants.isOSX ){
618
installer.addMoveAction(
620
installer.getInstallDir() + "/" + SystemProperties.getApplicationName() + ".app/Contents/Resources/Java/" + target_jar_name );
623
installer.addMoveAction(
625
installer.getInstallDir() + File.separator + target_jar_name );
627
}catch( Throwable e ){
629
rd.reportActivity("Update install failed:" + e.getMessage());
633
protected static boolean
635
String current_version,
636
String latest_version )
638
String current_base = Constants.getBaseVersion( current_version );
639
int current_inc = Constants.getIncrementalBuild( current_version );
641
String latest_base = Constants.getBaseVersion( latest_version );
642
int latest_inc = Constants.getIncrementalBuild( latest_version );
644
// currently we upgrade from, for example
645
// 1) 2.4.0.0 -> 2.4.0.2
646
// 2) 2.4.0.1_CVS -> 2.4.0.2
647
// 3) 2.4.0.1_B12 -> 2.4.0.2 and 2.4.0.1_B14
650
// 1) 2.4.0.0 -> 2.4.0.1_CVS or 2.4.0.1_B23
651
// 2) 2.4.0.1_CVS -> 2.4.0.1_B23
653
// for inc values: 0 = not CVS, -1 = _CVS, > 0 = Bnn
655
int major_comp = Constants.compareVersions( current_base, latest_base );
657
if ( major_comp < 0 && latest_inc == 0 ){
659
return( true ); // latest is higher version and not CVS
662
// same version, both are B versions and latest B is more recent
664
return( major_comp == 0 && current_inc > 0 && latest_inc > 0 && latest_inc > current_inc );
672
{ "2.4.0.0", "2.4.0.2", "true" },
673
{ "2.4.0.1_CVS", "2.4.0.2", "true" },
674
{ "2.4.0.1_B12", "2.4.0.2", "true" },
675
{ "2.4.0.1_B12", "2.4.0.1_B34", "true" },
676
{ "2.4.0.1_B12", "2.4.0.1_B6", "false" },
677
{ "2.4.0.0", "2.4.0.1_CVS", "false" },
678
{ "2.4.0.0", "2.4.0.1_B12", "false" },
679
{ "2.4.0.0", "2.4.0.0" , "false" },
680
{ "2.4.0.1_CVS", "2.4.0.1_CVS", "false" },
681
{ "2.4.0.1_B2", "2.4.0.1_B2", "false" },
682
{ "2.4.0.1_CVS", "2.4.0.1_B2", "false" },
683
{ "2.4.0.1_B2", "2.4.0.1_CVS", "false" },
687
for (int i=0;i<tests.length;i++){
689
System.out.println( shouldUpdate(tests[i][0],tests[i][1]) + " / " + tests[i][2] );
693
AEDiagnostics.startup();
695
CoreUpdateChecker checker = new CoreUpdateChecker();
697
checker.log = new LoggerImpl(null).getTimeStampedChannel("");
698
checker.rdf = new ResourceDownloaderFactoryImpl();
700
new ResourceDownloaderAdapter()
704
ResourceDownloader downloader,
707
System.out.println( activity );
711
reportPercentComplete(
712
ResourceDownloader downloader,
715
System.out.println( " % = " + percentage );
719
ResourceDownloader[] primaries = checker.getPrimaryDownloaders( "Azureus-2.0.3.0.jar" );
721
for (int i=0;i<primaries.length;i++){
723
System.out.println( "primary: " + primaries[i].getName());
727
ResourceDownloader rd = primaries[0];
729
rd.addListener( checker.rd_logger );
733
System.out.println( "done" );
735
}catch( Throwable e ){
2
* Created on 20-May-2004
3
* Created by Paul Gardner
4
* Copyright (C) 2004, 2005, 2006 Aelitis, All Rights Reserved.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
* AELITIS, SAS au capital de 46,603.30 euros
19
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
23
package org.gudy.azureus2.update;
34
import org.gudy.azureus2.core3.util.*;
35
import org.gudy.azureus2.core3.logging.*;
36
import org.gudy.azureus2.core3.logging.Logger;
37
import org.gudy.azureus2.core3.config.*;
38
import org.gudy.azureus2.core3.html.*;
40
import org.gudy.azureus2.plugins.*;
41
import org.gudy.azureus2.plugins.logging.*;
42
import org.gudy.azureus2.plugins.update.*;
43
import org.gudy.azureus2.plugins.utils.resourcedownloader.*;
45
import com.aelitis.azureus.core.versioncheck.*;
46
import com.aelitis.azureus.ui.UIFunctions;
47
import com.aelitis.azureus.ui.UIFunctionsManager;
52
implements Plugin, UpdatableComponent
54
public static final String LATEST_VERSION_PROPERTY = "latest_version";
55
public static final String MESSAGE_PROPERTY = "message";
57
public static final int RD_GET_DETAILS_RETRIES = 3;
58
public static final int RD_GET_MIRRORS_RETRIES = 3;
60
public static final int RD_SIZE_RETRIES = 3;
61
public static final int RD_SIZE_TIMEOUT = 10000;
63
protected static CoreUpdateChecker singleton;
65
protected PluginInterface plugin_interface;
66
protected ResourceDownloaderFactory rdf;
67
protected LoggerChannel log;
68
protected ResourceDownloaderListener rd_logger;
70
protected boolean first_check = true;
75
singleton.doUsageStatsSupport();
88
Map decoded = VersionCheckClient.getSingleton().getVersionCheckInfo(
89
first_check?VersionCheckClient.REASON_UPDATE_CHECK_START:VersionCheckClient.REASON_UPDATE_CHECK_PERIODIC);
91
displayUserMessage( decoded );
102
PluginInterface _plugin_interface )
104
plugin_interface = _plugin_interface;
106
plugin_interface.getPluginProperties().setProperty( "plugin.name", "Core Updater" );
108
log = plugin_interface.getLogger().getChannel("CoreUpdater");
111
new ResourceDownloaderAdapter()
115
ResourceDownloader downloader,
122
Properties props = plugin_interface.getPluginProperties();
124
props.setProperty( "plugin.version", plugin_interface.getAzureusVersion());
126
rdf = plugin_interface.getUtilities().getResourceDownloaderFactory();
128
plugin_interface.getUpdateManager().registerUpdatableComponent( this, true );
134
return( "Azureus Core" );
138
getMaximumCheckTime()
140
return( ( RD_SIZE_RETRIES * RD_SIZE_TIMEOUT )/1000);
145
final UpdateChecker checker )
148
String current_version = plugin_interface.getAzureusVersion();
150
log.log( "Update check starts: current = " + current_version );
152
Map decoded = VersionCheckClient.getSingleton().getVersionCheckInfo(
153
first_check?VersionCheckClient.REASON_UPDATE_CHECK_START:VersionCheckClient.REASON_UPDATE_CHECK_PERIODIC);
156
displayUserMessage( decoded );
158
String latest_version;
159
String latest_file_name;
161
byte[] b_version = (byte[])decoded.get("version");
163
if ( b_version != null ){
165
latest_version = new String( b_version );
167
plugin_interface.getPluginProperties().setProperty( LATEST_VERSION_PROPERTY, latest_version );
171
throw( new Exception( "No version found in reply" ));
174
byte[] b_filename = (byte[]) decoded.get("filename");
176
if ( b_filename != null ){
178
latest_file_name = new String( b_filename );
182
throw( new Exception( "No update file details in reply" ));
185
//latest_version = "3.0.0.3";
186
//latest_file_name = "http://torrents.aelitis.com:88/torrents/Azureus2.5.0.0.jar.torrent";
187
//latest_file_name = "Azureus2.5.0.0.jar.torrent";
189
String msg = "Core: latest_version = '" + latest_version + "', file = '" + latest_file_name + "'";
191
URL full_download_url;
193
// since 2501 we support a full download URL, falling back to SF mirrors if this
196
if ( latest_file_name.startsWith( "http" )){
199
full_download_url = new URL( latest_file_name );
201
}catch( Throwable e ){
203
full_download_url = null;
208
int pos = latest_file_name.lastIndexOf( '/' );
210
latest_file_name = latest_file_name.substring( pos+1 );
214
full_download_url = null;
217
checker.reportProgress( msg );
221
if ( !shouldUpdate( current_version, latest_version )){
226
final String f_latest_version = latest_version;
227
final String f_latest_file_name = latest_file_name;
229
ResourceDownloader top_downloader;
231
if ( full_download_url == null ){
233
ResourceDownloader[] primary_mirrors;
235
primary_mirrors = getPrimaryDownloaders( latest_file_name );
237
// the download hierarchy is primary mirrors first (randomised alternate)
238
// then backup mirrors (randomised alternate)
240
// we don't want to load the backup mirrors until the primary mirrors fail
242
ResourceDownloader random_primary_mirrors = rdf.getRandomDownloader( primary_mirrors );
244
ResourceDownloader backup_downloader =
246
new ResourceDownloaderDelayedFactory()
248
public ResourceDownloader
251
ResourceDownloader[] backup_mirrors = getBackupDownloaders( f_latest_file_name );
253
return( rdf.getRandomDownloader( backup_mirrors ));
258
rdf.getAlternateDownloader(
259
new ResourceDownloader[]
261
random_primary_mirrors,
267
ResourceDownloader full_rd = rdf.create( full_download_url );
269
full_rd = rdf.getSuffixBasedDownloader( full_rd );
271
ResourceDownloader primary_downloader =
273
new ResourceDownloaderDelayedFactory()
275
public ResourceDownloader
278
ResourceDownloader[] primary_mirrors = getPrimaryDownloaders( f_latest_file_name );
280
return( rdf.getRandomDownloader( primary_mirrors ));
284
ResourceDownloader backup_downloader =
286
new ResourceDownloaderDelayedFactory()
288
public ResourceDownloader
291
ResourceDownloader[] backup_mirrors = getBackupDownloaders( f_latest_file_name );
293
return( rdf.getRandomDownloader( backup_mirrors ));
299
rdf.getAlternateDownloader(
300
new ResourceDownloader[]
308
top_downloader.addListener( rd_logger );
310
// get size so it is cached
312
top_downloader.getSize();
315
byte[] info_b = (byte[])decoded.get( "info" );
319
if ( info_b != null ){
322
info = new String( info_b );
324
}catch( Throwable e ){
326
Debug.printStackTrace( e );
330
byte[] info_url_bytes = (byte[])decoded.get("info_url");
332
String info_url = null;
334
if ( info_url_bytes != null ){
337
info_url = new String( info_url_bytes );
339
}catch( Exception e ){
345
if ( info != null || info_url != null ){
353
}else if ( info_url == null ){
359
check = info + "|" + info_url;
362
byte[] sig = (byte[])decoded.get( "info_sig" );
368
Logger.log( new LogEvent( LogIDs.LOGGER, "info signature check failed - missing signature" ));
373
AEVerifier.verifyData( check, sig );
377
}catch( Throwable e ){
379
Logger.log( new LogEvent( LogIDs.LOGGER, "info signature check failed", e ));
394
desc = new String[]{"Core Azureus Version" };
398
desc = new String[]{"Core Azureus Version", info };
403
final Update update =
405
"Core Azureus Version",
409
Update.RESTART_REQUIRED_YES );
411
if ( info_url != null ){
413
update.setDescriptionURL(info_url);
416
top_downloader.addListener(
417
new ResourceDownloaderAdapter()
421
final ResourceDownloader downloader,
424
installUpdate( checker, update, downloader, f_latest_version, data );
429
}catch( Throwable e ){
433
Debug.printStackTrace( e );
449
* Log and display a user message if contained within reply.
450
* @param reply from server
456
// pick up any user message in the reply
459
Iterator it = reply.keySet().iterator();
461
while( it.hasNext()){
463
String key = (String)it.next();
465
// support message + message_sig
466
// message_1 + message_sig_1 etc
468
if ( key.startsWith( "message_sig" ) || !key.startsWith( "message" )){
473
byte[] message_bytes = (byte[])reply.get( key );
475
if ( message_bytes != null && message_bytes.length > 0 ){
477
String message = new String(message_bytes);
481
int pos = key.indexOf('_');
485
sig_key = "message_sig";
489
sig_key = "message_sig" + key.substring( pos );
492
String last_message_key = "CoreUpdateChecker.last" + key;
494
String last = COConfigurationManager.getStringParameter( last_message_key, "" );
496
if ( !message.equals( last )){
498
byte[] signature = (byte[])reply.get( sig_key );
500
if ( signature == null ){
502
Logger.log( new LogEvent( LogIDs.LOGGER, "Signature missing from message" ));
508
AEVerifier.verifyData( message, signature );
510
}catch( Throwable e ){
512
Logger.log( new LogEvent( LogIDs.LOGGER, "Message signature check failed", e ));
517
boolean completed = false;
519
if ( message.startsWith( "x:" )){
521
// emergency patch application
524
URL jar_url = new URL( message.substring(2));
526
Logger.log( new LogEvent( LogIDs.LOGGER, "Patch application requsted: url=" + jar_url ));
528
File temp_dir = AETemporaryFileHandler.createTempDir();
530
File jar_file = new File( temp_dir, "patch.jar" );
532
InputStream is = rdf.create( jar_url ).download();
535
FileUtil.copyFile( is, jar_file );
539
AEVerifier.verifyData( jar_file );
541
ClassLoader cl = CoreUpdateChecker.class.getClassLoader();
543
if ( cl instanceof URLClassLoader ){
545
URL[] old = ((URLClassLoader)cl).getURLs();
547
URL[] new_urls = new URL[old.length+1];
549
System.arraycopy( old, 0, new_urls, 1, old.length );
551
new_urls[0]= jar_file.toURL();
553
cl = new URLClassLoader( new_urls, cl );
557
cl = new URLClassLoader( new URL[]{jar_file.toURL()}, cl );
560
Class cla = cl.loadClass( "org.gudy.azureus2.update.version.Patch" );
573
}catch( Throwable e ){
575
Logger.log( new LogEvent( LogIDs.LOGGER, "Patch application failed", e ));
577
} else if ( message.startsWith("u:") && message.length() > 4 ) {
579
String type = message.substring(2, 3);
580
String url = message.substring(4);
581
UIFunctions uif = UIFunctionsManager.getUIFunctions();
583
uif.viewURL(url, null, 0.9, 0.9, true, type.equals("1"));
585
} catch (Throwable t) {
586
Logger.log( new LogEvent( LogIDs.LOGGER, "URL message failed", t ));
588
// mark as complete even if errored
592
int alert_type = LogAlert.AT_WARNING;
594
String alert_text = message;
596
if ( alert_text.startsWith("i:" )){
598
alert_type = LogAlert.AT_INFORMATION;
600
alert_text = alert_text.substring(2);
603
plugin_interface.getPluginProperties().setProperty( MESSAGE_PROPERTY, alert_text );
605
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, alert_type, alert_text));
612
COConfigurationManager.setParameter( last_message_key, message );
614
COConfigurationManager.save();
619
}catch( Throwable e ){
621
Debug.printStackTrace( e );
625
protected ResourceDownloader[]
626
getPrimaryDownloaders(
627
String latest_file_name )
629
log.log( "Downloading primary mirrors" );
631
List res = new ArrayList();
634
if ( latest_file_name == null ){
636
// very old method, non-mirror based
638
res.add( new URL( Constants.SF_WEB_SITE + "Azureus2.jar" ));
642
URL mirrors_url = new URL("http://prdownloads.sourceforge.net/azureus/" + latest_file_name + "?download");
644
ResourceDownloader rd = rdf.create( mirrors_url );
646
rd = rdf.getRetryDownloader( rd, RD_GET_MIRRORS_RETRIES );
648
rd.addListener( rd_logger );
650
String page = HTMLPageFactory.loadPage( rd.download()).getContent();
652
String pattern = "/azureus/" + latest_file_name + "?use_mirror=";
654
int position = page.indexOf(pattern);
656
while ( position > 0 ){
658
int end = page.indexOf(">", position);
666
String mirror = page.substring(position, end);
668
if ( mirror.endsWith("\"")){
670
mirror = mirror.substring(0,mirror.length()-1);
674
res.add( new URL( "http://prdownloads.sourceforge.net" + mirror ));
676
}catch( Throwable e ){
678
log.log( "Invalid URL read:" + mirror, e );
681
position = page.indexOf(pattern, position + 1);
685
}catch( Throwable e ){
687
log.log( "Failed to read primary mirror list", e );
690
ResourceDownloader[] dls = new ResourceDownloader[res.size()];
692
for (int i=0;i<res.size();i++){
694
URL url =(URL)res.get(i);
696
log.log( " Primary mirror:" +url.toString());
698
ResourceDownloader dl = rdf.create( url );
700
dl = rdf.getMetaRefreshDownloader( dl );
702
// add in a layer to do torrent based downloads if url ends with .torrent
704
dl = rdf.getSuffixBasedDownloader( dl );
712
protected ResourceDownloader[]
713
getBackupDownloaders(
714
String latest_file_name )
716
List res = new ArrayList();
719
if ( latest_file_name != null ){
721
log.log( "Downloading backup mirrors" );
723
URL mirrors_url = new URL("http://azureus.sourceforge.net/mirrors.php");
725
ResourceDownloader rd = rdf.create( mirrors_url );
727
rd = rdf.getRetryDownloader( rd, RD_GET_MIRRORS_RETRIES );
729
rd.addListener( rd_logger );
731
BufferedInputStream data = new BufferedInputStream(rd.download());
733
Map decoded = BDecoder.decode(data);
737
List mirrors = (List)decoded.get("mirrors");
739
for (int i=0;i<mirrors.size();i++){
741
String mirror = new String( (byte[])mirrors.get(i));
745
res.add( new URL( mirror + latest_file_name ));
746
// res.add( new URL( "http://torrents.aelitis.com:88/torrents/Azureus2.4.0.2_signed.jar.torrent" ));
750
log.log( "Invalid URL read:" + mirror, e );
754
}catch( Throwable e ){
756
log.log( "Failed to read backup mirror list", e );
759
ResourceDownloader[] dls = new ResourceDownloader[res.size()];
761
for (int i=0;i<res.size();i++){
763
URL url =(URL)res.get(i);
765
log.log( " Backup mirror:" +url.toString());
767
ResourceDownloader dl = rdf.create( url );
769
// add in .torrent decoder if appropriate
771
dl = rdf.getSuffixBasedDownloader( dl );
781
UpdateChecker checker,
783
ResourceDownloader rd,
788
data = update.verifyData( data, true );
790
rd.reportActivity( "Data verified successfully" );
792
String temp_jar_name = "Azureus2_" + version + ".jar";
793
String target_jar_name = "Azureus2.jar";
795
UpdateInstaller installer = checker.createInstaller();
797
installer.addResource( temp_jar_name, data );
799
if ( Constants.isOSX ){
801
installer.addMoveAction(
803
installer.getInstallDir() + "/" + SystemProperties.getApplicationName() + ".app/Contents/Resources/Java/" + target_jar_name );
806
installer.addMoveAction(
808
installer.getInstallDir() + File.separator + target_jar_name );
810
}catch( Throwable e ){
812
rd.reportActivity("Update install failed:" + e.getMessage());
816
protected static boolean
818
String current_version,
819
String latest_version )
821
String current_base = Constants.getBaseVersion( current_version );
822
int current_inc = Constants.getIncrementalBuild( current_version );
824
String latest_base = Constants.getBaseVersion( latest_version );
825
int latest_inc = Constants.getIncrementalBuild( latest_version );
827
// currently we upgrade from, for example
828
// 1) 2.4.0.0 -> 2.4.0.2
829
// 2) 2.4.0.1_CVS -> 2.4.0.2
830
// 3) 2.4.0.1_B12 -> 2.4.0.2 and 2.4.0.1_B14
833
// 1) 2.4.0.0 -> 2.4.0.1_CVS or 2.4.0.1_B23
834
// 2) 2.4.0.1_CVS -> 2.4.0.1_B23
836
// for inc values: 0 = not CVS, -1 = _CVS, > 0 = Bnn
838
int major_comp = Constants.compareVersions( current_base, latest_base );
840
if ( major_comp < 0 && latest_inc == 0 ){
842
return( true ); // latest is higher version and not CVS
845
// same version, both are B versions and latest B is more recent
847
return( major_comp == 0 && current_inc > 0 && latest_inc > 0 && latest_inc > current_inc );
855
{ "2.4.0.0", "2.4.0.2", "true" },
856
{ "2.4.0.1_CVS", "2.4.0.2", "true" },
857
{ "2.4.0.1_B12", "2.4.0.2", "true" },
858
{ "2.4.0.1_B12", "2.4.0.1_B34", "true" },
859
{ "2.4.0.1_B12", "2.4.0.1_B6", "false" },
860
{ "2.4.0.0", "2.4.0.1_CVS", "false" },
861
{ "2.4.0.0", "2.4.0.1_B12", "false" },
862
{ "2.4.0.0", "2.4.0.0" , "false" },
863
{ "2.4.0.1_CVS", "2.4.0.1_CVS", "false" },
864
{ "2.4.0.1_B2", "2.4.0.1_B2", "false" },
865
{ "2.4.0.1_CVS", "2.4.0.1_B2", "false" },
866
{ "2.4.0.1_B2", "2.4.0.1_CVS", "false" },
870
for (int i=0;i<tests.length;i++){
872
System.out.println( shouldUpdate(tests[i][0],tests[i][1]) + " / " + tests[i][2] );
876
AEDiagnostics.startup();
878
CoreUpdateChecker checker = new CoreUpdateChecker();
880
checker.log = new LoggerImpl(null).getTimeStampedChannel("");
881
checker.rdf = new ResourceDownloaderFactoryImpl();
883
new ResourceDownloaderAdapter()
887
ResourceDownloader downloader,
890
System.out.println( activity );
894
reportPercentComplete(
895
ResourceDownloader downloader,
898
System.out.println( " % = " + percentage );
902
ResourceDownloader[] primaries = checker.getPrimaryDownloaders( "Azureus-2.0.3.0.jar" );
904
for (int i=0;i<primaries.length;i++){
906
System.out.println( "primary: " + primaries[i].getName());
910
ResourceDownloader rd = primaries[0];
912
rd.addListener( checker.rd_logger );
916
System.out.println( "done" );
918
}catch( Throwable e ){