forked from I2P_Developers/i2p.i2p
Plugins
This commit is contained in:
@ -201,10 +201,7 @@ public class PluginStarter implements Runnable {
|
|||||||
File pluginUpdate = new File(ctx.getConfigDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName + "/app.xpi2p.zip" );
|
File pluginUpdate = new File(ctx.getConfigDir(), PluginUpdateHandler.PLUGIN_DIR + '/' + appName + "/app.xpi2p.zip" );
|
||||||
if(pluginUpdate.exists()) {
|
if(pluginUpdate.exists()) {
|
||||||
// Compare the start time of the router with the plugin.
|
// Compare the start time of the router with the plugin.
|
||||||
List<RouterContext> contexts = RouterContext.listContexts();
|
if(ctx.router().getWhenStarted() > pluginUpdate.lastModified()) {
|
||||||
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 (!FileUtil.extractZip(pluginUpdate, pluginDir)) {
|
if (!FileUtil.extractZip(pluginUpdate, pluginDir)) {
|
||||||
pluginUpdate.delete();
|
pluginUpdate.delete();
|
||||||
String foo = "Plugin '" + appName + "' failed to update! File '" + pluginUpdate +"' deleted. You may need to remove and install the plugin again.";
|
String foo = "Plugin '" + appName + "' failed to update! File '" + pluginUpdate +"' deleted. You may need to remove and install the plugin again.";
|
||||||
|
@ -121,27 +121,23 @@ public class PluginUpdateHandler extends UpdateHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected void update() {
|
protected void update() {
|
||||||
_updated = false;
|
_updated = false;
|
||||||
updateStatus("<b>" + _("Downloading plugin from {0}", _xpi2pURL) + "</b>");
|
|
||||||
if(_xpi2pURL.startsWith("file://")) {
|
if(_xpi2pURL.startsWith("file://")) {
|
||||||
|
updateStatus("<b>" + _("Attempting to copy plugin from {0}", _xpi2pURL) + "</b>");
|
||||||
// strip off "file://"
|
// strip off "file://"
|
||||||
String xpi2pfile = _xpi2pURL.substring(7);
|
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("<b>" + _("No file specified {0}", _xpi2pURL) + "</b>");
|
statusDone("<b>" + _("No file specified {0}", _xpi2pURL) + "</b>");
|
||||||
} else {
|
} else {
|
||||||
try {
|
// copy the contents of from to _updateFile
|
||||||
// copy the contents of from to _updateFile
|
long alreadyTransferred = (new File(xpi2pfile)).getAbsoluteFile().length();
|
||||||
long alreadyTransferred = (new File(xpi2pfile)).getCanonicalFile().length();
|
if(FileUtil.copy((new File(xpi2pfile)).getAbsolutePath(), _updateFile, true, false)) {
|
||||||
if(FileUtil.copy((new File(xpi2pfile)).getCanonicalPath(), _updateFile, true, false)) {
|
transferComplete(alreadyTransferred, alreadyTransferred, 0L, _xpi2pURL, _updateFile, false);
|
||||||
transferComplete(alreadyTransferred, alreadyTransferred, 0L, _xpi2pURL, _updateFile, false);
|
} else {
|
||||||
} else {
|
statusDone("<b>" + _("Failed to copy file {0}", _xpi2pURL) + "</b>");
|
||||||
statusDone("<b>" + _("File copy failed {0}", _xpi2pURL) + "</b>");
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
_log.error("Error copying plugin {0}", t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
updateStatus("<b>" + _("Downloading plugin from {0}", _xpi2pURL) + "</b>");
|
||||||
// use the same settings as for updater
|
// use the same settings as for updater
|
||||||
boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
|
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);
|
String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
|
||||||
@ -177,6 +173,7 @@ public class PluginUpdateHandler extends UpdateHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
|
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
|
||||||
|
boolean update = false;
|
||||||
updateStatus("<b>" + _("Plugin downloaded") + "</b>");
|
updateStatus("<b>" + _("Plugin downloaded") + "</b>");
|
||||||
File f = new File(_updateFile);
|
File f = new File(_updateFile);
|
||||||
File appDir = new SecureDirectory(_context.getConfigDir(), PLUGIN_DIR);
|
File appDir = new SecureDirectory(_context.getConfigDir(), PLUGIN_DIR);
|
||||||
@ -406,7 +403,7 @@ public class PluginUpdateHandler extends UpdateHandler {
|
|||||||
_log.error("Error stopping plugin " + appName, e);
|
_log.error("Error stopping plugin " + appName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
update = true;
|
||||||
} else {
|
} else {
|
||||||
if (Boolean.valueOf(props.getProperty("update-only")).booleanValue()) {
|
if (Boolean.valueOf(props.getProperty("update-only")).booleanValue()) {
|
||||||
to.delete();
|
to.delete();
|
||||||
@ -428,11 +425,10 @@ public class PluginUpdateHandler extends UpdateHandler {
|
|||||||
}
|
}
|
||||||
_updated = true;
|
_updated = true;
|
||||||
to.delete();
|
to.delete();
|
||||||
if (Boolean.valueOf(props.getProperty("dont-start-at-install")).booleanValue()) {
|
// install != update. Changing the user's settings like this is probabbly a bad idea.
|
||||||
if (Boolean.valueOf(props.getProperty("router-restart-required")).booleanValue())
|
if (Boolean.valueOf( props.getProperty("dont-start-at-install")).booleanValue()) {
|
||||||
statusDone("<b>" + _("Plugin {0} installed, router restart required", appName) + "</b>");
|
statusDone("<b>" + _("Plugin {0} installed", appName) + "</b>");
|
||||||
else {
|
if(!update) {
|
||||||
statusDone("<b>" + _("Plugin {0} installed", appName) + "</b>");
|
|
||||||
Properties pluginProps = PluginStarter.pluginProperties();
|
Properties pluginProps = PluginStarter.pluginProperties();
|
||||||
pluginProps.setProperty(PluginStarter.PREFIX + appName + PluginStarter.ENABLED, "false");
|
pluginProps.setProperty(PluginStarter.PREFIX + appName + PluginStarter.ENABLED, "false");
|
||||||
PluginStarter.storePluginProperties(pluginProps);
|
PluginStarter.storePluginProperties(pluginProps);
|
||||||
|
12
history.txt
12
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
|
2012-03-14 zzz
|
||||||
* Blockfile, i2psnark: Remove static logs
|
* Blockfile, i2psnark: Remove static logs
|
||||||
* DHSessionKeyBuilder:
|
* DHSessionKeyBuilder:
|
||||||
|
Reference in New Issue
Block a user