From dd336ea743039d881f0139ca7dccb87bab3db6a2 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 4 Nov 2020 18:32:07 +0000 Subject: [PATCH] plumbing for downloading attachments --- core/src/main/groovy/com/muwire/core/Core.groovy | 2 ++ .../com/muwire/core/download/DownloadManager.groovy | 11 +++++++++++ .../core/messenger/UIDownloadAttachmentEvent.groovy | 10 ++++++++++ 3 files changed, 23 insertions(+) create mode 100644 core/src/main/groovy/com/muwire/core/messenger/UIDownloadAttachmentEvent.groovy diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 1c7ec12e..7df3cf7c 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -81,6 +81,7 @@ import com.muwire.core.hostcache.SimpleHostCache import com.muwire.core.mesh.MeshManager import com.muwire.core.messenger.MessageReceivedEvent import com.muwire.core.messenger.Messenger +import com.muwire.core.messenger.UIDownloadAttachmentEvent import com.muwire.core.messenger.UIMessageEvent import com.muwire.core.search.BrowseManager import com.muwire.core.search.QueryEvent @@ -425,6 +426,7 @@ public class Core { eventBus.register(UIDownloadResumedEvent.class, downloadManager) eventBus.register(DownloadHopelessEvent.class, downloadManager) eventBus.register(UIDownloadCollectionEvent.class, downloadManager) + eventBus.register(UIDownloadAttachmentEvent.class, downloadManager) log.info("initializing upload manager") uploadManager = new UploadManager(eventBus, fileManager, meshManager, downloadManager, persisterFolderService, props) diff --git a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy index e03a3aa4..0126e2a1 100644 --- a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy +++ b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy @@ -6,6 +6,7 @@ import com.muwire.core.files.FileDownloadedEvent import com.muwire.core.files.FileHasher import com.muwire.core.mesh.Mesh import com.muwire.core.mesh.MeshManager +import com.muwire.core.messenger.UIDownloadAttachmentEvent import com.muwire.core.trust.TrustLevel import com.muwire.core.trust.TrustService import com.muwire.core.util.DataUtil @@ -109,6 +110,16 @@ public class DownloadManager { } } + public void onUIDownloadAttachmentEvent(UIDownloadAttachmentEvent e) { + Set sender = new HashSet<>() + sender.add(e.sender) + + File target = muSettings.downloadLocation + target = new File(target, e.attachment.name) + + doDownload(e.attachment.infoHash, target, e.attachment.length, e.attachment.pieceSizePow2, e.sequential, sender, null) + } + private Downloader doDownload(InfoHash infoHash, File target, long size, int pieceSize, boolean sequential, Set destinations, InfoHash collectionInfoHash) { File incompletes = muSettings.incompleteLocation diff --git a/core/src/main/groovy/com/muwire/core/messenger/UIDownloadAttachmentEvent.groovy b/core/src/main/groovy/com/muwire/core/messenger/UIDownloadAttachmentEvent.groovy new file mode 100644 index 00000000..4180c4c4 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/messenger/UIDownloadAttachmentEvent.groovy @@ -0,0 +1,10 @@ +package com.muwire.core.messenger + +import com.muwire.core.Event +import com.muwire.core.Persona + +class UIDownloadAttachmentEvent extends Event { + Persona sender + MWMessageAttachment attachment + boolean sequential +}