Jump to content
  • 0
Sign in to follow this  
alik01441

Urgent help please!

Question

How do I change my cache downloading link?
The old one (which was with the source+client) is outdated now.
Can someone help me?

Skype: alik01441

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0
Client Side > CacheDownloader.java:
[code]private String cacheLink = "YOUR LINK HERE"; // Link to cache[/code]

Share this post


Link to post
Share on other sites
  • 0
[quote name='uncalled for']Client Side > CacheDownloader.java:
[code]private String cacheLink = "YOUR LINK HERE"; // Link to cache[/code][/QUOTE]

I did...

This is my Cachedownloader.java now

[CODE]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;

[MENTION=19271]supp[/MENTION]ressWarnings("unused")
public class CacheDownloader {

private client client;

private final int BUFFER = 1024;

/*
* Only things you need to change
*
*/
private final int VERSION = 1; // Version of cache
private String cacheLink = "https://dl.dropboxusercontent.com/s/d1q7vj2y8rtsykt/Sunlightscape.cache.zip"; // 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("Downloading Cache Please wait...");
downloadFile(getCacheLink(), getArchivedName());

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

BufferedWriter versionFile = new BufferedWriter(new FileWriter(getCacheDir() + "/cacheVersion" + getCacheVersion() + ".dat"));
versionFile.close();
} else {
if(!version.exists()) {
//drawLoadingText("Downloading Cache Please wait...");
downloadFile(getCacheLink(), getArchivedName());

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

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

} 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 Cache " + percentage + "%");

}

System.out.println(localFileName + "\t" + numWritten);
drawLoadingText("Please wait while unzipping cache!");

} 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 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();
}
}[/CODE]

Share this post


Link to post
Share on other sites
  • 0
Then whats the problem? Does it not work properly? As in it doesn't download the cache?

Share this post


Link to post
Share on other sites
  • 0
[quote name='uncalled for']Then whats the problem? Does it not work properly? As in it doesn't download the cache?[/QUOTE]

Nvm, it worked!

Thanks!

Share this post


Link to post
Share on other sites
  • 0
[quote name='alik01441']Nvm, it worked!

Thanks![/QUOTE]
Np man :)

Share this post


Link to post
Share on other sites
  • 0
I've check out your advertisement thread. The cache link isn't your problem.

You have zipped the cache folder. You have to only zip the contents inside the folder.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×