import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
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;
/** The writer to write the results to. */
private final Writer writer;
+ private final Collection<Download> failedDownloads;
/**
* Creates a new command reader.
* @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.writer = new DuplicateLineSuppressingWriter(writer);
+ this.failedDownloads = failedDownloads;
/* initialize commands. */
ImmutableList.Builder<Command> commandBuilder = ImmutableList.builder();
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();
}
@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) {
}
}
+ 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.
*
@Subscribe
public void downloadFailed(DownloadFailed downloadFailed) {
Download download = downloadFailed.download();
+ 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) {