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
* 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<Resource> verifyResources (ProgressObserver obs, int[] alreadyValid,
Set<Resource> unpacked, List<Resource> toBeInstalled)
public void verifyResources (
ProgressObserver obs, int[] alreadyValid, Set<Resource> unpacked,
List<Resource> toInstall, List<Resource> toDownload)
throws InterruptedException
{
List<Resource> rsrcs = getAllActiveResources();
List<Resource> failures = new ArrayList<Resource>();
// 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;
}
/**
@@ -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<Resource> unpacked = new HashSet<Resource>();
_toBeInstalledResouces = new ArrayList<Resource>();
_toInstallResources = new ArrayList<Resource>();
_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<Resource> failures = _app.verifyResources(
_progobs, alreadyValid, unpacked, _toBeInstalledResouces);
if (failures == null) {
List<Resource> toDownload = new ArrayList<Resource>();
_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<Resource> _toBeInstalledResouces;
protected List<Resource> _toInstallResources;
protected boolean _readyToInstall;
protected boolean _enableTracking = true;