Made the shadow color configurable; set up sensible defaults so that we

can report errors even before we download a config file; catch and report
the case where the application install directory fucks us into not
working; redirect getdown's output into a log file in the install
directory as well.
This commit is contained in:
Michael Bayne
2004-07-26 22:57:03 +00:00
parent b24801cf43
commit 1ce7c8e515
3 changed files with 66 additions and 34 deletions
@@ -1,5 +1,5 @@
// //
// $Id: Application.java,v 1.17 2004/07/26 21:24:59 mdb Exp $ // $Id: Application.java,v 1.18 2004/07/26 22:57:03 mdb Exp $
package com.threerings.getdown.data; package com.threerings.getdown.data;
@@ -59,19 +59,22 @@ public class Application
public Rectangle progress; public Rectangle progress;
/** The color of the progress text. */ /** The color of the progress text. */
public Color progressText; public Color progressText = Color.black;
/** The color of the progress bar. */ /** The color of the progress bar. */
public Color progressBar; public Color progressBar = new Color(0x6699CC);
/** The dimensions of the status display. */ /** The dimensions of the status display. */
public Rectangle status; public Rectangle status;
/** The color of the status text. */ /** The color of the status text. */
public Color statusText; public Color statusText = Color.black;
/** The path (relative to the appdir) to the background image. */ /** The path (relative to the appdir) to the background image. */
public String background; public String background;
/** The color of the text shadow. */
public Color textShadow;
} }
/** Used by {@link #verifyMetadata} to communicate status in /** Used by {@link #verifyMetadata} to communicate status in
@@ -273,17 +276,14 @@ public class Application
// parse and return our application config // parse and return our application config
UpdateInterface ui = new UpdateInterface(); UpdateInterface ui = new UpdateInterface();
ui.name = (String)cdata.get("ui.name"); ui.name = (String)cdata.get("ui.name");
ui.progress = parseRect( ui.progress = parseRect(cdata, "ui.progress");
"ui.progress", (String)cdata.get("ui.progress"));
ui.progressText = parseColor( ui.progressText = parseColor(
"ui.progress_text", (String)cdata.get("ui.progress_text"), cdata, "ui.progress_text", ui.progressText);
Color.white);
ui.progressBar = parseColor( ui.progressBar = parseColor(
"ui.progress_bar", (String)cdata.get("ui.progress_bar"), cdata, "ui.progress_bar", ui.progressBar);
new Color(0x6699CC)); ui.status = parseRect(cdata, "ui.progress");
ui.status = parseRect("ui.progress", (String)cdata.get("ui.status")); ui.statusText = parseColor(cdata, "ui.status_text", ui.statusText);
ui.statusText = parseColor( ui.textShadow = parseColor(cdata, "ui.text_shadow", ui.textShadow);
"ui.status_text", (String)cdata.get("ui.status_text"), Color.white);
ui.background = (String)cdata.get("ui.background"); ui.background = (String)cdata.get("ui.background");
return ui; return ui;
} }
@@ -649,8 +649,9 @@ public class Application
} }
/** Used to parse rectangle specifications from the config file. */ /** Used to parse rectangle specifications from the config file. */
protected Rectangle parseRect (String name, String value) protected Rectangle parseRect (HashMap cdata, String name)
{ {
String value = (String)cdata.get(name);
if (!StringUtil.blank(value)) { if (!StringUtil.blank(value)) {
int[] v = StringUtil.parseIntArray(value); int[] v = StringUtil.parseIntArray(value);
if (v != null && v.length == 4) { if (v != null && v.length == 4) {
@@ -664,8 +665,9 @@ public class Application
} }
/** Used to parse color specifications from the config file. */ /** Used to parse color specifications from the config file. */
protected Color parseColor (String name, String value, Color defcolor) protected Color parseColor (HashMap cdata, String name, Color defcolor)
{ {
String value = (String)cdata.get(name);
if (!StringUtil.blank(value)) { if (!StringUtil.blank(value)) {
try { try {
return new Color(Integer.parseInt(value, 16)); return new Color(Integer.parseInt(value, 16));
@@ -1,5 +1,5 @@
// //
// $Id: Getdown.java,v 1.17 2004/07/26 21:24:59 mdb Exp $ // $Id: Getdown.java,v 1.18 2004/07/26 22:57:03 mdb Exp $
package com.threerings.getdown.launcher; package com.threerings.getdown.launcher;
@@ -44,13 +44,33 @@ public class Getdown extends Thread
public Getdown (File appDir) public Getdown (File appDir)
{ {
super("Getdown"); super("Getdown");
try {
_msgs = ResourceBundle.getBundle("com.threerings.getdown.messages");
} catch (Exception e) {
// welcome to hell, where java can't cope with a classpath
// that contains jars that live in a directory that contains a
// !, at least the same bug happens on all platforms
String dir = appDir.toString();
if (dir.equals(".")) {
dir = System.getProperty("user.dir");
}
String errmsg = "The directory in which this application is " +
"installed:\n" + dir + "\nis invalid. The directory " +
"must not contain the '!' character. Please reinstall.";
updateStatus(errmsg);
}
_app = new Application(appDir); _app = new Application(appDir);
_msgs = ResourceBundle.getBundle("com.threerings.getdown.messages");
_startup = System.currentTimeMillis(); _startup = System.currentTimeMillis();
} }
public void run () public void run ()
{ {
// if we have no messages, just bail because we're hosed; the
// error message will be displayed to the user already
if (_msgs == null) {
return;
}
try { try {
// first parses our application deployment file // first parses our application deployment file
try { try {
@@ -316,17 +336,15 @@ public class Getdown extends Thread
System.exit(-1); System.exit(-1);
} }
// // tee our output into a file in the application directory // pipe our output into a file in the application directory
// File log = new File(appDir, "getdown.log"); File log = new File(appDir, "launcher.log");
// try { try {
// FileOutputStream fout = new FileOutputStream(log); FileOutputStream fout = new FileOutputStream(log);
// System.setOut(new PrintStream( System.setOut(new PrintStream(fout));
// new TeeOutputStream(System.out, fout))); System.setErr(new PrintStream(fout));
// System.setErr(new PrintStream( } catch (IOException ioe) {
// new TeeOutputStream(System.err, fout))); Log.warning("Unable to redirect output to '" + log + "': " + ioe);
// } catch (IOException ioe) { }
// Log.warning("Unable to redirect output to '" + log + "': " + ioe);
// }
try { try {
Getdown app = new Getdown(appDir); Getdown app = new Getdown(appDir);
@@ -1,5 +1,5 @@
// //
// $Id: StatusPanel.java,v 1.10 2004/07/26 18:59:00 mdb Exp $ // $Id: StatusPanel.java,v 1.11 2004/07/26 22:57:03 mdb Exp $
package com.threerings.getdown.launcher; package com.threerings.getdown.launcher;
@@ -81,8 +81,10 @@ public class StatusPanel extends JComponent
String label = MessageFormat.format(msg, new Object[] { String label = MessageFormat.format(msg, new Object[] {
new Integer(percent), remstr }); new Integer(percent), remstr });
_newplab = new Label(label, _ifc.progressText, _font); _newplab = new Label(label, _ifc.progressText, _font);
_newplab.setAlternateColor(_shadow); if (_ifc.textShadow != null) {
_newplab.setStyle(Label.SHADOW); _newplab.setAlternateColor(_ifc.textShadow);
_newplab.setStyle(Label.SHADOW);
}
repaint(); repaint();
} }
@@ -94,8 +96,10 @@ public class StatusPanel extends JComponent
status = xlate(status); status = xlate(status);
_newlab = new Label(status, _ifc.statusText, _font); _newlab = new Label(status, _ifc.statusText, _font);
_newlab.setTargetWidth(_spos.width); _newlab.setTargetWidth(_spos.width);
_newlab.setAlternateColor(_shadow); if (_ifc.textShadow != null) {
_newlab.setStyle(Label.SHADOW); _newlab.setAlternateColor(_ifc.textShadow);
_newlab.setStyle(Label.SHADOW);
}
repaint(); repaint();
} }
@@ -108,6 +112,7 @@ public class StatusPanel extends JComponent
if (_bgimg != null) { if (_bgimg != null) {
gfx.drawImage(_bgimg, 0, 0, null); gfx.drawImage(_bgimg, 0, 0, null);
} else { } else {
gfx.setColor(getBackground());
gfx.fillRect(0, 0, getWidth(), getHeight()); gfx.fillRect(0, 0, getWidth(), getHeight());
} }
@@ -196,6 +201,14 @@ public class StatusPanel extends JComponent
/** Used by {@link #setStatus}, and {@link #setProgress}. */ /** Used by {@link #setStatus}, and {@link #setProgress}. */
protected String get (String key) protected String get (String key)
{ {
// if we have no _msgs that means we're probably recovering from a
// failure to load the translation messages in the first place, so
// just give them their key back because it's probably an english
// string; whee!
if (_msgs == null) {
return key;
}
// if this string is tainted, we don't translate it, instead we // if this string is tainted, we don't translate it, instead we
// simply remove the taint character and return it to the caller // simply remove the taint character and return it to the caller
if (key.startsWith(MessageUtil.TAINT_CHAR)) { if (key.startsWith(MessageUtil.TAINT_CHAR)) {
@@ -219,7 +232,6 @@ public class StatusPanel extends JComponent
protected Label _label, _newlab; protected Label _label, _newlab;
protected Label _plabel, _newplab; protected Label _plabel, _newplab;
protected Color _shadow = new Color(0x16486D);
protected UpdateInterface _ifc; protected UpdateInterface _ifc;
protected long[] _remain = new long[4]; protected long[] _remain = new long[4];