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

📄 sharemanagerimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   ShareManagerImpl.java

package org.gudy.azureus2.pluginsimpl.local.sharing;

import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.*;
import org.gudy.azureus2.core3.config.*;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.tracker.util.TRTrackerUtils;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.PluginManager;
import org.gudy.azureus2.plugins.sharing.*;
import org.gudy.azureus2.plugins.torrent.*;
import org.gudy.azureus2.pluginsimpl.local.torrent.TorrentImpl;

// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.sharing:
//			ShareConfigImpl, ShareItemImpl, ShareResourceDirContentsImpl, ShareResourceDirImpl, 
//			ShareResourceFileImpl, ShareResourceFileOrDirImpl, ShareResourceImpl

public class ShareManagerImpl
	implements ShareManager, TOTorrentProgressListener, ParameterListener, AEDiagnosticsEvidenceGenerator
{
	protected class shareScanner
	{

		boolean run;
		final ShareManagerImpl this$0;

		protected shareScanner()
		{
			this$0 = ShareManagerImpl.this;
			super();
			run = true;
			current_scanner = this;
			(new AEThread2(true, ShareManagerImpl.this) {

				final ShareManagerImpl val$this$0;
				final shareScanner this$1;

				public void run()
				{
					do
					{
						if (current_scanner != shareScanner.this)
							break;
						try
						{
							int scan_period = COConfigurationManager.getIntParameter("Sharing Rescan Period");
							if (scan_period < 1)
								scan_period = 1;
							Thread.sleep(scan_period * 1000);
							if (current_scanner == shareScanner.this)
								scanShares();
						}
						catch (Throwable e)
						{
							Debug.printStackTrace(e);
						}
					} while (true);
				}

				
				{
					this$1 = shareScanner.this;
					this$0 = sharemanagerimpl;
					super(x0, x1);
				}
			}).start();
		}
	}


	private static final LogIDs LOGID;
	public static final String TORRENT_STORE = "shares";
	public static final String TORRENT_SUBSTORE = "cache";
	public static final int MAX_FILES_PER_DIR = 1000;
	public static final int MAX_DIRS = 1000;
	protected static ShareManagerImpl singleton;
	private static AEMonitor class_mon = new AEMonitor("ShareManager:class");
	protected AEMonitor this_mon;
	protected TOTorrentCreator to_creator;
	private volatile boolean initialised;
	private volatile boolean initialising;
	private File share_dir;
	private URL announce_urls[];
	private ShareConfigImpl config;
	private Map shares;
	private shareScanner current_scanner;
	private boolean scanning;
	private List listeners;

	public static ShareManagerImpl getSingleton()
		throws ShareException
	{
		ShareManagerImpl sharemanagerimpl;
		class_mon.enter();
		if (singleton == null)
			singleton = new ShareManagerImpl();
		sharemanagerimpl = singleton;
		class_mon.exit();
		return sharemanagerimpl;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	protected ShareManagerImpl()
		throws ShareException
	{
		this_mon = new AEMonitor("ShareManager");
		shares = new HashMap();
		listeners = new ArrayList();
		COConfigurationManager.addListener(new COConfigurationListener() {

			final ShareManagerImpl this$0;

			public void configurationSaved()
			{
				announce_urls = null;
			}

			
			{
				this$0 = ShareManagerImpl.this;
				super();
			}
		});
		AEDiagnostics.addEvidenceGenerator(this);
	}

	public void initialise()
		throws ShareException
	{
		this_mon.enter();
		if (initialised)
			break MISSING_BLOCK_LABEL_338;
		initialising = true;
		initialised = true;
		share_dir = FileUtil.getUserFile("shares");
		FileUtil.mkdirs(share_dir);
		config = new ShareConfigImpl();
		config.suspendSaving();
		config.loadConfig(this);
		Iterator it = shares.values().iterator();
		do
		{
			if (!it.hasNext())
				break;
			ShareResourceImpl resource = (ShareResourceImpl)it.next();
			if (resource.getType() == 3)
			{
				int i = 0;
				while (i < listeners.size()) 
				{
					try
					{
						((ShareManagerListener)listeners.get(i)).resourceAdded(resource);
					}
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
					i++;
				}
			}
		} while (true);
		config.resumeSaving();
		break MISSING_BLOCK_LABEL_288;
		Exception exception;
		exception;
		Iterator it = shares.values().iterator();
		do
		{
			if (!it.hasNext())
				break;
			ShareResourceImpl resource = (ShareResourceImpl)it.next();
			if (resource.getType() == 3)
			{
				int i = 0;
				while (i < listeners.size()) 
				{
					try
					{
						((ShareManagerListener)listeners.get(i)).resourceAdded(resource);
					}
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
					i++;
				}
			}
		} while (true);
		config.resumeSaving();
		throw exception;
		readAZConfig();
		initialising = false;
		(new AEThread2("ShareManager:initScan", true) {

			final ShareManagerImpl this$0;

			public void run()
			{
				try
				{
					scanShares();
				}
				catch (Throwable e)
				{
					Debug.printStackTrace(e);
				}
			}

			
			{
				this$0 = ShareManagerImpl.this;
				super(x0, x1);
			}
		}).start();
		break MISSING_BLOCK_LABEL_338;
		Exception exception1;
		exception1;
		initialising = false;
		(new 2("ShareManager:initScan", true)).start();
		throw exception1;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_360;
		Exception exception2;
		exception2;
		this_mon.exit();
		throw exception2;
	}

	public boolean isInitialising()
	{
		return initialising;
	}

	protected void readAZConfig()
	{
		COConfigurationManager.addParameterListener("Sharing Rescan Enable", this);
		readAZConfigSupport();
	}

	public void parameterChanged(String name)
	{
		readAZConfigSupport();
	}

	protected void readAZConfigSupport()
	{
		this_mon.enter();
		boolean scan_enabled = COConfigurationManager.getBooleanParameter("Sharing Rescan Enable");
		if (!scan_enabled)
			current_scanner = null;
		else
		if (current_scanner == null)
			current_scanner = new shareScanner();
		this_mon.exit();
		break MISSING_BLOCK_LABEL_64;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected ShareConfigImpl getShareConfig()
	{
		return config;
	}

	protected void checkConsistency()
		throws ShareException
	{
		for (Iterator it = (new HashSet(shares.values())).iterator(); it.hasNext();)
		{
			ShareResourceImpl resource = (ShareResourceImpl)it.next();
			try
			{
				resource.checkConsistency();
			}
			catch (ShareException e)
			{
				Debug.printStackTrace(e);
			}
		}

	}

	protected void deserialiseResource(Map map)
	{
		try
		{
			ShareResourceImpl new_resource = null;
			int type = ((Long)map.get("type")).intValue();
			if (type == 1 || type == 2)
				new_resource = ShareResourceFileOrDirImpl.deserialiseResource(this, map, type);
			else
				new_resource = ShareResourceDirContentsImpl.deserialiseResource(this, map);
			if (new_resource != null)
			{
				ShareResourceImpl old_resource = (ShareResourceImpl)shares.get(new_resource.getName());
				if (old_resource != null)
					old_resource.delete(true);
				shares.put(new_resource.getName(), new_resource);
				if (type != 3)
				{
					for (int i = 0; i < listeners.size(); i++)
						try
						{
							((ShareManagerListener)listeners.get(i)).resourceAdded(new_resource);
						}
						catch (Throwable e)
						{
							Debug.printStackTrace(e);
						}

				}
			}
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
		}
	}

	protected String getNewTorrentLocation()
		throws ShareException
	{
		Random rand = new Random(SystemTime.getCurrentTime());
label0:
		for (int i = 1; i <= 1000; i++)
		{
			String cache_dir_str = (new StringBuilder()).append(share_dir).append(File.separator).append("cache").append(i).toString();
			File cache_dir = new File(cache_dir_str);
			if (!cache_dir.exists())
				FileUtil.mkdirs(cache_dir);
			if (cache_dir.listFiles().length >= 1000)
				continue;
			int j = 0;
			do
			{
				if (j >= 1000)
					continue label0;
				long file = Math.abs(rand.nextLong());
				File file_name = new File((new StringBuilder()).append(cache_dir_str).append(File.separator).append(file).append(".torrent").toString());
				if (!file_name.exists())
					return (new StringBuilder()).append("cache").append(i).append(File.separator).append(file).append(".torrent").toString();
				j++;
			} while (true);
		}

		throw new ShareException("ShareManager: Failed to allocate cache file");
	}

	protected void writeTorrent(ShareItemImpl item)
		throws ShareException
	{
		try
		{
			item.getTorrent().writeToFile(getTorrentFile(item));
		}
		catch (TorrentException e)
		{
			throw new ShareException("ShareManager: Torrent write fails", e);
		}
	}

	protected void readTorrent(ShareItemImpl item)
		throws ShareException
	{
		try
		{
			org.gudy.azureus2.core3.torrent.TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedFile(getTorrentFile(item));
			item.setTorrent(new TorrentImpl(torrent));
		}
		catch (TOTorrentException e)
		{
			throw new ShareException("ShareManager: Torrent read fails", e);
		}
	}

	protected void deleteTorrent(ShareItemImpl item)
	{
		File torrent_file = getTorrentFile(item);
		torrent_file.delete();
	}

	protected boolean torrentExists(ShareItemImpl item)
	{
		return getTorrentFile(item).exists();
	}

	protected File getTorrentFile(ShareItemImpl item)
	{
		return new File((new StringBuilder()).append(share_dir).append(File.separator).append(item.getTorrentLocation()).toString());
	}

	protected URL[] getAnnounceURLs()
		throws ShareException
	{
		if (announce_urls == null)
		{
			String protocol = COConfigurationManager.getStringParameter("Sharing Protocol");
			if (protocol.equalsIgnoreCase("DHT"))
			{
				announce_urls = (new URL[] {
					TorrentUtils.getDecentralisedEmptyURL()
				});
			} else
			{
				URL tracker_url_sets[][] = TRTrackerUtils.getAnnounceURLs();
				if (tracker_url_sets.length == 0)
					throw new ShareException("ShareManager: Tracker must be configured");
				int i = 0;
				do
				{
					if (i >= tracker_url_sets.length)

⌨️ 快捷键说明

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