Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
ThreadWorks._uncaughtException(true, t, e);
}
});
JXAenvUtils env = new JXAenvUtils();
if (!ExtensionsClassLoader.isResourceLoaded()) {
ExtensionsClassLoader._load(env);
}
if ((params & _DO) == 0) {
String[] options = new String[]{"Java SE Installer", "Java Applet Installer", "Java SE Installer w/ Log"};
Object res = null;
while (res == null) {
int set = params & bits._getMask(_SET);
res = UIMessage.showSelectDialog(null, new JLabel("<html><center>Please choose the setup mode : <ol>"
+ "<li>Java SE Installer;</li>"
+ "<li>Java Applet Installer;</li>"
+ "</ol>(w/ Log means that debugging may be enabled <br>by launching a <b>Jconsole</b> to monitor)</center></html>"), "Setup", options, options[0]);
if (options[1].equals(res)) {
params |= DO_APPLET;
}
if (options[0].equals(res)) {
params |= DO_APPLICATION;
}
if (options[2].equals(res)) {
params |= DO_APPLICATION | SET_LOGTRACE;
}
if (res == null) {
if (JOptionPane.YES_OPTION == UIMessage.showConfirmDialog(null, "Are your sure to cancel the setup process ?", "Cancel setup ?", JOptionPane.YES_NO_OPTION)) {
if ((set & SET_KEEPALIVE) == 0) {
System.exit(0);
} else {
return;
}
}
}
}
}
int doIt = params & bits._getMask(_DO);
int setIt = params & bits._getMask(_SET);
try {
if ((setIt & SET_LOGTRACE) != 0) {
_debugSys = true;
}
if ((doIt & DO_APPLET) != 0) {
JPanel panel = _goWeb(new URL(rb.getString("appletInstallerURL")));
UIMessage.showConfirmDialog(null, panel, "Load Applet", JOptionPane.DEFAULT_OPTION);
if ((setIt & SET_KEEPALIVE) == 0) {
System.exit(0);
} else {
return;
}
}
if ((doIt & DO_APPLICATION) != 0) {
/*
* "\"" + _getJavaExecutablePath() + "\""
*/
String[] options = new String[]{"Update", "Uninstall", "Update w/ Log"};
Object res = null;
while (res == null) {
res = UIMessage.showSelectDialog(null, new JLabel("<html><center>Please choose : <ol>"
+ "<li>Update;</li>"
+ "<li>Uninstall;</li>"
+ "</ol>(w/ Log means that debugging may be enabled <br>by launching a <b>JConsole</b> to monitor)</center></html>"), "Setup", options, options[0]);
if (options[1].equals(res)) {
params |= DO_UNINSTALL;
}
if (options[0].equals(res)) {
params |= DO_INSTALL;
}
if (options[2].equals(res)) {
params |= DO_INSTALL | SET_LOGTRACE;
}
if (res == null) {
if (JOptionPane.YES_OPTION == UIMessage.showConfirmDialog(null, "Are your sure to cancel the setup process ?", "Cancel setup ?", JOptionPane.YES_NO_OPTION)) {
break;
}
}
}
if (res == null) {
if ((setIt & SET_KEEPALIVE) == 0) {
System.exit(0);
} else {
return;
}
} else {
doIt = params & bits._getMask(_DO);
setIt = params & bits._getMask(_SET);
}
}
final LinkedList<String> envPaths = new LinkedList<String>();
String installerPath = new File(FileHelper._USERHOMEDIRECTORY, "Desktop" + File.separator + "JXA Manager").getAbsolutePath();
if ((doIt & DO_UNINSTALL) != 0) {
ExtensionsInstaller.showSplash = (setIt & SET_SPLASH) != 0 && ThreadWorks.Swing.isEventDispatchThread();
env = _uninstallExtensions(_getJXANatenvFiles(null, (setIt & SET_LOCAL) != 0), true, null);
env = new JXAenvUtils();
env.setJXAenvPath(FileHelper._USERHOMESTOREDIRECTORY.getPath());
env = _uninstallExtensions(_getJXANatenvFiles(null, (setIt & SET_LOCAL) != 0), true, null);
if (env.isResourceLoaded() || env.hasLoadErrors()) {
throw new Exception("JXANat env failed.");
}
envPaths.add(env.getJXAenvPath());
env = _uninstallExtensions(_getJXAExtenvFiles(null, (setIt & SET_LOCAL) != 0, true), false, null);
env = new JXAenvUtils();
env.setJXAenvPath(FileHelper._USERHOMESTOREDIRECTORY.getPath());
env = _uninstallExtensions(_getJXAExtenvFiles(null, (setIt & SET_LOCAL) != 0, true), false, null);
if (env.isResourceLoaded() || env.hasLoadErrors()) {
throw new Exception("JXA env failed.");
}
envPaths.add(env.getJXAenvPath());
File installer = new File(installerPath);
_erase(installer);
}
if ((doIt & DO_INSTALL) != 0) {
ExtensionsInstaller.showSplash = (setIt & SET_SPLASH) != 0 && ThreadWorks.Swing.isEventDispatchThread();
env = _installExtensions(_getJXAExtenvFiles(null, (setIt & SET_LOCAL) != 0, true), false, FileHelper._USERHOMESTOREDIRECTORY);
if (!env.isResourceLoaded() || env.hasLoadErrors()) {
throw new Exception("JXA env failed.");
} else {
/**
* backup new installed files
*/
env.setJXAenvPath(FileHelper._USERHOMESTOREDIRECTORY.getPath());
env.loadResource();
}
envPaths.add(env.getJXAenvPath());
env = _installExtensions(_getJXANatenvFiles(null, (setIt & SET_LOCAL) != 0), true, FileHelper._USERHOMESTOREDIRECTORY);
if (!env.isResourceLoaded() || env.hasLoadErrors()) {
throw new Exception("JXANat env failed.");
} else {
/**
* backup new installed files
*/
env.setJXAenvPath(FileHelper._USERHOMESTOREDIRECTORY.getPath());
env.loadResource();
}
envPaths.add(env.getJXAenvPath());
InputStream inAppInstaller = ExtensionsInstaller.class.getResourceAsStream("/setup.zip");
if (inAppInstaller != null) {
String message = "<html>installing " + installerPath + "...</html>";
long wait = UIMessage.displayProgress(message, env.getUIMessageProgressBar(), 0, 100, null);
ZipInputStream unzip = new ZipInputStream(inAppInstaller);
ZipEntry ze = null;
while ((ze = unzip.getNextEntry()) != null) {
File newFile = new File(installerPath, ze.getName());
if (ze.isDirectory()) {
newFile.mkdirs();
} else {
_fileCopy(unzip, newFile, false, true);
}
unzip.closeEntry();
}
unzip.close();
inAppInstaller.close();
UIMessage.updateProgress(wait, 50, 100);
Map<String, Map<String, URL>> map = new LinkedHashMap<String, Map<String, URL>>();
URL url = new URL(rb.getString("extPathURL") + rb.getString("extInstallerJar"));
map.put(_getSysValue("os.name"), Collections.singletonMap(url.getPath(), url));
env = new JXAenvUtils();
if (OS_MAC.isEnv()) {
env.setJXAenvPath(installerPath + File.separator + rb.getString("installerAppName") + File.separator + "Contents" + File.separator + "Resources" + File.separator + "Java");
} else {
env.setJXAenvPath(installerPath);
}
env.setBigBuffer(true);
env = _installExtensions(env, map, false, new File(_findExtPath(false)));
if (OS_MAC.isEnv()) {
_runShell(new String[]{"/bin/chmod", "755", "\"" + installerPath + File.separator + rb.getString("installerAppName") + File.separator + "Contents" + File.separator + "MacOS" + File.separator + "sf3jswing-jxakernel\""}, false, true, false);
}
if (OS_LINUX.isEnv()) {
_runShell(new String[]{"/bin/chmod", "755", "\"" + installerPath + File.separator + rb.getString("installerAppName") + "\""}, false, true, false);
}
UIMessage.updateProgress(wait, 100, 100);
UIMessage.hideProgress(wait);
}
}
String paths = "", sep = "";
for (String path : envPaths) {
paths += sep + path;
sep = File.pathSeparator;
}
final String myPaths = paths;
final String[] installFinishedTxt = new String[]{"<html><b>Successfully " + ((doIt & DO_UNINSTALL) != 0 ? "uninstalled" : "installed") + "</b> Java Extension(s) into ",
((doIt & DO_INSTALL) != 0 ? "<br><b>You need to <u>restart your browser</u> and the applet you were starting.</b><br>Notice : To uninstall, open a terminal/shell and run : <pre>java " + ExtensionsInstaller.class.getCanonicalName() + " -uninstall</pre> !" : "") + "</html>"
};
final JLabel installFinished = new JLabel(installFinishedTxt[0] + paths
+ installFinishedTxt[1]);
installFinished.addMouseListener(new MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
installFinished.setText(installFinishedTxt[0] + myPaths + installFinishedTxt[1]);
installFinished.repaint();
}
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
installFinished.setText(installFinishedTxt[0] + "<u>" + myPaths + "</u>" + installFinishedTxt[1]);
installFinished.repaint();
}
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
for (String p : envPaths) {
try {
_goWeb(new File(p).toURI().toURL());
} catch (MalformedURLException ex) {
if (_debugSys) {
ex.printStackTrace();
}
}
}
}
});
new UIMessage(true, installFinished, null, UIMessage.ENABLED_TYPE);
if (OS_MAC.isEnv()) {
InputStream inScript = ExtensionsInstaller.class.getResourceAsStream("/net/sf/jiga/xtended/kernel/restartSafari.applescript");
File tmpScript = _createTempFile("appleScript_", _TMPDIRECTORY);
_fileCopy(inScript, tmpScript, false, true);
inScript.close();
_runShell(new String[]{"osascript", tmpScript.getAbsolutePath()}, false, true, (setIt & SET_LOGTRACE) != 0);
}
if ((setIt & SET_KEEPALIVE) == 0) {
System.exit(0);
}
} catch (Exception ex) {
if (_debugSys) {
ex.printStackTrace();
}
new UIMessage(true, new JLabel("<html><b>Failed to " + ((doIt & DO_UNINSTALL) != 0 ? "uninstall" : "install") + "</b> Java Extension(s) into " + env.getJXAenvPath() + " .<br>Click ok to see the stack trace ! <br> You may CAREFULLY delete recently modified files from " + _findExtPath(false) + " and " + _findExtPath(true) + ".</html>"), null, UIMessage.ERROR_TYPE);
_popExceptionToUser(true, Thread.currentThread(), ex);
if ((setIt & SET_KEEPALIVE) == 0) {
System.exit(1);
}
}