Notify user when a download fails.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 11 Apr 2013 19:53:28 +0000 (21:53 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 11 Apr 2013 19:53:28 +0000 (21:53 +0200)
src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java

index c362a9b..b77ac2c 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Set;
 
 import net.pterodactylus.irc.DccReceiver;
 import net.pterodactylus.xdcc.core.Core;
+import net.pterodactylus.xdcc.core.event.DownloadFailed;
 import net.pterodactylus.xdcc.core.event.DownloadFinished;
 import net.pterodactylus.xdcc.core.event.DownloadStarted;
 import net.pterodactylus.xdcc.data.Bot;
@@ -193,6 +194,23 @@ public class CommandReader extends AbstractExecutionThreadService {
                }
        }
 
+       /**
+        * Called when a download fails.
+        *
+        * @param downloadFailed
+        *              The download failed event
+        */
+       @Subscribe
+       public void downloadFailed(DownloadFailed downloadFailed) {
+               Download download = downloadFailed.download();
+               try {
+                       writer.write(String.format("Download of %s (from %s, %s) has failed at %.1f%% and %s/s.\n", download.filename(), download.bot().name(), download.bot().network().name(), download.dccReceiver().progress() * 100.0 / download.dccReceiver().size(), f(download.dccReceiver().overallRate())));
+                       writer.flush();
+               } catch (IOException ioe1) {
+                       /* ignore. */
+               }
+       }
+
        //
        // PRIVATE METHODS
        //