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

📄 startserver.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:   StartServer.java

package org.gudy.azureus2.ui.swt;

import com.aelitis.azureus.core.*;
import com.aelitis.azureus.ui.UIFunctions;
import com.aelitis.azureus.ui.UIFunctionsManager;
import com.aelitis.azureus.ui.swt.UIFunctionsSWT;
import java.io.*;
import java.net.*;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.ui.swt.mainwindow.TorrentOpener;
import org.gudy.azureus2.ui.swt.sharing.ShareUtils;

public class StartServer
{

	private static final LogIDs LOGID;
	private ServerSocket socket;
	private int state;
	private boolean bContinue;
	public static final int STATE_FAULTY = 0;
	public static final int STATE_LISTENING = 1;
	protected List queued_torrents;
	protected boolean core_started;
	protected AEMonitor this_mon;

	public StartServer()
	{
		queued_torrents = new ArrayList();
		core_started = false;
		this_mon = new AEMonitor("StartServer");
		try
		{
			socket = new ServerSocket(6880, 50, InetAddress.getByName("127.0.0.1"));
			state = 1;
			if (Logger.isEnabled())
				Logger.log(new LogEvent(LOGID, "StartServer: listening on 127.0.0.1:6880 for passed torrent info"));
		}
		catch (Throwable t)
		{
			state = 0;
			String reason = t.getMessage() != null ? t.getMessage() : "<>";
			System.out.println((new StringBuilder()).append("StartServer ERROR: unable to bind to 127.0.0.1:6880 listening for passed torrent info: ").append(reason).toString());
		}
	}

	public void pollForConnections(final AzureusCore azureus_core)
	{
		azureus_core.addLifecycleListener(new AzureusCoreLifecycleAdapter() {

			final AzureusCore val$azureus_core;
			final StartServer this$0;

			public void componentCreated(AzureusCore core, AzureusCoreComponent component)
			{
				if (component instanceof UIFunctionsSWT)
					openQueuedTorrents(azureus_core);
			}

			
			{
				this$0 = StartServer.this;
				azureus_core = azureuscore;
				super();
			}
		});
		if (socket != null)
		{
			Thread t = new AEThread(azureus_core) {

				final AzureusCore val$azureus_core;
				final StartServer this$0;

				public void runSupport()
				{
					pollForConnectionsSupport(azureus_core);
				}

			
			{
				this$0 = StartServer.this;
				azureus_core = azureuscore;
				super(x0);
			}
			};
			t.setDaemon(true);
			t.start();
		}
	}

