From 3661d928c1a790871d7245f6a48d1ac600e1dbc6 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 24 Jan 2019 10:18:25 +0000 Subject: [PATCH] Added a URL::DownloadTask::getTargetLocation() method so the target file can be retrieved in the DownloadTask::Listener callbacks --- modules/juce_core/native/juce_mac_Network.mm | 4 ++-- modules/juce_core/network/juce_URL.cpp | 5 +++-- modules/juce_core/network/juce_URL.h | 9 ++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/juce_core/native/juce_mac_Network.mm b/modules/juce_core/native/juce_mac_Network.mm index 27f21f7538..797207633f 100644 --- a/modules/juce_core/native/juce_mac_Network.mm +++ b/modules/juce_core/native/juce_mac_Network.mm @@ -414,9 +414,10 @@ struct BackgroundDownloadTask : public URL::DownloadTask String extraHeadersToUse, URL::DownloadTask::Listener* listenerToUse, bool shouldUsePostRequest) - : targetLocation (targetLocationToUse), listener (listenerToUse), + : listener (listenerToUse), uniqueIdentifier (String (urlToUse.toString (true).hashCode64()) + String (Random().nextInt64())) { + targetLocation = targetLocationToUse; downloaded = -1; static DelegateClass cls; @@ -489,7 +490,6 @@ struct BackgroundDownloadTask : public URL::DownloadTask } //============================================================================== - File targetLocation; URL::DownloadTask::Listener* listener; NSObject* delegate = nil; NSURLSession* session = nil; diff --git a/modules/juce_core/network/juce_URL.cpp b/modules/juce_core/network/juce_URL.cpp index f3b7828992..a130bae3f1 100644 --- a/modules/juce_core/network/juce_URL.cpp +++ b/modules/juce_core/network/juce_URL.cpp @@ -40,8 +40,9 @@ struct FallbackDownloadTask : public URL::DownloadTask, jassert (fileStream != nullptr); jassert (stream != nullptr); - contentLength = stream->getTotalLength(); - httpCode = stream->getStatusCode(); + targetLocation = fileStream->getFile(); + contentLength = stream->getTotalLength(); + httpCode = stream->getStatusCode(); startThread(); } diff --git a/modules/juce_core/network/juce_URL.h b/modules/juce_core/network/juce_URL.h index 82e57829f0..4dfbd9e01e 100644 --- a/modules/juce_core/network/juce_URL.h +++ b/modules/juce_core/network/juce_URL.h @@ -359,15 +359,14 @@ public: /** Called when the download has finished. Be aware that this callback may come on an arbitrary thread. */ - virtual void finished (DownloadTask* task, bool success) = 0; + virtual void finished (URL::DownloadTask* task, bool success) = 0; /** Called periodically by the OS to indicate download progress. Beware that this callback may come on an arbitrary thread. */ - virtual void progress (DownloadTask* task, int64 bytesDownloaded, int64 totalLength); + virtual void progress (URL::DownloadTask* task, int64 bytesDownloaded, int64 totalLength); }; - /** Releases the resources of the download task, unregisters the listener and cancels the download if necessary. */ virtual ~DownloadTask(); @@ -391,10 +390,14 @@ public: /** Returns true if there was an error. */ inline bool hadError() const { return error; } + /** Returns the target file location that was provided in URL::downloadToFile. */ + File getTargetLocation() const { return targetLocation; } + protected: int64 contentLength = -1, downloaded = 0; bool finished = false, error = false; int httpCode = -1; + File targetLocation; DownloadTask();