diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index 6f915e7..e45f7cf 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -1,8 +1,9 @@ // -// $Id: Application.java,v 1.14 2004/07/20 07:35:56 mdb Exp $ +// $Id: Application.java,v 1.15 2004/07/26 17:52:32 mdb Exp $ package com.threerings.getdown.data; +import java.awt.Color; import java.awt.Rectangle; import java.io.BufferedReader; @@ -57,9 +58,18 @@ public class Application /** The dimensions of the progress bar. */ public Rectangle progress; + /** The color of the progress text. */ + public Color progressText; + + /** The color of the progress bar. */ + public Color progressBar; + /** The dimensions of the status display. */ public Rectangle status; + /** The color of the status text. */ + public Color statusText; + /** The path (relative to the appdir) to the background image. */ public String background; } @@ -265,7 +275,13 @@ public class Application ui.name = (String)cdata.get("ui.name"); ui.progress = parseRect( "ui.progress", (String)cdata.get("ui.progress")); + ui.progressText = parseColor( + "ui.progress_text", (String)cdata.get("ui.progress_text")); + ui.progressBar = parseColor( + "ui.progress_bar", (String)cdata.get("ui.progress_bar")); ui.status = parseRect("ui.progress", (String)cdata.get("ui.status")); + ui.statusText = parseColor( + "ui.status_text", (String)cdata.get("ui.status_text")); ui.background = (String)cdata.get("ui.background"); return ui; } @@ -422,6 +438,7 @@ public class Application // have also changed String olddig = (_digest == null) ? "" : _digest.getMetaDigest(); try { + status.updateStatus("m.checking"); downloadControlFile(Digest.DIGEST_FILE); _digest = new Digest(_appdir); if (!olddig.equals(_digest.getMetaDigest())) { @@ -643,6 +660,20 @@ public class Application return null; } + /** Used to parse color specifications from the config file. */ + protected Color parseColor (String name, String value) + { + if (!StringUtil.blank(value)) { + try { + return new Color(Integer.parseInt(value, 16)); + } catch (Exception e) { + Log.warning("Ignoring invalid '" + name + "' config '" + + value + "'."); + } + } + return Color.white; + } + protected File _appdir; protected File _config; protected Digest _digest; diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index 2e54a77..ab8872b 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -1,5 +1,5 @@ // -// $Id: Getdown.java,v 1.15 2004/07/20 01:27:32 mdb Exp $ +// $Id: Getdown.java,v 1.16 2004/07/26 17:52:32 mdb Exp $ package com.threerings.getdown.launcher; @@ -46,6 +46,7 @@ public class Getdown extends Thread super("Getdown"); _app = new Application(appDir); _msgs = ResourceBundle.getBundle("com.threerings.getdown.messages"); + _startup = System.currentTimeMillis(); } public void run () @@ -56,8 +57,13 @@ public class Getdown extends Thread _ifc = _app.init(); } catch (IOException ioe) { Log.warning("Failed to parse 'getdown.txt': " + ioe); + createInterface(); _app.attemptRecovery(); + // and re-initalize _ifc = _app.init(); + // now clear out our UI as we probably have a new one + _frame.dispose(); + _frame = null; } for (int ii = 0; ii < MAX_LOOPS; ii++) { @@ -209,6 +215,18 @@ public class Getdown extends Thread try { Process proc = _app.createProcess(); + + // if we have a UI open and we haven't been around for at + // least 5 seconds, don't stick a fork in ourselves straight + // away but give our lovely user a chance to see what we're + // doing + long uptime = System.currentTimeMillis() - _startup; + if (_frame != null && uptime < MIN_EXIST_TIME) { + try { + Thread.sleep(MIN_EXIST_TIME - uptime); + } catch (Exception e) { + } + } System.exit(0); } catch (IOException ioe) { Log.logStackTrace(ioe); @@ -246,7 +264,7 @@ public class Getdown extends Thread // create our user interface, and display it _frame = new JFrame(StringUtil.blank(_ifc.name) ? "" : _ifc.name); _frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - _status = new StatusPanel(_msgs, bounds, bgimg, ppos, spos); + _status = new StatusPanel(_msgs, bounds, bgimg, ppos, spos, _ifc); _frame.getContentPane().add(_status, BorderLayout.CENTER); _frame.pack(); SwingUtil.centerWindow(_frame); @@ -329,7 +347,10 @@ public class Getdown extends Thread protected JFrame _frame; protected StatusPanel _status; + protected long _startup; + protected static final int MAX_LOOPS = 5; + protected static final long MIN_EXIST_TIME = 5000L; protected static final Rectangle DEFAULT_PPOS = new Rectangle(5, 5, 300, 15); diff --git a/src/java/com/threerings/getdown/launcher/StatusPanel.java b/src/java/com/threerings/getdown/launcher/StatusPanel.java index 26fc9b5..f1e860a 100644 --- a/src/java/com/threerings/getdown/launcher/StatusPanel.java +++ b/src/java/com/threerings/getdown/launcher/StatusPanel.java @@ -1,12 +1,11 @@ // -// $Id: StatusPanel.java,v 1.5 2004/07/20 01:25:06 mdb Exp $ +// $Id: StatusPanel.java,v 1.6 2004/07/26 17:52:32 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.Font; import java.awt.Graphics2D; import java.awt.Graphics; import java.awt.Rectangle; @@ -24,6 +23,7 @@ import com.samskivert.text.MessageUtil; import com.samskivert.util.StringUtil; import com.threerings.getdown.Log; +import com.threerings.getdown.data.Application.UpdateInterface; /** * Displays download and patching status. @@ -31,13 +31,15 @@ import com.threerings.getdown.Log; public class StatusPanel extends JComponent { public StatusPanel (ResourceBundle msgs, Rectangle bounds, - BufferedImage bgimg, Rectangle ppos, Rectangle spos) + BufferedImage bgimg, Rectangle ppos, Rectangle spos, + UpdateInterface ifc) { _msgs = msgs; _bgimg = bgimg; _psize = new Dimension(bounds.width, bounds.height); _ppos = ppos; _spos = spos; + _ifc = ifc; } /** @@ -46,11 +48,17 @@ public class StatusPanel extends JComponent public void setProgress (int percent, long remaining) { _progress = percent; - String msg = (remaining > 1) ? "m.complete_remain" : "m.complete"; + String msg = "m.complete"; + int minutes = 0, seconds = 0; + if (remaining > 1) { + msg = "m.complete_remain"; + minutes = (int)(remaining / 60); + seconds = (int)(remaining % 60); + } msg = get(msg); String label = MessageFormat.format(msg, new Object[] { - new Integer(percent), new Long(remaining) }); - _newplab = new Label(label); + new Integer(percent), new Integer(minutes), new Integer(seconds) }); + _newplab = new Label(label, _ifc.progressText, _pfont); repaint(); } @@ -60,7 +68,7 @@ public class StatusPanel extends JComponent public void setStatus (String status) { status = xlate(status); - _newlab = new Label(status, _lcolor, null); + _newlab = new Label(status, _ifc.statusText, _sfont); _newlab.setTargetWidth(_spos.width); repaint(); } @@ -91,20 +99,15 @@ public class StatusPanel extends JComponent _newplab = null; } - Composite ocomp = gfx.getComposite(); - gfx.setComposite(PROGRESS_ALPHA); - gfx.setColor(Color.black); + gfx.setColor(_ifc.progressBar); gfx.fillRect(_ppos.x, _ppos.y, _progress * _ppos.width / 100, _ppos.height); - gfx.setComposite(ocomp); - gfx.setColor(_lcolor); 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); @@ -182,8 +185,8 @@ public class StatusPanel extends JComponent protected Label _plabel, _newplab; protected Color _lcolor = new Color(0xD7C94F); + protected UpdateInterface _ifc; - /** The alpha level at which to paint the progress bar. */ - protected static final Composite PROGRESS_ALPHA = - AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f); + protected static final Font _sfont = new Font("SansSerif", Font.PLAIN, 12); + protected static final Font _pfont = new Font("SansSerif", Font.BOLD, 12); } diff --git a/src/java/com/threerings/getdown/messages.properties b/src/java/com/threerings/getdown/messages.properties index 5722078..0eef4a4 100644 --- a/src/java/com/threerings/getdown/messages.properties +++ b/src/java/com/threerings/getdown/messages.properties @@ -1,5 +1,5 @@ # -# $Id: messages.properties,v 1.4 2004/07/19 12:39:08 mdb Exp $ +# $Id: messages.properties,v 1.5 2004/07/26 17:52:31 mdb Exp $ # # Getdown translation messages @@ -7,12 +7,13 @@ m.resolving = Resolving downloads... m.downloading = Downloading data... m.failure = Download failed: {0} +m.checking = Checking for update... m.validating = Validating... m.patching = Patching... m.launching = Launching... m.complete = {0}% complete -m.complete_remain = {0}% complete {1}s remaining +m.complete_remain = {0}% complete {1}:{2} remaining m.updating_metadata = Downloading control files...