Allow the arbitrary step percentages to be specified in getdown.txt.
This commit is contained in:
@@ -55,6 +55,7 @@ import java.security.Signature;
|
|||||||
import java.security.cert.Certificate;
|
import java.security.cert.Certificate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -108,6 +109,31 @@ public class Application
|
|||||||
/** Used to communicate information about the UI displayed when updating the application. */
|
/** Used to communicate information about the UI displayed when updating the application. */
|
||||||
public static class UpdateInterface
|
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<Integer> defaultPercents;
|
||||||
|
|
||||||
|
/** Enum constructor. */
|
||||||
|
Step (int... percents)
|
||||||
|
{
|
||||||
|
this.defaultPercents = intsToList(percents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** The human readable name of this application. */
|
/** The human readable name of this application. */
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
@@ -153,6 +179,11 @@ public class Application
|
|||||||
/** The patch notes URL. */
|
/** The patch notes URL. */
|
||||||
public String patchNotesUrl;
|
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<Step, List<Integer>> stepPercentages =
|
||||||
|
new EnumMap<Step, List<Integer>>(Step.class);
|
||||||
|
|
||||||
/** Generates a string representation of this instance. */
|
/** Generates a string representation of this instance. */
|
||||||
@Override
|
@Override
|
||||||
public String toString ()
|
public String toString ()
|
||||||
@@ -161,7 +192,14 @@ public class Application
|
|||||||
", prect=" + progress + ", pt=" + progressText + ", pb=" + progressBar +
|
", prect=" + progress + ", pt=" + progressText + ", pb=" + progressBar +
|
||||||
", srect=" + status + ", st=" + statusText + ", shadow=" + textShadow +
|
", srect=" + status + ", st=" + statusText + ", shadow=" + textShadow +
|
||||||
", err=" + installError + ", nrect=" + patchNotes +
|
", 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.patchNotes = parseRect(cdata, "ui.patch_notes", ui.patchNotes);
|
||||||
ui.patchNotesUrl = parseUrl(cdata, "ui.patch_notes_url", null);
|
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;
|
return ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1452,6 +1502,18 @@ public class Application
|
|||||||
return (rect == null) ? def : rect;
|
return (rect == null) ? def : rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make an immutable List from the specified int array.
|
||||||
|
*/
|
||||||
|
public static List<Integer> intsToList (int[] values)
|
||||||
|
{
|
||||||
|
List<Integer> list = new ArrayList<Integer>(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
|
* Takes a comma-separated String of four integers and returns a rectangle using those ints as
|
||||||
* the its x, y, width, and height.
|
* the its x, y, width, and height.
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ import com.samskivert.util.RunAnywhere;
|
|||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
import com.threerings.getdown.data.Application;
|
import com.threerings.getdown.data.Application;
|
||||||
|
import com.threerings.getdown.data.Application.UpdateInterface.Step;
|
||||||
import com.threerings.getdown.data.Resource;
|
import com.threerings.getdown.data.Resource;
|
||||||
import com.threerings.getdown.net.Downloader;
|
import com.threerings.getdown.net.Downloader;
|
||||||
import com.threerings.getdown.net.HTTPDownloader;
|
import com.threerings.getdown.net.HTTPDownloader;
|
||||||
@@ -93,30 +94,6 @@ import static com.threerings.getdown.Log.log;
|
|||||||
public abstract class Getdown extends Thread
|
public abstract class Getdown extends Thread
|
||||||
implements Application.StatusDisplay, ImageLoader
|
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)
|
public static void main (String[] args)
|
||||||
{
|
{
|
||||||
// legacy support
|
// legacy support
|
||||||
@@ -978,7 +955,7 @@ public abstract class Getdown extends Thread
|
|||||||
protected void setStep (Step step)
|
protected void setStep (Step step)
|
||||||
{
|
{
|
||||||
int finalPercent = -1;
|
int finalPercent = -1;
|
||||||
for (int perc : step.finalPercents) {
|
for (Integer perc : _ifc.stepPercentages.get(step)) {
|
||||||
if (perc > _stepMaxPercent) {
|
if (perc > _stepMaxPercent) {
|
||||||
finalPercent = perc;
|
finalPercent = perc;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user