📄 main.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: Main.java
package org.gudy.azureus2.ui.common;
import com.aelitis.azureus.core.*;
import com.aelitis.azureus.launcher.Launcher;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.*;
import org.apache.commons.cli.*;
import org.apache.log4j.*;
import org.apache.log4j.varia.DenyAllFilter;
import org.gudy.azureus2.core3.config.COConfigurationManager;
// Referenced classes of package org.gudy.azureus2.ui.common:
// IUserInterface, StartServer, UIConst, UserInterfaceFactory
public class Main
{
public static class StartSocket
{
public StartSocket(String args[])
{
Socket sck;
PrintWriter pw;
sck = null;
pw = null;
System.out.println("StartSocket: passing startup args to already-running process.");
sck = new Socket("127.0.0.1", 6880);
pw = new PrintWriter(new OutputStreamWriter(sck.getOutputStream()));
StringBuffer buffer = new StringBuffer("Azureus Start Server Access;args;");
for (int i = 0; i < args.length; i++)
{
String arg = args[i].replaceAll("&", "&&").replaceAll(";", "&;");
buffer.append(arg);
buffer.append(';');
}
pw.println(buffer.toString());
pw.flush();
Exception e;
try
{
if (pw != null)
pw.close();
}
// Misplaced declaration of an exception variable
catch (Exception e) { }
try
{
if (sck != null)
sck.close();
}
// Misplaced declaration of an exception variable
catch (Exception e) { }
break MISSING_BLOCK_LABEL_220;
e;
e.printStackTrace();
try
{
if (pw != null)
pw.close();
}
// Misplaced declaration of an exception variable
catch (Exception e) { }
try
{
if (sck != null)
sck.close();
}
// Misplaced declaration of an exception variable
catch (Exception e) { }
break MISSING_BLOCK_LABEL_220;
Exception exception;
exception;
try
{
if (pw != null)
pw.close();
}
catch (Exception e) { }
try
{
if (sck != null)
sck.close();
}
catch (Exception e) { }
throw exception;
}
}
public static String DEFAULT_UI = "swt";
public static StartServer start = null;
protected static AzureusCore core;
public Main()
{
}
private static CommandLine parseCommands(String args[], boolean constart)
{
if (args == null)
return null;
CommandLineParser parser = new PosixParser();
Options options = new Options();
options.addOption("h", "help", false, "Show this help.");
OptionBuilder.withLongOpt("exec");
OptionBuilder.hasArg();
OptionBuilder.withArgName("file");
OptionBuilder.withDescription("Execute script file. The file should end with 'logout', otherwise the parser thread doesn't stop.");
options.addOption(OptionBuilder.create('e'));
OptionBuilder.withLongOpt("command");
OptionBuilder.hasArg();
OptionBuilder.withArgName("command");
OptionBuilder.withDescription("Execute single script command. Try '-c help' for help on commands.");
options.addOption(OptionBuilder.create('c'));
OptionBuilder.withLongOpt("ui");
OptionBuilder.withDescription("Run <uis>. ',' separated list of user interfaces to run. The first one given will respond to requests without determinable source UI (e.g. further torrents added via command line).");
OptionBuilder.withArgName("uis");
OptionBuilder.hasArg();
options.addOption(OptionBuilder.create('u'));
CommandLine commands = null;
try
{
commands = parser.parse(options, args, true);
}
catch (ParseException exp)
{
Logger.getLogger("azureus2").error((new StringBuilder()).append("Parsing failed. Reason: ").append(exp.getMessage()).toString(), exp);
if (constart)
System.exit(2);
}
if (commands.hasOption('h') && constart)
{
HelpFormatter hf = new HelpFormatter();
hf.printHelp("java org.gudy.azureus2.ui.common.Main", "Optionally you can put torrent files to add to the end of the command line.\r\n", options, "Available User Interfaces: swt (default), web, console\r\nThe default interface is not started if you give either the '-e' or '-c' option (But you can start it by hand with '-u').", true);
System.exit(0);
}
return commands;
}
public static void initRootLogger()
{
if (Logger.getRootLogger().getAppender("ConsoleAppender") == null)
{
Appender app = new ConsoleAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"));
app.setName("ConsoleAppender");
app.addFilter(new DenyAllFilter());
Logger.getRootLogger().addAppender(app);
}
}
public static void main(String args[])
{
boolean mi;
if (Launcher.checkAndLaunch(org/gudy/azureus2/ui/common/Main, args))
return;
COConfigurationManager.preInitialise();
String mi_str = System.getProperty("MULTI_INSTANCE");
mi = mi_str != null && mi_str.equalsIgnoreCase("true");
initRootLogger();
CommandLine commands;
commands = parseCommands(args, true);
if (commands != null && directLaunch(args, commands))
return;
if (mi)
{
System.out.println("MULTI_INSTANCE enabled");
core = AzureusCoreFactory.create();
processArgs(args, core, commands);
return;
}
try
{
start = new StartServer();
if (start == null || start.getServerState() == 0)
{
new StartSocket(args);
} else
{
core = AzureusCoreFactory.create();
start.start();
processArgs(args, core, commands);
}
}
catch (AzureusCoreException e)
{
System.out.println("Start fails:");
e.printStackTrace();
}
return;
}
public static void shutdown()
{
if (start != null)
start.stopIt();
if (core != null)
try
{
core.stop();
}
catch (AzureusCoreException e)
{
System.out.println("Stop fails:");
e.printStackTrace();
}
SimpleDateFormat temp = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Logger.getLogger("azureus2").fatal((new StringBuilder()).append("Azureus stopped at ").append(temp.format(new Date())).toString());
}
public static boolean directLaunch(String args[], CommandLine commands)
{
if (commands.hasOption('u'))
{
String uinames = commands.getOptionValue('u');
if (uinames.indexOf(',') != -1)
return false;
if (!uinames.equalsIgnoreCase(DEFAULT_UI))
return false;
}
String uiclass = (new StringBuilder()).append("org.gudy.azureus2.ui.").append(DEFAULT_UI).append(".Main").toString();
Class main_class = Class.forName(uiclass);
Method main_method = main_class.getMethod("main", new Class[] {
[Ljava/lang/String;
});
main_method.invoke(null, new Object[] {
commands.getArgs()
});
return true;
Throwable e;
e;
e.printStackTrace();
return false;
}
public static void processArgs(String args[], AzureusCore new_core, CommandLine commands)
{
if (commands == null)
commands = parseCommands(args, false);
if (commands != null && args.length > 0 || new_core != null)
{
if (UIConst.UIS == null)
UIConst.UIS = new HashMap();
if (commands.hasOption('u'))
{
String uinames = commands.getOptionValue('u');
if (uinames.indexOf(',') == -1)
{
if (!UIConst.UIS.containsKey(uinames))
UIConst.UIS.put(uinames, UserInterfaceFactory.getUI(uinames));
} else
{
StringTokenizer stok = new StringTokenizer(uinames, ",");
do
{
if (!stok.hasMoreTokens())
break;
String uin = stok.nextToken();
if (!UIConst.UIS.containsKey(uin))
UIConst.UIS.put(uin, UserInterfaceFactory.getUI(uin));
} while (true);
}
} else
if (UIConst.UIS.isEmpty() && !commands.hasOption('c') && !commands.hasOption('e'))
UIConst.UIS.put(DEFAULT_UI, UserInterfaceFactory.getUI(DEFAULT_UI));
Iterator uis = UIConst.UIS.values().iterator();
boolean isFirst = true;
String theRest[] = commands.getArgs();
while (uis.hasNext())
{
IUserInterface ui = (IUserInterface)uis.next();
ui.init(isFirst, UIConst.UIS.size() > 1);
theRest = ui.processArgs(theRest);
isFirst = false;
}
if (new_core != null)
{
SimpleDateFormat temp = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
UIConst.startTime = new Date();
Logger.getLogger("azureus2").fatal((new StringBuilder()).append("Azureus started at ").append(temp.format(UIConst.startTime)).toString());
UIConst.setAzureusCore(new_core);
}
for (uis = UIConst.UIS.values().iterator(); uis.hasNext(); ((IUserInterface)uis.next()).startUI());
Constructor conConsoleInput = null;
try
{
Class clConsoleInput = Class.forName("org.gudy.azureus2.ui.console.ConsoleInput");
Class params[] = {
java/lang/String, com/aelitis/azureus/core/AzureusCore, java/io/Reader, java/io/PrintStream, java/lang/Boolean
};
conConsoleInput = clConsoleInput.getConstructor(params);
}
catch (Exception e)
{
e.printStackTrace();
}
if (commands.hasOption('e'))
if (conConsoleInput != null)
try
{
Object params[] = {
commands.getOptionValue('e'), new_core, new FileReader(commands.getOptionValue('e')), System.out, Boolean.FALSE
};
conConsoleInput.newInstance(params);
}
catch (FileNotFoundException e)
{
Logger.getLogger("azureus2").error((new StringBuilder()).append("Script file not found: ").append(e.toString()).toString());
}
catch (Exception e)
{
Logger.getLogger("azureus2").error((new StringBuilder()).append("Error invocating the script processor: ").append(e.toString()).toString());
}
else
Logger.getLogger("azureus2").error("ConsoleInput class not found. You need the console ui package to use '-e'");
if (commands.hasOption('c'))
if (conConsoleInput != null)
{
String comm = commands.getOptionValue('c');
comm = (new StringBuilder()).append(comm).append("\nlogout\n").toString();
Object params[] = {
commands.getOptionValue('c'), UIConst.getAzureusCore(), new StringReader(comm), System.out, Boolean.FALSE
};
try
{
conConsoleInput.newInstance(params);
}
catch (Exception e)
{
Logger.getLogger("azureus2").error((new StringBuilder()).append("Error invocating the script processor: ").append(e.toString()).toString());
}
} else
{
Logger.getLogger("azureus2").error("ConsoleInput class not found. You need the console ui package to use '-e'");
}
openTorrents(theRest);
} else
{
Logger.getLogger("azureus2").error("No commands to process");
}
}
public static void openTorrents(String torrents[])
{
if (UIConst.UIS != null && !UIConst.UIS.isEmpty() && torrents.length > 0)
{
for (int l = 0; l < torrents.length; l++)
((IUserInterface)UIConst.UIS.values().toArray()[0]).openTorrent(torrents[l]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -