diff --git a/src/main/java/com/threerings/getdown/data/Application.java b/src/main/java/com/threerings/getdown/data/Application.java index 613c900..c8fd1e3 100644 --- a/src/main/java/com/threerings/getdown/data/Application.java +++ b/src/main/java/com/threerings/getdown/data/Application.java @@ -55,6 +55,7 @@ import java.security.Signature; import java.security.cert.Certificate; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -108,6 +109,31 @@ public class Application /** Used to communicate information about the UI displayed when updating the application. */ public static class UpdateInterface { + /** + * The major steps involved in updating, along with some arbitrary percentages + * assigned to them, to mark global progress. + */ + public enum Step + { + UPDATE_JAVA(10), + VERIFY_METADATA(15, 65, 95), + DOWNLOAD(40), + PATCH(60), + VERIFY_RESOURCES(70, 97), + REDOWNLOAD_RESOURCES(90), + UNPACK(98), + LAUNCH(99); + + /** What is the final percent value for this step? */ + public final List defaultPercents; + + /** Enum constructor. */ + Step (int... percents) + { + this.defaultPercents = intsToList(percents); + } + } + /** The human readable name of this application. */ public String name; @@ -153,6 +179,11 @@ public class Application /** The patch notes URL. */ public String patchNotesUrl; + /** The global percentages for each step. A step may have more than one, and + * the lowest reasonable one is used if a step is revisited. */ + public Map> stepPercentages = + new EnumMap>(Step.class); + /** Generates a string representation of this instance. */ @Override public String toString () @@ -161,7 +192,14 @@ public class Application ", prect=" + progress + ", pt=" + progressText + ", pb=" + progressBar + ", srect=" + status + ", st=" + statusText + ", shadow=" + textShadow + ", err=" + installError + ", nrect=" + patchNotes + - ", notes=" + patchNotesUrl + "]"; + ", notes=" + patchNotesUrl + ", stepPercentages=" + stepPercentages + "]"; + } + + /** Initializer */ + { + for (Step step : Step.values()) { + stepPercentages.put(step, step.defaultPercents); + } } } @@ -636,6 +674,18 @@ public class Application ui.patchNotes = parseRect(cdata, "ui.patch_notes", ui.patchNotes); ui.patchNotesUrl = parseUrl(cdata, "ui.patch_notes_url", null); + // step progress percentages + for (UpdateInterface.Step step : UpdateInterface.Step.values()) { + String spec = (String)cdata.get("ui.percents." + step.name()); + if (spec != null) { + try { + ui.stepPercentages.put(step, intsToList(StringUtil.parseIntArray(spec))); + } catch (Exception e) { + log.warning("Failed to parse percentages for " + step + ": " + spec); + } + } + } + return ui; } @@ -1452,6 +1502,18 @@ public class Application return (rect == null) ? def : rect; } + /** + * Make an immutable List from the specified int array. + */ + public static List intsToList (int[] values) + { + List list = new ArrayList(values.length); + for (int val : values) { + list.add(val); + } + return Collections.unmodifiableList(list); + } + /** * Takes a comma-separated String of four integers and returns a rectangle using those ints as * the its x, y, width, and height. diff --git a/src/main/java/com/threerings/getdown/launcher/Getdown.java b/src/main/java/com/threerings/getdown/launcher/Getdown.java index 98c934f..4cb6ec7 100644 --- a/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -76,6 +76,7 @@ import com.samskivert.util.RunAnywhere; import com.samskivert.util.StringUtil; import com.threerings.getdown.data.Application; +import com.threerings.getdown.data.Application.UpdateInterface.Step; import com.threerings.getdown.data.Resource; import com.threerings.getdown.net.Downloader; import com.threerings.getdown.net.HTTPDownloader; @@ -93,30 +94,6 @@ import static com.threerings.getdown.Log.log; public abstract class Getdown extends Thread implements Application.StatusDisplay, ImageLoader { - /** - * The major steps. - */ - public enum Step - { - UPDATE_JAVA(10), - VERIFY_METADATA(15, 65, 95), - DOWNLOAD(40), - PATCH(60), - VERIFY_RESOURCES(70, 97), - REDOWNLOAD_RESOURCES(90), - UNPACK(98), - LAUNCH(99); - - /** What is the final percent value for this step? */ - public int[] finalPercents; - - /** Enum constructor. */ - Step (int... finalPercents) - { - this.finalPercents = finalPercents; - } - } - public static void main (String[] args) { // legacy support @@ -978,7 +955,7 @@ public abstract class Getdown extends Thread protected void setStep (Step step) { int finalPercent = -1; - for (int perc : step.finalPercents) { + for (Integer perc : _ifc.stepPercentages.get(step)) { if (perc > _stepMaxPercent) { finalPercent = perc; break;