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

📄 share.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:   Share.java

package org.gudy.azureus2.ui.console.commands;

import com.aelitis.azureus.core.AzureusCore;
import java.io.File;
import java.io.PrintStream;
import java.util.*;
import org.gudy.azureus2.core3.util.AEThread;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.PluginManager;
import org.gudy.azureus2.plugins.sharing.*;
import org.gudy.azureus2.plugins.torrent.TorrentManager;
import org.gudy.azureus2.ui.console.ConsoleInput;

// Referenced classes of package org.gudy.azureus2.ui.console.commands:
//			IConsoleCommand

public class Share extends IConsoleCommand
{

	public Share()
	{
		super("share");
	}

	public String getCommandDescriptions()
	{
		return "share <type> <path> [<properties>]\t\t\tShare a file or folder(s). Use without parameters to get a list of available options.";
	}

	public void printHelpExtra(PrintStream out, List args)
	{
		out.println("> -----");
		out.println("[share <type> <path> [<properties>]");
		out.println("type options:");
		out.println("file           Share a single file.");
		out.println("folder         Share a folder as a single multi-file torrent.");
		out.println("contents       Share files and sub-dirs in a folder as single and multi-file torrents.");
		out.println("rcontents      Share files and sub-dir files in a folder as separate torrents.");
		out.println("list           List the shares (path not required)");
		out.println("remove         Remove a share given its path");
		out.println("      <properties> is semicolon separated <name>=<value> list.");
		out.println("      Defined values are 'category=<cat>', 'private=<true/false>', 'dht_backup=<true/false>' and 'comment=<comment>' ('_' in <comment> are replaced with spaces)");
		out.println("          currently only 'category' can be applied to file/folder and the rest only apply to items added *after* the share has been defined");
		out.println("      For example: share contents /music category=music;private=true;comment=Great_Stuff");
		out.println("> -----");
	}

