Thread: Cache Never Unzips after Updating

Results 1 to 4 of 4
  1. #1 Cache Never Unzips after Updating 
    Registered Member flub1's Avatar
    Join Date
    Apr 2020
    Posts
    43
    Thanks given
    7
    Thanks received
    6
    Rep Power
    25
    Spoiler for ORIGINALISSUE:

    Hi all,

    Using a Ruse base and have been experiencing this issue since day 1.


    When I upload my new cache (Ensuring the correct permissions etc) then the client always fails to unzip it correctly.

    I believe that it is checking for files in the cache folder, before it has finished unzipping - I have tried to resolve this myself and spent hours looking up the issue, but I cannot work it out.



    Now whenever I update my Cache, the CacheVersion.dat file automatically updates itself based on Bytes in the Zip.
    (See error below)
    Spoiler for Image:


    In the error, you'll notice that it's trying to find the /achievement/ folder... That is present, please don't tell me to add that folder.

    To confirm, I have done the following;

    Ensured Cache is zipped, not the cache folder
    Ensured the correct file permissions exist on my FTP server
    Tested by unzipping the cache manually - Client now loads




    Thank you in advance,
    Disc: Flub#3610

    EDIT:


    As per Kevin's post, here is my CacheDownloader.java

    Spoiler for CacheDownloader.java:
    Code:
    package com.janus;
    
    import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLConnection;
    import java.nio.file.Files;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipInputStream;
    
    import javax.swing.*;
    
    public class CacheDownloader implements Runnable {
    
    	private static final String CACHE_PATH = System.getProperty("user.home") + File.separator + "JanusCache" + File.separator;
    	private static final String ZIP_URL = "*****";
    	private static final String VERSION_FILE = CACHE_PATH + "cacheVersion.dat";
    
    	private CacheDownloader.GUI g;
    
        @[Only registered and activated users can see links. ]ressWarnings("resource")
    	public long getCurrentVersion() {
    		try {
    			File versionDir = new File(VERSION_FILE);
    
    			if (!versionDir.exists()) {
    				versionDir.createNewFile();
    				return -1;
    			}
    
    			return Long.parseLong(new BufferedReader(new InputStreamReader(new FileInputStream(VERSION_FILE))).readLine());
    		} catch (Exception e) {
    			return -1;
    		}
    	}
    
    	public long getNewestVersion() {
    		try {
    			return ((HttpURLConnection) new URL(ZIP_URL).openConnection()).getContentLengthLong();
    		} catch (Exception e) {
    			handleException(e);
    			return -1;
    		}
    	}
    
    	private void handleException(Exception e) {
    		StringBuffer strBuff = new StringBuffer();
    
    		strBuff.append("Please Screenshot this message, and send it to an admin!\r\n\r\n");
    		strBuff.append(e.getClass().getName() + " \"" + e.getMessage() + "\"\r\n");
    
    		for (StackTraceElement s : e.getStackTrace()) {
    			strBuff.append(s.toString() + "\r\n");
    		}
    
    		alert("Exception [" + e.getClass().getSimpleName() + "]", strBuff.toString(), true);
    	}
    
    	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() {
    		try {
    			long newest = getNewestVersion();
    			long current = getCurrentVersion();
    
    			if (newest != current) {
    				g = new CacheDownloader.GUI();
    				g.setLocationRelativeTo(null);
    				g.setVisible(true);
    				updateCache();
    				new FileOutputStream(VERSION_FILE).write(String.valueOf(newest).getBytes());
    				g.dispose();
    			}
    		} catch (Exception e) {
    			handleException(e);
    		}
    	}
    
    	private void updateCache() {
    		File clientZip = downloadCache();
    
    		if (clientZip != null) {
    			unZip(clientZip);
    		}
    	}
    
    	private void unZip(File clientZip) {
    		try {
    			unZipFile(clientZip, new File(signlink.findcachedir()));
    			Files.delete(clientZip.toPath());
    		} catch (Exception e) {
    			handleException(e);
    		}
    	}
    
    	private void unZipFile(File zipFile, File outFile) throws IOException {
    		g.setStatus("Unzipping The Cache...");
    		g.setPercent(0);
    
    		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);
    					g.setPercent((int) ((curr * 100) / max));
    				}
    
    				out.flush();
    				out.close();
    			}
    		}
    
    		in.close();
    	}
    
    	private File downloadCache() {
    		g.setStatus("Downloading Cache... Hold Tight...");
    
    		File ret = new File(CACHE_PATH + "JanusCache.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;
    				g.setPercent((int) ((curr * 100) / max));
    			}
    
    			out.flush();
    			in.close();
    			return ret;
    		} catch (Exception e) {
    			handleException(e);
    			ret.delete();
    			return null;
    		}
    	}
    
    	public class GUI extends JFrame {
    		private static final long serialVersionUID = 1L;
    
    		/** Creates new form GUI */
    		public GUI() {
    			try {
    				UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    			} catch (Exception ignored) {
    
    			}
    
    			initComponents();
    		}
    
    		/**
    		 * This method is called from within the constructor to initialize the
    		 * form. WARNING: Do NOT modify this code. The content of this method is
    		 * always regenerated by the Form Editor.
    		 */
    		private void initComponents() {
    			jProgressBar1 = new JProgressBar();
    			jLabel1 = new JLabel();
    			jLabel2 = new JLabel();
    			jLabel3 = new JLabel();
    
    			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    			setTitle("Janus Cache Update");
    
    			addWindowListener(new java.awt.event.WindowAdapter() {
    				public void windowClosing(java.awt.event.WindowEvent evt) {
    					formWindowClosing(evt);
    				}
    			});
    
    			jLabel1.setText("Status:");
    			jLabel2.setText("N/A");
    			jLabel3.setText("0%");
    
    			GroupLayout layout = new GroupLayout(getContentPane());
    			getContentPane().setLayout(layout);
    			layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    				layout.createSequentialGroup()
    					.addContainerGap()
    					.addGroup(
    						layout.createParallelGroup(GroupLayout.Alignment.LEADING)
    							.addGroup(
    								layout.createSequentialGroup().addComponent(jLabel1).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 304, Short.MAX_VALUE)
    									.addComponent(jLabel3)).addComponent(jProgressBar1, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)).addContainerGap()));
    			layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    				layout.createSequentialGroup()
    					.addContainerGap()
    					.addGroup(
    						layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
    							.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jLabel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel3))
    							.addComponent(jLabel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    					.addComponent(jProgressBar1, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    			pack();
    		}
    
    		private void formWindowClosing(java.awt.event.WindowEvent evt) {
    
    		}
    
    		private int percent = 0;
    
    		public void setStatus(String s) {
    			jLabel2.setText(s);
    		}
    
    		public String getStatus() {
    			return jLabel2.getText();
    		}
    
    		public void setPercent(int amount) {
    			percent = amount;
    			jLabel3.setText(amount + "%");
    			jProgressBar1.setValue(amount);
    		}
    
    		public int getPercent() {
    			return percent;
    		}
    
    		private JLabel jLabel1;
    		private JLabel jLabel2;
    		private JLabel jLabel3;
    		private JProgressBar jProgressBar1;
    	}
    }



    Um I finally fixed this after ripping my hair out... Turns out that using WinRar to zip the files instead of "File->Send To Compressed zip" actually works......
    Last edited by flub1; 04-30-2020 at 10:52 AM. Reason: RESOLVED
    Reply With Quote  
     

  2. #2  
    Administrator

    Kevy's Avatar
    Join Date
    Jul 2006
    Posts
    1,240
    Thanks given
    91
    Thanks received
    1,617
    Rep Power
    5000
    In order for people to be able to help you should post some code also

    Please paste the code for the cache unzipping class, also make sure it includes the code that handles CacheVersion.dat.

    Thanks, Kevin.
    Thanks, Kevin.
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member flub1's Avatar
    Join Date
    Apr 2020
    Posts
    43
    Thanks given
    7
    Thanks received
    6
    Rep Power
    25
    Quote Originally Posted by Kevy View Post
    In order for people to be able to help you should post some code also

    Please paste the code for the cache unzipping class, also make sure it includes the code that handles CacheVersion.dat.

    Thanks, Kevin.
    Thanks for pointing that out Kevin, updated accordingly
    Reply With Quote  
     

  5. #4  
    Banned
    Join Date
    Apr 2020
    Posts
    29
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Hey bro add my on discord ill give you a hand caches, can be annoying at times,
    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. Client freeze after updating server cache
    By catinahat in forum Help
    Replies: 3
    Last Post: 08-02-2017, 06:53 PM
  2. Replies: 3
    Last Post: 12-13-2010, 11:11 PM
  3. How to type in caps in runescape(after update!)
    By iownzyou in forum Tips and Hints
    Replies: 13
    Last Post: 08-22-2009, 07:18 PM
  4. Writing cache requests to the update server
    By veer in forum Tutorials
    Replies: 4
    Last Post: 11-18-2007, 11:32 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •