mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Fixed a large-file linux problem and increased the win32 URL length limit.
This commit is contained in:
parent
3077c9a945
commit
a06e8336e5
5 changed files with 254 additions and 260 deletions
|
|
@ -246441,120 +246441,133 @@ private:
|
|||
if (sessionHandle != 0)
|
||||
{
|
||||
// break up the url..
|
||||
TCHAR file[1024], server[1024], username[1024], password[1024];
|
||||
const int fileNumChars = 65536;
|
||||
const int serverNumChars = 2048;
|
||||
const int usernameNumChars = 1024;
|
||||
const int passwordNumChars = 1024;
|
||||
HeapBlock<TCHAR> file (fileNumChars), server (serverNumChars),
|
||||
username (usernameNumChars), password (passwordNumChars);
|
||||
|
||||
URL_COMPONENTS uc = { 0 };
|
||||
uc.dwStructSize = sizeof (uc);
|
||||
uc.lpszUrlPath = file;
|
||||
uc.dwUrlPathLength = numElementsInArray (file);
|
||||
uc.dwUrlPathLength = fileNumChars;
|
||||
uc.lpszHostName = server;
|
||||
uc.dwHostNameLength = numElementsInArray (server);
|
||||
uc.dwHostNameLength = serverNumChars;
|
||||
uc.lpszUserName = username;
|
||||
uc.dwUserNameLength = numElementsInArray (username);
|
||||
uc.dwUserNameLength = usernameNumChars;
|
||||
uc.lpszPassword = password;
|
||||
uc.dwPasswordLength = numElementsInArray (password);
|
||||
uc.dwPasswordLength = passwordNumChars;
|
||||
|
||||
if (InternetCrackUrl (address.toWideCharPointer(), 0, 0, &uc))
|
||||
openConnection (uc, sessionHandle, progressCallback, progressCallbackContext);
|
||||
}
|
||||
}
|
||||
|
||||
void openConnection (URL_COMPONENTS& uc, HINTERNET sessionHandle,
|
||||
URL::OpenStreamProgressCallback* progressCallback,
|
||||
void* progressCallbackContext)
|
||||
{
|
||||
int disable = 1;
|
||||
InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
|
||||
|
||||
if (timeOutMs == 0)
|
||||
timeOutMs = 30000;
|
||||
else if (timeOutMs < 0)
|
||||
timeOutMs = -1;
|
||||
|
||||
InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
|
||||
|
||||
const bool isFtp = address.startsWithIgnoreCase ("ftp:");
|
||||
|
||||
#if WORKAROUND_TIMEOUT_BUG
|
||||
connection = 0;
|
||||
|
||||
{
|
||||
InternetConnectThread connectThread (uc, sessionHandle, connection, isFtp);
|
||||
connectThread.wait (timeOutMs);
|
||||
|
||||
if (connection == 0)
|
||||
{
|
||||
int disable = 1;
|
||||
InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
|
||||
InternetCloseHandle (sessionHandle);
|
||||
sessionHandle = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
connection = InternetConnect (sessionHandle, uc.lpszHostName, uc.nPort,
|
||||
uc.lpszUserName, uc.lpszPassword,
|
||||
isFtp ? INTERNET_SERVICE_FTP
|
||||
: INTERNET_SERVICE_HTTP,
|
||||
0, 0);
|
||||
#endif
|
||||
|
||||
if (timeOutMs == 0)
|
||||
timeOutMs = 30000;
|
||||
else if (timeOutMs < 0)
|
||||
timeOutMs = -1;
|
||||
if (connection != 0)
|
||||
{
|
||||
if (isFtp)
|
||||
request = FtpOpenFile (connection, uc.lpszUrlPath, GENERIC_READ,
|
||||
FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE, 0);
|
||||
else
|
||||
openHTTPConnection (uc, sessionHandle, progressCallback, progressCallbackContext);
|
||||
}
|
||||
}
|
||||
|
||||
InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
|
||||
void openHTTPConnection (URL_COMPONENTS& uc, HINTERNET sessionHandle,
|
||||
URL::OpenStreamProgressCallback* progressCallback,
|
||||
void* progressCallbackContext)
|
||||
{
|
||||
const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
|
||||
|
||||
const bool isFtp = address.startsWithIgnoreCase ("ftp:");
|
||||
DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES;
|
||||
|
||||
#if WORKAROUND_TIMEOUT_BUG
|
||||
connection = 0;
|
||||
if (address.startsWithIgnoreCase ("https:"))
|
||||
flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
|
||||
// IE7 seems to automatically work out when it's https)
|
||||
|
||||
request = HttpOpenRequest (connection, isPost ? _T("POST") : _T("GET"),
|
||||
uc.lpszUrlPath, 0, 0, mimeTypes, flags, 0);
|
||||
|
||||
if (request != 0)
|
||||
{
|
||||
INTERNET_BUFFERS buffers = { 0 };
|
||||
buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
|
||||
buffers.lpcszHeader = headers.toWideCharPointer();
|
||||
buffers.dwHeadersLength = headers.length();
|
||||
buffers.dwBufferTotal = (DWORD) postData.getSize();
|
||||
|
||||
if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
|
||||
{
|
||||
int bytesSent = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
InternetConnectThread connectThread (uc, sessionHandle, connection, isFtp);
|
||||
connectThread.wait (timeOutMs);
|
||||
const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
|
||||
DWORD bytesDone = 0;
|
||||
|
||||
if (connection == 0)
|
||||
if (bytesToDo > 0
|
||||
&& ! InternetWriteFile (request,
|
||||
static_cast <const char*> (postData.getData()) + bytesSent,
|
||||
bytesToDo, &bytesDone))
|
||||
{
|
||||
InternetCloseHandle (sessionHandle);
|
||||
sessionHandle = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
connection = InternetConnect (sessionHandle, uc.lpszHostName, uc.nPort,
|
||||
uc.lpszUserName, uc.lpszPassword,
|
||||
isFtp ? INTERNET_SERVICE_FTP
|
||||
: INTERNET_SERVICE_HTTP,
|
||||
0, 0);
|
||||
#endif
|
||||
|
||||
if (connection != 0)
|
||||
{
|
||||
if (isFtp)
|
||||
if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
|
||||
{
|
||||
request = FtpOpenFile (connection, uc.lpszUrlPath, GENERIC_READ,
|
||||
FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE, 0);
|
||||
if (HttpEndRequest (request, 0, 0, 0))
|
||||
return;
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
|
||||
|
||||
DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES;
|
||||
bytesSent += bytesDone;
|
||||
|
||||
if (address.startsWithIgnoreCase ("https:"))
|
||||
flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
|
||||
// IE7 seems to automatically work out when it's https)
|
||||
|
||||
request = HttpOpenRequest (connection, isPost ? _T("POST") : _T("GET"),
|
||||
uc.lpszUrlPath, 0, 0, mimeTypes, flags, 0);
|
||||
|
||||
if (request != 0)
|
||||
{
|
||||
INTERNET_BUFFERS buffers = { 0 };
|
||||
buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
|
||||
buffers.lpcszHeader = headers.toWideCharPointer();
|
||||
buffers.dwHeadersLength = headers.length();
|
||||
buffers.dwBufferTotal = (DWORD) postData.getSize();
|
||||
|
||||
if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
|
||||
{
|
||||
int bytesSent = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
|
||||
DWORD bytesDone = 0;
|
||||
|
||||
if (bytesToDo > 0
|
||||
&& ! InternetWriteFile (request,
|
||||
static_cast <const char*> (postData.getData()) + bytesSent,
|
||||
bytesToDo, &bytesDone))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
|
||||
{
|
||||
if (HttpEndRequest (request, 0, 0, 0))
|
||||
return;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
bytesSent += bytesDone;
|
||||
|
||||
if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, bytesSent, postData.getSize()))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, bytesSent, postData.getSize()))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebInputStream);
|
||||
|
|
@ -262114,20 +262127,18 @@ bool File::setAsCurrentWorkingDirectory() const
|
|||
|
||||
namespace
|
||||
{
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
typedef struct stat64 juce_statStruct; // (need to use the 64-bit version to work around a simulator bug)
|
||||
#else
|
||||
typedef struct stat juce_statStruct;
|
||||
#endif
|
||||
#if JUCE_LINUX || (JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T) // (this iOS stuff is to avoid a simulator bug)
|
||||
typedef struct stat64 juce_statStruct;
|
||||
#define JUCE_STAT stat64
|
||||
#else
|
||||
typedef struct stat juce_statStruct;
|
||||
#define JUCE_STAT stat
|
||||
#endif
|
||||
|
||||
bool juce_stat (const String& fileName, juce_statStruct& info)
|
||||
{
|
||||
return fileName.isNotEmpty()
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
&& (stat64 (fileName.toUTF8(), &info) == 0);
|
||||
#else
|
||||
&& (stat (fileName.toUTF8(), &info) == 0);
|
||||
#endif
|
||||
&& JUCE_STAT (fileName.toUTF8(), &info) == 0;
|
||||
}
|
||||
|
||||
// if this file doesn't exist, find a parent of it that does..
|
||||
|
|
@ -262147,14 +262158,14 @@ namespace
|
|||
void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize,
|
||||
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
|
||||
{
|
||||
if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0)
|
||||
if (isDir != nullptr || fileSize != nullptr || modTime != nullptr || creationTime != nullptr)
|
||||
{
|
||||
juce_statStruct info;
|
||||
const bool statOk = juce_stat (path, info);
|
||||
|
||||
if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
|
||||
if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0;
|
||||
if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0);
|
||||
if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
|
||||
if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0;
|
||||
if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0);
|
||||
if (creationTime != nullptr) *creationTime = Time (statOk ? (int64) info.st_ctime * 1000 : 0);
|
||||
}
|
||||
|
||||
|
|
@ -262183,14 +262194,8 @@ bool File::isDirectory() const
|
|||
|
||||
bool File::exists() const
|
||||
{
|
||||
juce_statStruct info;
|
||||
|
||||
return fullPath.isNotEmpty()
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
&& (lstat64 (fullPath.toUTF8(), &info) == 0);
|
||||
#else
|
||||
&& (lstat (fullPath.toUTF8(), &info) == 0);
|
||||
#endif
|
||||
&& access (fullPath.toUTF8(), F_OK) == 0;
|
||||
}
|
||||
|
||||
bool File::existsAsFile() const
|
||||
|
|
@ -272056,20 +272061,18 @@ bool File::setAsCurrentWorkingDirectory() const
|
|||
|
||||
namespace
|
||||
{
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
typedef struct stat64 juce_statStruct; // (need to use the 64-bit version to work around a simulator bug)
|
||||
#else
|
||||
typedef struct stat juce_statStruct;
|
||||
#endif
|
||||
#if JUCE_LINUX || (JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T) // (this iOS stuff is to avoid a simulator bug)
|
||||
typedef struct stat64 juce_statStruct;
|
||||
#define JUCE_STAT stat64
|
||||
#else
|
||||
typedef struct stat juce_statStruct;
|
||||
#define JUCE_STAT stat
|
||||
#endif
|
||||
|
||||
bool juce_stat (const String& fileName, juce_statStruct& info)
|
||||
{
|
||||
return fileName.isNotEmpty()
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
&& (stat64 (fileName.toUTF8(), &info) == 0);
|
||||
#else
|
||||
&& (stat (fileName.toUTF8(), &info) == 0);
|
||||
#endif
|
||||
&& JUCE_STAT (fileName.toUTF8(), &info) == 0;
|
||||
}
|
||||
|
||||
// if this file doesn't exist, find a parent of it that does..
|
||||
|
|
@ -272089,14 +272092,14 @@ namespace
|
|||
void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize,
|
||||
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
|
||||
{
|
||||
if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0)
|
||||
if (isDir != nullptr || fileSize != nullptr || modTime != nullptr || creationTime != nullptr)
|
||||
{
|
||||
juce_statStruct info;
|
||||
const bool statOk = juce_stat (path, info);
|
||||
|
||||
if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
|
||||
if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0;
|
||||
if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0);
|
||||
if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
|
||||
if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0;
|
||||
if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0);
|
||||
if (creationTime != nullptr) *creationTime = Time (statOk ? (int64) info.st_ctime * 1000 : 0);
|
||||
}
|
||||
|
||||
|
|
@ -272125,14 +272128,8 @@ bool File::isDirectory() const
|
|||
|
||||
bool File::exists() const
|
||||
{
|
||||
juce_statStruct info;
|
||||
|
||||
return fullPath.isNotEmpty()
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
&& (lstat64 (fullPath.toUTF8(), &info) == 0);
|
||||
#else
|
||||
&& (lstat (fullPath.toUTF8(), &info) == 0);
|
||||
#endif
|
||||
&& access (fullPath.toUTF8(), F_OK) == 0;
|
||||
}
|
||||
|
||||
bool File::existsAsFile() const
|
||||
|
|
@ -289063,20 +289060,18 @@ bool File::setAsCurrentWorkingDirectory() const
|
|||
|
||||
namespace
|
||||
{
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
typedef struct stat64 juce_statStruct; // (need to use the 64-bit version to work around a simulator bug)
|
||||
#else
|
||||
typedef struct stat juce_statStruct;
|
||||
#endif
|
||||
#if JUCE_LINUX || (JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T) // (this iOS stuff is to avoid a simulator bug)
|
||||
typedef struct stat64 juce_statStruct;
|
||||
#define JUCE_STAT stat64
|
||||
#else
|
||||
typedef struct stat juce_statStruct;
|
||||
#define JUCE_STAT stat
|
||||
#endif
|
||||
|
||||
bool juce_stat (const String& fileName, juce_statStruct& info)
|
||||
{
|
||||
return fileName.isNotEmpty()
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
&& (stat64 (fileName.toUTF8(), &info) == 0);
|
||||
#else
|
||||
&& (stat (fileName.toUTF8(), &info) == 0);
|
||||
#endif
|
||||
&& JUCE_STAT (fileName.toUTF8(), &info) == 0;
|
||||
}
|
||||
|
||||
// if this file doesn't exist, find a parent of it that does..
|
||||
|
|
@ -289096,14 +289091,14 @@ namespace
|
|||
void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize,
|
||||
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
|
||||
{
|
||||
if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0)
|
||||
if (isDir != nullptr || fileSize != nullptr || modTime != nullptr || creationTime != nullptr)
|
||||
{
|
||||
juce_statStruct info;
|
||||
const bool statOk = juce_stat (path, info);
|
||||
|
||||
if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
|
||||
if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0;
|
||||
if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0);
|
||||
if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
|
||||
if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0;
|
||||
if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0);
|
||||
if (creationTime != nullptr) *creationTime = Time (statOk ? (int64) info.st_ctime * 1000 : 0);
|
||||
}
|
||||
|
||||
|
|
@ -289132,14 +289127,8 @@ bool File::isDirectory() const
|
|||
|
||||
bool File::exists() const
|
||||
{
|
||||
juce_statStruct info;
|
||||
|
||||
return fullPath.isNotEmpty()
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
&& (lstat64 (fullPath.toUTF8(), &info) == 0);
|
||||
#else
|
||||
&& (lstat (fullPath.toUTF8(), &info) == 0);
|
||||
#endif
|
||||
&& access (fullPath.toUTF8(), F_OK) == 0;
|
||||
}
|
||||
|
||||
bool File::existsAsFile() const
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace JuceDummyNamespace {}
|
|||
*/
|
||||
#define JUCE_MAJOR_VERSION 1
|
||||
#define JUCE_MINOR_VERSION 54
|
||||
#define JUCE_BUILDNUMBER 11
|
||||
#define JUCE_BUILDNUMBER 12
|
||||
|
||||
/** Current Juce version number.
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
*/
|
||||
#define JUCE_MAJOR_VERSION 1
|
||||
#define JUCE_MINOR_VERSION 54
|
||||
#define JUCE_BUILDNUMBER 11
|
||||
#define JUCE_BUILDNUMBER 12
|
||||
|
||||
/** Current Juce version number.
|
||||
|
||||
|
|
|
|||
|
|
@ -225,20 +225,18 @@ bool File::setAsCurrentWorkingDirectory() const
|
|||
//==============================================================================
|
||||
namespace
|
||||
{
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
typedef struct stat64 juce_statStruct; // (need to use the 64-bit version to work around a simulator bug)
|
||||
#else
|
||||
typedef struct stat juce_statStruct;
|
||||
#endif
|
||||
#if JUCE_LINUX || (JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T) // (this iOS stuff is to avoid a simulator bug)
|
||||
typedef struct stat64 juce_statStruct;
|
||||
#define JUCE_STAT stat64
|
||||
#else
|
||||
typedef struct stat juce_statStruct;
|
||||
#define JUCE_STAT stat
|
||||
#endif
|
||||
|
||||
bool juce_stat (const String& fileName, juce_statStruct& info)
|
||||
{
|
||||
return fileName.isNotEmpty()
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
&& (stat64 (fileName.toUTF8(), &info) == 0);
|
||||
#else
|
||||
&& (stat (fileName.toUTF8(), &info) == 0);
|
||||
#endif
|
||||
&& JUCE_STAT (fileName.toUTF8(), &info) == 0;
|
||||
}
|
||||
|
||||
// if this file doesn't exist, find a parent of it that does..
|
||||
|
|
@ -258,14 +256,14 @@ namespace
|
|||
void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize,
|
||||
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
|
||||
{
|
||||
if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0)
|
||||
if (isDir != nullptr || fileSize != nullptr || modTime != nullptr || creationTime != nullptr)
|
||||
{
|
||||
juce_statStruct info;
|
||||
const bool statOk = juce_stat (path, info);
|
||||
|
||||
if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
|
||||
if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0;
|
||||
if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0);
|
||||
if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
|
||||
if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0;
|
||||
if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0);
|
||||
if (creationTime != nullptr) *creationTime = Time (statOk ? (int64) info.st_ctime * 1000 : 0);
|
||||
}
|
||||
|
||||
|
|
@ -294,14 +292,8 @@ bool File::isDirectory() const
|
|||
|
||||
bool File::exists() const
|
||||
{
|
||||
juce_statStruct info;
|
||||
|
||||
return fullPath.isNotEmpty()
|
||||
#if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T
|
||||
&& (lstat64 (fullPath.toUTF8(), &info) == 0);
|
||||
#else
|
||||
&& (lstat (fullPath.toUTF8(), &info) == 0);
|
||||
#endif
|
||||
&& access (fullPath.toUTF8(), F_OK) == 0;
|
||||
}
|
||||
|
||||
bool File::existsAsFile() const
|
||||
|
|
|
|||
|
|
@ -225,120 +225,133 @@ private:
|
|||
if (sessionHandle != 0)
|
||||
{
|
||||
// break up the url..
|
||||
TCHAR file[1024], server[1024], username[1024], password[1024];
|
||||
const int fileNumChars = 65536;
|
||||
const int serverNumChars = 2048;
|
||||
const int usernameNumChars = 1024;
|
||||
const int passwordNumChars = 1024;
|
||||
HeapBlock<TCHAR> file (fileNumChars), server (serverNumChars),
|
||||
username (usernameNumChars), password (passwordNumChars);
|
||||
|
||||
URL_COMPONENTS uc = { 0 };
|
||||
uc.dwStructSize = sizeof (uc);
|
||||
uc.lpszUrlPath = file;
|
||||
uc.dwUrlPathLength = numElementsInArray (file);
|
||||
uc.dwUrlPathLength = fileNumChars;
|
||||
uc.lpszHostName = server;
|
||||
uc.dwHostNameLength = numElementsInArray (server);
|
||||
uc.dwHostNameLength = serverNumChars;
|
||||
uc.lpszUserName = username;
|
||||
uc.dwUserNameLength = numElementsInArray (username);
|
||||
uc.dwUserNameLength = usernameNumChars;
|
||||
uc.lpszPassword = password;
|
||||
uc.dwPasswordLength = numElementsInArray (password);
|
||||
uc.dwPasswordLength = passwordNumChars;
|
||||
|
||||
if (InternetCrackUrl (address.toWideCharPointer(), 0, 0, &uc))
|
||||
openConnection (uc, sessionHandle, progressCallback, progressCallbackContext);
|
||||
}
|
||||
}
|
||||
|
||||
void openConnection (URL_COMPONENTS& uc, HINTERNET sessionHandle,
|
||||
URL::OpenStreamProgressCallback* progressCallback,
|
||||
void* progressCallbackContext)
|
||||
{
|
||||
int disable = 1;
|
||||
InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
|
||||
|
||||
if (timeOutMs == 0)
|
||||
timeOutMs = 30000;
|
||||
else if (timeOutMs < 0)
|
||||
timeOutMs = -1;
|
||||
|
||||
InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
|
||||
|
||||
const bool isFtp = address.startsWithIgnoreCase ("ftp:");
|
||||
|
||||
#if WORKAROUND_TIMEOUT_BUG
|
||||
connection = 0;
|
||||
|
||||
{
|
||||
InternetConnectThread connectThread (uc, sessionHandle, connection, isFtp);
|
||||
connectThread.wait (timeOutMs);
|
||||
|
||||
if (connection == 0)
|
||||
{
|
||||
int disable = 1;
|
||||
InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
|
||||
InternetCloseHandle (sessionHandle);
|
||||
sessionHandle = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
connection = InternetConnect (sessionHandle, uc.lpszHostName, uc.nPort,
|
||||
uc.lpszUserName, uc.lpszPassword,
|
||||
isFtp ? INTERNET_SERVICE_FTP
|
||||
: INTERNET_SERVICE_HTTP,
|
||||
0, 0);
|
||||
#endif
|
||||
|
||||
if (timeOutMs == 0)
|
||||
timeOutMs = 30000;
|
||||
else if (timeOutMs < 0)
|
||||
timeOutMs = -1;
|
||||
if (connection != 0)
|
||||
{
|
||||
if (isFtp)
|
||||
request = FtpOpenFile (connection, uc.lpszUrlPath, GENERIC_READ,
|
||||
FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE, 0);
|
||||
else
|
||||
openHTTPConnection (uc, sessionHandle, progressCallback, progressCallbackContext);
|
||||
}
|
||||
}
|
||||
|
||||
InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
|
||||
void openHTTPConnection (URL_COMPONENTS& uc, HINTERNET sessionHandle,
|
||||
URL::OpenStreamProgressCallback* progressCallback,
|
||||
void* progressCallbackContext)
|
||||
{
|
||||
const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
|
||||
|
||||
const bool isFtp = address.startsWithIgnoreCase ("ftp:");
|
||||
DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES;
|
||||
|
||||
#if WORKAROUND_TIMEOUT_BUG
|
||||
connection = 0;
|
||||
if (address.startsWithIgnoreCase ("https:"))
|
||||
flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
|
||||
// IE7 seems to automatically work out when it's https)
|
||||
|
||||
request = HttpOpenRequest (connection, isPost ? _T("POST") : _T("GET"),
|
||||
uc.lpszUrlPath, 0, 0, mimeTypes, flags, 0);
|
||||
|
||||
if (request != 0)
|
||||
{
|
||||
INTERNET_BUFFERS buffers = { 0 };
|
||||
buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
|
||||
buffers.lpcszHeader = headers.toWideCharPointer();
|
||||
buffers.dwHeadersLength = headers.length();
|
||||
buffers.dwBufferTotal = (DWORD) postData.getSize();
|
||||
|
||||
if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
|
||||
{
|
||||
int bytesSent = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
InternetConnectThread connectThread (uc, sessionHandle, connection, isFtp);
|
||||
connectThread.wait (timeOutMs);
|
||||
const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
|
||||
DWORD bytesDone = 0;
|
||||
|
||||
if (connection == 0)
|
||||
if (bytesToDo > 0
|
||||
&& ! InternetWriteFile (request,
|
||||
static_cast <const char*> (postData.getData()) + bytesSent,
|
||||
bytesToDo, &bytesDone))
|
||||
{
|
||||
InternetCloseHandle (sessionHandle);
|
||||
sessionHandle = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
connection = InternetConnect (sessionHandle, uc.lpszHostName, uc.nPort,
|
||||
uc.lpszUserName, uc.lpszPassword,
|
||||
isFtp ? INTERNET_SERVICE_FTP
|
||||
: INTERNET_SERVICE_HTTP,
|
||||
0, 0);
|
||||
#endif
|
||||
|
||||
if (connection != 0)
|
||||
{
|
||||
if (isFtp)
|
||||
if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
|
||||
{
|
||||
request = FtpOpenFile (connection, uc.lpszUrlPath, GENERIC_READ,
|
||||
FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE, 0);
|
||||
if (HttpEndRequest (request, 0, 0, 0))
|
||||
return;
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
|
||||
|
||||
DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES;
|
||||
bytesSent += bytesDone;
|
||||
|
||||
if (address.startsWithIgnoreCase ("https:"))
|
||||
flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
|
||||
// IE7 seems to automatically work out when it's https)
|
||||
|
||||
request = HttpOpenRequest (connection, isPost ? _T("POST") : _T("GET"),
|
||||
uc.lpszUrlPath, 0, 0, mimeTypes, flags, 0);
|
||||
|
||||
if (request != 0)
|
||||
{
|
||||
INTERNET_BUFFERS buffers = { 0 };
|
||||
buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
|
||||
buffers.lpcszHeader = headers.toWideCharPointer();
|
||||
buffers.dwHeadersLength = headers.length();
|
||||
buffers.dwBufferTotal = (DWORD) postData.getSize();
|
||||
|
||||
if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
|
||||
{
|
||||
int bytesSent = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
|
||||
DWORD bytesDone = 0;
|
||||
|
||||
if (bytesToDo > 0
|
||||
&& ! InternetWriteFile (request,
|
||||
static_cast <const char*> (postData.getData()) + bytesSent,
|
||||
bytesToDo, &bytesDone))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
|
||||
{
|
||||
if (HttpEndRequest (request, 0, 0, 0))
|
||||
return;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
bytesSent += bytesDone;
|
||||
|
||||
if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, bytesSent, postData.getSize()))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, bytesSent, postData.getSize()))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebInputStream);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue