diff --git a/src/main/java/com/threerings/getdown/data/Application.java b/src/main/java/com/threerings/getdown/data/Application.java index 422f060..84b28c9 100644 --- a/src/main/java/com/threerings/getdown/data/Application.java +++ b/src/main/java/com/threerings/getdown/data/Application.java @@ -1063,9 +1063,11 @@ public class Application * * @param alreadyValid if non-null a 1 element array that will have the number of "already * validated" resources filled in. + * @param unpacked a set to populate with unpacked resources. */ - public List verifyResources (ProgressObserver obs, int[] alreadyValid) - throws InterruptedException + public List verifyResources ( + ProgressObserver obs, int[] alreadyValid, Set unpacked) + throws InterruptedException { List rsrcs = getAllResources(); List failures = new ArrayList(); @@ -1095,11 +1097,16 @@ public class Application try { if (_digest.validateResource(rsrc, mpobs)) { // unpack this resource if appropriate - if (noUnpack || !rsrc.shouldUnpack() || rsrc.unpack()) { + if (noUnpack || !rsrc.shouldUnpack()) { // finally note that this resource is kosher rsrc.markAsValid(); continue; } + if (rsrc.unpack()) { + unpacked.add(rsrc); + rsrc.markAsValid(); + continue; + } log.info("Failure unpacking resource", "rsrc", rsrc); } @@ -1116,6 +1123,40 @@ public class Application return (failures.size() == 0) ? null : failures; } + /** + * Unpacks the resources that require it (we know that they're valid). + * + * @param unpacked a set of resources to skip because they're already unpacked. + */ + public void unpackResources (ProgressObserver obs, Set unpacked) + throws InterruptedException + { + List rsrcs = getActiveResources(); + + // total up the file size of the resources to unpack + long totalSize = 0L; + for (Iterator it = rsrcs.iterator(); it.hasNext(); ) { + Resource rsrc = it.next(); + if (rsrc.shouldUnpack() && !unpacked.contains(rsrc)) { + totalSize += rsrc.getLocal().length(); + } else { + it.remove(); + } + } + + MetaProgressObserver mpobs = new MetaProgressObserver(obs, totalSize); + for (Resource rsrc : rsrcs) { + if (Thread.interrupted()) { + throw new InterruptedException("m.applet_stopped"); + } + mpobs.startElement(rsrc.getLocal().length()); + if (!rsrc.unpack()) { + log.info("Failure unpacking resource", "rsrc", rsrc); + } + mpobs.progress(100); + } + } + /** * Clears all validation marker files. */ diff --git a/src/main/java/com/threerings/getdown/launcher/Getdown.java b/src/main/java/com/threerings/getdown/launcher/Getdown.java index e4f512f..8efe7a8 100644 --- a/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -51,10 +51,12 @@ import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; +import java.util.HashSet; import java.util.Map; import java.util.Iterator; import java.util.List; import java.util.ResourceBundle; +import java.util.Set; import ca.beq.util.win32.registry.RegistryKey; import ca.beq.util.win32.registry.RegistryValue; @@ -404,6 +406,9 @@ public abstract class Getdown extends Thread // time through int[] alreadyValid = new int[1]; + // we'll keep track of all the resources we unpack + Set unpacked = new HashSet(); + for (int ii = 0; ii < MAX_LOOPS; ii++) { // if we aren't running in a JVM that meets our version requirements, either // complain or attempt to download and install the appropriate version @@ -431,9 +436,22 @@ public abstract class Getdown extends Thread // now verify our resources... setStatus("m.validating", -1, -1L, false); - List failures = _app.verifyResources(_progobs, alreadyValid); + List failures = _app.verifyResources(_progobs, alreadyValid, unpacked); if (failures == null) { log.info("Resources verified."); + + // if we were downloaded in full from another service (say, Steam), we may + // not have unpacked all of our resources yet + if (Boolean.getBoolean("check_unpacked")) { + File ufile = _app.getLocalPath("unpacked.dat"); + if (!ufile.exists()) { + log.info("Performing initial unpack."); + setStatus("m.validating", -1, -1L, true); + _app.unpackResources(_progobs, unpacked); + ufile.createNewFile(); + } + } + // Only launch if we aren't in silent mode. Some mystery program starting out // of the blue would be disconcerting. if (!_silent || _launchInSilent) {