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

📄 sharemanagerimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						break;
					URL tracker_urls[] = tracker_url_sets[i];
					if (tracker_urls[0].getProtocol().equalsIgnoreCase(protocol))
					{
						announce_urls = tracker_urls;
						break;
					}
					i++;
				} while (true);
				if (announce_urls == null)
					throw new ShareException((new StringBuilder()).append("ShareManager: Tracker must be configured for protocol '").append(protocol).append("'").toString());
			}
		}
		return announce_urls;
	}

	protected boolean getAddHashes()
	{
		return COConfigurationManager.getBooleanParameter("Sharing Add Hashes");
	}

	public ShareResource[] getShares()
	{
		ShareResource res[] = new ShareResource[shares.size()];
		shares.values().toArray(res);
		return res;
	}

	protected ShareResourceImpl getResource(File file)
		throws ShareException
	{
		return (ShareResourceImpl)shares.get(file.getCanonicalFile().toString());
		IOException e;
		e;
		throw new ShareException("getCanonicalFile fails", e);
	}

	public ShareResource getShare(File file_or_dir)
	{
		return getResource(file_or_dir);
		ShareException e;
		e;
		return null;
	}

	public ShareResourceFile addFile(File file)
		throws ShareException, ShareResourceDeletionVetoException
	{
		return addFile(null, file);
	}

	protected ShareResourceFile addFile(ShareResourceDirContentsImpl parent, File file)
		throws ShareException, ShareResourceDeletionVetoException
	{
		if (Logger.isEnabled())
			Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("ShareManager: addFile '").append(file.toString()).append("'").toString()));
		return (ShareResourceFile)addFileOrDir(parent, file, 1, false);
		ShareException e;
		e;
		reportError(e);
		throw e;
	}

	public ShareResourceFile getFile(File file)
		throws ShareException
	{
		return ShareResourceFileImpl.getResource(this, file);
	}

	public ShareResourceDir addDir(File dir)
		throws ShareException, ShareResourceDeletionVetoException
	{
		return addDir(null, dir);
	}

	public ShareResourceDir addDir(ShareResourceDirContentsImpl parent, File dir)
		throws ShareException, ShareResourceDeletionVetoException
	{
		Exception exception;
		if (Logger.isEnabled())
			Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("ShareManager: addDir '").append(dir.toString()).append("'").toString()));
		ShareResourceDir shareresourcedir;
		try
		{
			this_mon.enter();
			shareresourcedir = (ShareResourceDir)addFileOrDir(parent, dir, 2, false);
		}
		catch (ShareException e)
		{
			reportError(e);
			throw e;
		}
		finally
		{
			this_mon.exit();
		}
		this_mon.exit();
		return shareresourcedir;
		throw exception;
	}

	public ShareResourceDir getDir(File file)
		throws ShareException
	{
		return ShareResourceDirImpl.getResource(this, file);
	}

	protected ShareResource addFileOrDir(ShareResourceDirContentsImpl parent, File file, int type, boolean modified)
		throws ShareException, ShareResourceDeletionVetoException
	{
		Exception exception;
		ShareResourceImpl shareresourceimpl;
		try
		{
			this_mon.enter();
			String name = file.getCanonicalFile().toString();
			ShareResource old_resource = (ShareResource)shares.get(name);
			if (old_resource != null)
				old_resource.delete();
			ShareResourceImpl new_resource;
			if (type == 1)
			{
				reportCurrentTask((new StringBuilder()).append("Adding file '").append(name).append("'").toString());
				new_resource = new ShareResourceFileImpl(this, parent, file);
			} else
			{
				reportCurrentTask((new StringBuilder()).append("Adding dir '").append(name).append("'").toString());
				new_resource = new ShareResourceDirImpl(this, parent, file);
			}
			shares.put(name, new_resource);
			config.saveConfig();
			for (int i = 0; i < listeners.size(); i++)
				try
				{
					if (modified)
						((ShareManagerListener)listeners.get(i)).resourceModified(new_resource);
					else
						((ShareManagerListener)listeners.get(i)).resourceAdded(new_resource);
				}
				catch (Throwable e)
				{
					Debug.printStackTrace(e);
				}

			shareresourceimpl = new_resource;
		}
		catch (IOException e)
		{
			throw new ShareException("getCanoncialFile fails", e);
		}
		finally
		{
			this_mon.exit();
		}
		this_mon.exit();
		return shareresourceimpl;
		throw exception;
	}

	public ShareResourceDirContents addDirContents(File dir, boolean recursive)
		throws ShareException, ShareResourceDeletionVetoException
	{
		Exception exception;
		if (Logger.isEnabled())
			Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("ShareManager: addDirContents '").append(dir.toString()).append("'").toString()));
		ShareResourceDirContents shareresourcedircontents;
		try
		{
			this_mon.enter();
			String name = dir.getCanonicalFile().toString();
			reportCurrentTask((new StringBuilder()).append("Adding dir contents '").append(name).append("', recursive = ").append(recursive).toString());
			ShareResource old_resource = (ShareResource)shares.get(name);
			if (old_resource != null)
				old_resource.delete();
			ShareResourceDirContents new_resource = new ShareResourceDirContentsImpl(this, dir, recursive, true);
			shares.put(name, new_resource);
			config.saveConfig();
			for (int i = 0; i < listeners.size(); i++)
				try
				{
					((ShareManagerListener)listeners.get(i)).resourceAdded(new_resource);
				}
				catch (Throwable e)
				{
					Debug.printStackTrace(e);
				}

			shareresourcedircontents = new_resource;
		}
		catch (IOException e)
		{
			reportError(e);
			throw new ShareException("getCanoncialFile fails", e);
		}
		catch (ShareException e)
		{
			reportError(e);
			throw e;
		}
		finally
		{
			this_mon.exit();
		}
		this_mon.exit();
		return shareresourcedircontents;
		throw exception;
	}

	protected void delete(ShareResourceImpl resource)
		throws ShareException
	{
		if (Logger.isEnabled())
			Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("ShareManager: resource '").append(resource.getName()).append("' deleted").toString()));
		this_mon.enter();
		shares.remove(resource.getName());
		resource.deleteInternal();
		config.saveConfig();
		for (int i = 0; i < listeners.size(); i++)
			try
			{
				((ShareManagerListener)listeners.get(i)).resourceDeleted(resource);
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}

		this_mon.exit();
		break MISSING_BLOCK_LABEL_148;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void scanShares()
		throws ShareException
	{
		this_mon.enter();
		if (scanning)
		{
			this_mon.exit();
			return;
		}
		scanning = true;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_47;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
		if (Logger.isEnabled())
			Logger.log(new LogEvent(LOGID, "ShareManager: scanning resources for changes"));
		checkConsistency();
		this_mon.enter();
		scanning = false;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_144;
		Exception exception1;
		exception1;
		this_mon.exit();
		throw exception1;
		Exception exception2;
		exception2;
		this_mon.enter();
		scanning = false;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_142;
		Exception exception3;
		exception3;
		this_mon.exit();
		throw exception3;
		throw exception2;
	}

	protected void setTorrentCreator(TOTorrentCreator _to_creator)
	{
		to_creator = _to_creator;
	}

	public void cancelOperation()
	{
		TOTorrentCreator temp = to_creator;
		if (temp != null)
			temp.cancel();
	}

	public void reportProgress(int percent_complete)
	{
		for (int i = 0; i < listeners.size(); i++)
			try
			{
				((ShareManagerListener)listeners.get(i)).reportProgress(percent_complete);
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}

	}

	public void reportCurrentTask(String task_description)
	{
		for (int i = 0; i < listeners.size(); i++)
			try
			{
				((ShareManagerListener)listeners.get(i)).reportCurrentTask(task_description);
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}

	}

	protected void reportError(Throwable e)
	{
		String message = e.getMessage();
		if (message != null)
			reportCurrentTask(Debug.getNestedExceptionMessage(e));
		else
			reportCurrentTask(e.toString());
	}

	public void addListener(ShareManagerListener l)
	{
		listeners.add(l);
	}

	public void removeListener(ShareManagerListener l)
	{
		listeners.remove(l);
	}

	public void generate(IndentWriter writer)
	{
		writer.println("Shares");
		writer.indent();
		ShareResource shares[] = getShares();
		HashSet share_map = new HashSet();
		for (int i = 0; i < shares.length; i++)
		{
			ShareResource share = shares[i];
			if (share instanceof ShareResourceDirContents)
			{
				share_map.add(share);
				continue;
			}
			if (share.getParent() == null)
				writer.println(getDebugName(share));
		}

		Iterator it = share_map.iterator();
		TorrentManager tm = AzureusCoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getTorrentManager();
		org.gudy.azureus2.plugins.torrent.TorrentAttribute category_attribute = tm.getAttribute("Category");
		org.gudy.azureus2.plugins.torrent.TorrentAttribute props_attribute = tm.getAttribute("ShareProperties");
		ShareResourceDirContents root;
		for (; it.hasNext(); generate(writer, root))
		{
			root = (ShareResourceDirContents)it.next();
			String cat = root.getAttribute(category_attribute);
			String props = root.getAttribute(props_attribute);
			String extra = cat != null ? (new StringBuilder()).append(",cat=").append(cat).toString() : "";
			extra = (new StringBuilder()).append(extra).append(props != null ? (new StringBuilder()).append(",props=").append(props).toString() : "").toString();
			extra = (new StringBuilder()).append(extra).append(",rec=").append(root.isRecursive()).toString();
			writer.println((new StringBuilder()).append(root.getName()).append(extra).toString());
		}

		writer.exdent();
		break MISSING_BLOCK_LABEL_345;
		Exception exception;
		exception;
		writer.exdent();
		throw exception;
	}

	protected void generate(IndentWriter writer, ShareResourceDirContents node)
	{
		writer.indent();
		ShareResource kids[] = node.getChildren();
		for (int i = 0; i < kids.length; i++)
		{
			ShareResource kid = kids[i];
			writer.println(getDebugName(kid));
			if (kid instanceof ShareResourceDirContents)
				generate(writer, (ShareResourceDirContents)kid);
		}

		writer.exdent();
		break MISSING_BLOCK_LABEL_77;
		Exception exception;
		exception;
		writer.exdent();
		throw exception;
	}

	protected String getDebugName(ShareResource _share)
	{
		Torrent torrent = null;
		try
		{
			if (_share instanceof ShareResourceFile)
			{
				ShareResourceFile share = (ShareResourceFile)_share;
				torrent = share.getItem().getTorrent();
			} else
			if (_share instanceof ShareResourceDir)
			{
				ShareResourceDir share = (ShareResourceDir)_share;
				torrent = share.getItem().getTorrent();
			}
		}
		catch (Throwable e) { }
		if (torrent == null)
			return Debug.secretFileName(_share.getName());
		else
			return (new StringBuilder()).append(Debug.secretFileName(torrent.getName())).append("/").append(ByteFormatter.encodeString(torrent.getHash())).toString();
	}

	static 
	{
		LOGID = LogIDs.PLUGIN;
	}



}

⌨️ 快捷键说明

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