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) {
|
||||
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) {
|
||||
gui.status(String.format(this.guiPattern + " %.0f %%", 100.0f * this.partial / this.total));
|
||||
}
|
||||
|
||||
@@ -519,6 +519,7 @@ public class ServerRequest extends Thread {
|
||||
InputStream is = null;
|
||||
OutputStream output = null;
|
||||
|
||||
long written = 0;
|
||||
try {
|
||||
Response response = this.HTTPRequest(url_);
|
||||
|
||||
@@ -534,7 +535,6 @@ public class ServerRequest extends Thread {
|
||||
// only update the gui every 1MB
|
||||
byte[] buffer = new byte[1024 * 1024];
|
||||
int len;
|
||||
long written = 0;
|
||||
|
||||
this.log.debug("Downloading file from " + response.request().url().host());
|
||||
LocalDateTime startRequestTime = LocalDateTime.now();
|
||||
@@ -574,6 +574,8 @@ public class ServerRequest extends Thread {
|
||||
throw new SheepItExceptionNoSpaceLeftOnDevice();
|
||||
}
|
||||
|
||||
gui_.getDownloadProgress().removeProgress(written);
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(sw));
|
||||
this.log.error("Server::HTTPGetFile Exception " + e + " stacktrace " + sw.toString());
|
||||
|
||||
Reference in New Issue
Block a user