X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fcore%2FCore.java;h=0c66644be59e7d27ad2c73519a584061898ab77b;hb=dca760d9a6b05c401fdb67729cdd43281bb5daf6;hp=d2531485a285b67e5961c64ae1757660fc9887db;hpb=e622c80c04262cd8e774ea9cf47f23bbcf1fc68c;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/xdcc/core/Core.java b/src/main/java/net/pterodactylus/xdcc/core/Core.java index d253148..0c66644 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -43,6 +43,7 @@ import net.pterodactylus.xdcc.core.event.BotAdded; 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; @@ -72,6 +73,12 @@ public class Core extends AbstractIdleService { /** 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 channels = Sets.newHashSet(); @@ -87,6 +94,9 @@ public class Core extends AbstractIdleService { /** The currently known bots. */ private final Table networkBots = HashBasedTable.create(); + /** The current downloads. */ + private final Map downloads = Maps.newHashMap(); + /** The current DCC receivers. */ private final Collection dccReceivers = Sets.newHashSet(); @@ -95,10 +105,16 @@ public class Core extends AbstractIdleService { * * @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; } // @@ -179,6 +195,9 @@ public class Core extends AbstractIdleService { return; } + Download download = new Download(bot, pack); + downloads.put(pack.name(), download); + try { connection.sendMessage(bot.name(), "XDCC SEND " + pack.id()); } catch (IOException ioe1) { @@ -325,10 +344,22 @@ public class Core extends AbstractIdleService { */ @Subscribe public void dccSendReceived(DccSendReceived dccSendReceived) { + Optional network = getNetwork(dccSendReceived.connection()); + if (!network.isPresent()) { + return; + } + + Download download = downloads.get(dccSendReceived.filename()); + if (download == null) { + /* unknown download, ignore. */ + return; + } + logger.info(String.format("Starting download of %s.", dccSendReceived.filename())); try { - OutputStream fileOutputStream = new FileOutputStream(new File("/home/bombe/Temp", dccSendReceived.filename())); - DccReceiver dccReceiver = new DccReceiver(dccSendReceived.inetAddress(), dccSendReceived.port(), dccSendReceived.filename(), dccSendReceived.filesize(), fileOutputStream); + 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(); } catch (FileNotFoundException fnfe1) {