diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index f804b034..d1dacd64 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -57,6 +57,7 @@ public class Core { final Persona me final File home final Properties i2pOptions + final MuWireSettings muOptions private final TrustService trustService private final PersisterService persisterService @@ -70,6 +71,7 @@ public class Core { public Core(MuWireSettings props, File home, String myVersion) { this.home = home + this.muOptions = props log.info "Initializing I2P context" I2PAppContext.getGlobalContext().logManager() I2PAppContext.getGlobalContext()._logManager = new MuWireLogManager() @@ -141,7 +143,7 @@ public class Core { log.info "initializing file manager" - FileManager fileManager = new FileManager(eventBus) + FileManager fileManager = new FileManager(eventBus, props) eventBus.register(FileHashedEvent.class, fileManager) eventBus.register(FileLoadedEvent.class, fileManager) eventBus.register(FileDownloadedEvent.class, fileManager) diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index 0636d5a1..8eef431d 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -12,6 +12,7 @@ class MuWireSettings { File downloadLocation String sharedFiles CrawlerResponse crawlerResponse + boolean shareDownloadedFiles MuWireSettings() { this(new Properties()) @@ -27,6 +28,7 @@ class MuWireSettings { sharedFiles = props.getProperty("sharedFiles") downloadRetryInterval = Integer.parseInt(props.getProperty("downloadRetryInterval","15")) updateCheckInterval = Integer.parseInt(props.getProperty("updateCheckInterval","36")) + shareDownloadedFiles = Boolean.parseBoolean(props.getProperty("shareDownloadedFiles","true")) } void write(OutputStream out) throws IOException { @@ -38,6 +40,7 @@ class MuWireSettings { props.setProperty("downloadLocation", downloadLocation.getAbsolutePath()) props.setProperty("downloadRetryInterval", String.valueOf(downloadRetryInterval)) props.setProperty("updateCheckInterval", String.valueOf(updateCheckInterval)) + props.setProperty("shareDownloadedFiles", String.valueOf(shareDownloadedFiles)) if (sharedFiles != null) props.setProperty("sharedFiles", sharedFiles) props.store(out, "") diff --git a/core/src/main/groovy/com/muwire/core/files/FileManager.groovy b/core/src/main/groovy/com/muwire/core/files/FileManager.groovy index 88796dcf..f9110d48 100644 --- a/core/src/main/groovy/com/muwire/core/files/FileManager.groovy +++ b/core/src/main/groovy/com/muwire/core/files/FileManager.groovy @@ -2,6 +2,7 @@ package com.muwire.core.files import com.muwire.core.EventBus import com.muwire.core.InfoHash +import com.muwire.core.MuWireSettings import com.muwire.core.SharedFile import com.muwire.core.search.ResultsEvent import com.muwire.core.search.SearchEvent @@ -14,18 +15,22 @@ class FileManager { final EventBus eventBus + final MuWireSettings settings final Map> rootToFiles = Collections.synchronizedMap(new HashMap<>()) final Map fileToSharedFile = Collections.synchronizedMap(new HashMap<>()) final Map> nameToFiles = new HashMap<>() final SearchIndex index = new SearchIndex() - FileManager(EventBus eventBus) { + FileManager(EventBus eventBus, MuWireSettings settings) { + this.settings = settings this.eventBus = eventBus } void onFileHashedEvent(FileHashedEvent e) { - if (e.sharedFile != null) - addToIndex(e.sharedFile) + if (settings.shareDownloadedFiles) { + if (e.sharedFile != null) + addToIndex(e.sharedFile) + } } void onFileLoadedEvent(FileLoadedEvent e) { diff --git a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy index 9b6b9fdc..a7d12c28 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy @@ -56,6 +56,10 @@ class OptionsController { boolean onlyTrusted = view.allowUntrustedCheckbox.model.isSelected() model.onlyTrusted = onlyTrusted settings.setAllowUntrusted(!onlyTrusted) + + boolean shareDownloaded = view.shareDownloadedCheckbox.model.isSelected() + model.shareDownloadedFiles = shareDownloaded + settings.shareDownloadedFiles = shareDownloaded File settingsFile = new File(core.home, "MuWire.properties") settingsFile.withOutputStream { diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 4747e862..b0093a18 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -265,6 +265,8 @@ class MainFrameModel { } void onFileDownloadedEvent(FileDownloadedEvent e) { + if (!core.muOptions.shareDownloadedFiles) + return infoHashes.add(e.downloadedFile.infoHash) runInsideUIAsync { shared << e.downloadedFile diff --git a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy index 00f23e53..5627d1ca 100644 --- a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy @@ -12,6 +12,7 @@ class OptionsModel { @Observable String downloadRetryInterval @Observable String updateCheckInterval @Observable boolean onlyTrusted + @Observable boolean shareDownloadedFiles // i2p options @Observable String inboundLength @@ -24,6 +25,7 @@ class OptionsModel { downloadRetryInterval = settings.downloadRetryInterval updateCheckInterval = settings.updateCheckInterval onlyTrusted = !settings.allowUntrusted() + shareDownloadedFiles = settings.shareDownloadedFiles Core core = application.context.get("core") inboundLength = core.i2pOptions["inbound.length"] diff --git a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy index ab2a8f35..f6a3e635 100644 --- a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy @@ -28,6 +28,7 @@ class OptionsView { def retryField def updateField def allowUntrustedCheckbox + def shareDownloadedCheckbox def inboundLengthField def inboundQuantityField @@ -54,6 +55,9 @@ class OptionsView { label(text : "Only allow trusted connections", constraints : gbc(gridx: 0, gridy : 2)) allowUntrustedCheckbox = checkBox(selected : bind {model.onlyTrusted}, constraints : gbc(gridx: 1, gridy : 2)) + + label(text : "Share downloaded files", constraints : gbc(gridx : 0, gridy:3)) + shareDownloadedCheckbox = checkBox(selected : bind {model.shareDownloadedFiles}, constraints : gbc(gridx :1, gridy:3)) } i = builder.panel {