📄 scriptbeforestartup.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: ScriptBeforeStartup.java
package org.gudy.azureus2.platform.unix;
import com.aelitis.azureus.core.impl.AzureusCoreSingleInstanceClient;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.util.*;
public class ScriptBeforeStartup
{
private static PrintStream sysout;
private static Object display;
public ScriptBeforeStartup()
{
}
public static void main(String args[])
{
System.setProperty("transitory.startup", "1");
sysout = System.out;
try
{
System.setOut(new PrintStream(new FileOutputStream("/dev/stderr")));
}
catch (FileNotFoundException e) { }
String mi_str = System.getProperty("MULTI_INSTANCE");
boolean mi = mi_str != null && mi_str.equalsIgnoreCase("true");
if (!mi)
{
boolean argsSent = (new AzureusCoreSingleInstanceClient()).sendArgs(args, 500);
if (argsSent)
{
String msg = (new StringBuilder()).append("Passing startup args to already-running ").append(Constants.APP_NAME).append(" java process listening on [127.0.0.1: 6880]").toString();
log(msg);
sysout.println("exit");
return;
}
}
String scriptAfterShutdown = COConfigurationManager.getStringParameter("scriptaftershutdown", null);
COConfigurationManager.removeParameter("scriptaftershutdown.exit");
COConfigurationManager.removeParameter("scriptaftershutdown");
COConfigurationManager.save();
if (scriptAfterShutdown != null)
{
log((new StringBuilder()).append("Script after ").append(Constants.APP_NAME).append(" shutdown did not run.. running now").toString());
sysout.println(scriptAfterShutdown);
if (scriptAfterShutdown.indexOf("$0") < 0)
{
sysout.println("echo \"Restarting Azureus..\"");
sysout.println("$0\n");
}
sysout.println("exit");
return;
}
String moz = getNewGreDir();
if (moz != null)
{
String s = (new StringBuilder()).append("export MOZILLA_FIVE_HOME=\"").append(moz).append("\"\n").append("if [ \"$LD_LIBRARY_PATH x\" = \" x\" ] ; then\n").append("\texport LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME;\n").append("else\n").append("\texport LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME:$LD_LIBRARY_PATH\n").append("fi\n").toString();
sysout.println(s);
log("setting LD_LIBRARY_PATH to: $LD_LIBRARY_PATH");
log("setting MOZILLA_FIVE_HOME to: $MOZILLA_FIVE_HOME");
} else
{
log("GRE/XULRunner automatically found");
}
}
public static String getNewGreDir()
{
String grePath = null;
String confList[] = {
"/etc/gre64.conf", "/etc/gre.d/gre64.conf", "/etc/gre.conf", "/etc/gre.d/gre.conf", "/etc/gre.d/xulrunner.conf", "/etc/gre.d/libxul0d.conf"
};
if (canOpenBrowser())
return null;
log("Auto-scanning for GRE/XULRunner. You can skip this by appending the GRE path to LD_LIBRARY_PATH and setting MOZILLA_FIVE_HOME.");
try
{
Pattern pat = Pattern.compile("GRE_PATH=(.*)", 2);
for (int i = 0; i < confList.length; i++)
{
File file = new File(confList[i]);
if (!file.isFile() || !file.canRead())
continue;
log((new StringBuilder()).append(" checking ").append(file).append(" for GRE_PATH").toString());
String fileText = FileUtil.readFileAsString(file, 16384);
if (fileText == null)
continue;
Matcher matcher = pat.matcher(fileText);
if (!matcher.find())
continue;
String possibleGrePath = matcher.group(1);
if (!isValidGrePath(new File(possibleGrePath)))
continue;
grePath = possibleGrePath;
break;
}
if (grePath == null)
{
ArrayList possibleDirs = new ArrayList();
File libDir = new File("/usr");
libDir.listFiles(new FileFilter(possibleDirs) {
final ArrayList val$possibleDirs;
public boolean accept(File pathname)
{
if (pathname.getName().startsWith("lib"))
possibleDirs.add(pathname);
return false;
}
{
possibleDirs = arraylist;
super();
}
});
possibleDirs.add(new File("/usr/local"));
possibleDirs.add(new File("/opt"));
String possibleDirNames[] = {
"mozilla", "firefox", "seamonkey", "xulrunner"
};
FileFilter ffIsPossibleDir = new FileFilter(possibleDirNames) {
final String val$possibleDirNames[];
public boolean accept(File pathname)
{
String name = pathname.getName().toLowerCase();
for (int i = 0; i < possibleDirNames.length; i++)
if (name.startsWith(possibleDirNames[i]))
return true;
return false;
}
{
possibleDirNames = as;
super();
}
};
Iterator iter = possibleDirs.iterator();
do
{
if (!iter.hasNext())
break;
File dir = (File)iter.next();
File possibleFullDirs[] = dir.listFiles(ffIsPossibleDir);
int i = 0;
do
{
if (i >= possibleFullDirs.length)
break;
log((new StringBuilder()).append(" checking ").append(possibleFullDirs[i]).append(" for GRE").toString());
if (isValidGrePath(possibleFullDirs[i]))
{
grePath = possibleFullDirs[i].getAbsolutePath();
break;
}
i++;
} while (true);
} while (grePath == null);
}
if (grePath != null)
{
log((new StringBuilder()).append("GRE found at ").append(grePath).append(".").toString());
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", grePath);
}
}
catch (Throwable t)
{
log((new StringBuilder()).append("Error trying to find suitable GRE: ").append(Debug.getNestedExceptionMessage(t)).toString());
grePath = null;
}
if (!canOpenBrowser())
log((new StringBuilder()).append("Can't create browser. Will try to set LD_LIBRARY_PATH and hope ").append(Constants.APP_NAME).append("has better luck.").toString());
return grePath;
}
private static boolean canOpenBrowser()
{
Class claDisplay = Class.forName("org.eclipse.swt.widgets.Display");
if (display != null)
display = claDisplay.newInstance();
Class claShell = Class.forName("org.eclipse.swt.widgets.Shell");
Constructor shellConstruct = claShell.getConstructor(new Class[] {
claDisplay
});
Object shell = shellConstruct.newInstance(new Object[] {
display
});
Class claBrowser = Class.forName("org.eclipse.swt.browser.Browser");
Constructor constructors[] = claBrowser.getConstructors();
int i = 0;
do
{
if (i >= constructors.length)
break;
if (constructors[i].getParameterTypes().length == 2)
{
Object browser = constructors[i].newInstance(new Object[] {
shell, new Integer(0)
});
Method methSetUrl = claBrowser.getMethod("setUrl", new Class[] {
java/lang/String
});
methSetUrl.invoke(browser, new Object[] {
"about:blank"
});
break;
}
i++;
} while (true);
Method methDisposeShell = claShell.getMethod("dispose", new Class[0]);
methDisposeShell.invoke(shell, new Object[0]);
return true;
Throwable e;
e;
log((new StringBuilder()).append("Browser check failed with: ").append(Debug.getNestedExceptionMessage(e)).toString());
return false;
}
private static boolean isValidGrePath(File dir)
{
if (!dir.isDirectory())
return false;
if ((new File(dir, "components/libwidget_gtk.so")).exists() || (new File(dir, "libwidget_gtk.so")).exists())
{
log((new StringBuilder()).append("\tCan not use GRE from ").append(dir).append(" as it's too old (GTK2 version required).").toString());
return false;
}
if (!(new File(dir, "components/libwidget_gtk2.so")).exists() && !(new File(dir, "libwidget_gtk2.so")).exists())
{
log((new StringBuilder()).append("\tCan not use GRE from ").append(dir).append(" because it's missing components/libwidget_gtk2.so.").toString());
return false;
} else
{
return true;
}
}
private static void log(String string)
{
sysout.println((new StringBuilder()).append("echo \"").append(string.replaceAll("\"", "\\\"")).append("\"").toString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -