Fix: ui, set a global progress on the download

This commit is contained in:
Laurent Clouet
2024-04-11 15:24:50 +00:00
parent 50ddc9ae3f
commit 74b39797ce
8 changed files with 97 additions and 58 deletions

View File

@@ -36,15 +36,13 @@ public class DownloadManager {
private Log log;
// task specific objects
private String gui_text; // what do display on the gui
private String local_target;
private String md5; // expected md5 of the file, for check purpose
private String remote; // remote url
public DownloadManager(Server server, Gui gui, Log log, String gui_text, String local_target, String md5, String remote) {
public DownloadManager(Server server, Gui gui, Log log, String local_target, String md5, String remote) {
this.server = server;
this.gui = gui;
this.gui_text = gui_text;
this.log = log;
this.local_target = local_target;
this.md5 = md5;
@@ -61,15 +59,14 @@ public class DownloadManager {
do {
// if the binary or scene already exists in the cache
if (local_path_file.exists()) {
this.gui.status("Reusing cached " + this.gui_text);
this.gui.status("Reusing cached");
return Error.Type.OK;
}
// if the binary or scene is being downloaded by another client
else if (this.lockExists()) {
// Wait and check every second for file download completion but only update the GUI every 10 seconds to minimise CPU load
if (remaining % 10000 == 0) {
this.gui.status(String.format("Another client is downloading the %s. Cancel in %dmin %ds",
this.gui_text,
this.gui.status(String.format("Another client is downloading. Cancel in %dmin %ds",
TimeUnit.MILLISECONDS.toMinutes(remaining),
TimeUnit.MILLISECONDS.toSeconds(remaining) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(remaining))
));
@@ -100,16 +97,14 @@ public class DownloadManager {
}
}
this.gui.status(String.format("Downloading %s", this.gui_text));
this.gui.status(String.format("Downloading"));
return this.downloadActual();
}
private Error.Type downloadActual() throws SheepItException {
String update_ui = "Downloading " + this.gui_text;
// must download the archive
Error.Type ret = this.server.HTTPGetFile(this.remote, this.local_target, this.gui, update_ui);
Error.Type ret = this.server.HTTPGetFile(this.remote, this.local_target, this.gui);
if (ret == Error.Type.RENDERER_KILLED_BY_SERVER || ret == Error.Type.RENDERER_KILLED_BY_USER_OVER_TIME || ret == Error.Type.RENDERER_KILLED_BY_USER) {
return ret;
@@ -121,11 +116,11 @@ public class DownloadManager {
while ((ret != Error.Type.OK || md5_check == false) && attempts < this.maxDownloadFileAttempts) {
if (ret != Error.Type.OK) {
this.gui.error(String.format("Unable to download %s (error %s). Retrying now", this.gui_text, ret));
this.gui.error(String.format("Unable to download (error %s). Retrying now", ret));
this.log.debug("DownloadManager::downloadActual problem with Server.HTTPGetFile (return: " + ret + ") removing local file (path: " + this.local_target + ")");
}
else if (md5_check == false) {
this.gui.error(String.format("Verification of downloaded %s has failed. Retrying now", this.gui_text));
this.gui.error(String.format("Verification of downloaded %s has failed. Retrying now"));
this.log.debug("DownloadManager::downloadActual problem with Client::checkFile mismatch on md5, removing local file (path: " + this.local_target + ")");
}
@@ -134,7 +129,7 @@ public class DownloadManager {
this.log.debug("DownloadManager::downloadActual failed, let's try again (" + (attempts + 1) + "/" + this.maxDownloadFileAttempts + ") ...");
String partial_target = this.local_target + ".partial";
ret = this.server.HTTPGetFile(this.remote, partial_target, this.gui, update_ui);
ret = this.server.HTTPGetFile(this.remote, partial_target, this.gui);
md5_check = this.check();
attempts++;