Skip to content

Commit

Permalink
Added a URL::DownloadTask::getTargetLocation() method so the target f…
Browse files Browse the repository at this point in the history
…ile can be retrieved in the DownloadTask::Listener callbacks
  • Loading branch information
ed95 committed Jan 24, 2019
1 parent ee89aa8 commit 3661d92
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions modules/juce_core/native/juce_mac_Network.mm
Expand Up @@ -414,9 +414,10 @@ static void didCompleteWithError (id self, SEL, NSURLConnection*, NSURLSessionTa
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;
Expand Down Expand Up @@ -489,7 +490,6 @@ bool connect()
}

//==============================================================================
File targetLocation;
URL::DownloadTask::Listener* listener;
NSObject<NSURLSessionDelegate>* delegate = nil;
NSURLSession* session = nil;
Expand Down
5 changes: 3 additions & 2 deletions modules/juce_core/network/juce_URL.cpp
Expand Up @@ -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();
}
Expand Down
9 changes: 6 additions & 3 deletions modules/juce_core/network/juce_URL.h
Expand Up @@ -359,15 +359,14 @@ class JUCE_API URL

/** 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();
Expand All @@ -391,10 +390,14 @@ class JUCE_API URL
/** 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();

Expand Down

0 comments on commit 3661d92

Please sign in to comment.