Skip to content

Commit

Permalink
overhauled UI + combined Java and XMage installs + added feature to f…
Browse files Browse the repository at this point in the history
…orce updates
  • Loading branch information
BetaSteward committed Dec 7, 2014
1 parent d951f04 commit 601a74e
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 262 deletions.
46 changes: 29 additions & 17 deletions src/main/java/com/xmage/launcher/DownloadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
Expand All @@ -26,34 +28,44 @@
public abstract class DownloadTask extends SwingWorker<Void, Void> {

private static final int BUFFER_SIZE = 4096;
private static final Logger logger = LoggerFactory.getLogger(DownloadTask.class);

private final JProgressBar progressBar;

public DownloadTask(JProgressBar progressBar) {
this.progressBar = progressBar;
}

protected void download(URL downloadURL, String saveDirectory, String cookies) throws IOException {
Downloader dl = new Downloader();
dl.connect(downloadURL, cookies);
protected boolean download(URL downloadURL, String saveDirectory, String cookies) throws IOException {
try {
Downloader dl = new Downloader();
dl.connect(downloadURL, cookies);

BufferedInputStream in = dl.getInputStream();
BufferedInputStream in = dl.getInputStream();

File temp = new File(saveDirectory + File.separator + "xmage.dl");
FileOutputStream fout = new FileOutputStream(temp);
File temp = new File(saveDirectory + File.separator + "xmage.dl");
FileOutputStream fout = new FileOutputStream(temp);

final byte data[] = new byte[BUFFER_SIZE];
int count;
long total = 0;
long size = dl.getSize();
progressBar.setValue(0);
while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
fout.write(data, 0, count);
total += count;
progressBar.setValue((int)((total * 100)/size));
final byte data[] = new byte[BUFFER_SIZE];
int count;
long total = 0;
long size = dl.getSize();
progressBar.setValue(0);
while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
fout.write(data, 0, count);
total += count;
progressBar.setValue((int)((total * 100)/size));
}
fout.close();
dl.disconnect();
return true;
}
catch (IOException ex) {
progressBar.setValue(0);
this.cancel(true);
logger.error("Error: ", ex);
return false;
}
fout.close();
dl.disconnect();
}

public void torrent(File from, File to) throws IOException {
Expand Down
Loading

0 comments on commit 601a74e

Please sign in to comment.