From b1c85ddb2e02cf5404cc692dcb3e2c375fa52f8e Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 29 Jun 2017 10:37:51 -0700 Subject: [PATCH] Restructure code to be less wonky. --- .../threerings/getdown/data/Application.java | 17 ++++++----- .../threerings/getdown/launcher/Getdown.java | 29 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/threerings/getdown/data/Application.java b/src/main/java/com/threerings/getdown/data/Application.java index c9d06e8..14218ce 100644 --- a/src/main/java/com/threerings/getdown/data/Application.java +++ b/src/main/java/com/threerings/getdown/data/Application.java @@ -1274,13 +1274,15 @@ 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. + * @param toInstall a list into which to add resources that need to be installed. + * @param toDownload a list into which to add resources that need to be downloaded. */ - public List verifyResources (ProgressObserver obs, int[] alreadyValid, - Set unpacked, List toBeInstalled) + public void verifyResources ( + ProgressObserver obs, int[] alreadyValid, Set unpacked, + List toInstall, List toDownload) throws InterruptedException { List rsrcs = getAllActiveResources(); - List failures = new ArrayList(); // obtain the sizes of the resources to validate long[] sizes = new long[rsrcs.size()]; @@ -1308,9 +1310,10 @@ public class Application try { if (_digest.validateResource(rsrc, robs)) { // if the resource is valid but has no _local file, add it to to-install list - if (!toBeInstalled.contains(rsrc) && !rsrc.getLocal().exists() && + if (!toInstall.contains(rsrc) && !rsrc.getLocal().exists() && rsrc.getLocalNew().exists()) { - toBeInstalled.add(rsrc); + toInstall.add(rsrc); + continue; } // unpack this resource if appropriate if (noUnpack || !rsrc.shouldUnpack()) { @@ -1333,10 +1336,8 @@ public class Application } finally { robs.progress(100); } - failures.add(rsrc); + toDownload.add(rsrc); } - - return (failures.size() == 0) ? null : failures; } /** diff --git a/src/main/java/com/threerings/getdown/launcher/Getdown.java b/src/main/java/com/threerings/getdown/launcher/Getdown.java index c2be622..26aa688 100644 --- a/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -133,7 +133,7 @@ public abstract class Getdown extends Thread */ public boolean isUpdateAvailable () { - return _readyToInstall && !_toBeInstalledResouces.isEmpty(); + return _readyToInstall && !_toInstallResources.isEmpty(); } /** @@ -143,13 +143,13 @@ public abstract class Getdown extends Thread { if (_readyToInstall) { log.info("Installing downloaded resources:"); - for (Resource resource : _toBeInstalledResouces) { + for (Resource resource : _toInstallResources) { resource.install(); if (Thread.interrupted()) { throw new InterruptedException("m.applet_stopped"); } } - _toBeInstalledResouces.clear(); + _toInstallResources.clear(); _readyToInstall = false; log.info("Install completed."); } else { @@ -442,7 +442,7 @@ public abstract class Getdown extends Thread // we'll keep track of all the resources we unpack Set unpacked = new HashSet(); - _toBeInstalledResouces = new ArrayList(); + _toInstallResources = new ArrayList(); _readyToInstall = false; //setStep(Step.START); @@ -476,9 +476,10 @@ public abstract class Getdown extends Thread // now verify our resources... setStep(Step.VERIFY_RESOURCES); setStatusAsync("m.validating", -1, -1L, false); - List failures = _app.verifyResources( - _progobs, alreadyValid, unpacked, _toBeInstalledResouces); - if (failures == null) { + List toDownload = new ArrayList(); + _app.verifyResources(_progobs, alreadyValid, unpacked, + _toInstallResources, toDownload); + if (toDownload.size() == 0) { log.info("Resources verified."); // if we were downloaded in full from another service (say, Steam), we may @@ -528,10 +529,10 @@ public abstract class Getdown extends Thread return; } - // we have failures, those will be redownloaded so we note them as to-be-installed - for (Resource r : failures) { - if (!_toBeInstalledResouces.contains(r)) { - _toBeInstalledResouces.add(r); + // we have resources to download, also note them as to-be-installed + for (Resource r : toDownload) { + if (!_toInstallResources.contains(r)) { + _toInstallResources.add(r); } } @@ -542,10 +543,10 @@ public abstract class Getdown extends Thread reportTrackingEvent("app_start", -1); // redownload any that are corrupt or invalid... - log.info(failures.size() + " of " + _app.getAllActiveResources().size() + + log.info(toDownload.size() + " of " + _app.getAllActiveResources().size() + " rsrcs require update (" + alreadyValid[0] + " assumed valid)."); setStep(Step.REDOWNLOAD_RESOURCES); - download(failures); + download(toDownload); reportTrackingEvent("app_complete", -1); @@ -1281,7 +1282,7 @@ public abstract class Getdown extends Thread protected boolean _launchInSilent; protected long _startup; - protected List _toBeInstalledResouces; + protected List _toInstallResources; protected boolean _readyToInstall; protected boolean _enableTracking = true;