share downloaded files

This commit is contained in:
Zlatin Balevsky
2019-06-05 17:33:34 +01:00
parent 7fe78a0719
commit 581fce4643
3 changed files with 24 additions and 2 deletions

View File

@@ -47,7 +47,7 @@ public class DownloadManager {
destinations.add(it.sender.destination) destinations.add(it.sender.destination)
} }
def downloader = new Downloader(this, me, e.target, size, def downloader = new Downloader(eventBus, this, me, e.target, size,
infohash, pieceSize, connector, destinations, infohash, pieceSize, connector, destinations,
incompletes) incompletes)
executor.execute({downloader.download()} as Runnable) executor.execute({downloader.download()} as Runnable)

View File

@@ -10,7 +10,10 @@ import java.util.concurrent.Executors
import java.util.logging.Level import java.util.logging.Level
import com.muwire.core.Constants import com.muwire.core.Constants
import com.muwire.core.DownloadedFile
import com.muwire.core.EventBus
import com.muwire.core.connection.I2PConnector import com.muwire.core.connection.I2PConnector
import com.muwire.core.files.FileDownloadedEvent
import groovy.util.logging.Log import groovy.util.logging.Log
import net.i2p.data.Destination import net.i2p.data.Destination
@@ -27,6 +30,7 @@ public class Downloader {
rv rv
}) })
private final EventBus eventBus
private final DownloadManager downloadManager private final DownloadManager downloadManager
private final Persona me private final Persona me
private final File file private final File file
@@ -42,10 +46,13 @@ public class Downloader {
private volatile boolean cancelled private volatile boolean cancelled
private volatile boolean eventFired
public Downloader(DownloadManager downloadManager, Persona me, File file, long length, InfoHash infoHash, public Downloader(EventBus eventBus, DownloadManager downloadManager,
Persona me, File file, long length, InfoHash infoHash,
int pieceSizePow2, I2PConnector connector, Set<Destination> destinations, int pieceSizePow2, I2PConnector connector, Set<Destination> destinations,
File incompletes) { File incompletes) {
this.eventBus = eventBus
this.me = me this.me = me
this.downloadManager = downloadManager this.downloadManager = downloadManager
this.file = file this.file = file
@@ -195,6 +202,10 @@ public class Downloader {
log.log(Level.WARNING,"Exception while downloading",bad) log.log(Level.WARNING,"Exception while downloading",bad)
} finally { } finally {
currentState = WorkerState.FINISHED currentState = WorkerState.FINISHED
if (downloaded.isComplete() && !eventFired) {
eventFired = true
eventBus.publish(new FileDownloadedEvent(downloadedFile : new DownloadedFile(file, infoHash, Collections.emptySet())))
}
endpoint?.close() endpoint?.close()
} }
} }

View File

@@ -15,6 +15,7 @@ import com.muwire.core.connection.ConnectionEvent
import com.muwire.core.connection.DisconnectionEvent import com.muwire.core.connection.DisconnectionEvent
import com.muwire.core.download.DownloadStartedEvent import com.muwire.core.download.DownloadStartedEvent
import com.muwire.core.download.Downloader import com.muwire.core.download.Downloader
import com.muwire.core.files.FileDownloadedEvent
import com.muwire.core.files.FileHashedEvent import com.muwire.core.files.FileHashedEvent
import com.muwire.core.files.FileLoadedEvent import com.muwire.core.files.FileLoadedEvent
import com.muwire.core.files.FileSharedEvent import com.muwire.core.files.FileSharedEvent
@@ -100,6 +101,7 @@ class MainFrameModel {
core.eventBus.register(TrustEvent.class, this) core.eventBus.register(TrustEvent.class, this)
core.eventBus.register(QueryEvent.class, this) core.eventBus.register(QueryEvent.class, this)
core.eventBus.register(UpdateAvailableEvent.class, this) core.eventBus.register(UpdateAvailableEvent.class, this)
core.eventBus.register(FileDownloadedEvent.class, this)
timer.schedule({ timer.schedule({
int retryInterval = application.context.get("muwire-settings").downloadRetryInterval int retryInterval = application.context.get("muwire-settings").downloadRetryInterval
@@ -261,4 +263,13 @@ class MainFrameModel {
JOptionPane.showMessageDialog(null, "A new version of MuWire is available from $e.signer. Please update to $e.version") JOptionPane.showMessageDialog(null, "A new version of MuWire is available from $e.signer. Please update to $e.version")
} }
} }
void onFileDownloadedEvent(FileDownloadedEvent e) {
infoHashes.add(e.downloadedFile.infoHash)
runInsideUIAsync {
shared << e.downloadedFile
JTable table = builder.getVariable("shared-files-table")
table.model.fireTableDataChanged()
}
}
} }