forked from I2P_Developers/i2p.i2p
Refactor and tag update status messages
This commit is contained in:
@@ -63,7 +63,7 @@ public class UnsignedUpdateHandler extends UpdateHandler {
|
|||||||
/** Get the file */
|
/** Get the file */
|
||||||
@Override
|
@Override
|
||||||
protected void update() {
|
protected void update() {
|
||||||
_status = "<b>Updating</b>";
|
updateStatus("<b>" + _("Updating") + "</b>");
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Starting unsigned update URL: " + _zipURL);
|
_log.debug("Starting unsigned update URL: " + _zipURL);
|
||||||
// always proxy for now
|
// always proxy for now
|
||||||
@@ -85,10 +85,10 @@ public class UnsignedUpdateHandler extends UpdateHandler {
|
|||||||
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) {
|
||||||
File updFile = new File(_updateFile);
|
File updFile = new File(_updateFile);
|
||||||
if (FileUtil.verifyZip(updFile)) {
|
if (FileUtil.verifyZip(updFile)) {
|
||||||
_status = "<b>Update downloaded</b>";
|
updateStatus("<b>" + _("Update downloaded") + "</b>");
|
||||||
} else {
|
} else {
|
||||||
updFile.delete();
|
updFile.delete();
|
||||||
_status = "<b>Unsigned update file is corrupt</b> from " + url;
|
updateStatus("<b>" + _("Unsigned update file from {0} is corrupt", url) + "</b>");
|
||||||
_log.log(Log.CRIT, "Corrupt zip file from " + url);
|
_log.log(Log.CRIT, "Corrupt zip file from " + url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -108,20 +108,22 @@ public class UnsignedUpdateHandler extends UpdateHandler {
|
|||||||
_context.router().saveConfig();
|
_context.router().saveConfig();
|
||||||
if ("install".equals(policy)) {
|
if ("install".equals(policy)) {
|
||||||
_log.log(Log.CRIT, "Update was downloaded, restarting to install it");
|
_log.log(Log.CRIT, "Update was downloaded, restarting to install it");
|
||||||
_status = "<b>Update downloaded</b><br>Restarting";
|
updateStatus("<b>" + _("Update downloaded") + "</b><br>" + _("Restarting"));
|
||||||
restart();
|
restart();
|
||||||
} else {
|
} else {
|
||||||
_log.log(Log.CRIT, "Update was downloaded, will be installed at next restart");
|
_log.log(Log.CRIT, "Update was downloaded, will be installed at next restart");
|
||||||
_status = "<b>Update downloaded</b><br>";
|
StringBuilder buf = new StringBuilder(64);
|
||||||
|
buf.append("<b>").append(_("Update downloaded")).append("</b><br>");
|
||||||
if (System.getProperty("wrapper.version") != null)
|
if (System.getProperty("wrapper.version") != null)
|
||||||
_status += "Click Restart to install";
|
buf.append(_("Click Restart to install"));
|
||||||
else
|
else
|
||||||
_status += "Click Shutdown and restart to install";
|
buf.append(_("Click Shutdown and restart to install"));
|
||||||
_status += " Version " + _zipVersion;
|
buf.append(' ').append(_("Version {0}", _zipVersion));
|
||||||
|
updateStatus(buf.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_log.log(Log.CRIT, "Failed copy to " + to);
|
_log.log(Log.CRIT, "Failed copy to " + to);
|
||||||
_status = "<b>Failed copy to " + to + "</b>";
|
updateStatus("<b>" + _("Failed copy to {0}", to) + "</b>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,7 @@ public class UpdateHandler {
|
|||||||
protected RouterContext _context;
|
protected RouterContext _context;
|
||||||
protected Log _log;
|
protected Log _log;
|
||||||
protected String _updateFile;
|
protected String _updateFile;
|
||||||
protected static String _status = "";
|
private static String _status = "";
|
||||||
private String _action;
|
private String _action;
|
||||||
private String _nonce;
|
private String _nonce;
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ public class UpdateHandler {
|
|||||||
public UpdateRunner() {
|
public UpdateRunner() {
|
||||||
_isRunning = false;
|
_isRunning = false;
|
||||||
this.done = false;
|
this.done = false;
|
||||||
_status = "<b>Updating</b>";
|
updateStatus("<b>" + _("Updating") + "</b>");
|
||||||
}
|
}
|
||||||
public boolean isRunning() { return _isRunning; }
|
public boolean isRunning() { return _isRunning; }
|
||||||
public boolean isDone() {
|
public boolean isDone() {
|
||||||
@@ -142,7 +142,7 @@ public class UpdateHandler {
|
|||||||
_isRunning = false;
|
_isRunning = false;
|
||||||
}
|
}
|
||||||
protected void update() {
|
protected void update() {
|
||||||
_status = "<b>Updating</b>";
|
updateStatus("<b>" + _("Updating") + "</b>");
|
||||||
String updateURL = selectUpdateURL();
|
String updateURL = selectUpdateURL();
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Selected update URL: " + updateURL);
|
_log.debug("Selected update URL: " + updateURL);
|
||||||
@@ -169,19 +169,18 @@ public class UpdateHandler {
|
|||||||
}
|
}
|
||||||
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {
|
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {
|
||||||
StringBuilder buf = new StringBuilder(64);
|
StringBuilder buf = new StringBuilder(64);
|
||||||
buf.append("<b>Updating</b> ");
|
buf.append("<b>").append(_("Updating")).append("</b> ");
|
||||||
double pct = ((double)alreadyTransferred + (double)currentWrite) /
|
double pct = ((double)alreadyTransferred + (double)currentWrite) /
|
||||||
((double)alreadyTransferred + (double)currentWrite + (double)bytesRemaining);
|
((double)alreadyTransferred + (double)currentWrite + (double)bytesRemaining);
|
||||||
synchronized (_pct) {
|
synchronized (_pct) {
|
||||||
buf.append(_pct.format(pct));
|
buf.append(_pct.format(pct));
|
||||||
}
|
}
|
||||||
buf.append(":<br>\n");
|
buf.append(":<br>\n");
|
||||||
buf.append(DataHelper.formatSize(currentWrite + alreadyTransferred));
|
buf.append(_("{0}B transferred", DataHelper.formatSize(currentWrite + alreadyTransferred)));
|
||||||
buf.append("B transferred");
|
updateStatus(buf.toString());
|
||||||
_status = buf.toString();
|
|
||||||
}
|
}
|
||||||
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) {
|
||||||
_status = "<b>Update downloaded</b>";
|
updateStatus("<b>" + _("Update downloaded") + "</b>");
|
||||||
TrustedUpdate up = new TrustedUpdate(_context);
|
TrustedUpdate up = new TrustedUpdate(_context);
|
||||||
File f = new File(_updateFile);
|
File f = new File(_updateFile);
|
||||||
File to = new File(_context.getRouterDir(), Router.UPDATE_FILE);
|
File to = new File(_context.getRouterDir(), Router.UPDATE_FILE);
|
||||||
@@ -201,22 +200,23 @@ public class UpdateHandler {
|
|||||||
_context.router().saveConfig();
|
_context.router().saveConfig();
|
||||||
if ("install".equals(policy)) {
|
if ("install".equals(policy)) {
|
||||||
_log.log(Log.CRIT, "Update was VERIFIED, restarting to install it");
|
_log.log(Log.CRIT, "Update was VERIFIED, restarting to install it");
|
||||||
_status = "<b>Update verified</b><br>Restarting";
|
updateStatus("<b>" + _("Update verified") + "</b><br>" + _("Restarting"));
|
||||||
restart();
|
restart();
|
||||||
} else {
|
} else {
|
||||||
_log.log(Log.CRIT, "Update was VERIFIED, will be installed at next restart");
|
_log.log(Log.CRIT, "Update was VERIFIED, will be installed at next restart");
|
||||||
_status = "<b>Update downloaded</b><br>";
|
StringBuilder buf = new StringBuilder(64);
|
||||||
|
buf.append("<b>").append(_("Update downloaded")).append("</b><br>");
|
||||||
if (System.getProperty("wrapper.version") != null)
|
if (System.getProperty("wrapper.version") != null)
|
||||||
_status += "Click Restart to install";
|
buf.append(_("Click Restart to install"));
|
||||||
else
|
else
|
||||||
_status += "Click Shutdown and restart to install";
|
buf.append(_("Click Shutdown and restart to install"));
|
||||||
if (up.newVersion() != null)
|
if (up.newVersion() != null)
|
||||||
_status += " Version " + up.newVersion();
|
buf.append(' ').append(_("Version {0}", up.newVersion()));
|
||||||
|
updateStatus(buf.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = err + " from " + url;
|
_log.log(Log.CRIT, err + " from " + url);
|
||||||
_log.log(Log.CRIT, err);
|
updateStatus("<b>" + err + ' ' + _("from {0}", url) + " </b>");
|
||||||
_status = "<b>" + err + "</b>";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {
|
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {
|
||||||
@@ -224,7 +224,7 @@ public class UpdateHandler {
|
|||||||
_log.log(Log.CRIT, "Update from " + url + " did not download completely (" +
|
_log.log(Log.CRIT, "Update from " + url + " did not download completely (" +
|
||||||
bytesRemaining + " remaining after " + currentAttempt + " tries)");
|
bytesRemaining + " remaining after " + currentAttempt + " tries)");
|
||||||
|
|
||||||
_status = "<b>Transfer failed</b>";
|
updateStatus("<b>" + _("Transfer failed") + "</b>");
|
||||||
}
|
}
|
||||||
public void headerReceived(String url, int attemptNum, String key, String val) {}
|
public void headerReceived(String url, int attemptNum, String key, String val) {}
|
||||||
public void attempting(String url) {}
|
public void attempting(String url) {}
|
||||||
@@ -251,4 +251,30 @@ public class UpdateHandler {
|
|||||||
_log.log(Log.DEBUG, "Picked update source " + index + ".");
|
_log.log(Log.DEBUG, "Picked update source " + index + ".");
|
||||||
return (String) URLList.get(index);
|
return (String) URLList.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateStatus(String s) {
|
||||||
|
_status = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** translate a string */
|
||||||
|
protected String _(String s) {
|
||||||
|
return Messages.getString(s, _context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* translate a string with a parameter
|
||||||
|
* This is a lot more expensive than _(s), so use sparingly.
|
||||||
|
*
|
||||||
|
* @param s string to be translated containing {0}
|
||||||
|
* The {0} will be replaced by the parameter.
|
||||||
|
* Single quotes must be doubled, i.e. ' -> '' in the string.
|
||||||
|
* @param o parameter, not translated.
|
||||||
|
* To tranlslate parameter also, use _("foo {0} bar", _("baz"))
|
||||||
|
* Do not double the single quotes in the parameter.
|
||||||
|
* Use autoboxing to call with ints, longs, floats, etc.
|
||||||
|
*/
|
||||||
|
protected String _(String s, Object o) {
|
||||||
|
return Messages.getString(s, o, _context);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user