Thread: Cache Downloader

Results 1 to 8 of 8
  1. #1 Cache Downloader 
    Banned
    Join Date
    May 2013
    Age
    22
    Posts
    557
    Thanks given
    35
    Thanks received
    45
    Rep Power
    0
    Hey everyone, I posted this error previously but no one provided sufficient help for me, if anyone can help me out there is a rep++ and thanks coming your way.



    Also, 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/u/171587564/Alchemize%20Cache.zip";
    	public static final String VERSION_URL = "https://dl.dropboxusercontent.com/u/171587564/Alchemize%20Cache/cacheVersion.dat";
    	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 put it on the forums!\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 is finished downloading");
    				alert("Cache has been completely downloaded, The client will start now.");
    				OutputStream out = new FileOutputStream(VERSION_FILE);
    				out.write(String.valueOf(newest).getBytes());;
    				client.start();
    			}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;
    		}
    	}
    }
    Reply With Quote  
     

  2. #2  
    Banned
    Join Date
    May 2013
    Age
    22
    Posts
    557
    Thanks given
    35
    Thanks received
    45
    Rep Power
    0
    Bump
    Reply With Quote  
     

  3. #3  
    Banned
    Join Date
    May 2013
    Age
    22
    Posts
    557
    Thanks given
    35
    Thanks received
    45
    Rep Power
    0
    Bump again
    Reply With Quote  
     

  4. #4  
    Donator


    Join Date
    Mar 2012
    Posts
    1,023
    Thanks given
    221
    Thanks received
    299
    Rep Power
    605
    Post this in RS2 Client next time.

    Java.io - FileNotFoundException means the cache hosted from the dropbox doesn't exist OR it's not in a public folder.
    Reply With Quote  
     

  5. #5  
    Banned
    Join Date
    May 2013
    Age
    22
    Posts
    557
    Thanks given
    35
    Thanks received
    45
    Rep Power
    0
    Quote Originally Posted by Blanket View Post
    Post this in RS2 Client next time.

    Java.io - FileNotFoundException means the cache hosted from the dropbox doesn't exist OR it's not in a public folder.
    When I click okay it runs fine and nothing else occurs though
    Reply With Quote  
     

  6. #6  
    Registered Member

    Join Date
    May 2012
    Age
    28
    Posts
    1,548
    Thanks given
    415
    Thanks received
    231
    Rep Power
    81
    Update the cachversion link... In the error, it cclearly says there was something wrong with your link, use common sense.
    Inactive.


    Spoiler for FirstDesign:
    Reply With Quote  
     

  7. #7  
    Banned
    Join Date
    May 2013
    Age
    22
    Posts
    557
    Thanks given
    35
    Thanks received
    45
    Rep Power
    0
    Quote Originally Posted by Solstice View Post
    Update the cachversion link... In the error, it cclearly says there was something wrong with your link, use common sense.
    What to?
    Reply With Quote  
     

  8. #8  
    Banned
    Join Date
    May 2013
    Age
    22
    Posts
    557
    Thanks given
    35
    Thanks received
    45
    Rep Power
    0
    Nevermind I deleted the entire updateCache system, no further posts are needed.
    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. 417 cache download!
    By Mr.Andrew Gover in forum RS2 Client
    Replies: 14
    Last Post: 12-15-2007, 07:25 PM
  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
  •