Thread: Auto Cache Downloader

Results 1 to 6 of 6
  1. #1 Auto Cache Downloader 
    Registered Member
    Join Date
    Nov 2011
    Posts
    134
    Thanks given
    6
    Thanks received
    1
    Rep Power
    11
    Hello, I've been trying to fix this for hours now, with no luck. I feel like It's just something stupid I'm missing but can't find it.

    I'm using This Tutorial for my cache down loader.
    Here's my UpdateCache.java

    Code:
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.zip.*;
    import sign.signlink;
    import java.io.*;
    import javax.swing.JOptionPane;
    
    public class UpdateCache implements Runnable {
    
    	public static final String ZIP_URL = "https://dl.dropboxusercontent.com/s/43x1xk7kzh0xhcp/LostLegacyCache.zip";
    	public static final String VERSION_URL = "http://insanepkz.netii.net/cache/Version.text";
    	public static final String VERSION_FILE = sign.signlink.findcachedir()+"cacheVersion.dat";
    	private client client;
    	client frame;
        public UpdateCache(client client) {
                    this.client = client;
        }
    		
        private void drawLoadingText(int amount, String text) {
                    client.drawLoadingText(amount, text);
        }
    	
    	public double getCurrentVersion(){
    		try {
    			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(VERSION_FILE)));
    			return Double.parseDouble(br.readLine());
    		} catch (Exception e) {
    			return 0.1;
    		}
    	}
    	
    	public double getNewestVersion(){
    		try {
    			URL tmp = new URL(VERSION_URL);
    			BufferedReader br = new BufferedReader(new InputStreamReader(tmp.openStream()));
    			return Double.parseDouble(br.readLine());
    		} catch (Exception e) {
    			handleException(e);
    			return -1;
    		}
    	}
    	
    	private void handleException(Exception e){
    		StringBuilder strBuff = new StringBuilder();
    		strBuff.append("Please Screenshot this message, and send it to an admin!\r\n\r\n");
            StringBuilder append = strBuff.append(e.getClass().getName()).append(" \"").append(e.getMessage()).append("\"\r\n");
    		for(StackTraceElement s : e.getStackTrace())
    			strBuff.append(s.toString()).append("\r\n");
    		alert("Exception [" + e.getClass().getSimpleName() + "]",strBuff.toString(),true);
    	}
    	
    	private void alert(String msg){
    		alert("Message",msg,false);
    	}
    	
    	private void alert(String title,String msg,boolean error){
    		JOptionPane.showMessageDialog(null,
    			   msg,
    			   title,
    			    (error ? JOptionPane.ERROR_MESSAGE : JOptionPane.PLAIN_MESSAGE));
    	}
    	
    	@Override
    	public void run() {
    	drawLoadingText(0, "Checking Versions");
    		try{
    		double newest = getNewestVersion();
    		if(newest > this.getCurrentVersion()){
    			int n = JOptionPane.showConfirmDialog(
    				    null,
    				    "There is an update to version " + newest + "\n" +
    					"Would you like to update?",
    				    "Current version: "+ getCurrentVersion(),
    				    JOptionPane.YES_NO_OPTION);
    			if(n == 0){
    				updateClient();
    				drawLoadingText(0, "Cache has been updated, please restart the client!");
    				alert("Cache has been updated, please restart the client!");
    				OutputStream out = new FileOutputStream(VERSION_FILE);
    				out.write(String.valueOf(newest).getBytes());;
    				System.exit(0);
    			}else{
    				alert(" Your client may not load correct " +
    				getCurrentVersion());
    				//System.exit(0);
    			}
    		}
    		}catch(Exception e){
    			handleException(e);
    		}
    	}
    	
    	private void updateClient() {
    		File clientZip = downloadClient();
    		if(clientZip != null){
    		unZip(clientZip);
    		}
    	}
    	
    	private void unZip(File clientZip) {
    		try {
    			unZipFile(clientZip,new File(sign.signlink.findcachedir()));
    			clientZip.delete();
    		} catch (IOException e) {
    			handleException(e);
    		}
    	}
    	
    	private void unZipFile(File zipFile,File outFile) throws IOException{
    		ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
    		ZipEntry e;
    		long max = 0;
    		long curr = 0;
    		while((e = zin.getNextEntry()) != null)
    			max += e.getSize();
    		zin.close();
    		ZipInputStream in = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
    		while((e = in.getNextEntry()) != null){
    			if(e.isDirectory())
    				new File(outFile,e.getName()).mkdirs();
    			else{
    				FileOutputStream out = new FileOutputStream(new File(outFile,e.getName()));
    				byte[] b = new byte[1024];
    				int len;
    				while((len = in.read(b,0,b.length)) > -1){
    					curr += len;
    						out.write(b, 0, len);
    						setUnzipPercent((int)((curr * 100) / max));
    				}
    				out.flush();
    				out.close();
    			}
    		}
    	}
    
    	public int percent = 0;
    	
    	public void setDownloadPercent(int amount){
    	        percent = amount;
    			drawLoadingText(amount, "Downloading Cache" + " - " + amount + "%");
    	}
    	
    	public int percent2 = 0;
    	
    	public void setUnzipPercent(int amount2){
    	        percent2 = amount2;
    			drawLoadingText(amount2, "Extracting Cache" + " - " + amount2 + "%");
    	}
    
    	private File downloadClient(){
    		File ret = new File(signlink.findcachedir()+"cache.zip");
    		try{
    		OutputStream out = new FileOutputStream(ret);
    		URLConnection conn = new URL(ZIP_URL).openConnection();
    		InputStream in = conn.getInputStream();
    		long max = conn.getContentLength();
    		long curr = 0;
    		byte[] b = new byte[1024];
    		int len;
    		while((len = in.read(b, 0, b.length)) > -1){
    			out.write(b,0,len);
    			curr += len;
    			setDownloadPercent((int)((curr * 100) / max));
    		}
    		out.flush();
    		out.close();
    		in.close();
    		return ret;
    		}catch(Exception e){
    			handleException(e);
    				ret.delete();
    			return null;
    		}
    	}
    }
    When it runs, it asks me to download the new cache, I hit yes, and the client black screens. When I check where the cache should be, it is like this.


    The cache.rar needs to be extracted, but isn't. Any help on fixing this is greatly appreciated.
    I have skype and TV if they're needed.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Karma_K's Avatar
    Join Date
    Nov 2012
    Posts
    4,283
    Thanks given
    152
    Thanks received
    610
    Rep Power
    108
    Quote Originally Posted by 24jared24 View Post
    Hello, I've been trying to fix this for hours now, with no luck. I feel like It's just something stupid I'm missing but can't find it.

    I'm using This Tutorial for my cache down loader.
    Here's my UpdateCache.java

    Code:
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.zip.*;
    import sign.signlink;
    import java.io.*;
    import javax.swing.JOptionPane;
    
    public class UpdateCache implements Runnable {
    
    	public static final String ZIP_URL = "https://dl.dropboxusercontent.com/s/43x1xk7kzh0xhcp/LostLegacyCache.zip";
    	public static final String VERSION_URL = "http://insanepkz.netii.net/cache/Version.text";
    	public static final String VERSION_FILE = sign.signlink.findcachedir()+"cacheVersion.dat";
    	private client client;
    	client frame;
        public UpdateCache(client client) {
                    this.client = client;
        }
    		
        private void drawLoadingText(int amount, String text) {
                    client.drawLoadingText(amount, text);
        }
    	
    	public double getCurrentVersion(){
    		try {
    			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(VERSION_FILE)));
    			return Double.parseDouble(br.readLine());
    		} catch (Exception e) {
    			return 0.1;
    		}
    	}
    	
    	public double getNewestVersion(){
    		try {
    			URL tmp = new URL(VERSION_URL);
    			BufferedReader br = new BufferedReader(new InputStreamReader(tmp.openStream()));
    			return Double.parseDouble(br.readLine());
    		} catch (Exception e) {
    			handleException(e);
    			return -1;
    		}
    	}
    	
    	private void handleException(Exception e){
    		StringBuilder strBuff = new StringBuilder();
    		strBuff.append("Please Screenshot this message, and send it to an admin!\r\n\r\n");
            StringBuilder append = strBuff.append(e.getClass().getName()).append(" \"").append(e.getMessage()).append("\"\r\n");
    		for(StackTraceElement s : e.getStackTrace())
    			strBuff.append(s.toString()).append("\r\n");
    		alert("Exception [" + e.getClass().getSimpleName() + "]",strBuff.toString(),true);
    	}
    	
    	private void alert(String msg){
    		alert("Message",msg,false);
    	}
    	
    	private void alert(String title,String msg,boolean error){
    		JOptionPane.showMessageDialog(null,
    			   msg,
    			   title,
    			    (error ? JOptionPane.ERROR_MESSAGE : JOptionPane.PLAIN_MESSAGE));
    	}
    	
    	@Override
    	public void run() {
    	drawLoadingText(0, "Checking Versions");
    		try{
    		double newest = getNewestVersion();
    		if(newest > this.getCurrentVersion()){
    			int n = JOptionPane.showConfirmDialog(
    				    null,
    				    "There is an update to version " + newest + "\n" +
    					"Would you like to update?",
    				    "Current version: "+ getCurrentVersion(),
    				    JOptionPane.YES_NO_OPTION);
    			if(n == 0){
    				updateClient();
    				drawLoadingText(0, "Cache has been updated, please restart the client!");
    				alert("Cache has been updated, please restart the client!");
    				OutputStream out = new FileOutputStream(VERSION_FILE);
    				out.write(String.valueOf(newest).getBytes());;
    				System.exit(0);
    			}else{
    				alert(" Your client may not load correct " +
    				getCurrentVersion());
    				//System.exit(0);
    			}
    		}
    		}catch(Exception e){
    			handleException(e);
    		}
    	}
    	
    	private void updateClient() {
    		File clientZip = downloadClient();
    		if(clientZip != null){
    		unZip(clientZip);
    		}
    	}
    	
    	private void unZip(File clientZip) {
    		try {
    			unZipFile(clientZip,new File(sign.signlink.findcachedir()));
    			clientZip.delete();
    		} catch (IOException e) {
    			handleException(e);
    		}
    	}
    	
    	private void unZipFile(File zipFile,File outFile) throws IOException{
    		ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
    		ZipEntry e;
    		long max = 0;
    		long curr = 0;
    		while((e = zin.getNextEntry()) != null)
    			max += e.getSize();
    		zin.close();
    		ZipInputStream in = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
    		while((e = in.getNextEntry()) != null){
    			if(e.isDirectory())
    				new File(outFile,e.getName()).mkdirs();
    			else{
    				FileOutputStream out = new FileOutputStream(new File(outFile,e.getName()));
    				byte[] b = new byte[1024];
    				int len;
    				while((len = in.read(b,0,b.length)) > -1){
    					curr += len;
    						out.write(b, 0, len);
    						setUnzipPercent((int)((curr * 100) / max));
    				}
    				out.flush();
    				out.close();
    			}
    		}
    	}
    
    	public int percent = 0;
    	
    	public void setDownloadPercent(int amount){
    	        percent = amount;
    			drawLoadingText(amount, "Downloading Cache" + " - " + amount + "%");
    	}
    	
    	public int percent2 = 0;
    	
    	public void setUnzipPercent(int amount2){
    	        percent2 = amount2;
    			drawLoadingText(amount2, "Extracting Cache" + " - " + amount2 + "%");
    	}
    
    	private File downloadClient(){
    		File ret = new File(signlink.findcachedir()+"cache.zip");
    		try{
    		OutputStream out = new FileOutputStream(ret);
    		URLConnection conn = new URL(ZIP_URL).openConnection();
    		InputStream in = conn.getInputStream();
    		long max = conn.getContentLength();
    		long curr = 0;
    		byte[] b = new byte[1024];
    		int len;
    		while((len = in.read(b, 0, b.length)) > -1){
    			out.write(b,0,len);
    			curr += len;
    			setDownloadPercent((int)((curr * 100) / max));
    		}
    		out.flush();
    		out.close();
    		in.close();
    		return ret;
    		}catch(Exception e){
    			handleException(e);
    				ret.delete();
    			return null;
    		}
    	}
    }
    When it runs, it asks me to download the new cache, I hit yes, and the client black screens. When I check where the cache should be, it is like this.


    The cache.rar needs to be extracted, but isn't. Any help on fixing this is greatly appreciated.
    I have skype and TV if they're needed.
    Did you .rar your cache folder or the content inside. You're suppose to .zip just the content inside your cache and not the folder itself
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Nov 2011
    Posts
    134
    Thanks given
    6
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by Karma_K View Post
    Did you .rar your cache folder or the content inside. You're suppose to .zip just the content inside your cache and not the folder itself
    I zipped the content, not the folder...
    Reply With Quote  
     

  4. #4  
    Loominarty Confirmed
    Illuminati's Avatar
    Join Date
    Jul 2013
    Posts
    113
    Thanks given
    10
    Thanks received
    39
    Rep Power
    30
    .zip?

    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Nov 2011
    Posts
    134
    Thanks given
    6
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by Majin View Post
    .zip?
    yes...
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Nov 2011
    Posts
    134
    Thanks given
    6
    Thanks received
    1
    Rep Power
    11
    This is what the archive looks like on dropbox
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Auto Cache Downloading
    By James in forum Tutorials
    Replies: 113
    Last Post: 09-27-2008, 04:25 PM
  2. Auto Cache Downloading (Here's how!)
    By Ninja Cat in forum Tutorials
    Replies: 22
    Last Post: 03-11-2008, 02:50 PM
  3. Auto Cache Downloading Client (OPEN SOURCE)
    By eyrescape in forum Downloads
    Replies: 8
    Last Post: 01-06-2008, 10:51 AM
  4. Auto Cache download?
    By Eportal in forum Tutorials
    Replies: 4
    Last Post: 10-07-2007, 06:34 PM
  5. Buying Auto cache downloading webclient
    By wildy in forum RS2 Client
    Replies: 2
    Last Post: 08-24-2007, 03:40 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •