diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java index d6f8be9a11..8b28164a1b 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java @@ -201,10 +201,7 @@ public class PluginStarter implements Runnable { File pluginUpdate = new File(ctx.getConfigDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName + "/app.xpi2p.zip" ); if(pluginUpdate.exists()) { // Compare the start time of the router with the plugin. - List contexts = RouterContext.listContexts(); - if ( (contexts == null) || (contexts.isEmpty()) ) - throw new IllegalStateException("No contexts. This is usually because the router is either starting up or shutting down."); - if(contexts.get(0).router().getWhenStarted() > pluginUpdate.lastModified()) { + if(ctx.router().getWhenStarted() > pluginUpdate.lastModified()) { if (!FileUtil.extractZip(pluginUpdate, pluginDir)) { pluginUpdate.delete(); String foo = "Plugin '" + appName + "' failed to update! File '" + pluginUpdate +"' deleted. You may need to remove and install the plugin again."; diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java index 5d69c4bfc2..f225f5fe46 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateHandler.java @@ -121,27 +121,23 @@ public class PluginUpdateHandler extends UpdateHandler { @Override protected void update() { _updated = false; - updateStatus("" + _("Downloading plugin from {0}", _xpi2pURL) + ""); if(_xpi2pURL.startsWith("file://")) { + updateStatus("" + _("Attempting to copy plugin from {0}", _xpi2pURL) + ""); // strip off "file://" String xpi2pfile = _xpi2pURL.substring(7); - if(xpi2pfile.isEmpty()) { + if(xpi2pfile.length() == 0) { // This is actually what String.isEmpty() does, so it should be safe. statusDone("" + _("No file specified {0}", _xpi2pURL) + ""); } else { - try { - // copy the contents of from to _updateFile - long alreadyTransferred = (new File(xpi2pfile)).getCanonicalFile().length(); - if(FileUtil.copy((new File(xpi2pfile)).getCanonicalPath(), _updateFile, true, false)) { - transferComplete(alreadyTransferred, alreadyTransferred, 0L, _xpi2pURL, _updateFile, false); - } else { - statusDone("" + _("File copy failed {0}", _xpi2pURL) + ""); - } - } catch (Throwable t) { - _log.error("Error copying plugin {0}", t); + // copy the contents of from to _updateFile + long alreadyTransferred = (new File(xpi2pfile)).getAbsoluteFile().length(); + if(FileUtil.copy((new File(xpi2pfile)).getAbsolutePath(), _updateFile, true, false)) { + transferComplete(alreadyTransferred, alreadyTransferred, 0L, _xpi2pURL, _updateFile, false); + } else { + statusDone("" + _("Failed to copy file {0}", _xpi2pURL) + ""); } - } } else { + updateStatus("" + _("Downloading plugin from {0}", _xpi2pURL) + ""); // use the same settings as for updater boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue(); String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST); @@ -177,6 +173,7 @@ public class PluginUpdateHandler extends UpdateHandler { @Override public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) { + boolean update = false; updateStatus("" + _("Plugin downloaded") + ""); File f = new File(_updateFile); File appDir = new SecureDirectory(_context.getConfigDir(), PLUGIN_DIR); @@ -406,7 +403,7 @@ public class PluginUpdateHandler extends UpdateHandler { _log.error("Error stopping plugin " + appName, e); } } - + update = true; } else { if (Boolean.valueOf(props.getProperty("update-only")).booleanValue()) { to.delete(); @@ -428,11 +425,10 @@ public class PluginUpdateHandler extends UpdateHandler { } _updated = true; to.delete(); - if (Boolean.valueOf(props.getProperty("dont-start-at-install")).booleanValue()) { - if (Boolean.valueOf(props.getProperty("router-restart-required")).booleanValue()) - statusDone("" + _("Plugin {0} installed, router restart required", appName) + ""); - else { - statusDone("" + _("Plugin {0} installed", appName) + ""); + // install != update. Changing the user's settings like this is probabbly a bad idea. + if (Boolean.valueOf( props.getProperty("dont-start-at-install")).booleanValue()) { + statusDone("" + _("Plugin {0} installed", appName) + ""); + if(!update) { Properties pluginProps = PluginStarter.pluginProperties(); pluginProps.setProperty(PluginStarter.PREFIX + appName + PluginStarter.ENABLED, "false"); PluginStarter.storePluginProperties(pluginProps); diff --git a/history.txt b/history.txt index 4dd034daba..1cffdfe911 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,15 @@ +2012-03-15 sponge + * Plugins: + - String.isEmpty() [ java 6 ] -> (String.length() == 0) [ java 5 ] + - for a file: URL, use "Attempting to copy plugin from" message + - s/{0}// on non-translated string + - grammar: "File copy failed {0}" -> "Failed to copy file from {0}" + - use the context provided to get startup time + - getCanonicalPath() -> getAbsolutePath() + - install != update. Don't change the user's settings, and don't restart + it on an update if "dont-start-at-install". This gives the same + functionality as before. + 2012-03-14 zzz * Blockfile, i2psnark: Remove static logs * DHSessionKeyBuilder: