Here's the cachedownloader file, it's a 614 client.
Code:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class CacheDownloader extends JPanel {
/**
*
*/
private static final long serialVersionUID = -4838881615456366747L;
public String cacheLink = "http://dl.dropbox.com/u/44338767/Client_Cache.zip";
public String saveDirectory = cachedir.findcachedir();
public String fileToExtract = getSaveDirectory() + getFileName();
public JProgressBar progressBar;
public JFrame aJFrame;
public int currentVersion = 1;
public String getCacheLink() {
return cacheLink;
}
public String getSaveDirectory() {
return saveDirectory;
}
public int getCacheVersion() {
return currentVersion;
}
public CacheDownloader() {
progressBar = new JProgressBar(0, 100);
add(progressBar);
progressBar.setValue(0);
progressBar.setStringPainted(true);
}
public void updateProgressBar(int value) {
progressBar.setValue(value);
}
public CacheDownloader downloadCache() {
try {
File saveLocation = new File(getSaveDirectory());
File versionLocation = new File(getSaveDirectory() + "CacheVersion" + getCacheVersion() + ".dat");
if (!saveLocation.exists()) {
downloadFile(getCacheLink(), getFileName());
unZip();
BufferedWriter versionFile = new BufferedWriter(new FileWriter(getSaveDirectory() + "CacheVersion" + getCacheVersion() + ".dat"));
versionFile.close();
deleteDownloadedZipFile(getFileName());
} else {
if (!versionLocation.exists()) {
downloadFile(getCacheLink(), getFileName());
unZip();
BufferedWriter versionFile = new BufferedWriter(new FileWriter(getSaveDirectory() + "CacheVersion" + getCacheVersion() + ".dat"));
versionFile.close();
deleteDownloadedZipFile(getFileName());
} else
return null;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public void downloadFile(String address, String fileName) {
OutputStream fileDestination = null;
URLConnection fileToDownload;
InputStream readFileToDownload = null;
CacheDownloader download = new CacheDownloader();
JFrame frame = new JFrame("Downloading Cache");
frame.setResizable(false);
frame.setContentPane(download);
frame.setSize(250, 60);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
try {
URL url = new URL(address);
fileDestination = new BufferedOutputStream(new FileOutputStream(getSaveDirectory() + fileName));
fileToDownload = url.openConnection();
readFileToDownload = fileToDownload.getInputStream();
byte[] data = new byte[1024];
int numRead;
long numWritten = 0;
int length = fileToDownload.getContentLength();
while ((numRead = readFileToDownload.read(data)) != -1) {
fileDestination.write(data, 0, numRead);
numWritten += numRead;
int percentage = (int)(((double)numWritten / (double)length) * 100D);
download.updateProgressBar(percentage);
}
frame.setVisible(false);
JOptionPane.showMessageDialog(this.aJFrame, "The Cache has finished downloading!");
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (readFileToDownload != null)
readFileToDownload.close();
if (fileDestination != null)
fileDestination.close();
} catch (IOException ioe) {
}
}
}
public String getFileName() {
int lastSlashIndex = getCacheLink().lastIndexOf('/');
if (lastSlashIndex >= 0 && lastSlashIndex < getCacheLink().length() -1)
return getCacheLink().substring(lastSlashIndex + 1);
return "";
}
public void deleteDownloadedZipFile(String fileName) {
File f = new File(getSaveDirectory() + fileName);
if (!f.exists())
throw new IllegalArgumentException(
"Delete: no such file or directory: " + fileName);
if (!f.canWrite())
throw new IllegalArgumentException("Delete: write protected: "
+ fileName);
if (f.isDirectory()) {
String[] files = f.list();
if (files.length > 0)
throw new IllegalArgumentException(
"Delete: directory not empty: " + fileName);
}
boolean success = f.delete();
if (!success)
throw new IllegalArgumentException("Delete: deletion failed");
}
public 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(getSaveDirectory() + e.getName())).mkdir();
} else {
if (e.getName().equals(fileToExtract)) {
unzip(zin, fileToExtract);
break;
}
unzip(zin, getSaveDirectory() + e.getName());
}
}
zin.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void unzip(ZipInputStream zin, String s) throws IOException {
FileOutputStream out = new FileOutputStream(s);
byte[] b = new byte[1024];
int len = 0;
while ((len = zin.read(b)) != -1) {
out.write(b, 0, len);
}
out.close();
}
}