Plugins: Handle 'file://' URLs for installation and updates.

This commit is contained in:
sponge
2012-03-13 05:49:02 +00:00
parent d29da5597f
commit 92c3d33ce5
2 changed files with 70 additions and 29 deletions

View File

@ -6,15 +6,12 @@ import java.util.Map;
import java.util.Properties;
import net.i2p.CoreVersion;
import net.i2p.I2PAppContext;
import net.i2p.crypto.TrustedUpdate;
import net.i2p.data.DataHelper;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.util.EepGet;
import net.i2p.util.FileUtil;
import net.i2p.util.I2PAppThread;
import net.i2p.util.Log;
import net.i2p.util.OrderedProperties;
import net.i2p.util.SecureDirectory;
import net.i2p.util.SimpleScheduler;
@ -124,6 +121,26 @@ public class PluginUpdateHandler extends UpdateHandler {
protected void update() {
_updated = false;
updateStatus("<b>" + _("Downloading plugin from {0}", _xpi2pURL) + "</b>");
if(_xpi2pURL.startsWith("file://")) {
// strip off "file://"
String xpi2pfile = _xpi2pURL.substring(7);
if(xpi2pfile.isEmpty()) {
statusDone("<b>" + _("No file specified {0}", _xpi2pURL) + "</b>");
} 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("<b>" + _("File copy failed {0}", _xpi2pURL) + "</b>");
}
} catch (Throwable t) {
_log.error("Error copying plugin {0}", t);
}
}
} else {
// 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);
@ -140,6 +157,7 @@ public class PluginUpdateHandler extends UpdateHandler {
_log.error("Error downloading plugin", t);
}
}
}
@Override
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {
@ -302,7 +320,6 @@ public class PluginUpdateHandler extends UpdateHandler {
statusDone("<b>" + _("Downloaded plugin is for new installs only, but the plugin is already installed", url) + "</b>");
return;
}
// compare previous version
File oldPropFile = new File(destDir, "plugin.config");
Properties oldProps = new OrderedProperties();
@ -358,7 +375,24 @@ public class PluginUpdateHandler extends UpdateHandler {
statusDone("<b>" + _("Plugin requires Jetty version {0} or lower", maxVersion) + "</b>");
return;
}
/*
// not ready yet...
// do we defer extraction and installation?
if (Boolean.valueOf(props.getProperty("router-restart-required")).booleanValue() && !Boolean.valueOf(props.getProperty("dont-start-at-install")).booleanValue()) {
// Yup!
if (!destDir.mkdir()) {
to.delete();
statusDone("<b>" + _("Cannot create plugin directory {0}", destDir.getAbsolutePath()) + "</b>");
return;
}
if(!FileUtil.copy(to, destDir, true, true)) {
statusDone("<b>" + _("Cannot copy plugin to directory {0}", destDir.getAbsolutePath()) + "</b>");
}
// we don't need the original file anymore.
to.delete();
statusDone("<b>" + _("Plugin will be installed on next restart.") + "</b>");
}
*/
if (PluginStarter.isPluginRunning(appName, _context)) {
wasRunning = true;
try {
@ -390,7 +424,6 @@ public class PluginUpdateHandler extends UpdateHandler {
statusDone("<b>" + _("Failed to install plugin in {0}", destDir.getAbsolutePath()) + "</b>");
return;
}
_updated = true;
to.delete();
if (Boolean.valueOf(props.getProperty("dont-start-at-install")).booleanValue()) {

View File

@ -1,3 +1,11 @@
2012-03-13 sponge
* Plugins:
- Handle 'file://' URLs for installation and updates.
You must specify the entire path, e.g.
file:///home/someone/magicplugin.xpi2p
- This works for updates too!
- Only tested on Linux, needs to be tested on Windows.
2012-03-12 zzz
* Console:
- Better IPv6 test, hopefully will work on Windows