X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fcore%2FCore.java;h=8aa31e20884dcdead822fe1389df71ed0fb97cb6;hb=d49b149690e24825e9a3bc75f9d53094a7b660b4;hp=96555e39576c62adbfba5fac4d537ae4a10cb7cb;hpb=2fb2343aea0a4c6d81fa1acb76e8ad85844f82b2;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 96555e3..8aa31e2 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,18 +73,30 @@ 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(); /** The channels that are currentlymonitored. */ private final Collection joinedChannels = Sets.newHashSet(); + /** The channels that are joined but not configured. */ + private final Collection extraChannels = Sets.newHashSet(); + /** The current network connections. */ private final Map networkConnections = Collections.synchronizedMap(Maps.newHashMap()); /** 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(); @@ -92,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; } // @@ -122,6 +141,15 @@ public class Core extends AbstractIdleService { } /** + * Returns all currently joined channels that are not configured. + * + * @return All currently joined but not configured channels + */ + public Collection extraChannels() { + return ImmutableSet.copyOf(extraChannels); + } + + /** * Returns all currently known bots. * * @return All currently known bots @@ -167,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) { @@ -251,6 +282,9 @@ public class Core extends AbstractIdleService { Optional channel = getChannel(network.get(), channelJoined.channel()); if (!channel.isPresent()) { + /* it’s an extra channel. */ + extraChannels.add(new Channel(network.get(), channelJoined.channel())); + logger.info(String.format("Joined extra Channel %s on %s.", channelJoined.channel(), network.get().name())); return; } @@ -312,8 +346,9 @@ public class Core extends AbstractIdleService { 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())); - 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) {