More user interfacely goodness, localized text, added code to attempt to

redownload getdown.txt if we choke while parsing it.
This commit is contained in:
Michael Bayne
2004-07-07 10:45:20 +00:00
parent d3449f4518
commit ea0059770f
4 changed files with 95 additions and 23 deletions
@@ -1,5 +1,5 @@
// //
// $Id: Application.java,v 1.6 2004/07/07 08:42:40 mdb Exp $ // $Id: Application.java,v 1.7 2004/07/07 10:45:20 mdb Exp $
package com.threerings.getdown.data; package com.threerings.getdown.data;
@@ -246,6 +246,16 @@ public class Application
return new File(_appdir, path); return new File(_appdir, path);
} }
/**
* Attempts to redownload the <code>getdown.txt</code> file based on
* information parsed from a previous call to {@link #init}.
*/
public void attemptRecovery ()
throws IOException
{
downloadControlFile(CONFIG_FILE);
}
/** /**
* Invokes the process associated with this application definition. * Invokes the process associated with this application definition.
*/ */
@@ -473,7 +483,8 @@ public class Application
throw new NestableIOException("Invalid path '" + path + "'.", e); throw new NestableIOException("Invalid path '" + path + "'.", e);
} }
Log.info("Attempting to refetch '" + path + "'."); Log.info("Attempting to refetch '" + path + "' from '" +
targetURL + "'.");
// stream the URL into our temporary file // stream the URL into our temporary file
InputStream fin = null; InputStream fin = null;
@@ -1,5 +1,5 @@
// //
// $Id: Getdown.java,v 1.5 2004/07/07 08:42:40 mdb Exp $ // $Id: Getdown.java,v 1.6 2004/07/07 10:45:20 mdb Exp $
package com.threerings.getdown.launcher; package com.threerings.getdown.launcher;
@@ -15,7 +15,9 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.text.MessageFormat;
import java.util.List; import java.util.List;
import java.util.ResourceBundle;
import org.apache.commons.io.TeeOutputStream; import org.apache.commons.io.TeeOutputStream;
@@ -35,14 +37,21 @@ public class Getdown
public Getdown (File appDir) public Getdown (File appDir)
{ {
_app = new Application(appDir); _app = new Application(appDir);
_msgs = ResourceBundle.getBundle("com.threerings.getdown.messages");
} }
public void run () public void run ()
{ {
try { try {
for (int ii = 0; ii < MAX_LOOPS; ii++) { try {
_ifc = _app.init(); _ifc = _app.init();
} catch (IOException ioe) {
Log.warning("Failed to parse 'getdown.txt': " + ioe);
_app.attemptRecovery();
_ifc = _app.init();
}
for (int ii = 0; ii < MAX_LOOPS; ii++) {
if (_app.verifyMetadata()) { if (_app.verifyMetadata()) {
Log.info("Application requires update."); Log.info("Application requires update.");
update(); update();
@@ -91,13 +100,12 @@ public class Getdown
Downloader.Observer obs = new Downloader.Observer() { Downloader.Observer obs = new Downloader.Observer() {
public void resolvingDownloads () { public void resolvingDownloads () {
Log.info("Resolving downloads..."); Log.info("Resolving downloads...");
_status.setStatus("Resolving downloads..."); _status.setStatus(_msgs.getString("m.resolving"));
} }
public void downloadProgress (int percent, long remaining) { public void downloadProgress (int percent, long remaining) {
_status.setStatus("Download progress " + percent + "%, " + _status.setStatus(_msgs.getString("m.downloading"));
remaining + " seconds remaining."); _status.setProgress(percent, remaining);
_status.setProgress(percent);
if (percent == 100) { if (percent == 100) {
synchronized (lock) { synchronized (lock) {
lock.notify(); lock.notify();
@@ -106,7 +114,10 @@ public class Getdown
} }
public void downloadFailed (Resource rsrc, Exception e) { public void downloadFailed (Resource rsrc, Exception e) {
_status.setStatus("Download failed: " + e.getMessage()); String msg = MessageFormat.format(
_msgs.getString("m.failure"),
new Object[] { e.getMessage() });
_status.setStatus(msg);
Log.warning("Download failed [rsrc=" + rsrc + "]."); Log.warning("Download failed [rsrc=" + rsrc + "].");
Log.logStackTrace(e); Log.logStackTrace(e);
synchronized (lock) { synchronized (lock) {
@@ -134,7 +145,7 @@ public class Getdown
protected void launch () protected void launch ()
{ {
if (_status != null) { if (_status != null) {
_status.setStatus("Launching..."); _status.setStatus(_msgs.getString("m.launching"));
} }
try { try {
@@ -175,7 +186,8 @@ public class Getdown
// create our user interface, and display it // create our user interface, and display it
_frame = new JFrame(StringUtil.blank(_ifc.name) ? "" : _ifc.name); _frame = new JFrame(StringUtil.blank(_ifc.name) ? "" : _ifc.name);
_status = new StatusPanel(bounds, bgimg, ppos, spos); _frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_status = new StatusPanel(_msgs, bounds, bgimg, ppos, spos);
_frame.getContentPane().add(_status, BorderLayout.CENTER); _frame.getContentPane().add(_status, BorderLayout.CENTER);
_frame.pack(); _frame.pack();
SwingUtil.centerWindow(_frame); SwingUtil.centerWindow(_frame);
@@ -220,6 +232,7 @@ public class Getdown
protected Application _app; protected Application _app;
protected Application.UpdateInterface _ifc; protected Application.UpdateInterface _ifc;
protected ResourceBundle _msgs;
protected JFrame _frame; protected JFrame _frame;
protected StatusPanel _status; protected StatusPanel _status;
@@ -1,9 +1,11 @@
// //
// $Id: StatusPanel.java,v 1.1 2004/07/07 08:42:40 mdb Exp $ // $Id: StatusPanel.java,v 1.2 2004/07/07 10:45:20 mdb Exp $
package com.threerings.getdown.launcher; package com.threerings.getdown.launcher;
import java.awt.AlphaComposite;
import java.awt.Color; import java.awt.Color;
import java.awt.Composite;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Graphics; import java.awt.Graphics;
@@ -12,16 +14,21 @@ import java.awt.image.BufferedImage;
import javax.swing.JComponent; import javax.swing.JComponent;
import java.text.MessageFormat;
import java.util.ResourceBundle;
import com.samskivert.swing.Label; import com.samskivert.swing.Label;
import com.samskivert.swing.util.SwingUtil;
/** /**
* Displays download and patching status. * Displays download and patching status.
*/ */
public class StatusPanel extends JComponent public class StatusPanel extends JComponent
{ {
public StatusPanel (Rectangle bounds, BufferedImage bgimg, public StatusPanel (ResourceBundle msgs, Rectangle bounds,
Rectangle ppos, Rectangle spos) BufferedImage bgimg, Rectangle ppos, Rectangle spos)
{ {
_msgs = msgs;
_bgimg = bgimg; _bgimg = bgimg;
_psize = new Dimension(bounds.width, bounds.height); _psize = new Dimension(bounds.width, bounds.height);
_ppos = ppos; _ppos = ppos;
@@ -31,9 +38,14 @@ public class StatusPanel extends JComponent
/** /**
* Adjusts the progress display to the specified percentage. * Adjusts the progress display to the specified percentage.
*/ */
public void setProgress (int percent) public void setProgress (int percent, long remaining)
{ {
_progress = percent; _progress = percent;
String msg = (remaining > 1) ? "m.complete_remain" : "m.complete";
msg = _msgs.getString(msg);
String label = MessageFormat.format(msg, new Object[] {
new Integer(percent), new Long(remaining) });
_newplab = new Label(label);
repaint(); repaint();
} }
@@ -53,29 +65,46 @@ public class StatusPanel extends JComponent
super.paintComponent(g); super.paintComponent(g);
Graphics2D gfx = (Graphics2D)g; Graphics2D gfx = (Graphics2D)g;
// if we have a new label; lay it out
if (_newlab != null) {
_newlab.layout(gfx);
_label = _newlab;
_newlab = null;
}
if (_bgimg != null) { if (_bgimg != null) {
gfx.drawImage(_bgimg, 0, 0, null); gfx.drawImage(_bgimg, 0, 0, null);
} else { } else {
gfx.fillRect(0, 0, getWidth(), getHeight()); gfx.fillRect(0, 0, getWidth(), getHeight());
} }
gfx.setColor(Color.blue); Object oalias = SwingUtil.activateAntiAliasing(gfx);
// if we have new labels; lay them out
if (_newlab != null) {
_newlab.layout(gfx);
_label = _newlab;
_newlab = null;
}
if (_newplab != null) {
_newplab.layout(gfx);
_plabel = _newplab;
_newplab = null;
}
Composite ocomp = gfx.getComposite();
gfx.setComposite(PROGRESS_ALPHA);
gfx.setColor(Color.black);
gfx.fillRect(_ppos.x, _ppos.y, _progress * _ppos.width / 100, gfx.fillRect(_ppos.x, _ppos.y, _progress * _ppos.width / 100,
_ppos.height); _ppos.height);
gfx.setComposite(ocomp);
gfx.setColor(Color.white); gfx.setColor(Color.white);
if (_plabel != null) {
int xmarg = (_ppos.width - _plabel.getSize().width)/2;
int ymarg = (_ppos.height - _plabel.getSize().height)/2;
_plabel.render(gfx, _ppos.x + xmarg, _ppos.y + ymarg);
}
gfx.draw(_ppos); gfx.draw(_ppos);
if (_label != null) { if (_label != null) {
_label.render(gfx, _spos.x, _spos.y); _label.render(gfx, _spos.x, _spos.y);
} }
SwingUtil.restoreAntiAliasing(gfx, oalias);
} }
// documentation inherited // documentation inherited
@@ -88,6 +117,13 @@ public class StatusPanel extends JComponent
protected Dimension _psize; protected Dimension _psize;
protected Rectangle _ppos, _spos; protected Rectangle _ppos, _spos;
protected ResourceBundle _msgs;
protected int _progress = 0; protected int _progress = 0;
protected Label _label, _newlab; protected Label _label, _newlab;
protected Label _plabel, _newplab;
/** The alpha level at which to paint the progress bar. */
protected static final Composite PROGRESS_ALPHA =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f);
} }
@@ -0,0 +1,12 @@
#
# $Id: messages.properties,v 1.1 2004/07/07 10:45:20 mdb Exp $
#
# Getdown translation messages
m.resolving = Resolving downloads...
m.downloading = Downloading data...
m.failure = Download failed: {0}
m.launching = Launching application...
m.complete = {0}% complete
m.complete_remain = {0}% complete {1}s remaining