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

📄 addfind.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:   AddFind.java

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

import com.aelitis.azureus.core.AzureusCoreException;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.apache.commons.cli.*;
import org.gudy.azureus2.ui.console.ConsoleInput;
import org.pf.file.FileFinder;
import org.pf.text.StringUtil;

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

public class AddFind extends OptionsConsoleCommand
{

	public AddFind()
	{
		super("add", "a");
		OptionBuilder.withArgName("outputDir");
		OptionBuilder.withLongOpt("output");
		OptionBuilder.hasArg();
		OptionBuilder.withDescription("override default download directory");
		OptionBuilder.withType(java/io/File);
		getOptions().addOption(OptionBuilder.create('o'));
		getOptions().addOption("r", "recurse", false, "recurse sub-directories.");
		getOptions().addOption("f", "find", false, "only find files, don't add.");
		getOptions().addOption("h", "help", false, "display help about this command");
		getOptions().addOption("l", "list", false, "list previous find results");
	}

	public String getCommandDescriptions()
	{
		return "add [addoptions] [.torrent path|url]\t\ta\tAdd a download from the given .torrent file path or url. Example: 'add /path/to/the.torrent' or 'add http://www.url.com/to/the.torrent'";
	}

	public void execute(String commandName, ConsoleInput ci, CommandLine commands)
	{
		if (commands.hasOption('l'))
		{
			ci.out.println("> -----");
			showAdds(ci);
			ci.out.println("> -----");
			return;
		}
		if (commands.hasOption('h') || commands.getArgs().length == 0)
		{
			printHelp(ci.out, (String)null);
			return;
		}
		String outputDir = ".";
		if (commands.hasOption('o'))
			outputDir = commands.getOptionValue('o');
		else
			outputDir = ci.getDefaultSaveDirectory();
		File f = new File(outputDir);
		if (!f.isAbsolute())
			try
			{
				outputDir = (new File(".", outputDir)).getCanonicalPath();
			}
			catch (IOException e)
			{
				throw new AzureusCoreException((new StringBuilder()).append("exception occurred while converting directory: ./").append(outputDir).append(" to its canonical path").toString());
			}
		boolean scansubdir = commands.hasOption('r');
		boolean finding = commands.hasOption('f');
		String whatelse[] = commands.getArgs();
		for (int i = 0; i < whatelse.length; i++)
		{
			String arg = whatelse[i];
			try
			{
				new URL(arg);
				addRemote(ci, arg, outputDir);
			}
			catch (MalformedURLException e)
			{
				addLocal(ci, arg, outputDir, scansubdir, finding);
			}
		}

	}

	protected void addRemote(ConsoleInput ci, String arg, String outputDir)
	{
		ci.out.println((new StringBuilder()).append("> Starting Download of ").append(arg).append(" ...").toString());
		try
		{
			ci.downloadRemoteTorrent(arg, outputDir);
		}
		catch (Exception e)
		{
			ci.out.println((new StringBuilder()).append("An error occurred while downloading torrent: ").append(e.getMessage()).toString());
			e.printStackTrace(ci.out);
		}
	}

	protected void addLocal(ConsoleInput ci, String arg, String outputDir, boolean scansubdir, boolean finding)
	{
		arg = transformLocalArgument(arg);
		File test = new File(arg);
		if (test.exists())
		{
			if (test.isDirectory())
			{
				File toadd[] = FileFinder.findFiles(arg, "*.torrent;*.tor", scansubdir);
				if (toadd != null && toadd.length > 0)
				{
					addFiles(ci, toadd, finding, outputDir);
				} else
				{
					ci.adds = null;
					ci.out.println((new StringBuilder()).append("> Directory '").append(arg).append("' seems to contain no torrent files.").toString());
				}
			} else
			{
				ci.downloadTorrent(arg, outputDir);
				ci.out.println((new StringBuilder()).append("> '").append(arg).append("' added.").toString());
				ci.torrents.clear();
			}
			return;
		}
		String dirName;
		try
		{
			int id = Integer.parseInt(arg);
			if (ci.adds != null && ci.adds.length > id)
			{
				String torrentPath = ci.adds[id].getAbsolutePath();
				ci.downloadTorrent(torrentPath, outputDir);
				ci.out.println((new StringBuilder()).append("> '").append(torrentPath).append("' added.").toString());
				ci.torrents.clear();
			} else
			{
				ci.out.println((new StringBuilder()).append("> No such file id '").append(id).append("'. Try \"add -l\" to list available files").toString());
			}
			return;
		}
		catch (NumberFormatException e)
		{
			dirName = test.getParent();
		}
		if (dirName == null)
			dirName = ".";
		String filePattern = test.getName();
		File files[] = FileFinder.findFiles(dirName, filePattern, false);
		if (files != null && files.length > 0)
		{
			addFiles(ci, files, finding, outputDir);
		} else
		{
			ci.adds = null;
			ci.out.println((new StringBuilder()).append("> No files found. Searched for '").append(filePattern).append("' in '").append(dirName).append("'").toString());
		}
	}

	protected String transformLocalArgument(String arg)
	{
		if (arg.startsWith("~/") || arg.equals("~"))
			arg = StringUtil.current().replaceAll(arg, "~", System.getProperty("user.home"));
		return arg;
	}

	protected void addFiles(ConsoleInput ci, File toadd[], boolean finding, String outputDir)
	{
		ci.out.println("> -----");
		ci.out.println((new StringBuilder()).append("> Found ").append(toadd.length).append(" files:").toString());
		if (finding)
		{
			ci.adds = toadd;
			showAdds(ci);
		} else
		{
			for (int i = 0; i < toadd.length; i++)
			{
				ci.downloadTorrent(toadd[i].getAbsolutePath(), outputDir);
				ci.out.println((new StringBuilder()).append("> '").append(toadd[i].getAbsolutePath()).append("' added.").toString());
				ci.torrents.clear();
			}

		}
		ci.out.println("> -----");
	}

	private void showAdds(ConsoleInput ci)
	{
		if (ci.adds == null || ci.adds.length == 0)
		{
			ci.out.println("> No files found. Try \"add -f <path>\" first");
			return;
		}
		for (int i = 0; i < ci.adds.length; i++)
		{
			ci.out.print((new StringBuilder()).append(">\t").append(i).append(":\t").toString());
			try
			{
				ci.out.println(ci.adds[i].getCanonicalPath());
			}
			catch (Exception e)
			{
				ci.out.println(ci.adds[i].getAbsolutePath());
			}
		}

		ci.out.println("> To add, simply type 'add <id>'");
	}
}

⌨️ 快捷键说明

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