clean up and fix the possibly broken browser launcher config

This commit is contained in:
zzz
2009-01-02 20:09:20 +00:00
parent 908c542b40
commit d61af12867

View File

@ -3,14 +3,13 @@ package net.i2p.router.web;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
import java.util.TreeMap;
import java.util.List;
import net.i2p.apps.systray.SysTray;
import net.i2p.apps.systray.UrlLauncher;
import net.i2p.data.DataHelper;
import net.i2p.router.Router;
import net.i2p.router.startup.ClientAppConfig;
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) {
File f = new File("clients.config");
Properties p = new Properties();
try {
DataHelper.loadProps(p, f);
int i = 0;
int launchIndex = -1;
while (true) {
String className = p.getProperty("clientApp." + i + ".main");
if (className == null) break;
if (UrlLauncher.class.getName().equals(className)) {
launchIndex = i;
break;
}
i++;
List clients = ClientAppConfig.getClientApps(_context);
boolean found = false;
for (int cur = 0; cur < clients.size(); cur++) {
ClientAppConfig ca = (ClientAppConfig) clients.get(cur);
if (UrlLauncher.class.getName().equals(ca.className)) {
ca.disabled = !shouldLaunchBrowser;
found = true;
break;
}
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);
}
}