Added the ability to specify a patch notes URL. When Getdown needs to

patch, it will provide a button to access the URL if it's non-empty.
This commit is contained in:
Andrzej Kapolka
2011-09-23 01:03:23 +00:00
parent 4687e45596
commit 9dde9d119a
5 changed files with 85 additions and 3 deletions
@@ -146,6 +146,12 @@ public class Application
/** Where to point the user for help with install errors. */
public String installError;
/** The dimensions of the patch notes button. */
public Rectangle patchNotes = new Rectangle(5, 50, 112, 26);
/** The patch notes URL. */
public String patchNotesUrl;
/** Generates a string representation of this instance. */
@Override
public String toString ()
@@ -153,7 +159,8 @@ public class Application
return "[name=" + name + ", bg=" + backgroundImage + ", pi=" + progressImage +
", prect=" + progress + ", pt=" + progressText + ", pb=" + progressBar +
", srect=" + status + ", st=" + statusText + ", shadow=" + textShadow +
", err=" + installError + "]";
", err=" + installError + ", nrect=" + patchNotes +
", notes=" + patchNotesUrl + "]";
}
}
@@ -623,6 +630,10 @@ public class Application
ui.installError = MessageUtil.taint(ui.installError);
}
// the patch notes bits
ui.patchNotes = parseRect(cdata, "ui.patch_notes", ui.patchNotes);
ui.patchNotesUrl = (String)cdata.get("ui.patch_notes_url");
return ui;
}
@@ -27,13 +27,18 @@ package com.threerings.getdown.launcher;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import java.io.BufferedReader;
import java.io.File;
@@ -630,6 +635,16 @@ public abstract class Getdown extends Thread
}
}
// show the patch notes button, if applicable
if (!StringUtil.isBlank(_ifc.patchNotesUrl)) {
createInterface(false);
EventQueue.invokeLater(new Runnable() {
public void run () {
_patchNotes.setVisible(true);
}
});
}
// download the patch files...
download(list);
@@ -796,8 +811,17 @@ public abstract class Getdown extends Thread
public void run () {
if (_status == null) {
_container = createContainer();
_layers = new JLayeredPane();
_container.add(_layers, BorderLayout.CENTER);
_patchNotes = new JButton(new AbstractAction(
_msgs.getString("m.patch_notes")) {
@Override public void actionPerformed (ActionEvent event) {
showDocument(_ifc.patchNotesUrl);
}
});
_layers.add(_patchNotes);
_status = new StatusPanel(_msgs);
_container.add(_status, BorderLayout.CENTER);
_layers.add(_status);
initInterface();
} else if (reinit) {
initInterface();
@@ -819,6 +843,12 @@ public abstract class Getdown extends Thread
_background = newBackgrounds;
}
_status.init(_ifc, _background, getProgressImage());
Dimension size = _status.getPreferredSize();
_status.setSize(size);
_layers.setPreferredSize(size);
_patchNotes.setBounds(_ifc.patchNotes);
_patchNotes.setVisible(false);
}
protected RotatingBackgrounds getBackground ()
@@ -950,6 +980,11 @@ public abstract class Getdown extends Thread
return null;
}
/**
* Requests to show the document at the specified URL in a new window.
*/
protected abstract void showDocument (String url);
/**
* Requests that Getdown exit. In applet mode this does nothing.
*/
@@ -1026,7 +1061,9 @@ public abstract class Getdown extends Thread
protected ResourceBundle _msgs;
protected Container _container;
protected JLayeredPane _layers;
protected StatusPanel _status;
protected JButton _patchNotes;
protected AbortPanel _abort;
protected RotatingBackgrounds _background;
@@ -43,6 +43,7 @@ import javax.swing.WindowConstants;
import com.samskivert.swing.util.SwingUtil;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.RunAnywhere;
import com.samskivert.util.StringUtil;
import static com.threerings.getdown.Log.log;
@@ -162,6 +163,29 @@ public class GetdownApp
}
}
@Override
protected void showDocument (String url) {
String[] cmdarray;
if (RunAnywhere.isWindows()) {
String osName = System.getProperty("os.name");
if (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1) {
cmdarray = new String[] {
"command.com", "/c", "start", "\"" + url + "\"" };
} else {
cmdarray = new String[] {
"cmd.exe", "/c", "start", "\"\"", "\"" + url + "\"" };
}
} else if (RunAnywhere.isMacOS()) {
cmdarray = new String[] { "open", url };
} else { // Linux, Solaris, etc.
cmdarray = new String[] { "firefox", url };
}
try {
Runtime.getRuntime().exec(cmdarray);
} catch (Exception e) {
log.warning("Failed to open browser.", "cmdarray", cmdarray, e);
}
}
@Override
protected void exit (int exitCode) {
System.exit(exitCode);
}
@@ -147,6 +147,14 @@ public class GetdownApplet extends JApplet
return GetdownApplet.this;
}
@Override
protected void showDocument (String url) {
try {
getAppletContext().showDocument(new URL(url), "_blank");
} catch (MalformedURLException e) {
log.warning("Invalid document url.", "url", url, e);
}
}
@Override
protected void launch () {
// if so configured, create a server socket to listen
// for a connection from the app
@@ -44,6 +44,8 @@ m.validating = Validating...
m.patching = Patching...
m.launching = Launching...
m.patch_notes = Patch Notes...
m.complete = {0}% complete
m.complete_remain = {0}% complete {1} remaining
@@ -75,7 +77,7 @@ m.init_error = The application has failed to launch due to the following \
information on how to handle such problems.
m.readonly_error = The directory in which this application is installed: \
\n{0}\nis read-only. Please install the applicaton into a directory where \
\n{0}\nis read-only. Please install the application into a directory where \
you have write access.
m.missing_resource = The application has failed to launch due to a missing \