X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fui%2Fstdin%2FCommandReader.java;h=e9bcc3ce8af199e61303c7ea8890f54c702c1504;hb=7cf4d960b265bfa56af6c7abda94eaf00233c6c0;hp=83c98023d8aa9d50f2c7ed06a3f20bd57d6b018c;hpb=f76ee64d2cd93a0439c6306e1fcf6230c633590c;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java index 83c9802..e9bcc3c 100644 --- a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java +++ b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java @@ -28,6 +28,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; import java.io.Writer; +import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -39,6 +40,7 @@ import net.pterodactylus.xdcc.core.event.DownloadStarted; import net.pterodactylus.xdcc.core.event.GenericMessage; import net.pterodactylus.xdcc.core.event.MessageReceived; import net.pterodactylus.xdcc.data.Download; +import net.pterodactylus.xdcc.util.io.DuplicateLineSuppressingWriter; import com.google.common.base.Joiner; import com.google.common.base.Optional; @@ -62,7 +64,7 @@ public class CommandReader extends AbstractExecutionThreadService { /** The writer to write the results to. */ private final Writer writer; - private final DownloadFailures downloadFailures; + private final Collection failedDownloads; /** * Creates a new command reader. @@ -74,10 +76,10 @@ public class CommandReader extends AbstractExecutionThreadService { * @param writer * The write to write results to */ - public CommandReader(Core core, Reader reader, Writer writer, DownloadFailures downloadFailures) { + public CommandReader(Core core, Reader reader, Writer writer, Collection failedDownloads) { this.reader = new BufferedReader(reader); - this.writer = writer; - this.downloadFailures = downloadFailures; + this.writer = new DuplicateLineSuppressingWriter(writer); + this.failedDownloads = failedDownloads; /* initialize commands. */ ImmutableList.Builder commandBuilder = ImmutableList.builder(); @@ -88,8 +90,8 @@ public class CommandReader extends AbstractExecutionThreadService { commandBuilder.add(new ListConnectionsCommand(core)); commandBuilder.add(new AbortDownloadCommand(core)); commandBuilder.add(new DisconnectCommand(core)); - commandBuilder.add(new FailedDownloadsCommand(downloadFailures)); - commandBuilder.add(new RestartCommand(core, downloadFailures)); + commandBuilder.add(new FailedDownloadsCommand(failedDownloads)); + commandBuilder.add(new RestartCommand(core, failedDownloads)); commandBuilder.add(new ResearchCommand(core)); commands = commandBuilder.build(); } @@ -154,6 +156,7 @@ public class CommandReader extends AbstractExecutionThreadService { @Subscribe public void downloadFinished(DownloadFinished downloadFinished) { Download download = downloadFinished.download(); + removeFailedDownloads(download.pack().name()); try { 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) { @@ -161,6 +164,16 @@ public class CommandReader extends AbstractExecutionThreadService { } } + private void removeFailedDownloads(String name) { + List failedDownloadsToRemove = new ArrayList<>(); + for (Download failedDownload : failedDownloads) { + if (failedDownload.pack().name().equals(name)) { + failedDownloadsToRemove.add(failedDownload); + } + } + failedDownloads.removeAll(failedDownloadsToRemove); + } + /** * Called when a download fails. * @@ -170,7 +183,7 @@ public class CommandReader extends AbstractExecutionThreadService { @Subscribe public void downloadFailed(DownloadFailed downloadFailed) { Download download = downloadFailed.download(); - downloadFailures.addFailedDownload(download, System.currentTimeMillis()); + failedDownloads.add(download); try { 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) {