我有一个RuneScape
私人服务器,我有一个客户端。
我正在尝试创建一个webclient,我已经完成但是出于某种原因它从我的网站下载缓存并保留在cache.zip中。它不会提取它只是下载到我所做的位置。我很难过,需要帮助解决这个问题,因为我向我的会员承诺今晚会在线。
以下是下载缓存时文件夹的样子。
假设将文件中的文件解压缩到文件夹中。
这是我的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.ZipEntry;
import java.util.zip.ZipInputStream;
import sign.Signlink;
public class CacheDownloader {
private Client Client;
private final int BUFFER = 1024;
private final int VERSION = 1;
private String cacheLink = "http://www.survivalpkz.com/client/cache.zip";
private String fileToExtract = getCacheDir() + getArchivedName();
public CacheDownloader(Client Client) {
this.Client = Client;
}
private void drawLoadingText(String text) {
Client.drawLoadingText(35, text);
}
private void drawLoadingText(int amount, String text) {
Client.drawLoadingText(amount, 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()) {
downloadFile(getCacheLink(), getArchivedName());
System.out.println("Unzipping the Cache.");
unZip();
System.out.println("Cache has Unzipped.");
BufferedWriter versionFile = new BufferedWriter(new FileWriter(
getCacheDir() + "/cacheVersion" + getCacheVersion()
+ ".dat"));
versionFile.close();
} else {
if (!version.exists()) {
downloadFile(getCacheLink(), getArchivedName());
System.out.println("Unzipping the Cache.");
unZip();
System.out.println("Cache has Unzipped.");
BufferedWriter versionFile = new BufferedWriter(
new FileWriter(getCacheDir() + "/cacheVersion"
+ getCacheVersion() + ".dat"));
versionFile.close();
} else {
return null;
}
}
} catch (Exception e) {
}
return null;
}
private void downloadFile(String address, String localFileName) {
OutputStream out = null;
URLConnection conn;
InputStream in = null;
try {
URL url = new URL(address);
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 Cache " + percentage
+ "%");
}
System.out.println(localFileName + "\t" + numWritten);
drawLoadingText("Finished downloading " + getArchivedName() + "!");
} 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 retreving Archive.");
}
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("Unzipping: " + e.getName());
}
zin.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private void unzip(ZipInputStream zin, String s) throws IOException {
FileOutputStream out = new FileOutputStream(s);
byte[] b = new byte[BUFFER];
int len = 0;
while ((len = zin.read(b)) != -1) {
out.write(b, 0, len);
}
out.close();
}
}
答案 0 :(得分:0)
您正在运行哪个版本?...
例如,在718 webclient中,您不必执行与缓存相关的任何操作!
我的webclient小程序:
<center>
<applet name="Pre-Evolution" width="900px" height="600px" archive="Pre-Evolution_Client.jar" code="Loader.class" mayscript="">
<param name="worldid" value="2"/>
<param name="members" value="1"/>
<param name="modewhat" value="2"/>
<param name="modewhere" value="2"/>
<param name="safemode" value="1"/>
<param name="lang" value="0"/>
<param name="affid" value="0"/>
<param name="settings" value="ROEqp2kbj*NX9PSCbdgpOvokkMwrCkXjg3c6KXgaLZY"/>
<param name="cookieprefix" value=""/>
<param name="cookiehost" value=".google.com"/>
<param name="plug" value="0"/>
<param name="js" value="1"/>
<param name="game" value="0"/>
<param name="colourid" value="0"/>
</applet>
</center>