clean up and fix the possibly broken browser launcher config
This commit is contained in:
@ -3,14 +3,13 @@ package net.i2p.router.web;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import net.i2p.apps.systray.SysTray;
|
import net.i2p.apps.systray.SysTray;
|
||||||
import net.i2p.apps.systray.UrlLauncher;
|
import net.i2p.apps.systray.UrlLauncher;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.router.Router;
|
import net.i2p.router.Router;
|
||||||
|
import net.i2p.router.startup.ClientAppConfig;
|
||||||
|
|
||||||
import org.tanukisoftware.wrapper.WrapperManager;
|
import org.tanukisoftware.wrapper.WrapperManager;
|
||||||
|
|
||||||
@ -143,80 +142,22 @@ public class ConfigServiceHandler extends FormHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String NL = System.getProperty("line.separator");
|
|
||||||
private void browseOnStartup(boolean shouldLaunchBrowser) {
|
private void browseOnStartup(boolean shouldLaunchBrowser) {
|
||||||
File f = new File("clients.config");
|
List clients = ClientAppConfig.getClientApps(_context);
|
||||||
Properties p = new Properties();
|
boolean found = false;
|
||||||
try {
|
for (int cur = 0; cur < clients.size(); cur++) {
|
||||||
DataHelper.loadProps(p, f);
|
ClientAppConfig ca = (ClientAppConfig) clients.get(cur);
|
||||||
|
if (UrlLauncher.class.getName().equals(ca.className)) {
|
||||||
int i = 0;
|
ca.disabled = !shouldLaunchBrowser;
|
||||||
int launchIndex = -1;
|
found = true;
|
||||||
while (true) {
|
|
||||||
String className = p.getProperty("clientApp." + i + ".main");
|
|
||||||
if (className == null) break;
|
|
||||||
if (UrlLauncher.class.getName().equals(className)) {
|
|
||||||
launchIndex = i;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((launchIndex >= 0) && shouldLaunchBrowser)
|
|
||||||
return;
|
|
||||||
if ((launchIndex < 0) && !shouldLaunchBrowser)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (shouldLaunchBrowser) {
|
|
||||||
p.setProperty("clientApp." + i + ".main", UrlLauncher.class.getName());
|
|
||||||
p.setProperty("clientApp." + i + ".name", "BrowserLauncher");
|
|
||||||
p.setProperty("clientApp." + i + ".args", "http://localhost:7657/index.jsp");
|
|
||||||
p.setProperty("clientApp." + i + ".delay", "5");
|
|
||||||
} else {
|
|
||||||
p.remove("clientApp." + launchIndex + ".main");
|
|
||||||
p.remove("clientApp." + launchIndex + ".name");
|
|
||||||
p.remove("clientApp." + launchIndex + ".args");
|
|
||||||
p.remove("clientApp." + launchIndex + ".onBoot");
|
|
||||||
p.remove("clientApp." + launchIndex + ".delay");
|
|
||||||
|
|
||||||
i = launchIndex + 1;
|
|
||||||
while (true) {
|
|
||||||
String main = p.getProperty("clientApp." + i + ".main");
|
|
||||||
String name = p.getProperty("clientApp." + i + ".name");
|
|
||||||
String args = p.getProperty("clientApp." + i + ".args");
|
|
||||||
String boot = p.getProperty("clientApp." + i + ".onBoot");
|
|
||||||
String delay= p.getProperty("clientApp." + i + ".delay");
|
|
||||||
|
|
||||||
if (main == null) break;
|
|
||||||
|
|
||||||
p.setProperty("clientApp." + (i-1) + ".main", main);
|
|
||||||
p.setProperty("clientApp." + (i-1) + ".name", name);
|
|
||||||
p.setProperty("clientApp." + (i-1) + ".args", args);
|
|
||||||
if (boot != null)
|
|
||||||
p.setProperty("clientApp." + (i-1) + ".onBoot", boot);
|
|
||||||
if (delay != null)
|
|
||||||
p.setProperty("clientApp." + (i-1) + ".delay", delay);
|
|
||||||
|
|
||||||
p.remove("clientApp." + i + ".main");
|
|
||||||
p.remove("clientApp." + i + ".name");
|
|
||||||
p.remove("clientApp." + i + ".args");
|
|
||||||
p.remove("clientApp." + i + ".onBoot");
|
|
||||||
p.remove("clientApp." + i + ".delay");
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TreeMap sorted = new TreeMap(p);
|
|
||||||
FileWriter out = new FileWriter(f);
|
|
||||||
for (Iterator iter = sorted.keySet().iterator(); iter.hasNext(); ) {
|
|
||||||
String name = (String)iter.next();
|
|
||||||
String val = (String)sorted.get(name);
|
|
||||||
out.write(name + "=" + val + NL);
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
addFormError("Error updating the client config");
|
|
||||||
}
|
}
|
||||||
|
// releases <= 0.6.5 deleted the entry completely
|
||||||
|
if (shouldLaunchBrowser && !found) {
|
||||||
|
ClientAppConfig ca = new ClientAppConfig(UrlLauncher.class.getName(), "consoleBrowser", "http://localhost:7657", 5, false);
|
||||||
|
clients.add(ca);
|
||||||
|
}
|
||||||
|
ClientAppConfig.writeClientAppConfig(_context, clients);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user