Thread: Repacking Cache

Results 1 to 2 of 2
  1. #1 Repacking Cache 
    Registered Member
    Join Date
    Jul 2017
    Posts
    24
    Thanks given
    16
    Thanks received
    1
    Rep Power
    10
    What's wrong with my method?

    There are 2 errors.
    -IndexLength doesn't work correctly.
    -When I edit out IndexLength with a numerical value the client attempts to repack the cache but has an error doing so.


    I edited IndexLength to 3, since that is how many items I'm actually adding, and it attempts to repack it but the console gives me an error.


    Code:
    public void repackCacheIndex(int cacheIndex) {
    		System.out.println("Started repacking index " + cacheIndex + ".");
    		int indexLength = new File(indexLocation(cacheIndex, -1)).listFiles().length;
    		File[] file = new File(indexLocation(cacheIndex, -1)).listFiles();
    		try {
    			for (int index = 0; index < indexLength; index++) {
    				int fileIndex = Integer.parseInt(getFileNameWithoutExtension(file[index].toString()));
    				byte[] data = fileToByteArray(cacheIndex, fileIndex);
    				if (data != null && data.length > 0) {
    					cacheIndices[cacheIndex].put(data.length, data, fileIndex);
    					System.out.println("Repacked " + fileIndex + ".");
    				} else {
    					System.out.println("Unable to locate index " + fileIndex + ".");
    				}
    			}
    		} catch (Exception e) {
    			System.out.println("Error packing cache index " + cacheIndex + ".");
    		}
    		System.out.println("Finished repacking " + cacheIndex + ".");
    	}
    Reply With Quote  
     

  2. #2  
    Donator
    ownervs911's Avatar
    Join Date
    Jul 2013
    Posts
    166
    Thanks given
    6
    Thanks received
    4
    Rep Power
    11
    Quote Originally Posted by paepay1023 View Post
    What's wrong with my method?

    There are 2 errors.
    -IndexLength doesn't work correctly.
    -When I edit out IndexLength with a numerical value the client attempts to repack the cache but has an error doing so.


    I edited IndexLength to 3, since that is how many items I'm actually adding, and it attempts to repack it but the console gives me an error.


    Code:
    public void repackCacheIndex(int cacheIndex) {
    		System.out.println("Started repacking index " + cacheIndex + ".");
    		int indexLength = new File(indexLocation(cacheIndex, -1)).listFiles().length;
    		File[] file = new File(indexLocation(cacheIndex, -1)).listFiles();
    		try {
    			for (int index = 0; index < indexLength; index++) {
    				int fileIndex = Integer.parseInt(getFileNameWithoutExtension(file[index].toString()));
    				byte[] data = fileToByteArray(cacheIndex, fileIndex);
    				if (data != null && data.length > 0) {
    					cacheIndices[cacheIndex].put(data.length, data, fileIndex);
    					System.out.println("Repacked " + fileIndex + ".");
    				} else {
    					System.out.println("Unable to locate index " + fileIndex + ".");
    				}
    			}
    		} catch (Exception e) {
    			System.out.println("Error packing cache index " + cacheIndex + ".");
    		}
    		System.out.println("Finished repacking " + cacheIndex + ".");
    	}
    I have the Repack cache and its working for me here the code from the client I use

    Code:
    	
    	public void repackCacheIndex(int cacheIndex) {
    		System.out.println("Started repacking index " + cacheIndex + ".");
    		int indexLength = new File(indexLocation(cacheIndex, -1)).listFiles().length;
    		File[] file = new File(indexLocation(cacheIndex, -1)).listFiles();
    		try {
    			for (int index = 0; index < indexLength; index++) {
    				int fileIndex = Integer
    						.parseInt(getFileNameWithoutExtension(file[index]
    								.toString()));
    				byte[] data = fileToByteArray(cacheIndex, fileIndex);
    				if (data != null && data.length > 0) {
    					decompressors[cacheIndex].method234(data.length, data,
    							fileIndex);
    					System.out.println("Repacked " + fileIndex + ".");
    				} else {
    					System.out.println("Unable to locate index " + fileIndex
    							+ ".");
    				}
    			}
    		} catch (Exception e) {
    			System.out.println("Error packing cache index " + cacheIndex + ".");
    		}
    		System.out.println("Finished repacking " + cacheIndex + ".");
    	}
    
    	public String indexLocation(int cacheIndex, int index) {
            return Signlink.findcachedir() + "index" + cacheIndex + "/" + (index != -1 ? index + ".gz" : "");
        }
    	 public static String getFileNameWithoutExtension(String fileName) {
    	        File tmpFile = new File(fileName);
    	        tmpFile.getName();
    	        int whereDot = tmpFile.getName().lastIndexOf('.');
    	        if (0 < whereDot && whereDot <= tmpFile.getName().length() - 2) {
    	            return tmpFile.getName().substring(0, whereDot);
    	        }
    	        return "";
    	    }
    
    	 public byte[] fileToByteArray(int cacheIndex, int index) {
    	        try {
    	            if (indexLocation(cacheIndex, index).length() <= 0 || indexLocation(cacheIndex, index) == null) {
    	                return null;
    	            }
    	            File file = new File(indexLocation(cacheIndex, index));
    	            byte[] fileData = new byte[(int) file.length()];
    	            FileInputStream fis = new FileInputStream(file);
    	            fis.read(fileData);
    	            fis.close();
    	            return fileData;
    	        } catch (Exception e) {
    	            return null;
    	        }
    	    }
    }


    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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

Similar Threads

  1. Replies: 12
    Last Post: 03-13-2014, 11:14 PM
  2. Repack cache?
    By Dev_RyanJ in forum Help
    Replies: 2
    Last Post: 02-04-2014, 06:13 PM
  3. Repack Cache!
    By JAM3SS in forum Buying
    Replies: 1
    Last Post: 09-15-2012, 05:20 PM
  4. Repacking cache
    By JAM3SS in forum Buying
    Replies: 4
    Last Post: 06-18-2012, 10:42 PM
  5. [POC] Repacked Cache [download + client + tut]
    By Clienthax in forum RS2 Client
    Replies: 22
    Last Post: 05-06-2008, 09:39 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •