From d2533cc4d610f0a6808d5a4a1f50dcbdfd2c5ab6 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 2 Jun 2019 00:22:33 +0100 Subject: [PATCH] retry failed downloads, every 15 minutes by default --- .../com/muwire/core/MuWireSettings.groovy | 3 ++ .../com/muwire/gui/MainFrameModel.groovy | 43 +++++++++++++------ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index 832688bf..74e8484d 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -6,6 +6,7 @@ class MuWireSettings { final boolean isLeaf boolean allowUntrusted + int downloadRetryInterval String nickname File downloadLocation String sharedFiles @@ -23,6 +24,7 @@ class MuWireSettings { downloadLocation = new File((String)props.getProperty("downloadLocation", System.getProperty("user.home"))) sharedFiles = props.getProperty("sharedFiles") + downloadRetryInterval = Integer.parseInt(props.getProperty("downloadRetryInterval","15")) } void write(OutputStream out) throws IOException { @@ -32,6 +34,7 @@ class MuWireSettings { props.setProperty("crawlerResponse", crawlerResponse.toString()) props.setProperty("nickname", nickname) props.setProperty("downloadLocation", downloadLocation.getAbsolutePath()) + props.setProperty("downloadRetryInterval", "15") if (sharedFiles != null) props.setProperty("sharedFiles", sharedFiles) props.store(out, "") diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index d8814002..08f16422 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -12,6 +12,7 @@ import com.muwire.core.connection.ConnectionAttemptStatus import com.muwire.core.connection.ConnectionEvent import com.muwire.core.connection.DisconnectionEvent import com.muwire.core.download.DownloadStartedEvent +import com.muwire.core.download.Downloader import com.muwire.core.files.FileHashedEvent import com.muwire.core.files.FileLoadedEvent import com.muwire.core.files.FileSharedEvent @@ -56,6 +57,21 @@ class MainFrameModel { volatile Core core void mvcGroupInit(Map args) { + + Timer timer = new Timer("download-pumper", true) + timer.schedule({ + runInsideUIAsync { + if (!mvcGroup.alive) + return + builder.getVariable("uploads-table")?.model.fireTableDataChanged() + + def downloadTable = builder.getVariable("downloads-table") + int selectedRow = downloadTable.getSelectedRow() + downloadTable.model.fireTableDataChanged() + downloadTable.selectionModel.setSelectionInterval(selectedRow,selectedRow) + } + }, 1000, 1000) + application.addPropertyChangeListener("core", {e -> coreInitialized = (e.getNewValue() != null) core = e.getNewValue() @@ -70,20 +86,21 @@ class MainFrameModel { core.eventBus.register(UploadFinishedEvent.class, this) core.eventBus.register(TrustEvent.class, this) core.eventBus.register(QueryEvent.class, this) - }) - Timer timer = new Timer("download-pumper", true) - timer.schedule({ - runInsideUIAsync { - if (!mvcGroup.alive) - return - builder.getVariable("uploads-table")?.model.fireTableDataChanged() - - def downloadTable = builder.getVariable("downloads-table") - int selectedRow = downloadTable.getSelectedRow() - downloadTable.model.fireTableDataChanged() - downloadTable.selectionModel.setSelectionInterval(selectedRow,selectedRow) + + int retryInterval = application.context.get("muwire-settings").downloadRetryInterval + if (retryInterval > 0) { + retryInterval *= 60000 + timer.schedule({ + runInsideUIAsync { + downloads.each { + if (it.downloader.currentState == Downloader.DownloadState.FAILED) + it.downloader.resume() + } + } + }, retryInterval, retryInterval) } - }, 1000, 1000) + + }) } void onUIResultEvent(UIResultEvent e) {