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:
@@ -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;
|
||||
|
||||
@@ -246,6 +246,16 @@ public class Application
|
||||
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.
|
||||
*/
|
||||
@@ -473,7 +483,8 @@ public class Application
|
||||
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
|
||||
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;
|
||||
|
||||
@@ -15,7 +15,9 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.apache.commons.io.TeeOutputStream;
|
||||
|
||||
@@ -35,14 +37,21 @@ public class Getdown
|
||||
public Getdown (File appDir)
|
||||
{
|
||||
_app = new Application(appDir);
|
||||
_msgs = ResourceBundle.getBundle("com.threerings.getdown.messages");
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
try {
|
||||
for (int ii = 0; ii < MAX_LOOPS; ii++) {
|
||||
try {
|
||||
_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()) {
|
||||
Log.info("Application requires update.");
|
||||
update();
|
||||
@@ -91,13 +100,12 @@ public class Getdown
|
||||
Downloader.Observer obs = new Downloader.Observer() {
|
||||
public void resolvingDownloads () {
|
||||
Log.info("Resolving downloads...");
|
||||
_status.setStatus("Resolving downloads...");
|
||||
_status.setStatus(_msgs.getString("m.resolving"));
|
||||
}
|
||||
|
||||
public void downloadProgress (int percent, long remaining) {
|
||||
_status.setStatus("Download progress " + percent + "%, " +
|
||||
remaining + " seconds remaining.");
|
||||
_status.setProgress(percent);
|
||||
_status.setStatus(_msgs.getString("m.downloading"));
|
||||
_status.setProgress(percent, remaining);
|
||||
if (percent == 100) {
|
||||
synchronized (lock) {
|
||||
lock.notify();
|
||||
@@ -106,7 +114,10 @@ public class Getdown
|
||||
}
|
||||
|
||||
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.logStackTrace(e);
|
||||
synchronized (lock) {
|
||||
@@ -134,7 +145,7 @@ public class Getdown
|
||||
protected void launch ()
|
||||
{
|
||||
if (_status != null) {
|
||||
_status.setStatus("Launching...");
|
||||
_status.setStatus(_msgs.getString("m.launching"));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -175,7 +186,8 @@ public class Getdown
|
||||
|
||||
// create our user interface, and display it
|
||||
_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.pack();
|
||||
SwingUtil.centerWindow(_frame);
|
||||
@@ -220,6 +232,7 @@ public class Getdown
|
||||
protected Application _app;
|
||||
protected Application.UpdateInterface _ifc;
|
||||
|
||||
protected ResourceBundle _msgs;
|
||||
protected JFrame _frame;
|
||||
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;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Graphics;
|
||||
@@ -12,16 +14,21 @@ import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.samskivert.swing.Label;
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
|
||||
/**
|
||||
* Displays download and patching status.
|
||||
*/
|
||||
public class StatusPanel extends JComponent
|
||||
{
|
||||
public StatusPanel (Rectangle bounds, BufferedImage bgimg,
|
||||
Rectangle ppos, Rectangle spos)
|
||||
public StatusPanel (ResourceBundle msgs, Rectangle bounds,
|
||||
BufferedImage bgimg, Rectangle ppos, Rectangle spos)
|
||||
{
|
||||
_msgs = msgs;
|
||||
_bgimg = bgimg;
|
||||
_psize = new Dimension(bounds.width, bounds.height);
|
||||
_ppos = ppos;
|
||||
@@ -31,9 +38,14 @@ public class StatusPanel extends JComponent
|
||||
/**
|
||||
* Adjusts the progress display to the specified percentage.
|
||||
*/
|
||||
public void setProgress (int percent)
|
||||
public void setProgress (int percent, long remaining)
|
||||
{
|
||||
_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();
|
||||
}
|
||||
|
||||
@@ -53,29 +65,46 @@ public class StatusPanel extends JComponent
|
||||
super.paintComponent(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) {
|
||||
gfx.drawImage(_bgimg, 0, 0, null);
|
||||
} else {
|
||||
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,
|
||||
_ppos.height);
|
||||
gfx.setComposite(ocomp);
|
||||
|
||||
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);
|
||||
|
||||
if (_label != null) {
|
||||
_label.render(gfx, _spos.x, _spos.y);
|
||||
}
|
||||
|
||||
SwingUtil.restoreAntiAliasing(gfx, oalias);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -88,6 +117,13 @@ public class StatusPanel extends JComponent
|
||||
protected Dimension _psize;
|
||||
protected Rectangle _ppos, _spos;
|
||||
|
||||
protected ResourceBundle _msgs;
|
||||
|
||||
protected int _progress = 0;
|
||||
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
|
||||
Reference in New Issue
Block a user