Restructure code to be less wonky.

This commit is contained in:
Michael Bayne
2017-06-29 10:37:51 -07:00
parent 1922919995
commit b1c85ddb2e
2 changed files with 24 additions and 22 deletions
@@ -1274,13 +1274,15 @@ public class Application
* @param alreadyValid if non-null a 1 element array that will have the number of "already * @param alreadyValid if non-null a 1 element array that will have the number of "already
* validated" resources filled in. * validated" resources filled in.
* @param unpacked a set to populate with unpacked resources. * @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<Resource> verifyResources (ProgressObserver obs, int[] alreadyValid, public void verifyResources (
Set<Resource> unpacked, List<Resource> toBeInstalled) ProgressObserver obs, int[] alreadyValid, Set<Resource> unpacked,
List<Resource> toInstall, List<Resource> toDownload)
throws InterruptedException throws InterruptedException
{ {
List<Resource> rsrcs = getAllActiveResources(); List<Resource> rsrcs = getAllActiveResources();
List<Resource> failures = new ArrayList<Resource>();
// obtain the sizes of the resources to validate // obtain the sizes of the resources to validate
long[] sizes = new long[rsrcs.size()]; long[] sizes = new long[rsrcs.size()];
@@ -1308,9 +1310,10 @@ public class Application
try { try {
if (_digest.validateResource(rsrc, robs)) { if (_digest.validateResource(rsrc, robs)) {
// if the resource is valid but has no _local file, add it to to-install list // 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()) { rsrc.getLocalNew().exists()) {
toBeInstalled.add(rsrc); toInstall.add(rsrc);
continue;
} }
// unpack this resource if appropriate // unpack this resource if appropriate
if (noUnpack || !rsrc.shouldUnpack()) { if (noUnpack || !rsrc.shouldUnpack()) {
@@ -1333,10 +1336,8 @@ public class Application
} finally { } finally {
robs.progress(100); robs.progress(100);
} }
failures.add(rsrc); toDownload.add(rsrc);
} }
return (failures.size() == 0) ? null : failures;
} }
/** /**
@@ -133,7 +133,7 @@ public abstract class Getdown extends Thread
*/ */
public boolean isUpdateAvailable () public boolean isUpdateAvailable ()
{ {
return _readyToInstall && !_toBeInstalledResouces.isEmpty(); return _readyToInstall && !_toInstallResources.isEmpty();
} }
/** /**
@@ -143,13 +143,13 @@ public abstract class Getdown extends Thread
{ {
if (_readyToInstall) { if (_readyToInstall) {
log.info("Installing downloaded resources:"); log.info("Installing downloaded resources:");
for (Resource resource : _toBeInstalledResouces) { for (Resource resource : _toInstallResources) {
resource.install(); resource.install();
if (Thread.interrupted()) { if (Thread.interrupted()) {
throw new InterruptedException("m.applet_stopped"); throw new InterruptedException("m.applet_stopped");
} }
} }
_toBeInstalledResouces.clear(); _toInstallResources.clear();
_readyToInstall = false; _readyToInstall = false;
log.info("Install completed."); log.info("Install completed.");
} else { } else {
@@ -442,7 +442,7 @@ public abstract class Getdown extends Thread
// we'll keep track of all the resources we unpack // we'll keep track of all the resources we unpack
Set<Resource> unpacked = new HashSet<Resource>(); Set<Resource> unpacked = new HashSet<Resource>();
_toBeInstalledResouces = new ArrayList<Resource>(); _toInstallResources = new ArrayList<Resource>();
_readyToInstall = false; _readyToInstall = false;
//setStep(Step.START); //setStep(Step.START);
@@ -476,9 +476,10 @@ public abstract class Getdown extends Thread
// now verify our resources... // now verify our resources...
setStep(Step.VERIFY_RESOURCES); setStep(Step.VERIFY_RESOURCES);
setStatusAsync("m.validating", -1, -1L, false); setStatusAsync("m.validating", -1, -1L, false);
List<Resource> failures = _app.verifyResources( List<Resource> toDownload = new ArrayList<Resource>();
_progobs, alreadyValid, unpacked, _toBeInstalledResouces); _app.verifyResources(_progobs, alreadyValid, unpacked,
if (failures == null) { _toInstallResources, toDownload);
if (toDownload.size() == 0) {
log.info("Resources verified."); log.info("Resources verified.");
// if we were downloaded in full from another service (say, Steam), we may // if we were downloaded in full from another service (say, Steam), we may
@@ -528,10 +529,10 @@ public abstract class Getdown extends Thread
return; return;
} }
// we have failures, those will be redownloaded so we note them as to-be-installed // we have resources to download, also note them as to-be-installed
for (Resource r : failures) { for (Resource r : toDownload) {
if (!_toBeInstalledResouces.contains(r)) { if (!_toInstallResources.contains(r)) {
_toBeInstalledResouces.add(r); _toInstallResources.add(r);
} }
} }
@@ -542,10 +543,10 @@ public abstract class Getdown extends Thread
reportTrackingEvent("app_start", -1); reportTrackingEvent("app_start", -1);
// redownload any that are corrupt or invalid... // 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)."); " rsrcs require update (" + alreadyValid[0] + " assumed valid).");
setStep(Step.REDOWNLOAD_RESOURCES); setStep(Step.REDOWNLOAD_RESOURCES);
download(failures); download(toDownload);
reportTrackingEvent("app_complete", -1); reportTrackingEvent("app_complete", -1);
@@ -1281,7 +1282,7 @@ public abstract class Getdown extends Thread
protected boolean _launchInSilent; protected boolean _launchInSilent;
protected long _startup; protected long _startup;
protected List<Resource> _toBeInstalledResouces; protected List<Resource> _toInstallResources;
protected boolean _readyToInstall; protected boolean _readyToInstall;
protected boolean _enableTracking = true; protected boolean _enableTracking = true;