int FtpDownloadInet::GetFileSize(wchar_t* URL) const { HINTERNET hFtp = NULL; HINTERNET hRemoteFile; int nTotal; Url url(URL); hFtp = InternetConnect(m_hInternet, url.GetHostname(), 0, DEFAULT_FTP_USERNAME, DEFAULT_FTP_PASSWORD, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE,0); if (hFtp == 0) { DWORD status = GetLastError(); g_log.Log(L"FtpDownloadInet::GetFileSize. Error '%u' calling InternetConnect and getting '%s'", (wchar_t *) status, URL); return false; } hRemoteFile = FtpOpenFile(hFtp, url.GetPathAndFileName(), GENERIC_READ, FTP_TRANSFER_TYPE_BINARY,0); if (hRemoteFile == 0) { DWORD status = GetLastError(); g_log.Log(L"FtpDownloadInet::GetFileSize. Error '%u' calling FtpOpenFile and getting '%s'", (wchar_t *) status, URL); return false; } nTotal = _getFileSize(hRemoteFile); InternetCloseHandle(hFtp); InternetCloseHandle(hRemoteFile); return nTotal; }
void sfSoundPlayer::setFilePath(string inFilePath) { if (inFilePath != "") { filePath = inFilePath; // do not stream small files: they won't play int fileSize = _getFileSize(inFilePath); doStream = (fileSize < 1024 * sfAppSettings::getIntValue("SOUNDFILE_MIN_KBSIZE_FOR_STREAMING") ) ? 0 : 1; loadSound(filePath, doStream); play(); } }
DWORD64 Fs::_getFileSizeEx(LPWSTR file) { DWORD64 size = (DWORD64)(-1); HANDLE handle = CWA(kernel32, CreateFileW)(file, GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if(handle != INVALID_HANDLE_VALUE) { size = _getFileSize(handle); CWA(kernel32, CloseHandle)(handle); } return size; }
int HttpDownloadInet::GetFileSize(wchar_t* URL) const { int nTotal; HINTERNET hRemoteFile; hRemoteFile = _internetOpenUrl(URL); if (hRemoteFile == NULL) return 0; nTotal = _getFileSize(hRemoteFile); InternetCloseHandle(hRemoteFile); return nTotal; }
bool HttpDownloadInet::GetFile(wchar_t* URL, wchar_t* file, ProgressStatus progress, void *data) { HINTERNET hRemoteFile; HANDLE hWrite; DWORD dwRead, dwWritten; int nTotal, nCurrent; Url url(URL); hRemoteFile = _internetOpenUrl(URL); if (hRemoteFile == NULL) return false; hWrite = CreateFile(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hWrite == INVALID_HANDLE_VALUE) { InternetCloseHandle(hRemoteFile); return false; } BYTE buffer[32768]; nTotal = _getFileSize(hRemoteFile); nCurrent = 0; while (InternetReadFile(hRemoteFile, buffer, sizeof (buffer) - 1, &dwRead)) { if (dwRead == 0) break; nCurrent+= dwRead; if (progress != NULL) { if (progress (nTotal, nCurrent, data) == false) break; } Window::ProcessMessages(); WriteFile(hWrite, buffer, dwRead, &dwWritten, NULL); } CloseHandle(hWrite); InternetCloseHandle(hRemoteFile); return dwRead == 0; }
bool FtpDownloadInet::GetFile(wchar_t* URL, wchar_t* file, ProgressStatus progress, void *data) { HINTERNET hFtp = NULL; HINTERNET hRemoteFile; HANDLE hWrite; DWORD dwRead, dwWritten; int nTotal, nCurrent; Url url(URL); hFtp = InternetConnect(m_hInternet, url.GetHostname(), 0, DEFAULT_FTP_USERNAME, DEFAULT_FTP_PASSWORD, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE,0); if (hFtp == 0) { DWORD status = GetLastError(); g_log.Log(L"FtpDownloadInet::GetFile. Error '%u' calling InternetConnect and getting '%s'", (wchar_t *) status, URL); return false; } hRemoteFile = FtpOpenFile(hFtp, url.GetPathAndFileName(), GENERIC_READ, FTP_TRANSFER_TYPE_BINARY,0); if (hRemoteFile == 0) { DWORD status = GetLastError(); g_log.Log(L"FtpDownloadInet::GetFile. Error '%u' calling FtpOpenFile and getting '%s'", (wchar_t *) status, URL); return false; } hWrite = CreateFile(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hWrite == INVALID_HANDLE_VALUE) { InternetCloseHandle(hRemoteFile); return false; } BYTE buffer[32768]; nTotal = _getFileSize(hRemoteFile); nCurrent = 0; while (InternetReadFile(hRemoteFile, buffer, sizeof (buffer) - 1, &dwRead)) { if (dwRead == 0) break; nCurrent+= dwRead; if (progress != NULL) { if (progress (nTotal, nCurrent, data) == false) break; } Window::ProcessMessages(); WriteFile(hWrite, buffer, dwRead, &dwWritten, NULL); } InternetCloseHandle(hFtp); CloseHandle(hWrite); InternetCloseHandle(hRemoteFile); return dwRead == 0; }