Fix: #60 wrong progress on download error
This commit is contained in:
@@ -41,6 +41,18 @@ public class DownloadProgress {
|
|||||||
|
|
||||||
public synchronized void addProgress(long progress) {
|
public synchronized void addProgress(long progress) {
|
||||||
this.partial += progress;
|
this.partial += progress;
|
||||||
|
this.updateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In case of an issue on a download, remove the already downloaded progress
|
||||||
|
*/
|
||||||
|
public synchronized void removeProgress(long progress) {
|
||||||
|
this.partial -= progress;
|
||||||
|
this.updateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateUI() {
|
||||||
if (this.total != 0) {
|
if (this.total != 0) {
|
||||||
gui.status(String.format(this.guiPattern + " %.0f %%", 100.0f * this.partial / this.total));
|
gui.status(String.format(this.guiPattern + " %.0f %%", 100.0f * this.partial / this.total));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -518,7 +518,8 @@ public class ServerRequest extends Thread {
|
|||||||
this.log.debug("Server::HTTPGetFile destination: " + destination_);
|
this.log.debug("Server::HTTPGetFile destination: " + destination_);
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
|
|
||||||
|
long written = 0;
|
||||||
try {
|
try {
|
||||||
Response response = this.HTTPRequest(url_);
|
Response response = this.HTTPRequest(url_);
|
||||||
|
|
||||||
@@ -534,7 +535,6 @@ public class ServerRequest extends Thread {
|
|||||||
// only update the gui every 1MB
|
// only update the gui every 1MB
|
||||||
byte[] buffer = new byte[1024 * 1024];
|
byte[] buffer = new byte[1024 * 1024];
|
||||||
int len;
|
int len;
|
||||||
long written = 0;
|
|
||||||
|
|
||||||
this.log.debug("Downloading file from " + response.request().url().host());
|
this.log.debug("Downloading file from " + response.request().url().host());
|
||||||
LocalDateTime startRequestTime = LocalDateTime.now();
|
LocalDateTime startRequestTime = LocalDateTime.now();
|
||||||
@@ -574,6 +574,8 @@ public class ServerRequest extends Thread {
|
|||||||
throw new SheepItExceptionNoSpaceLeftOnDevice();
|
throw new SheepItExceptionNoSpaceLeftOnDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gui_.getDownloadProgress().removeProgress(written);
|
||||||
|
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
e.printStackTrace(new PrintWriter(sw));
|
e.printStackTrace(new PrintWriter(sw));
|
||||||
this.log.error("Server::HTTPGetFile Exception " + e + " stacktrace " + sw.toString());
|
this.log.error("Server::HTTPGetFile Exception " + e + " stacktrace " + sw.toString());
|
||||||
|
|||||||
Reference in New Issue
Block a user