Odd Auto cache downloader error

Hey Mopar,

My auto cache downloader, downloads the cache to the user folder, but when trying to load up fully, rejects the background image.

See Error

My cache downloader:

[code]package org.ruse.client;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**

  • Handles cache downloading
    */
    public class CacheDownloader {
    //Note for madara, convert www.dropbox.com to dl.dropboxusercontent.com and remove ?dl= off the end
    private static final String CACHE_FILE_NAME = “RuseCache.zip”; //The name of the actual .zip file,
    private static final String CACHE_URL = “https://dl.dropboxusercontent.com/s/uetvcfyg0jm9c65/RuseCache.zip”; //The url to the .zip file
    private static final String NEWEST_VERSION_FILE_URL = “https://dl.dropboxusercontent.com/s/elt3xlai6pwcejc/cacheVersion.txt”; //The url to the current cache_versiont txt file
    private static final String CURRENT_VERSION_FILE = “cacheVersion.txt”; //The location of the local cache_version txt file
    //Below links are just the directory the images are in, not the images.zip
    public static final String URL_TO_LOADING_IMAGES = “http://postmortem.comxa.com/”; // make sure you log into 000webhost often or itll deactivate
    public static final String MIRROR_URL_TO_LOADING_IMAGES = “http://postmortem.comxa.com/”; //If first link is broken, it will attempt to download from here

    public static boolean UPDATING = true;

    public static boolean updatedCache() {
    try {

     	double newest = getNewestVersion();
     	double current = getCurrentVersion();
     	if(cacheDownloadRequired(newest, current)) {
     		downloadCache();
     		unzipCache();
     		setLatestCacheVersion(newest);
     	}
     	
     	UPDATING = false;
     	
     	return true;
     	
     } catch(Exception e) {
     	e.printStackTrace();
     }
     UPDATING = false;
     return false;
    

    }

    public static boolean cacheDownloadRequired(double newest, double current) {
    return newest > current;
    }

    public static void downloadCache() throws IOException {
    URL url = new URL(CACHE_URL);
    HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
    httpConn.addRequestProperty(“User-Agent”, “Mozilla/4.76”);
    int responseCode = httpConn.getResponseCode();

     // always check HTTP response code first
     if (responseCode == HttpURLConnection.HTTP_OK) {
     	String fileName = CACHE_FILE_NAME;
     	// opens input stream from the HTTP connection
     	InputStream inputStream = httpConn.getInputStream();
     	String saveFilePath = Signlink.getCacheDirectory() + File.separator + fileName;
    
     	// opens an output stream to save into file
     	FileOutputStream outputStream = new FileOutputStream(saveFilePath);
    
     	int bytesRead = -1;
     	byte[] buffer = new byte[4096];
     	//long startTime = System.currentTimeMillis();
     	//int downloaded = 0;
     	long numWritten = 0;
     	int length = httpConn.getContentLength();
     	while ((bytesRead = inputStream.read(buffer)) != -1) {
     		outputStream.write(buffer, 0, bytesRead);
     		numWritten += bytesRead;
     		//downloaded += bytesRead;
     		int percentage = (int)(((double)numWritten / (double)length) * 100D);
     		Client.getClient().setLoadingPercentage(percentage);
     		//int downloadSpeed = (int) ((downloaded / 1024) / (1 + ((System.currentTimeMillis() - startTime) / 1000)));
     		//Client.getClient().drawSmoothLoading(percentage, (new StringBuilder()).append("Downloading "+percentage+"% ").append("@ "+downloadSpeed+"Kb/s").toString());
     		//System.out.println((new StringBuilder()).append("Downloading "+percentage+"% ").append("@ "+downloadSpeed+"Kb/s").toString());
     		//drawLoadingText(percentage, (new StringBuilder()).append("Downloading "+downloadingText+""+s+": "+percentage+"% ").append("@ "+downloadSpeed+"Kb/s").toString());
     	}
    
     	outputStream.close();
     	inputStream.close();
    
     } else {
     	System.out.println("Cache host replied HTTP code: " + responseCode);
     }
     httpConn.disconnect();
    

    }

    private static void unzipCache() {
    try {
    final File file = new File(Signlink.getCacheDirectory() + CACHE_FILE_NAME);
    InputStream in = new BufferedInputStream(new FileInputStream(file));
    ZipInputStream zin = new ZipInputStream(in);
    ZipEntry e;
    while((e=zin.getNextEntry()) != null) {
    if(e.isDirectory()) {
    (new File(Signlink.getCacheDirectory() + e.getName())).mkdir();
    } else {
    if (e.getName().equals(file.getName())) {
    unzipPartlyArchive(zin, file.getName());
    break;
    }
    unzipPartlyArchive(zin, Signlink.getCacheDirectory() + e.getName());
    }
    }
    zin.close();
    file.delete();
    } catch(Exception e) {
    e.printStackTrace();
    }
    }

    /**

    • Unzips a partly archive

    • @param zin The zip inputstream

    • @param s The location of the zip file

    • @throws IOException The method can throw an IOException.
      */
      private static void unzipPartlyArchive(ZipInputStream zin, String s) throws Exception {
      FileOutputStream out = new FileOutputStream(s);
      //drawLoadingText(100, “Unpacking data…”);
      byte [] b = new byte[1024];
      int len = 0;

      while ((len = zin.read(b)) != -1) {
      out.write(b,0,len);
      }
      out.close();
      }

    public static double getCurrentVersion()
    {
    try
    {
    File file = new File(Signlink.getCacheDirectory() + CURRENT_VERSION_FILE);
    if(!file.exists()) {
    return 0.0;
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
    double version = Double.parseDouble(br.readLine());
    br.close();
    return version;
    }
    catch (Exception e) {}
    return 0.1D;
    }

    public static double getNewestVersion()
    {
    try
    {
    URL url = new URL(NEWEST_VERSION_FILE_URL);
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.addRequestProperty(“User-Agent”, “Mozilla/4.76”);
    BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    double version = Double.parseDouble(br.readLine());
    br.close();
    return version;
    }
    catch (Exception e) {}
    return 0.1D;
    }

    public static void setLatestCacheVersion(double newest) throws IOException {
    BufferedWriter bw = new BufferedWriter(new FileWriter(Signlink.getCacheDirectory() + CURRENT_VERSION_FILE));
    bw.write(""+newest+"");
    bw.close();
    }
    }
    [/code]

My signlink

[code]package org.ruse.client;

import java.applet.Applet;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.security.SecureRandom;
import java.util.Random;

import org.ruse.Configuration;

public final class Signlink implements Runnable {

private static boolean active;
public static RandomAccessFile cache_dat = null;
public static final RandomAccessFile[] cache_idx = new RandomAccessFile[Client.CACHE_INDEX_COUNT];
public static String dns = null;
private static String dnsreq = null;
public static Applet mainapp = null;
public static boolean reporterror = true;
private static byte[] savebuf = null;
private static int savelen;
private static String savereq = null;
private static InetAddress socketip;
private static int socketreq;
public static int storeid = 32;
public static boolean sunjava;
private static int threadliveid;
private static Runnable threadreq = null;
private static int threadreqpri = 1;
public static long uid;
private static String urlreq = null;

public static synchronized void dnslookup(String s) {
	dns = s;
	dnsreq = s;
}

public static void release() {
	try {
		if (cache_dat != null) {
			cache_dat.close();
		}

		for (RandomAccessFile file : cache_idx) {
			if (file != null) {
				file.close();
			}
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
}

public static String getCacheDirectory() {
	String cacheLoc = System.getProperty("user.home") + "/";
	if(Configuration.DROPBOX_MODE) {
		cacheLoc = "./";
	}
	cacheLoc += Configuration.CACHE_DIRECTORY_NAME + "/";
	File cacheDir = new File(cacheLoc);
	if(!cacheDir.exists()) {
		cacheDir.mkdir();
	}
	return cacheLoc;
}

public static String getIdentifierFile() {
	return (!System.getProperty("os.name").toLowerCase().contains("windows") ? System.getProperty("user.home") : System.getenv("APPDATA")) + "/.fallout/";
}

/**
 * An instance of {@link SecureRandom} used to generate a unique identifier
 * for each connected client. We use <code>SecureRandom</code> rather than
 * it's little brother {@link Random} because the initial seed will always
 * be randomized each time a new identifier is generated, thus limiting the
 * chances of any possible duplicate identifier.
 */
private static final Random KEY_GEN = new SecureRandom();

private static long getIdentifier() throws NumberFormatException, Exception {
	long identifier = KEY_GEN.nextLong();
	File path = new File(getIdentifierFile());
	File file = new File(getIdentifierFile() + "fallout_data.dat");
	if (!path.exists()) {
		path.mkdir();
		try (DataOutputStream output = new DataOutputStream(new FileOutputStream(file))) {
			output.writeLong(identifier);
			output.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	} else {
		try (DataInputStream input = new DataInputStream(new FileInputStream(file))) {
			identifier = input.readLong();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	return identifier;
}

public static void reportError(String s) {
	System.out.println("Error: " + s);
}

public static void startpriv(InetAddress inetaddress) {
	threadliveid = (int) (Math.random() * 99999999D);

	if (active) {
		try {
			Thread.sleep(500L);
		} catch (Exception _ex) {
		}

		active = false;
	}

	socketreq = 0;
	threadreq = null;
	dnsreq = null;
	savereq = null;
	urlreq = null;
	socketip = inetaddress;
	Thread thread = new Thread(new Signlink());
	thread.setDaemon(true);
	thread.start();

	while (!active) {
		try {
			Thread.sleep(50L);
		} catch (Exception _ex) {
		}
	}
}

public static synchronized void startthread(Runnable runnable, int i) {
	threadreqpri = i;
	threadreq = runnable;
}

private Signlink() {
}

@Override
public void run() {
	active = true;
	File s = new File(getCacheDirectory());
	try {
		uid = getIdentifier();
	} catch (Exception e) {
		e.printStackTrace();
	}

	try {
		cache_dat = new RandomAccessFile(s + "/main_file_cache.dat", "rw");

		for (int i = 0; i < Client.CACHE_INDEX_COUNT; i++) {
			cache_idx[i] = new RandomAccessFile(s + "/main_file_cache.idx" + i, "rw");
		}
	} catch (Exception exception) {
		exception.printStackTrace();
	}

	for (int i = threadliveid; threadliveid == i;) {
		if (socketreq != 0) {
			try {
				new Socket(socketip, socketreq);
			} catch (Exception _ex) {
			}

			socketreq = 0;
		} else if (threadreq != null) {
			Thread thread = new Thread(threadreq);
			thread.setDaemon(true);
			thread.start();
			thread.setPriority(threadreqpri);
			threadreq = null;
		} else if (dnsreq != null) {
			try {
				dns = InetAddress.getByName(dnsreq).getHostName();
			} catch (Exception _ex) {
				dns = "unknown";
			}

			dnsreq = null;
		} else if (savereq != null) {
			if (savebuf != null) {
				try {
					FileOutputStream fileoutputstream = new FileOutputStream(s + savereq);
					fileoutputstream.write(savebuf, 0, savelen);
					fileoutputstream.close();
				} catch (Exception _ex) {
				}
			}

			savereq = null;
		} else if (urlreq != null) {
			try {
				new DataInputStream(new URL(mainapp.getCodeBase(), urlreq).openStream());
			} catch (Exception _ex) {
			}

			urlreq = null;
		}
		try {
			Thread.sleep(50L);
		} catch (Exception _ex) {
		}
	}
}

}
[/code]