2014-11-20 13:21:19 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010-2014 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
2020-05-28 13:28:42 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
2014-11-20 13:21:19 +00:00
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; version 2
|
|
|
|
|
* of the License.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.sheepit.client.standalone;
|
|
|
|
|
|
2015-01-15 23:20:17 +01:00
|
|
|
import com.sheepit.client.Client;
|
2014-11-20 13:21:19 +00:00
|
|
|
import com.sheepit.client.Gui;
|
|
|
|
|
import com.sheepit.client.Log;
|
2016-10-12 00:34:51 +02:00
|
|
|
import com.sheepit.client.Stats;
|
2020-09-12 10:00:24 +10:00
|
|
|
import com.sheepit.client.TransferStats;
|
2017-02-19 14:19:48 +01:00
|
|
|
import com.sheepit.client.standalone.text.CLIInputActionHandler;
|
|
|
|
|
import com.sheepit.client.standalone.text.CLIInputObserver;
|
2016-10-12 00:34:51 +02:00
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
import sun.misc.Signal;
|
|
|
|
|
import sun.misc.SignalHandler;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
2020-06-03 01:10:14 +10:00
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
2020-06-14 20:01:32 +10:00
|
|
|
import java.util.Collections;
|
2020-06-03 01:10:14 +10:00
|
|
|
import java.util.Date;
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
public class GuiText implements Gui {
|
2015-04-08 20:32:24 +01:00
|
|
|
public static final String type = "text";
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
private int framesRendered;
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
private int sigIntCount = 0;
|
2014-11-20 13:21:19 +00:00
|
|
|
private Log log;
|
2020-06-03 01:10:14 +10:00
|
|
|
private DateFormat df;
|
2020-06-17 18:24:59 +10:00
|
|
|
private String eta;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
2015-01-27 21:44:32 +00:00
|
|
|
private Client client;
|
|
|
|
|
|
2014-11-20 13:21:19 +00:00
|
|
|
public GuiText() {
|
|
|
|
|
this.framesRendered = 0;
|
|
|
|
|
this.log = Log.getInstance(null);
|
2020-06-03 01:10:14 +10:00
|
|
|
this.df = new SimpleDateFormat("MMM dd HH:mm:ss");
|
2020-06-17 18:24:59 +10:00
|
|
|
this.eta = "";
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void start() {
|
2015-01-27 21:44:32 +00:00
|
|
|
if (client != null) {
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2017-02-19 14:19:48 +01:00
|
|
|
CLIInputObserver cli_input_observer = new CLIInputObserver(client);
|
|
|
|
|
cli_input_observer.addListener(new CLIInputActionHandler());
|
|
|
|
|
Thread cli_input_observer_thread = new Thread(cli_input_observer);
|
|
|
|
|
cli_input_observer_thread.start();
|
|
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
Signal.handle(new Signal("INT"), new SignalHandler() {
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void handle(Signal signal) {
|
2016-01-27 13:41:11 +01:00
|
|
|
sigIntCount++;
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2016-01-27 13:41:11 +01:00
|
|
|
if (sigIntCount == 4) {
|
|
|
|
|
// This is only for ugly issues that might occur
|
|
|
|
|
System.out.println("WARNING: Hitting Ctrl-C again will force close the application.");
|
|
|
|
|
}
|
|
|
|
|
else if (sigIntCount == 5) {
|
|
|
|
|
Signal.raise(new Signal("INT"));
|
|
|
|
|
Runtime.getRuntime().halt(0);
|
|
|
|
|
}
|
|
|
|
|
else if (client.isRunning() && client.isSuspended() == false) {
|
|
|
|
|
client.askForStop();
|
|
|
|
|
System.out.println("Will exit after current frame... Press Ctrl+C again to exit now.");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
client.stop();
|
2016-02-16 23:51:16 +01:00
|
|
|
GuiText.this.stop();
|
2016-01-27 13:41:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-01-05 09:35:59 +01:00
|
|
|
|
2015-01-27 21:44:32 +00:00
|
|
|
client.run();
|
|
|
|
|
client.stop();
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void stop() {
|
2016-01-27 13:41:11 +01:00
|
|
|
Runtime.getRuntime().halt(0);
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
|
|
|
|
@Override public void updateTrayIcon(Integer percentage) {
|
2020-03-19 23:48:06 +01:00
|
|
|
}
|
2020-05-28 13:28:42 +02:00
|
|
|
|
|
|
|
|
@Override public void status(String msg_) {
|
2020-04-26 23:35:05 +10:00
|
|
|
status(msg_, false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void status(String msg_, boolean overwriteSuspendedMsg) {
|
2014-11-20 13:21:19 +00:00
|
|
|
log.debug("GUI " + msg_);
|
2020-04-26 23:35:05 +10:00
|
|
|
|
|
|
|
|
if (client != null && client.isSuspended()) {
|
|
|
|
|
if (overwriteSuspendedMsg) {
|
2020-06-03 01:10:14 +10:00
|
|
|
System.out.println(String.format("%s %s", this.df.format(new Date()), msg_));
|
2020-04-26 23:35:05 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-06-03 01:10:14 +10:00
|
|
|
System.out.println(String.format("%s %s", this.df.format(new Date()), msg_));
|
2020-04-26 23:35:05 +10:00
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-17 18:24:59 +10:00
|
|
|
@Override public void status(String msg, int progress) {
|
|
|
|
|
this.status(msg, progress, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-14 20:01:32 +10:00
|
|
|
@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)));
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void error(String err_) {
|
2020-06-03 01:10:14 +10:00
|
|
|
System.out.println(String.format("ERROR: %s %s", this.df.format(new Date()), err_));
|
2014-11-20 13:21:19 +00:00
|
|
|
log.error("Error " + err_);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void AddFrameRendered() {
|
2014-11-20 13:21:19 +00:00
|
|
|
this.framesRendered += 1;
|
2020-06-03 01:10:14 +10:00
|
|
|
System.out.println(String.format("%s Frames rendered: %d", this.df.format(new Date()), this.framesRendered));
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:00:24 +10:00
|
|
|
@Override public synchronized void displayTransferStats(TransferStats downloads, TransferStats uploads) {
|
|
|
|
|
System.out.println(String
|
|
|
|
|
.format("%s Session downloads: %s @ %s/s / Uploads: %s @ %s/s", this.df.format(new Date()), downloads.getSessionTraffic(),
|
|
|
|
|
downloads.getAverageSessionSpeed(), uploads.getSessionTraffic(), uploads.getAverageSessionSpeed()));
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void displayStats(Stats stats) {
|
2020-06-03 01:10:14 +10:00
|
|
|
System.out.println(String.format("%s Frames remaining: %d", this.df.format(new Date()), stats.getRemainingFrame()));
|
|
|
|
|
System.out.println(String.format("%s Credits earned: %d", this.df.format(new Date()), stats.getCreditsEarnedDuringSession()));
|
2016-10-12 00:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void displayUploadQueueStats(int queueSize, long queueVolume) {
|
2020-04-20 01:01:43 +10:00
|
|
|
// No need to check if the queue is not empty to show the volume bc this line is always shown at the end
|
|
|
|
|
// of the render process in text GUI (unless an error occurred, where the file is uploaded synchronously)
|
2020-06-03 01:10:14 +10:00
|
|
|
System.out.println(String.format("%s Queued uploads: %d (%.2fMB)", this.df.format(new Date()), queueSize, (queueVolume / 1024.0 / 1024.0)));
|
2020-04-20 01:01:43 +10:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setRenderingProjectName(String name_) {
|
2016-10-12 00:34:51 +02:00
|
|
|
if (name_ != null && name_.isEmpty() == false) {
|
2020-06-03 01:10:14 +10:00
|
|
|
System.out.println(String.format("%s Rendering project \"%s\"", this.df.format(new Date()), name_));
|
2016-10-12 00:34:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setRemainingTime(String time_) {
|
2020-06-17 18:24:59 +10:00
|
|
|
this.eta = time_;
|
2016-10-12 00:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setRenderingTime(String time_) {
|
2020-06-03 01:10:14 +10:00
|
|
|
System.out.println(String.format("%s Rendering %s", this.df.format(new Date()), time_));
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setClient(Client cli) {
|
2015-01-27 21:44:32 +00:00
|
|
|
client = cli;
|
2015-01-15 23:20:17 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void setComputeMethod(String computeMethod) {
|
2020-06-03 01:10:14 +10:00
|
|
|
System.out.println(String.format("%s Compute method: %s", this.df.format(new Date()), computeMethod));
|
2017-05-07 21:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public Client getClient() {
|
2015-01-27 21:44:32 +00:00
|
|
|
return client;
|
2015-01-15 23:20:17 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 13:28:42 +02:00
|
|
|
@Override public void successfulAuthenticationEvent(String publickey) {
|
2019-08-22 21:35:26 +02:00
|
|
|
|
|
|
|
|
}
|
2020-06-14 20:01:32 +10:00
|
|
|
|
|
|
|
|
private String showProgress(String message, int progress, long size) {
|
|
|
|
|
StringBuilder progressBar = new StringBuilder(140);
|
|
|
|
|
|
2020-06-17 18:24:59 +10:00
|
|
|
if (progress < 100) {
|
|
|
|
|
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)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this.eta.equals("")) {
|
|
|
|
|
progressBar.append(String.format(" ETA %s", this.eta));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
progressBar.append(String.join("", Collections.nCopies(60 - progressBar.length(), " ")));
|
2020-06-14 20:01:32 +10:00
|
|
|
}
|
2020-06-17 18:24:59 +10:00
|
|
|
// If progress has reached 100%
|
|
|
|
|
else {
|
|
|
|
|
progressBar
|
|
|
|
|
.append(message)
|
|
|
|
|
.append(" done")
|
|
|
|
|
.append(String.join("", Collections.nCopies(60 - progressBar.length(), " ")))
|
|
|
|
|
.append("\n");
|
2020-06-14 20:01:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return progressBar.toString();
|
|
|
|
|
}
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|