Remove failed downloads when a download finishes.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 15 Jan 2014 05:34:22 +0000 (06:34 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 15 Jan 2014 05:34:22 +0000 (06:34 +0100)
src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java

index 56bfd33..e9bcc3c 100644 (file)
@@ -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;
 
@@ -155,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) {
@@ -162,6 +164,16 @@ public class CommandReader extends AbstractExecutionThreadService {
                }
        }
 
+       private void removeFailedDownloads(String name) {
+               List<Download> failedDownloadsToRemove = new ArrayList<>();
+               for (Download failedDownload : failedDownloads) {
+                       if (failedDownload.pack().name().equals(name)) {
+                               failedDownloadsToRemove.add(failedDownload);
+                       }
+               }
+               failedDownloads.removeAll(failedDownloadsToRemove);
+       }
+
        /**
         * Called when a download fails.
         *