Fix: ui, set a global progress on the download
This commit is contained in:
@@ -491,7 +491,7 @@ public class Server extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
public Error.Type HTTPGetFile(String url_, String destination_, Gui gui_, String status_) throws SheepItException {
|
||||
public Error.Type HTTPGetFile(String url_, String destination_, Gui gui_) throws SheepItException {
|
||||
this.log.debug("Server::HTTPGetFile destination: " + destination_);
|
||||
InputStream is = null;
|
||||
OutputStream output = null;
|
||||
@@ -508,10 +508,14 @@ public class Server extends Thread {
|
||||
output = new FileOutputStream(destination_ + ".partial");
|
||||
|
||||
long size = response.body().contentLength();
|
||||
byte[] buffer = new byte[8 * 1024];
|
||||
// only update the gui every 1MB
|
||||
byte[] buffer = new byte[1024 * 1024];
|
||||
int len = 0;
|
||||
long written = 0;
|
||||
long lastUpd = 0; // last GUI progress update
|
||||
|
||||
if (size != -1) {
|
||||
gui_.getDownloadProgress().addTotal(size);
|
||||
}
|
||||
|
||||
this.log.debug("Downloading file from " + response.request().url().host());
|
||||
LocalDateTime startRequestTime = LocalDateTime.now();
|
||||
@@ -526,20 +530,13 @@ public class Server extends Thread {
|
||||
|
||||
output.write(buffer, 0, len);
|
||||
written += len;
|
||||
|
||||
if ((written - lastUpd) > 1000000) { // only update the gui every 1MB
|
||||
if (size != -1) { // no header for contentlength
|
||||
gui_.status(status_, (int) (100.0 * written / size), written);
|
||||
}
|
||||
lastUpd = written;
|
||||
}
|
||||
gui_.getDownloadProgress().addProgress(len);
|
||||
}
|
||||
|
||||
LocalDateTime endRequestTime = LocalDateTime.now();
|
||||
Duration duration = Duration.between(startRequestTime, endRequestTime);
|
||||
this.dlStats.calc(written, ((duration.getSeconds() * 1000) + (duration.getNano() / 1000000)));
|
||||
gui_.displayTransferStats(dlStats, ulStats);
|
||||
gui_.status(status_, 100, size);
|
||||
|
||||
this.log.debug(String.format("File downloaded at %s/s, written %d bytes", new TransferStats(size, duration.toMillis() + 1).getAverageSessionSpeed(), written));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user