Only store the failed downloads.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / ui / stdin / CommandReader.java
index 01d0051..fc1a48f 100644 (file)
@@ -19,6 +19,9 @@ package net.pterodactylus.xdcc.ui.stdin;
 
 import static com.google.common.collect.FluentIterable.from;
 import static java.util.Arrays.asList;
+import static net.pterodactylus.xdcc.ui.stdin.Ansi.bold;
+import static net.pterodactylus.xdcc.ui.stdin.Ansi.green;
+import static net.pterodactylus.xdcc.ui.stdin.Ansi.red;
 import static net.pterodactylus.xdcc.ui.stdin.Command.TO_NAME;
 
 import java.io.BufferedReader;
@@ -59,6 +62,7 @@ public class CommandReader extends AbstractExecutionThreadService {
 
        /** The writer to write the results to. */
        private final Writer writer;
+       private final Collection<Download> failedDownloads;
 
        /**
         * Creates a new command reader.
@@ -70,9 +74,10 @@ public class CommandReader extends AbstractExecutionThreadService {
         * @param writer
         *              The write to write results to
         */
-       public CommandReader(Core core, Reader reader, Writer writer) {
+       public CommandReader(Core core, Reader reader, Writer writer, Collection<Download> failedDownloads) {
                this.reader = new BufferedReader(reader);
                this.writer = writer;
+               this.failedDownloads = failedDownloads;
 
                /* initialize commands. */
                ImmutableList.Builder<Command> commandBuilder = ImmutableList.builder();
@@ -83,6 +88,9 @@ public class CommandReader extends AbstractExecutionThreadService {
                commandBuilder.add(new ListConnectionsCommand(core));
                commandBuilder.add(new AbortDownloadCommand(core));
                commandBuilder.add(new DisconnectCommand(core));
+               commandBuilder.add(new FailedDownloadsCommand(failedDownloads));
+               commandBuilder.add(new RestartCommand(core, failedDownloads));
+               commandBuilder.add(new ResearchCommand(core));
                commands = commandBuilder.build();
        }
 
@@ -131,7 +139,7 @@ public class CommandReader extends AbstractExecutionThreadService {
        public void downloadStarted(DownloadStarted downloadStarted) {
                Download download = downloadStarted.download();
                try {
-                       writeLine(String.format("Download of %s (from %s, %s) has started.", download.pack().name(), download.bot().name(), download.bot().network().name()));
+                       writeLine(String.format("Download of %s (from %s, %s) has started.", bold(download.pack().name()), download.bot().name(), download.bot().network().name()));
                } catch (IOException ioe1) {
                        /* ignore. */
                }
@@ -147,7 +155,7 @@ public class CommandReader extends AbstractExecutionThreadService {
        public void downloadFinished(DownloadFinished downloadFinished) {
                Download download = downloadFinished.download();
                try {
-                       writeLine(String.format("Download of %s (from %s, %s) has finished, at %s/s.", download.pack().name(), download.bot().name(), download.bot().network().name(), f(download.dccReceiver().overallRate())));
+                       writeLine(green(String.format("Download of %s (from %s, %s) has finished, at %s/s.", download.pack().name(), download.bot().name(), download.bot().network().name(), f(download.dccReceiver().overallRate()))));
                } catch (IOException ioe1) {
                        /* ignore. */
                }
@@ -162,8 +170,9 @@ public class CommandReader extends AbstractExecutionThreadService {
        @Subscribe
        public void downloadFailed(DownloadFailed downloadFailed) {
                Download download = downloadFailed.download();
+               failedDownloads.add(download);
                try {
-                       writeLine(String.format("Download of %s (from %s, %s) has failed at %.1f%% and %s/s.", download.filename(), download.bot().name(), download.bot().network().name(), download.dccReceiver().progress() * 100.0 / download.dccReceiver().size(), f(download.dccReceiver().overallRate())));
+                       writeLine(red(String.format("Download of %s (from %s, %s) has failed at %.1f%% and %s/s.", download.filename(), download.bot().name(), download.bot().network().name(), download.dccReceiver().progress() * 100.0 / download.dccReceiver().size(), f(download.dccReceiver().overallRate()))));
                } catch (IOException ioe1) {
                        /* ignore. */
                }