- Hide update buttons and update config if install dir is readonly or if configured

This commit is contained in:
zzz
2010-02-02 15:25:26 +00:00
parent 794db19b6d
commit 6801fc667a
4 changed files with 53 additions and 19 deletions

View File

@@ -36,6 +36,8 @@ public class ConfigUpdateHandler extends FormHandler {
public static final String DEFAULT_PROXY_PORT = "" + DEFAULT_PROXY_PORT_INT;
/** default false */
public static final String PROP_UPDATE_UNSIGNED = "router.updateUnsigned";
/** default false - use for distros */
public static final String PROP_UPDATE_DISABLED = "router.updateDisabled";
/** no default */
public static final String PROP_ZIP_URL = "router.updateUnsignedURL";

View File

@@ -5,8 +5,21 @@ import net.i2p.crypto.TrustedUpdate;
import net.i2p.data.DataHelper;
public class ConfigUpdateHelper extends HelperBase {
private boolean _dontInstall;
public ConfigUpdateHelper() {}
/** hook this so we can call dontInstall() once after getting a context */
@Override
public void setContextId(String contextId) {
super.setContextId(contextId);
_dontInstall = NewsFetcher.getInstance(_context).dontInstall();
}
public boolean canInstall() {
return !_dontInstall;
}
public boolean updateAvailable() {
return true;
}
@@ -80,27 +93,34 @@ public class ConfigUpdateHelper extends HelperBase {
return buf.toString();
}
/**
* Right now the jsp hides the whole select box if _dontInstall is true but this could change
*/
public String getUpdatePolicySelectBox() {
String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY, ConfigUpdateHandler.DEFAULT_UPDATE_POLICY);
StringBuilder buf = new StringBuilder(256);
buf.append("<select name=\"updatePolicy\">");
if ("notify".equals(policy))
buf.append("<option value=\"notify\" selected=\"true\">").append(_("Notify only")).append("</option>");
else
buf.append("<option value=\"notify\">" + _("Notify only") + "</option>");
buf.append("<option value=\"notify\"");
if ("notify".equals(policy) || _dontInstall)
buf.append(" selected=\"true\"");
buf.append('>').append(_("Notify only")).append("</option>");
if ("download".equals(policy))
buf.append("<option value=\"download\" selected=\"true\">" + _("Download and verify only") + "</option>");
else
buf.append("<option value=\"download\">" + _("Download and verify only") + "</option>");
buf.append("<option value=\"download\"");
if (_dontInstall)
buf.append(" disabled=\"true\"");
else if ("download".equals(policy))
buf.append(" selected=\"true\"");
buf.append('>').append(_("Download and verify only")).append("</option>");
if (System.getProperty("wrapper.version") != null) {
if ("install".equals(policy))
buf.append("<option value=\"install\" selected=\"true\">" + _("Download, verify, and restart") + "</option>");
else
buf.append("<option value=\"install\">" + _("Download, verify, and restart") + "</option>");
buf.append("<option value=\"install\"");
if (_dontInstall)
buf.append(" disabled=\"true\"");
else if ("install".equals(policy))
buf.append(" selected=\"true\"");
buf.append('>').append(_("Download, verify, and restart")).append("</option>");
}
buf.append("</select>\n");

View File

@@ -103,9 +103,16 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
}
}
boolean dontInstall() {
File test = new File(_context.getBaseDir(), "history.txt");
boolean readonly = ((test.exists() && !test.canWrite()) || (!_context.getBaseDir().canWrite()));
boolean disabled = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_UPDATE_DISABLED)).booleanValue();
return readonly || disabled;
}
private boolean shouldInstall() {
String policy = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_POLICY);
if ("notify".equals(policy))
if ("notify".equals(policy) || dontInstall())
return false;
File zip = new File(_context.getRouterDir(), Router.UPDATE_FILE);
return !zip.exists();
@@ -158,7 +165,8 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
public boolean shouldFetchUnsigned() {
String url = _context.getProperty(ConfigUpdateHandler.PROP_ZIP_URL);
return url != null && url.length() > 0 &&
Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED)).booleanValue();
Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED)).booleanValue() &&
!dontInstall();
}
/**
@@ -304,7 +312,7 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Our version was NOT found (" + RouterVersion.VERSION + "), update needed");
_updateAvailable = true;
_updateAvailable = !dontInstall();
if (shouldInstall()) {
if (_log.shouldLog(Log.DEBUG))