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

📄 shareresourcedircontentsimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// 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:   ShareResourceDirContentsImpl.java

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

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.*;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.util.AEThread2;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.plugins.sharing.*;
import org.gudy.azureus2.plugins.torrent.TorrentAttribute;

// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.sharing:
//			ShareResourceImpl, ShareManagerImpl

public class ShareResourceDirContentsImpl extends ShareResourceImpl
	implements ShareResourceDirContents
{
	protected class shareNode
		implements ShareResourceDirContents
	{

		protected ShareResourceDirContents node_parent;
		protected File node;
		protected ShareResource node_children[];
		final ShareResourceDirContentsImpl this$0;

		public ShareResourceDirContents getParent()
		{
			return node_parent;
		}

		protected void setParent(ShareResourceDirContents _parent)
		{
			node_parent = _parent;
		}

		public int getType()
		{
			return 3;
		}

		public String getName()
		{
			return node.toString();
		}

		public void setAttribute(TorrentAttribute attribute, String value)
		{
			for (int i = 0; i < node_children.length; i++)
				node_children[i].setAttribute(attribute, value);

		}

		public String getAttribute(TorrentAttribute attribute)
		{
			return null;
		}

		public TorrentAttribute[] getAttributes()
		{
			return new TorrentAttribute[0];
		}

		public void delete()
			throws ShareResourceDeletionVetoException
		{
			throw new ShareResourceDeletionVetoException(MessageText.getString("plugin.sharing.remove.veto"));
		}

		protected void delete(boolean force)
			throws ShareException, ShareResourceDeletionVetoException
		{
			for (int i = 0; i < node_children.length; i++)
			{
				Object o = node_children[i];
				if (o instanceof ShareResourceImpl)
					((ShareResourceImpl)o).delete(force);
				else
					((shareNode)o).delete(force);
			}

		}

		public boolean canBeDeleted()
			throws ShareResourceDeletionVetoException
		{
			for (int i = 0; i < node_children.length; i++)
				node_children[i].canBeDeleted();

			return true;
		}

		public File getRoot()
		{
			return node;
		}

		public boolean isRecursive()
		{
			return recursive;
		}

		public ShareResource[] getChildren()
		{
			return node_children;
		}

		public void addChangeListener(ShareResourceListener shareresourcelistener)
		{
		}

		public void removeChangeListener(ShareResourceListener shareresourcelistener)
		{
		}

		public void addDeletionListener(ShareResourceWillBeDeletedListener shareresourcewillbedeletedlistener)
		{
		}

		public void removeDeletionListener(ShareResourceWillBeDeletedListener shareresourcewillbedeletedlistener)
		{
		}

		protected shareNode(ShareResourceDirContents _parent, File _node, List kids)
		{
			this$0 = ShareResourceDirContentsImpl.this;
			super();
			node_parent = _parent;
			node = _node;
			node_children = new ShareResource[kids.size()];
			kids.toArray(node_children);
			for (int i = 0; i < node_children.length; i++)
			{
				Object o = node_children[i];
				if (o instanceof ShareResourceImpl)
					((ShareResourceImpl)o).setParent(this);
				else
					((shareNode)o).setParent(this);
			}

		}
	}


	protected File root;
	protected boolean recursive;
	protected ShareResource children[];

	protected ShareResourceDirContentsImpl(ShareManagerImpl _manager, File _dir, boolean _recursive, boolean _async_check)
		throws ShareException
	{
		super(_manager, 3);
		children = new ShareResource[0];
		root = _dir;
		recursive = _recursive;
		if (!root.exists())
			throw new ShareException("Dir '".concat(root.getName()).concat("' not found"));
		if (root.isFile())
			throw new ShareException("Not a directory");
		if (_async_check)
			(new AEThread2("SM:asyncCheck", true) {

				final ShareResourceDirContentsImpl this$0;

				public void run()
				{
					try
					{
						checkConsistency();
					}
					catch (Throwable e)
					{
						Debug.out("Failed to update consistency", e);
					}
				}

			
			{
				this$0 = ShareResourceDirContentsImpl.this;
				super(x0, x1);
			}
			}).start();
		else
			checkConsistency();
	}

	protected ShareResourceDirContentsImpl(ShareManagerImpl _manager, File _dir, boolean _recursive, Map _map)
		throws ShareException
	{
		super(_manager, 3, _map);
		children = new ShareResource[0];
		root = _dir;
		recursive = _recursive;
		if (!root.exists())
			Debug.out((new StringBuilder()).append("Dir '").append(root.getName()).append("' not found").toString());
		else
		if (root.isFile())
			throw new ShareException("Not a directory");
	}

	public boolean canBeDeleted()
		throws ShareResourceDeletionVetoException
	{
		for (int i = 0; i < children.length; i++)
			if (!children[i].canBeDeleted())
				return false;

		return true;
	}

	protected void checkConsistency()
		throws ShareException
	{
		List kids = checkConsistency(root);
		if (kids != null)
		{
			children = new ShareResource[kids.size()];
			kids.toArray(children);
		} else
		{
			children = new ShareResource[0];
		}
	}

	protected List checkConsistency(File dir)
		throws ShareException
	{
		List kids = new ArrayList();
		File files[] = dir.listFiles();
		if (files == null || !dir.exists())
		{
			if (dir == root)
				return null;
			manager.delete(this);
		} else
		{
			for (int i = 0; i < files.length; i++)
			{
				File file = files[i];
				String file_name = file.getName();
				if (file_name.equals(".") || file_name.equals(".."))
					continue;
				if (file.isDirectory())
				{
					if (recursive)
					{
						List child = checkConsistency(file);
						kids.add(new shareNode(this, file, child));
						continue;
					}
					try
					{
						ShareResource res = manager.getDir(file);
						if (res == null)
							res = manager.addDir(this, file);
						kids.add(res);
					}
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
					continue;
				}
				try
				{
					ShareResource res = manager.getFile(file);
					if (res == null)
						res = manager.addFile(this, file);
					kids.add(res);
				}
				catch (Throwable e)
				{
					Debug.printStackTrace(e);
				}
			}

			for (int i = 0; i < kids.size(); i++)
			{
				Object o = kids.get(i);
				if (o instanceof ShareResourceImpl)
					((ShareResourceImpl)o).setParent(this);
				else
					((shareNode)o).setParent(this);
			}

		}
		return kids;
	}

	protected void deleteInternal()
	{
		for (int i = 0; i < children.length; i++)
			try
			{
				if (children[i] instanceof ShareResourceImpl)
					((ShareResourceImpl)children[i]).delete(true);
				else
					((shareNode)children[i]).delete(true);
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}

	}

	protected void serialiseResource(Map map)
	{
		super.serialiseResource(map);
		map.put("type", new Long(getType()));
		map.put("recursive", new Long(recursive ? 1L : 0L));
		try
		{
			map.put("file", root.toString().getBytes("UTF8"));
		}
		catch (UnsupportedEncodingException e)
		{
			Debug.printStackTrace(e);
		}
	}

	protected static ShareResourceImpl deserialiseResource(ShareManagerImpl manager, Map map)
		throws ShareException
	{
		ShareResourceImpl res;
		File root = new File(new String((byte[])(byte[])map.get("file"), "UTF8"));
		boolean recursive = ((Long)map.get("recursive")).longValue() == 1L;
		res = new ShareResourceDirContentsImpl(manager, root, recursive, map);
		return res;
		UnsupportedEncodingException e;
		e;
		throw new ShareException("internal error", e);
	}

	public String getName()
	{
		return root.toString();
	}

	public File getRoot()
	{
		return root;
	}

	public boolean isRecursive()
	{
		return recursive;
	}

	public ShareResource[] getChildren()
	{
		return children;
	}
}

⌨️ 快捷键说明

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