	public void execute(String commandName, ConsoleInput ci, List args)
	{
		if (args.isEmpty())
		{
			printHelp(ci.out, args);
			return;
		}
		ShareManager share_manager;
		try
		{
			share_manager = ci.azureus_core.getPluginManager().getDefaultPluginInterface().getShareManager();
		}
		catch (ShareException e)
		{
			ci.out.println((new StringBuilder()).append("ERROR: ").append(e.getMessage()).append(" ::").toString());
			Debug.printStackTrace(e);
			return;
		}
		String arg = (String)args.remove(0);
		if (args.isEmpty() && "list".equalsIgnoreCase(arg))
		{
			ShareResource shares[] = share_manager.getShares();
			if (shares.length == 0)
			{
				ci.out.println("> No shares found");
			} else
			{
				HashSet share_map = new HashSet();
				int share_num = 0;
				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)
						ci.out.println((new StringBuilder()).append("> ").append(share_num++).append(": ").append(shares[i].getName()).toString());
				}

				Iterator it = share_map.iterator();
				TorrentManager tm = ci.azureus_core.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(); outputChildren(ci, "    ", 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();
					ci.out.println((new StringBuilder()).append("> ").append(share_num++).append(": ").append(root.getName()).append(extra).toString());
				}

			}
			return;
		}
		File path = new File((String)args.get(0));
		if (!path.exists())
		{
			ci.out.println((new StringBuilder()).append("ERROR: path [").append(path).append("] does not exist.").toString());
			return;
		}
		if ("remove".equalsIgnoreCase(arg))
		{
			ShareResource shares[] = share_manager.getShares();
			boolean done = false;
			int i = 0;
			do
			{
				if (i >= shares.length)
					break;
				if (shares[i].getName().equals(path.toString()))
				{
					try
					{
						shares[i].delete();
						ci.out.println((new StringBuilder()).append("> Share ").append(path.toString()).append(" removed").toString());
						done = true;
					}
					catch (Throwable e)
					{
						ci.out.println((new StringBuilder()).append("ERROR: ").append(e.getMessage()).append(" ::").toString());
						Debug.printStackTrace(e);
					}
					break;
				}
				i++;
			} while (true);
			if (!done)
				ci.out.println((new StringBuilder()).append("> Share ").append(path.toString()).append(" not found").toString());
			return;
		}
		String category = null;
		String props = null;
		if (args.size() == 2)
		{
			String properties = (String)args.get(1);
			for (StringTokenizer tok = new StringTokenizer(properties, ";"); tok.hasMoreTokens();)
			{
				String token = tok.nextToken();
				int pos = token.indexOf('=');
				if (pos == -1)
				{
					ci.out.println((new StringBuilder()).append("ERROR: invalid properties string '").append(properties).append("'").toString());
					return;
				}
				String lhs = token.substring(0, pos).trim().toLowerCase();
				String rhs = token.substring(pos + 1).trim();
				if (lhs.equals("category"))
					category = rhs;
				else
				if (lhs.equals("private") || lhs.equals("dht_backup") || lhs.equals("comment"))
				{
					if (props == null)
						props = "";
					if (lhs.equals("comment"))
						rhs = rhs.replace('_', ' ');
					if (rhs.length() > 0)
						props = (new StringBuilder()).append(props).append(props.length() != 0 ? ";" : "").append(lhs).append("=").append(rhs).toString();
				} else
				{
					ci.out.println((new StringBuilder()).append("ERROR: invalid properties string '").append(properties).append("'").toString());
					return;
				}
			}

		}
		String f_category = category;
		String f_props = props;
		(new AEThread(f_props) {

			final ShareManager val$share_manager;
			final File val$path;
			final String val$arg;
			final ConsoleInput val$ci;
			final String val$f_category;
			final String val$f_props;
			final Share this$0;

			public void runSupport()
			{
				try
				{
					ShareResource resource = share_manager.getShare(path);
					if ("file".equalsIgnoreCase(arg))
					{
						ci.out.println((new StringBuilder()).append("File [").append(path).append("] share being processed in background...").toString());
						if (resource == null)
							resource = share_manager.addFile(path);
					} else
					if ("folder".equalsIgnoreCase(arg))
					{
						ci.out.println((new StringBuilder()).append("Folder [").append(path).append("] share being processed in background...").toString());
						if (resource == null)
							resource = share_manager.addDir(path);
					} else
					if ("contents".equalsIgnoreCase(arg))
					{
						ci.out.println((new StringBuilder()).append("Folder contents [").append(path).append("] share being processed in background...").toString());
						if (resource == null)
							resource = share_manager.addDirContents(path, false);
					} else
					if ("rcontents".equalsIgnoreCase(arg))
					{
						ci.out.println((new StringBuilder()).append("Folder contents recursive [").append(path).append("] share being processed in background...").toString());
						if (resource == null)
							resource = share_manager.addDirContents(path, true);
					} else
					{
						ci.out.println((new StringBuilder()).append("ERROR: type '").append(arg).append("' unknown.").toString());
					}
					if (resource != null)
					{
						TorrentManager tm = ci.azureus_core.getPluginManager().getDefaultPluginInterface().getTorrentManager();
						String cat = f_category;
						if (cat != null)
						{
							if (cat.length() == 0)
								cat = null;
							resource.setAttribute(tm.getAttribute("Category"), cat);
						}
						String pro = f_props;
						if (pro != null)
						{
							if (pro.length() == 0)
								pro = null;
							resource.setAttribute(tm.getAttribute("ShareProperties"), pro);
						}
					}
					if (resource != null)
						ci.out.println("... processing complete");
				}
				catch (Throwable e)
				{
					ci.out.println((new StringBuilder()).append("ERROR: ").append(e.getMessage()).append(" ::").toString());
					Debug.printStackTrace(e);
				}
			}

			
			{
				this$0 = Share.this;
				share_manager = sharemanager;
				path = file;
				arg = s;
				ci = consoleinput;
				f_category = s1;
				f_props = s2;
				super(x0);
			}
		}).start();
	}

	protected void outputChildren(ConsoleInput ci, String indent, ShareResourceDirContents node)
	{
		ShareResource kids[] = node.getChildren();
		for (int i = 0; i < kids.length; i++)
		{
			ShareResource kid = kids[i];
			ci.out.println((new StringBuilder()).append(indent).append(kid.getName()).toString());
			if (kid instanceof ShareResourceDirContents)
				outputChildren(ci, (new StringBuilder()).append(indent).append("    ").toString(), (ShareResourceDirContents)kid);
		}

	}
}

⌨️ 快捷键说明

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