1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a URL::DownloadTask::getTargetLocation() method so the target file can be retrieved in the DownloadTask::Listener callbacks

This commit is contained in:
ed 2019-01-24 10:18:25 +00:00
parent ee89aa8898
commit 3661d928c1
3 changed files with 11 additions and 7 deletions

View file

@ -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<NSURLSessionDelegate>* delegate = nil;
NSURLSession* session = nil;

View file

@ -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();
}

View file

@ -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();