⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pluginupdateplugin.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					if ( ids[j].equalsIgnoreCase( plugin_id )){
						
						found	= true;
						
						break;
					}
				}
				
				if ( !found ){
					
					if ( !pi_being_checked.isBuiltIn()){
						
						log.log( LoggerChannel.LT_INFORMATION, "Skipping " + plugin_id + " as not listed on web site");
					}

					continue;
				}
				
				String			plugin_names		= (String)plugins_to_check_names.get( plugin_id );
				final boolean	plugin_unloadable 	= ((Boolean)plugins_to_check_unloadable.get( plugin_id )).booleanValue();
				
				log.log( LoggerChannel.LT_INFORMATION, "Checking " + plugin_id);
				
				try{
					
					SFPluginDetails	details = loader.getPluginDetails( plugin_id );
	
					if ( plugin_names.length() == 0 ){
						
						plugin_names = details.getName();
					}
					
					boolean az_cvs = plugin_interface.getUtilities().isCVSVersion();
					
					String pi_version_info = pi_being_checked.getPluginProperties().getProperty( "plugin.version.info" );
					
					String az_plugin_version	= pi_being_checked.getPluginVersion();
					
					String sf_plugin_version	= details.getVersion();
					
					String sf_comp_version		= sf_plugin_version;
					
					if ( az_cvs ){
						
						String	sf_cvs_version = details.getCVSVersion();
						
						if ( sf_cvs_version.length() > 0 ){
							
								// sf cvs version ALWAYS ends in _CVS
							
							sf_plugin_version	= sf_cvs_version;
							
							sf_comp_version = sf_plugin_version.substring(0,sf_plugin_version.length()-4);
						}
					}
					
					if (	 sf_comp_version.length() == 0 ||
							!Character.isDigit(sf_comp_version.charAt(0))){
						
						log.log( LoggerChannel.LT_INFORMATION, "Skipping " + plugin_id + " as no valid version to check");

						continue;					
					}
					
					// 	System.out.println("comp version = " + sf_comp_version );
					
					int	comp = PluginUtils.comparePluginVersions( az_plugin_version, sf_comp_version );
					
						// if they're the same version and latest is CVS then stick a _CVS on
						// the end of current to avoid confusion
					
					log.log( LoggerChannel.LT_INFORMATION, 
								"    Current: " + az_plugin_version + 
								(comp==0&&sf_plugin_version.endsWith( "_CVS")?"_CVS":"")+
								", Latest: " + sf_plugin_version + (pi_version_info==null?"":" [" + pi_version_info + "]"));
					
					if ( comp < 0 && ! ( pi_being_checked.getPlugin() instanceof UpdatableComponent)){
													
							// only update if newer verison + plugin itself doesn't handle
							// the update
						
						String sf_plugin_download	= details.getDownloadURL();
						
						if ( az_cvs ){
							
							String	sf_cvs_version = details.getCVSVersion();
							
							if ( sf_cvs_version.length() > 0 ){
								
								sf_plugin_download	= details.getCVSDownloadURL();
							}
						}

						log.log( LoggerChannel.LT_INFORMATION, "    Description:" );
						
						List	update_desc = new ArrayList();
						
						List	desc_lines = HTMLUtils.convertHTMLToText( "", details.getDescription());
						
						logMultiLine( "        ", desc_lines );
						
						update_desc.addAll( desc_lines );
						
						log.log( LoggerChannel.LT_INFORMATION, "    Comment:" );
						
						List	comment_lines = HTMLUtils.convertHTMLToText( "    ", details.getComment());

						logMultiLine( "    ", comment_lines );
						
						update_desc.addAll( comment_lines );
						
						String msg =   "A newer version (version " + sf_plugin_version + ") of plugin '" + 
										plugin_id + "' " +
										(plugin_names.length()==0?"":"(" + plugin_names + ") " ) +
										"is available. ";
						
						log.log( LoggerChannel.LT_INFORMATION, "" );
						
						log.log( 	LoggerChannel.LT_INFORMATION, "        " + msg + "Download from "+
									sf_plugin_download);
						
						ResourceDownloaderFactory rdf =  plugin_interface.getUtilities().getResourceDownloaderFactory();
						
						ResourceDownloader direct_rdl = rdf.create( new URL( sf_plugin_download ));

							// work out what the torrent download will be, if it exists 
							// sf_plugin_download will be something like ../plugins/safepeer_2.4.zip
							//     torrent is safepeer_2.4.zip.torrent
						
						String	torrent_download = Constants.AELITIS_TORRENTS;
						
						int	slash_pos = sf_plugin_download.lastIndexOf("/");
						
						if ( slash_pos == -1 ){
							
							torrent_download += sf_plugin_download;
							
						}else{
							
							torrent_download += sf_plugin_download.substring( slash_pos + 1 );
						}
						
						torrent_download	+= ".torrent";
						
						ResourceDownloader torrent_rdl = rdf.create( new URL( torrent_download ));

						torrent_rdl	= rdf.getSuffixBasedDownloader( torrent_rdl );
						
							// create an alternate downloader with torrent attempt first
						
						ResourceDownloader alternate_rdl = rdf.getAlternateDownloader( new ResourceDownloader[]{ torrent_rdl, direct_rdl });
						
							// get size so it is cached
						
						rdf.getTimeoutDownloader(rdf.getRetryDownloader(alternate_rdl,RD_SIZE_RETRIES),RD_SIZE_TIMEOUT).getSize();
																			
						String[]	update_d = new String[update_desc.size()];
						
						update_desc.toArray( update_d );
							
						num_updates_found++;
						
						addUpdate( 
								pi_being_checked,
								checker,
								plugin_id + "/" + plugin_names,
								update_d,
								sf_plugin_version,
								alternate_rdl,
								sf_plugin_download.toLowerCase().endsWith(".jar"),
								plugin_unloadable?Update.RESTART_REQUIRED_NO:Update.RESTART_REQUIRED_YES,
								true );
			
						}
				}catch( Throwable e ){
					
					log.log("    Plugin check failed", e ); 
				}
			}
						
		}catch( Throwable e ){
			
			log.log("Failed to load plugin details", e );
			
			checker.failed();
			
		}finally{
			
				// any prior failure will take precedence
			
			checker.completed();
		}
		
		return( num_updates_found );
	}
	
	public void
	addUpdate(
		final PluginInterface			pi_for_update,
		final UpdateChecker				checker,
		final String					update_name,
		final String[]					update_details,
		final String					version,
		final ResourceDownloader		resource_downloader,
		final boolean					is_jar,
		final int						restart_type,
		final boolean					verify )
	{
		final Update update = checker.addUpdate(
				update_name,
				update_details,
				version,
				resource_downloader,
				restart_type );

		update.setUserObject( pi_for_update );
		
		resource_downloader.addListener( 
			new ResourceDownloaderAdapter()
			{
				public boolean
				completed(
					final ResourceDownloader	downloader,
					InputStream					data )
				{	
						// during the update phase report any messages
						// to the downloader
					
					LoggerChannelListener	list = 
						new LoggerChannelListener()
						{
						public void
							messageLogged(
								int		type,
								String	content )
							{
								downloader.reportActivity( content );
							}
							
							public void
							messageLogged(
								String		str,
								Throwable	error )
							{
								downloader.reportActivity( str );
							}
						};
			
					try{
						
						log.addListener(list);
							
						installUpdate( 
								checker,
								update,
								pi_for_update,
								restart_type == Update.RESTART_REQUIRED_NO,
								is_jar,
								version, 
								data,
								verify );
						
						return( true );
					}finally{
						
						log.removeListener( list );
					}
				}
			});	
	}
	
	
	protected void
	installUpdate(
		UpdateChecker		checker,
		Update				update,
		PluginInterface		plugin,		// note this will be first one if > 1 defined
		boolean				unloadable,
		boolean				is_jar,		// false -> zip 
		String				version,
		InputStream			data,
		boolean				verify )
	{
		log.log( LoggerChannel.LT_INFORMATION,
				 "Installing plugin " + plugin.getPluginID() + ", version " + version );

		String	target_version = version.endsWith("_CVS")?version.substring(0,version.length()-4):version;

		String	plugin_dir	= plugin.getPluginDirectoryName();
		
		UpdateInstaller	installer	= null;
		
		try{
		
			data = update.verifyData( data, verify );
		
			log.log( "    Data verification stage complete" );
			
			boolean update_txt_found	= false;

			if ( plugin_dir == null || plugin_dir.length() == 0 ){
				
					// update to a built-in plugin
				
				log.log( LoggerChannel.LT_INFORMATION, "    This is a built-in plugin, updating core" );

				CorePatchChecker.patchAzureus2( update.getCheckInstance(), data, plugin.getPluginID() + "_" + version, log );
				
					// always need to restart for this
				
				update.setRestartRequired( Update.RESTART_REQUIRED_YES );
				
			}else{
				
			
	
					// .jar files get copied straight in with the right version number
					// .zip files need to be unzipped. There are various possibilities for
					// target dir depending on the contents of the zip file. Basically we
					// need to remove any zip paths to ensure it ends up in the right place
					// There's also the issue of overwriting stuff like "plugin.properties"
					// and any other config files....
								
				String	target = plugin_dir + File.separator + 
									plugin.getPluginID() + "_" + target_version + (is_jar?".jar":".zip");
				
				FileUtil.copyFile( data, new FileOutputStream(target));
			
				if ( !is_jar ){
					
					ZipInputStream	zis = 
						new ZipInputStream( 
								new BufferedInputStream( new FileInputStream( target ) ));
					
					
						// first look for a common dir prefix and platform-specific stuff
					
					String	common_prefix = null;
				
					String	selected_platform		= null;
					List	selected_sub_platforms	= new ArrayList();
					
					try{
						while( true ){
							
							ZipEntry	entry = zis.getNextEntry();
								
							if ( entry == null ){
								
								break;
							}
							
							String	name = entry.getName();
							
							if ( !( name.equals( "azureus.sig" ) || name.endsWith("/"))){
								
								if ( common_prefix == null ){
									
									common_prefix = name;
									
								}else{
									int	len = 0;
									
									for (int i=0;i<Math.min(common_prefix.length(), name.length());i++){
										
										if ( common_prefix.charAt(i) == name.charAt(i)){
											
											len++;
											
										}else{
											
											break;
										}
									}
									
									common_prefix = common_prefix.substring(0,len);
								}
								
								int	plat_pos = name.indexOf( "platform/" );
								
								if ( plat_pos != -1 ){
									
									plat_pos += 9;
									
									int	plat_end_pos = name.indexOf( "/", plat_pos );
									
									if ( plat_end_pos != -1 ){
										
										String	platform 		= name.substring( plat_pos, plat_end_pos );
										String	sub_platform 	= null;
										
										int	sub_plat_pos = platform.indexOf("_");
										
										if ( sub_plat_pos != -1 ){
											
											sub_platform = platform.substring( sub_plat_pos+1 );
											
											platform	= platform.substring(0,sub_plat_pos);
										}
																	
										if ( 	(Constants.isWindows && platform.equalsIgnoreCase( "windows" )) ||
												(Constants.isLinux && platform.equalsIgnoreCase( "linux" ))	||
												(Constants.isUnix && platform.equalsIgnoreCase( "unix" ))	||
												(Constants.isFreeBSD && platform.equalsIgnoreCase( "freebsd" ))	||
												(Constants.isSolaris && platform.equalsIgnoreCase( "solaris" ))	||
												(Constants.isOSX && platform.equalsIgnoreCase( "osx" ))){
											
										
											selected_platform = platform;
											
											if ( sub_platform != null ){
												
												if ( !selected_sub_platforms.contains( sub_platform )){
												
													selected_sub_platforms.add( sub_platform );
												}
											}
										}
									}
								}
							}
																		
							byte[]	buffer = new byte[65536];
							
							while( true ){
							
								int	len = zis.read( buffer );
								
								if ( len <= 0 ){
									
									break;
								}
							}
						}
					}finally{
						
						zis.close();
					}
	
					if ( selected_platform != null ){
						
						String[]	options = new String[selected_sub_platforms.size()];
						
						selected_sub_platforms.toArray( options );

						if ( options.length == 1 ){
							
							selected_platform += "_" + options[0];
							
							log.log( LoggerChannel.LT_INFORMATION,
									"platform is '" + selected_platform +"'" );

						}else if ( options.length > 1 ){
													
							String selected_sub_platform = (String) 
								update.getDecision(
										UpdateManagerDecisionListener.DT_STRING_ARRAY_TO_STRING,
										"Select Platform",
										"Multiple platform options exist for this plugin, please select required one",
										options );
							
							if ( selected_sub_platform == null ){
								
								throw( new Exception( "Valid sub-platform selection not selected" ));
								
							}else{
								
								selected_platform += "_" + selected_sub_platform;
								
								log.log( LoggerChannel.LT_INFORMATION,
										"platform is '" + selected_platform +"'" );

							}
						}
					}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -