import net.pterodactylus.xdcc.core.event.CoreStarted;
import net.pterodactylus.xdcc.data.Bot;
import net.pterodactylus.xdcc.data.Channel;
+import net.pterodactylus.xdcc.data.Download;
import net.pterodactylus.xdcc.data.Network;
import net.pterodactylus.xdcc.data.Pack;
import net.pterodactylus.xdcc.data.Server;
/** The event bus. */
private final EventBus eventBus;
+ /** The temporary directory to download files to. */
+ private final String temporaryDirectory;
+
+ /** The directory to move finished downloads to. */
+ private final String finalDirectory;
+
/** The channels that should be monitored. */
private final Collection<Channel> channels = Sets.newHashSet();
/** The currently known bots. */
private final Table<Network, String, Bot> networkBots = HashBasedTable.create();
+ /** The current downloads. */
+ private final Map<String, Download> downloads = Maps.newHashMap();
+
/** The current DCC receivers. */
private final Collection<DccReceiver> dccReceivers = Sets.newHashSet();
*
* @param eventBus
* The event bus
+ * @param temporaryDirectory
+ * The directory to download files to
+ * @param finalDirectory
+ * The directory to move finished files to
*/
@Inject
- public Core(EventBus eventBus) {
+ public Core(EventBus eventBus, String temporaryDirectory, String finalDirectory) {
this.eventBus = eventBus;
+ this.temporaryDirectory = temporaryDirectory;
+ this.finalDirectory = finalDirectory;
}
//
return;
}
+ Download download = new Download(bot, pack);
+ downloads.put(pack.name(), download);
+
try {
connection.sendMessage(bot.name(), "XDCC SEND " + pack.id());
} catch (IOException ioe1) {
public void dccSendReceived(DccSendReceived dccSendReceived) {
logger.info(String.format("Starting download of %s.", dccSendReceived.filename()));
try {
- OutputStream fileOutputStream = new FileOutputStream(new File("/home/bombe/Temp", dccSendReceived.filename()));
+ File outputFile = new File(temporaryDirectory, dccSendReceived.filename());
+ OutputStream fileOutputStream = new FileOutputStream(outputFile);
DccReceiver dccReceiver = new DccReceiver(eventBus, dccSendReceived.inetAddress(), dccSendReceived.port(), dccSendReceived.filename(), dccSendReceived.filesize(), fileOutputStream);
dccReceivers.add(dccReceiver);
dccReceiver.start();