Fixed a few more bugs with ResourceGrabber and found a bug, in GUIUpdater, todo has potential fix.

This commit is contained in:
Travis Burtrum 2012-01-28 13:07:59 -05:00 committed by moparisthebest
parent a7c7a4ac22
commit f7fd42f8d3
3 changed files with 39 additions and 5 deletions

View File

@ -45,6 +45,7 @@ public class CRCClassLoader extends URLClassLoader {
private Map<String, byte[]> classes = new HashMap<String, byte[]>();
private long crcVal = 0;
private boolean fileExists = false;
//private ClassLoader parent = null;
private ProtectionDomain pd = null;
@ -99,7 +100,9 @@ public class CRCClassLoader extends URLClassLoader {
if (backupURL != null) {
System.out.println("CRC checksum failed, downloading new file.");
//if(ret == null || ret.getCRC() != 0)
if(ret != null && ret.fileExists())
System.out.println("CRC checksum failed, downloading new file.");
// URLConnection uc = new URL(backupURL).openConnection();
// InputStream in = uc.getInputStream();
@ -124,7 +127,7 @@ public class CRCClassLoader extends URLClassLoader {
ret = new CRCClassLoader(jarFileLoc, parent);
}
if (ret.successfullyLoaded(expectedCRC)) {
if (!ret.successfullyLoaded(expectedCRC) && ret.getCRC() != 0) {
String s = "CRC checksum failed. crc:" + ret.getCRC() + " expected:" + expectedCRC;
if (crcMismatchException)
throw new IOException(s);
@ -147,11 +150,13 @@ public class CRCClassLoader extends URLClassLoader {
if(jarFileLoc == null)
return;
File f = new File(jarFileLoc);
if (!f.exists() || !f.isFile()) {
System.err.println("Jar file doesn't exist: " + jarFileLoc);
fileExists = f.exists() && f.isFile() && f.canRead();
if (!fileExists) {
Debug.debug("Jar file doesn't exist: " + jarFileLoc);
return;
}
if (updateCRC)
classes = new HashMap<String, byte[]>();
@ -200,6 +205,10 @@ public class CRCClassLoader extends URLClassLoader {
return crcVal;
}
public boolean fileExists(){
return this.fileExists;
}
public boolean successfullyLoaded(long expectedCRC){
if(expectedCRC == 0)
return classesLoaded > 0;
@ -213,6 +222,7 @@ public class CRCClassLoader extends URLClassLoader {
return "CRCClassLoader{" +
"crcVal=" + crcVal +
", classesLoaded=" + classesLoaded +
", fileExists=" + fileExists +
//", successfullyLoaded(0)=" + successfullyLoaded(0) +
'}';
}

View File

@ -51,5 +51,18 @@ public abstract class CompleteRunnable implements Runnable {
this.ex = ex;
}
@Override
public String toString() {
return "CompleteRunnable{" +
"uid=" + uid +
", url='" + url + '\'' +
", savePath='" + savePath + '\'' +
", extract=" + extract +
", uniqueFolder=" + uniqueFolder +
", ci=" + ci +
", ex=" + ex +
'}';
}
public abstract void run();
}

View File

@ -347,7 +347,7 @@ public class ResourceGrabber {
boolean listFileExists = listFile.exists() && listFile.canRead() && listFile.isFile();
// if this file exists, and ci is null, or expectedChecksum is 0, just return -1 (already downloaded)
//System.out.printf("listFileExists: '%b', ci: '%s'\n", listFileExists, ci);
if (listFileExists && (ci == null || ci.getExpectedChecksum() == 0))
if (listFileExists && (ci != null && ci.getExpectedChecksum() == 0))
return -1;
// check crc if we are supposed to
if (ci != null && listFileExists) {
@ -614,8 +614,10 @@ public class ResourceGrabber {
public void actionPerformed(ActionEvent e) {
synchronized (downloadItems) {
for (final DlListener dll : downloadItems) {
System.out.println("dll: "+dll);
//System.out.println("uid : " + dll.uid);
//System.out.println("status: " + dll.getStatus().toString());
//todo: to make sure we hit all statuses in order, perhaps a synchronized queue and pop statuses from the stack?
switch (dll.getStatus()) {
case NOT_STARTED:
break;
@ -828,6 +830,15 @@ public class ResourceGrabber {
//System.out.println("DlListener equals: " + other);
return ((other != null) && (other instanceof DlListener) && (((DlListener) other).uid == this.uid));
}
@Override
public String toString() {
return "DlListener{" +
"uid=" + uid +
", autoRemove=" + autoRemove +
", status=" + getStatus().toString() +
'}';
}
}
private class DownloadItemPanel extends JPanel {