PDA

View Full Version : [PI] Cache Download Issue [2M RSGP REWARD]



Time
May 21st, 2011, 03:56
Hey guys. I'm working on my client, and I need to know how to get my cache to load correctly.

From what I can tell, the cache isn't downloading correctly, or it doesn't extract it correctly.

EDIT:
I worked on it some more. Now it downloads the cache like it normally would, then it says, "Loading Cache Library" then counts from 0 - 100%. When it hits 100%, I get the message, "Error Loading... Please Report!". Here's the error message I get on the cmd:



BrokenX is loading..
brokenXcache.zip 71062710
java.io.FileNotFoundException: C:\brokenXcache\brokenXcache\cacheVersion1.dat (T
he system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at CacheDownloader.unzip(CacheDownloader.java:220)
at CacheDownloader.unZip(CacheDownloader.java:177)
at CacheDownloader.downloadCache(CacheDownloader.java :79)
at client.startUp(client.java:8459)
at RSApplet.run(RSApplet.java:33)
at client.run(client.java:5759)
at java.lang.Thread.run(Unknown Source)
java.io.FileNotFoundException: C:\brokenXcache\Maps\mapConfig.txt (The system ca
nnot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at client.setNewMaps(client.java:72)
at client.startUp(client.java:8460)
at RSApplet.run(RSApplet.java:33)
at client.run(client.java:5759)
at java.lang.Thread.run(Unknown Source)
java.io.FileNotFoundException: C:\brokenXcache\brokenXcache\cacheVersion1.dat (T
he system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at Update.unZipFile(Update.java:66)
at Update.<init>(Update.java:29)
at client.streamLoaderForName(client.java:4457)
at client.startUp(client.java:8470)
at RSApplet.run(RSApplet.java:33)
at client.run(client.java:5759)
at java.lang.Thread.run(Unknown Source)




If it helps, here's my CacheDownloader.java


import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.BufferedOutputStream;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URLConnection;
import java.net.URL;
import java.util.zip.ZipFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.Enumeration;

import sign.signlink;

public class CacheDownloader {

private client client;

private final int BUFFER = 1024;

private final int VERSION = 1; // Version of cache
//private String cacheLink = "Only the registered members can see the link."; // Link to cache
private String cacheLink = "Only the registered members can see the link."; // Link to cache

private String fileToExtract = getCacheDir() + getArchivedName();

public CacheDownloader(client client) {
this.client = client;
}

private void drawLoadingText(String text) {
client.drawLoadingText(35, text);
//System.out.println(text);
}


private void drawLoadingText(int amount, String text) {
client.drawLoadingText(amount, text);
//System.out.println(text);
}

private String getCacheDir() {
return signlink.findcachedir();
}

private String getCacheLink() {
return cacheLink;
}

private int getCacheVersion() {
return VERSION;
}

public CacheDownloader downloadCache() {
try {
File location = new File(getCacheDir());
File version = new File(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat");

if(!location.exists()) {
//drawLoadingText("Loading new Updates....");
downloadFile(getCacheLink(), getArchivedName());

unZip();
//System.out.println("UNZIP");

BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
versionFile.close();
deleteZIP(getArchivedName());
} else {
if(!version.exists()) {
//drawLoadingText("~ First Time Installation, Only Once! ~");
downloadFile(getCacheLink(), getArchivedName());

unZip();
//System.out.println("UNZIP");

BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
versionFile.close();
deleteZIP(getArchivedName());

} else {
return null;
}
}
} catch(Exception e) {

}
return null;
}

private void downloadFile(String adress, String localFileName) {
OutputStream out = null;
URLConnection conn;
InputStream in = null;

try {

URL url = new URL(adress);
out = new BufferedOutputStream(
new FileOutputStream(getCacheDir() + "/" +localFileName));

conn = url.openConnection();
in = conn.getInputStream();

byte[] data = new byte[BUFFER];

int numRead;
long numWritten = 0;
int length = conn.getContentLength();


while((numRead = in.read(data)) != -1) {
out.write(data, 0, numRead);
numWritten += numRead;

int percentage = (int)(((double)numWritten / (double)length) * 100D);
drawLoadingText(percentage, "Downloading BrokenX Cache " + percentage + "%...");

}

System.out.println(localFileName + "\t" + numWritten);
drawLoadingText("Unpacking..");

} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}

}

private String getArchivedName() {
int lastSlashIndex = getCacheLink().lastIndexOf('/');
if (lastSlashIndex >= 0
&& lastSlashIndex < getCacheLink().length() -1) {
return getCacheLink().substring(lastSlashIndex + 1);
} else {
//System.err.println("error retreiving archivaed name.");
}
return "";
}




private void unZip() {

try {
InputStream in =
new BufferedInputStream(new FileInputStream(fileToExtract));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry e;

while((e=zin.getNextEntry()) != null) {

if(e.isDirectory()) {
(new File(getCacheDir() + e.getName())).mkdir();
} else {

if (e.getName().equals(fileToExtract)) {
unzip(zin, fileToExtract);
break;
}
unzip(zin, getCacheDir() + e.getName());
}
//System.out.println("unzipping2 " + e.getName());
}
zin.close();

} catch(Exception e) {
e.printStackTrace();
}
}

private void deleteZIP(String fileName){
// A File object to represent the filename
File f = new File(getCacheDir() + fileName);

// Make sure the file or directory exists and isn't write protected
if (!f.exists())
throw new IllegalArgumentException(
"Delete: no such file or directory: " + fileName);

if (!f.canWrite())
throw new IllegalArgumentException("Delete: write protected: "
+ fileName);

// If it is a directory, make sure it is empty
if (f.isDirectory()) {
String[] files = f.list();
if (files.length > 0)
throw new IllegalArgumentException(
"Delete: directory not empty: " + fileName);
}

// Attempt to delete it
boolean success = f.delete();

if (!success)
throw new IllegalArgumentException("Delete: deletion failed");

}

private void unzip(ZipInputStream zin, String s)
throws IOException {

FileOutputStream out = new FileOutputStream(s);
//System.out.println("unzipping " + s);
byte [] b = new byte[BUFFER];
int len = 0;

while ((len = zin.read(b)) != -1) {
out.write(b,0,len);
}
out.close();
}
}


If you need anything else, please don't hesitate to ask.
Anyone who would be willing to get on TeamViewer would be SUPER helpful.


Paying 2m RSGP + Rep for anyone who helps me figure this out.
Thanks,
TimeBroken.

Spear
May 21st, 2011, 03:57
Do you have mapConfig? That's what it's not finding.

Time
May 21st, 2011, 03:58
Do you have mapConfig? That's what it's not finding.
I do. When I physically move my cache to my C:\, it works fine. It's just not auto-downloading.

Spear
May 21st, 2011, 04:01
I do. When I physically move my cache to my C:\, it works fine. It's just not auto-downloading.

Do you have TV?

Scotticus
May 21st, 2011, 04:01
I do. When I physically move my cache to my C:\, it works fine. It's just not auto-downloading.

Make sure the MapConfig is in the ZIP That the cache is auto downloading from..

Time
May 21st, 2011, 04:10
Do you have TV?

I do. I'll get on with you in just a second. :)


Make sure the MapConfig is in the ZIP That the cache is auto downloading from..

It is.

i dont use soap
May 28th, 2011, 22:18
u have to put the cache dir to brokenxcache/brokenxcache because atm i think urs is just brokenxcache/

cruel ko
May 28th, 2011, 22:25
on your siglink document do the names match the cache folder on client

Josh
May 28th, 2011, 22:32
Post your signlink.java please. :o

cruel ko
May 28th, 2011, 22:51
look for


public static String findcachedir() {
String as[] = {"./"};
if(storeid < 32 || storeid > 34)
storeid = 32;
String s = "yourcachefoldernamehere";
for(int i = 0; i < as.length; i++)
try {
String s1 = as[i];
if(s1.length() > 0) {
File file = new File(s1);
if(!file.exists())
continue;
}


and



public static String sencondDir() {
File file = new File("C:/yourcachefoldernamehere/");
if (!file.exists())
file.mkdir();
return file.toString();
}


and replace yourcachefoldername here with what you have your folder named with your cache

TeamPrimalX
March 28th, 2012, 06:29
Could some one Tv me too please :( I got same problem.

high105
May 17th, 2012, 07:00
Also, just saying, make sure your cache is zip correctly.

Cart
May 17th, 2012, 20:52
Also, just saying, make sure your cache is zip correctly.

Telling him a year later isn't much help.