	private void pollForConnectionsSupport(AzureusCore azureus_core)
	{
		bContinue = true;
_L2:
		BufferedReader br;
		if (!bContinue)
			break; /* Loop/switch isn't completed */
		br = null;
		Socket sck = socket.accept();
		String address = sck.getInetAddress().getHostAddress();
		if (address.equals("localhost") || address.equals("127.0.0.1"))
		{
			br = new BufferedReader(new InputStreamReader(sck.getInputStream(), "UTF8"));
			String line = br.readLine();
			if (Logger.isEnabled())
				Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("Main::startServer: received '").append(line).append("'").toString()));
			if (line != null)
			{
				String args[] = parseArgs(line);
				if (args != null && args.length > 0)
				{
					String debug_str = args[0];
					for (int i = 1; i < args.length; i++)
						debug_str = (new StringBuilder()).append(debug_str).append(" ; ").append(args[i]).toString();

					Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("Main::startServer: decoded to '").append(debug_str).append("'").toString()));
					processArgs(azureus_core, args);
				}
			}
		}
		sck.close();
		Exception e;
		try
		{
			if (br != null)
				br.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		continue; /* Loop/switch isn't completed */
		e;
		if (!(e instanceof SocketException))
			Debug.printStackTrace(e);
		try
		{
			if (br != null)
				br.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		if (true) goto _L2; else goto _L1
		Exception exception;
		exception;
		try
		{
			if (br != null)
				br.close();
		}
		catch (Exception e) { }
		throw exception;
_L1:
	}

	private static String[] parseArgs(String line)
	{
		if (!line.startsWith("Azureus Start Server Access;"))
			return null;
		ArrayList parts = new ArrayList();
		StringBuffer buf = new StringBuffer();
		boolean escape_mode = false;
		for (int i = "Azureus Start Server Access".length() + 1; i < line.length(); i++)
		{
			char c = line.charAt(i);
			if (escape_mode)
			{
				buf.append(c);
				escape_mode = false;
				continue;
			}
			if (c == '&')
			{
				escape_mode = true;
				continue;
			}
			if (c == ';')
			{
				parts.add(buf.toString());
				buf.setLength(0);
			} else
			{
				buf.append(c);
			}
		}

		if (buf.length() > 0)
			parts.add(buf.toString());
		return (String[])(String[])parts.toArray(new String[parts.size()]);
	}

	protected void processArgs(AzureusCore azureus_core, String args[])
	{
		boolean open;
		int i;
		if (args.length < 1 || !args[0].equals("args"))
			return;
		if (args.length == 1 || !COConfigurationManager.getBooleanParameter("add_torrents_silently"))
			showMainWindow();
		open = true;
		i = 1;
_L3:
		if (i >= args.length) goto _L2; else goto _L1
_L1:
		String file_name;
		boolean queued;
		String arg = args[i];
		if (i == 1)
		{
			if (arg.equalsIgnoreCase("--closedown"))
			{
				UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
				if (uiFunctions != null)
					uiFunctions.dispose(false, false);
				return;
			}
			if (arg.equalsIgnoreCase("--open"))
				continue; /* Loop/switch isn't completed */
			if (arg.equalsIgnoreCase("--share"))
			{
				open = false;
				continue; /* Loop/switch isn't completed */
			}
		}
		file_name = arg;
		File file = new File(file_name);
		if (!file.exists() && !isURI(file_name))
		{
			if (file_name.length() == 40)
			{
				byte hash[] = null;
				try
				{
					hash = ByteFormatter.decodeString(file_name);
				}
				catch (Throwable e) { }
				if (hash != null && hash.length == 20)
					file_name = (new StringBuilder()).append("magnet:?xt=urn:btih:").append(Base32.encode(hash)).toString();
			}
			if (file_name.length() == 32)
			{
				byte hash[] = null;
				try
				{
					hash = Base32.decode(file_name);
				}
				catch (Throwable e) { }
				if (hash != null && hash.length == 20)
					file_name = (new StringBuilder()).append("magnet:?xt=urn:btih:").append(file_name).toString();
			}
		}
		if (isURI(file_name))
		{
			if (Logger.isEnabled())
				Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("StartServer: args[").append(i).append("] handling as a URI: ").append(file_name).toString()));
		} else
		{
			try
			{
				if (!file.exists())
					throw new Exception("File not found");
				file_name = file.getCanonicalPath();
				Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("StartServer: file = ").append(file_name).toString()));
			}
			catch (Throwable e)
			{
				Logger.log(new LogAlert(true, 3, (new StringBuilder()).append("Failed to access torrent file '").append(file_name).append("'. Ensure sufficient temporary file space ").append("available (check browser cache usage).").toString()));
			}
		}
		queued = false;
		this_mon.enter();
		if (!core_started)
		{
			queued_torrents.add(((Object) (new Object[] {
				file_name, new Boolean(open)
			})));
			queued = true;
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_512;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
		if (!queued)
			handleFile(azureus_core, file_name, open);
		i++;
		  goto _L3
_L2:
	}

	protected boolean isURI(String file_name)
	{
		String file_name_lower = file_name.toLowerCase();
		return file_name_lower.startsWith("http:") || file_name_lower.startsWith("https:") || file_name_lower.startsWith("magnet:") || file_name_lower.startsWith("dht:");
	}

	protected void handleFile(AzureusCore azureus_core, String file_name, boolean open)
	{
		try
		{
			if (open)
			{
				TorrentOpener.openTorrent(file_name);
			} else
			{
				File f = new File(file_name);
				if (f.isDirectory())
					ShareUtils.shareDir(azureus_core, file_name);
				else
					ShareUtils.shareFile(azureus_core, file_name);
			}
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
		}
	}

	protected void openQueuedTorrents(AzureusCore azureus_core)
	{
		this_mon.enter();
		core_started = true;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_32;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
		for (int i = 0; i < queued_torrents.size(); i++)
		{
			Object entry[] = (Object[])(Object[])queued_torrents.get(i);
			String file_name = (String)entry[0];
			boolean open = ((Boolean)entry[1]).booleanValue();
			handleFile(azureus_core, file_name, open);
		}

		return;
	}

	protected void showMainWindow()
	{
		UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
		if (uiFunctions != null)
			uiFunctions.bringToFront();
	}

	public void stopIt()
	{
		bContinue = false;
		try
		{
			socket.close();
		}
		catch (Throwable e) { }
	}

	public int getState()
	{
		return state;
	}

	public static void main(String args[])
	{
		String input_tests[] = {
			"a;b;c", "test", "Azureus Start Server Access;b;c;d", "Azureus Start Server Access;b;c&;d;e", "Azureus Start Server Access;b;c&&;d;e", "Azureus Start Server Access;b;c&&&;d;e"
		};
		String output_results[][] = {
			null, null, {
				"b", "c", "d"
			}, {
				"b", "c;d", "e"
			}, {
				"b", "c&", "d", "e"
			}, {
				"b", "c&;d", "e"
			}
		};
		for (int i = 0; i < input_tests.length; i++)
		{
			System.out.println((new StringBuilder()).append("Testing: ").append(input_tests[i]).toString());
			String result[] = parseArgs(input_tests[i]);
			if (result != output_results[i] && !Arrays.equals(result, output_results[i]))
			{
				System.out.println("TEST FAILED");
				System.out.println((new StringBuilder()).append("  Expected: ").append(Arrays.asList(output_results[i])).toString());
				System.out.println((new StringBuilder()).append("  Decoded : ").append(Arrays.asList(result)).toString());
				System.exit(1);
			}
		}

		System.out.println("Done.");
	}

	static 
	{
		LOGID = LogIDs.GUI;
	}

}

⌨️ 快捷键说明

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