For those of you who want to pack models, animations, and maps into the cache but don't know how, here are some methods I've written to make the client do it for you with one simple calling of a method.
Add these methods in client.java:
Spoiler for Methods:
Code:
public String indexLocation(int cacheIndex, int index) {
return signlink.findcachedir() + "index" + cacheIndex + "/" + (index != -1 ? index + ".gz" : "");
}
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 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;
}
}
And if you need getFileNameWithoutExtension, here it is:
Code:
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 "";
}
What this will do is it will find the index directory with the gzipped files, and pack only the files in the directory, so you can also use this to repack a few models at a time.
For those of you who want to pack models, animations, and maps into the cache but don't know how, here are some methods I've written to make the client do it for you with one simple calling of a method.
Add these methods in client.java:
Spoiler for Methods:
Code:
public String indexLocation(int cacheIndex, int index) {
return signlink.findcachedir() + "index" + cacheIndex + "/" + (index != -1 ? index + ".gz" : "");
}
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 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;
}
}
And if you need getFileNameWithoutExtension, here it is:
Code:
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 "";
}
signlink.java, replace the top part of run() with this:
Code:
public void run() {
active = true;
String s = findcachedir();
uid = getuid(s);
try {
cache_dat = new RandomAccessFile(s + "main_file_cache.dat", "rw");
for(int j = 0; j < 5; j++) {
cache_idx[j] = new RandomAccessFile(s + "main_file_cache.idx" + j, "rw");
}
} catch(Exception exception) {
exception.printStackTrace();
}
Now if you want to repack an index:
Place the folder containing all the gzipped files in the cache folder.
Make sure the folder is called index#, so for example models would be located at "/cache/index1/#.gz".
In the startup method, simply call 'repackCacheIndex(#)'.
models = index1
animations = index2
maps = index4
What this will do is it will find the index directory with the gzipped files, and pack only the files in the directory, so you can also use this to repack a few models at a time.
Thanks so much needed this for the unlimiting cache.
Originally Posted by Infexis
How is it recognizing if it's a map, or if it's an animation?
Originally Posted by Galkon
Now if you want to repack an index:
Place the folder containing all the gzipped files in the cache folder.
Make sure the folder is called index#, so for example models would be located at "/cache/index1/#.gz".
In the startup method, simply call 'repackCacheIndex(#)'.
models = index1
animations = index2
maps = index4
What this will do is it will find the index directory with the gzipped files, and pack only the files in the directory, so you can also use this to repack a few models at a time.