Fix: #60 wrong progress on download error

This commit is contained in:
Laurent Clouet
2025-06-30 09:58:10 +02:00
parent 19788260cb
commit c7bac99a90
2 changed files with 16 additions and 2 deletions

View File

@@ -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));
} }

View File

@@ -519,6 +519,7 @@ public class ServerRequest extends Thread {
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());