@@ -554,7 +554,7 @@ private: | |||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) | ||||
}; | }; | ||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
std::unique_ptr<URL::DownloadTask> URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
{ | { | ||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | ||||
} | } | ||||
@@ -642,7 +642,7 @@ public: | |||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) | ||||
}; | }; | ||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
std::unique_ptr<URL::DownloadTask> URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
{ | { | ||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | ||||
} | } | ||||
@@ -576,7 +576,7 @@ private: | |||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) | ||||
}; | }; | ||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
std::unique_ptr<URL::DownloadTask> URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
{ | { | ||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | ||||
} | } | ||||
@@ -648,12 +648,12 @@ struct BackgroundDownloadTask : public URL::DownloadTask | |||||
HashMap<String, BackgroundDownloadTask*, DefaultHashFunctions, CriticalSection> BackgroundDownloadTask::activeSessions; | HashMap<String, BackgroundDownloadTask*, DefaultHashFunctions, CriticalSection> BackgroundDownloadTask::activeSessions; | ||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool usePostRequest) | |||||
std::unique_ptr<URL::DownloadTask> URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool usePostRequest) | |||||
{ | { | ||||
std::unique_ptr<BackgroundDownloadTask> downloadTask (new BackgroundDownloadTask (*this, targetLocation, extraHeaders, listener, usePostRequest)); | std::unique_ptr<BackgroundDownloadTask> downloadTask (new BackgroundDownloadTask (*this, targetLocation, extraHeaders, listener, usePostRequest)); | ||||
if (downloadTask->initOK() && downloadTask->connect()) | if (downloadTask->initOK() && downloadTask->connect()) | ||||
return downloadTask.release(); | |||||
return downloadTask; | |||||
return nullptr; | return nullptr; | ||||
} | } | ||||
@@ -663,7 +663,7 @@ void URL::DownloadTask::juce_iosURLSessionNotify (const String& identifier) | |||||
BackgroundDownloadTask::invokeNotify (identifier); | BackgroundDownloadTask::invokeNotify (identifier); | ||||
} | } | ||||
#else | #else | ||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool usePost) | |||||
std::unique_ptr<URL::DownloadTask> URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool usePost) | |||||
{ | { | ||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, usePost); | return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, usePost); | ||||
} | } | ||||
@@ -930,7 +930,7 @@ private: | |||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (URLConnectionState) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (URLConnectionState) | ||||
}; | }; | ||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
std::unique_ptr<URL::DownloadTask> URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
{ | { | ||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | ||||
} | } | ||||
@@ -636,7 +636,7 @@ bool JUCE_CALLTYPE Process::openEmailWithAttachments (const String& targetEmailA | |||||
return mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS; | return mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS; | ||||
} | } | ||||
URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
std::unique_ptr<URL::DownloadTask> URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) | |||||
{ | { | ||||
return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); | ||||
} | } | ||||
@@ -26,13 +26,13 @@ namespace juce | |||||
struct FallbackDownloadTask : public URL::DownloadTask, | struct FallbackDownloadTask : public URL::DownloadTask, | ||||
public Thread | public Thread | ||||
{ | { | ||||
FallbackDownloadTask (FileOutputStream* outputStreamToUse, | |||||
FallbackDownloadTask (std::unique_ptr<FileOutputStream> outputStreamToUse, | |||||
size_t bufferSizeToUse, | size_t bufferSizeToUse, | ||||
WebInputStream* streamToUse, | |||||
std::unique_ptr<WebInputStream> streamToUse, | |||||
URL::DownloadTask::Listener* listenerToUse) | URL::DownloadTask::Listener* listenerToUse) | ||||
: Thread ("DownloadTask thread"), | : Thread ("DownloadTask thread"), | ||||
fileStream (outputStreamToUse), | |||||
stream (streamToUse), | |||||
fileStream (std::move (outputStreamToUse)), | |||||
stream (std::move (streamToUse)), | |||||
bufferSize (bufferSizeToUse), | bufferSize (bufferSizeToUse), | ||||
buffer (bufferSize), | buffer (bufferSize), | ||||
listener (listenerToUse) | listener (listenerToUse) | ||||
@@ -110,22 +110,25 @@ void URL::DownloadTask::Listener::progress (DownloadTask*, int64, int64) {} | |||||
URL::DownloadTask::Listener::~Listener() {} | URL::DownloadTask::Listener::~Listener() {} | ||||
//============================================================================== | //============================================================================== | ||||
URL::DownloadTask* URL::DownloadTask::createFallbackDownloader (const URL& urlToUse, | |||||
const File& targetFileToUse, | |||||
const String& extraHeadersToUse, | |||||
Listener* listenerToUse, | |||||
bool usePostRequest) | |||||
std::unique_ptr<URL::DownloadTask> URL::DownloadTask::createFallbackDownloader (const URL& urlToUse, | |||||
const File& targetFileToUse, | |||||
const String& extraHeadersToUse, | |||||
Listener* listenerToUse, | |||||
bool usePostRequest) | |||||
{ | { | ||||
const size_t bufferSize = 0x8000; | const size_t bufferSize = 0x8000; | ||||
targetFileToUse.deleteFile(); | targetFileToUse.deleteFile(); | ||||
if (auto outputStream = std::unique_ptr<FileOutputStream> (targetFileToUse.createOutputStream (bufferSize))) | |||||
if (auto outputStream = targetFileToUse.createOutputStream (bufferSize)) | |||||
{ | { | ||||
std::unique_ptr<WebInputStream> stream (new WebInputStream (urlToUse, usePostRequest)); | |||||
auto stream = std::make_unique<WebInputStream> (urlToUse, usePostRequest); | |||||
stream->withExtraHeaders (extraHeadersToUse); | stream->withExtraHeaders (extraHeadersToUse); | ||||
if (stream->connect (nullptr)) | if (stream->connect (nullptr)) | ||||
return new FallbackDownloadTask (outputStream.release(), bufferSize, stream.release(), listenerToUse); | |||||
return std::make_unique<FallbackDownloadTask> (std::move (outputStream), | |||||
bufferSize, | |||||
std::move (stream), | |||||
listenerToUse); | |||||
} | } | ||||
return nullptr; | return nullptr; | ||||
@@ -415,7 +415,7 @@ public: | |||||
private: | private: | ||||
friend class URL; | friend class URL; | ||||
static DownloadTask* createFallbackDownloader (const URL&, const File&, const String&, Listener*, bool); | |||||
static std::unique_ptr<DownloadTask> createFallbackDownloader (const URL&, const File&, const String&, Listener*, bool); | |||||
public: | public: | ||||
#if JUCE_IOS | #if JUCE_IOS | ||||
@@ -436,10 +436,10 @@ public: | |||||
using a native OS background network task. Such tasks automatically deal with | using a native OS background network task. Such tasks automatically deal with | ||||
network re-connections and continuing your download while your app is suspended. | network re-connections and continuing your download while your app is suspended. | ||||
*/ | */ | ||||
DownloadTask* downloadToFile (const File& targetLocation, | |||||
String extraHeaders = String(), | |||||
DownloadTask::Listener* listener = nullptr, | |||||
bool usePostCommand = false); | |||||
std::unique_ptr<DownloadTask> downloadToFile (const File& targetLocation, | |||||
String extraHeaders = String(), | |||||
DownloadTask::Listener* listener = nullptr, | |||||
bool usePostCommand = false); | |||||
//============================================================================== | //============================================================================== | ||||
/** Tries to download the entire contents of this URL into a binary data block. | /** Tries to download the entire contents of this URL into a binary data block. | ||||