diff --git a/src/com/sheepit/client/Client.java b/src/com/sheepit/client/Client.java index edd80d2..edb4dfe 100644 --- a/src/com/sheepit/client/Client.java +++ b/src/com/sheepit/client/Client.java @@ -703,14 +703,14 @@ import lombok.Data; private int downloadFile(Job ajob, String local_path, String md5_server, String url, String download_type) throws FermeExceptionNoSpaceLeftOnDevice { File local_path_file = new File(local_path); - String update_ui = "Downloading " + download_type + " %s %%"; + String update_ui = "Downloading " + download_type; if (local_path_file.exists() == true) { this.gui.status("Reusing cached " + download_type); return 0; } - this.gui.status("Downloading " + download_type); + this.gui.status(String.format("Downloading %s", download_type), 0, 0); // must download the archive int ret = this.server.HTTPGetFile(url, local_path, this.gui, update_ui); diff --git a/src/com/sheepit/client/Gui.java b/src/com/sheepit/client/Gui.java index 3403bf9..f5e39c3 100644 --- a/src/com/sheepit/client/Gui.java +++ b/src/com/sheepit/client/Gui.java @@ -28,6 +28,8 @@ public interface Gui { public void status(String msg_, boolean overwriteSuspendedMsg); + public void status(String msg_, int progress, long size); + public void updateTrayIcon(Integer percentage_); public void setRenderingProjectName(String name_); diff --git a/src/com/sheepit/client/Server.java b/src/com/sheepit/client/Server.java index 96f520f..740b578 100644 --- a/src/com/sheepit/client/Server.java +++ b/src/com/sheepit/client/Server.java @@ -439,7 +439,7 @@ public class Server extends Thread { written += len; if ((written - lastUpd) > 1000000) { // only update the gui every 1MB - gui_.status(String.format(status_, (int) (100.0 * written / size))); + gui_.status(status_, (int) (100.0 * written / size), written); lastUpd = written; } } @@ -448,7 +448,7 @@ public class Server extends Thread { output.close(); is.close(); - gui_.status(String.format(status_, 100)); + gui_.status(status_, 100, size); long end = new Date().getTime(); this.log.debug(String.format("File downloaded at %.1f kB/s, written %d B", ((float) (size / 1000)) / ((float) (end - start) / 1000), written)); diff --git a/src/com/sheepit/client/standalone/GuiSwing.java b/src/com/sheepit/client/standalone/GuiSwing.java index 947641e..ac38ceb 100644 --- a/src/com/sheepit/client/standalone/GuiSwing.java +++ b/src/com/sheepit/client/standalone/GuiSwing.java @@ -191,6 +191,12 @@ public class GuiSwing extends JFrame implements Gui { } } + @Override public void status(String msg, int progress, long size) { + if (activityWorking != null) { + this.activityWorking.setStatus(String.format("%s %d%%", msg, progress)); + } + } + @Override public void setRenderingProjectName(String name_) { if (activityWorking != null) { this.activityWorking.setRenderingProjectName(name_); diff --git a/src/com/sheepit/client/standalone/GuiText.java b/src/com/sheepit/client/standalone/GuiText.java index a4e1183..b0a892d 100644 --- a/src/com/sheepit/client/standalone/GuiText.java +++ b/src/com/sheepit/client/standalone/GuiText.java @@ -31,6 +31,7 @@ import sun.misc.SignalHandler; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Collections; import java.util.Date; public class GuiText implements Gui { @@ -110,6 +111,11 @@ public class GuiText implements Gui { } } + @Override public void status(String msg, int progress, long size) { + System.out.print("\r"); + System.out.print(String.format("%s %s", this.df.format(new Date()), showProgress(msg, progress, size))); + } + @Override public void error(String err_) { System.out.println(String.format("ERROR: %s %s", this.df.format(new Date()), err_)); log.error("Error " + err_); @@ -160,4 +166,28 @@ public class GuiText implements Gui { @Override public void successfulAuthenticationEvent(String publickey) { } + + private String showProgress(String message, int progress, long size) { + StringBuilder progressBar = new StringBuilder(140); + progressBar + .append(message) + .append(" ") + .append(String.join("", Collections.nCopies(progress == 0 ? 2 : 2 - (int) (Math.log10(progress)), " "))) + .append(String.format("%d%% [", progress)) + .append(String.join("", Collections.nCopies((int)(progress/5), "="))) + .append('>') + .append(String.join("", Collections.nCopies(20 - (int)(progress / 5), " "))) + .append(']'); + + if (size > 0) { + progressBar.append(String.format(" %dMB", (size / 1024 / 1024))); + } + + // Once the process has completed, show the output in a new line + if (progress == 100) { + progressBar.append("\n"); + } + + return progressBar.toString(); + } } diff --git a/src/com/sheepit/client/standalone/GuiTextOneLine.java b/src/com/sheepit/client/standalone/GuiTextOneLine.java index 43e2a20..f470be3 100644 --- a/src/com/sheepit/client/standalone/GuiTextOneLine.java +++ b/src/com/sheepit/client/standalone/GuiTextOneLine.java @@ -30,6 +30,7 @@ import sun.misc.SignalHandler; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Collections; import java.util.Date; public class GuiTextOneLine implements Gui { @@ -122,12 +123,17 @@ public class GuiTextOneLine implements Gui { } } + @Override public void status(String msg, int progress, long size) { + status = showProgress(msg, progress, size); + updateLine(); + } + @Override public void setRenderingProjectName(String name_) { if (name_ == null || name_.isEmpty()) { project = ""; } else { - project = "Project \"" + name_ + "\" |"; + project = name_ + " |"; } updateLine(); } @@ -154,7 +160,7 @@ public class GuiTextOneLine implements Gui { } @Override public void setRemainingTime(String time_) { - status = "(remaining " + time_ + ")"; + status = "Rendering (remaining " + time_ + ")"; updateLine(); } @@ -184,14 +190,42 @@ public class GuiTextOneLine implements Gui { System.out.print("\r"); - line = String.format("%s Frames: %d Points: %s | Queued uploads: %d%s | %s %s %s", df.format(new Date()), rendered, - creditsEarned != null ? creditsEarned : "unknown", this.uploadQueueSize, - (this.uploadQueueSize > 0 ? String.format(" (%.2fMB)", (this.uploadQueueVolume / 1024.0 / 1024.0)) : ""), project, computeMethod, - status + (exiting ? " (Exiting after all frames are uploaded)" : "")); + line = String.format("%s Frames: %d Points: %s | Upload Queue: %d%s | %%s %s %s", df.format(new Date()), rendered, + creditsEarned != null ? creditsEarned : "unknown", this.uploadQueueSize, + (this.uploadQueueSize > 0 ? String.format(" (%.2fMB)", (this.uploadQueueVolume / 1024.0 / 1024.0)) : ""), computeMethod, + status + (exiting ? " (Exiting after all frames are uploaded)" : "")); + + if (line.length() + project.length() > 120) { + // If the line without the project name is already >120 characters (might happen if the user has thousands of frames and millions of points in the + // session + is exiting after all frames are uploaded) then set the line to 117c to avoid a negative number exception in substring function + int lineLength = (line.length() >= 120 ? 117 : line.length()); + line = String.format(line, project.substring(0, 117 - lineLength) + "..."); + } + else { + line = String.format(line, project); + } System.out.print(line); for (int i = line.length(); i <= charToRemove; i++) { System.out.print(" "); } } + + private String showProgress(String message, int progress, long size) { + StringBuilder progressBar = new StringBuilder(140); + progressBar + .append(message) + .append(String.join("", Collections.nCopies(progress == 0 ? 2 : 2 - (int) (Math.log10(progress)), " "))) + .append(String.format(" %d%%%% [", progress)) + .append(String.join("", Collections.nCopies((int) (progress / 10), "="))) + .append('>') + .append(String.join("", Collections.nCopies(10 - (int) (progress / 10), " "))) + .append(']'); + + if (size > 0) { + progressBar.append(String.format(" %dMB", (size / 1024 / 1024))); + } + + return progressBar.toString(); + } }