MCPcopy Create free account
hub / github.com/diasurgical/devilution / BaseHttp_Open

Function BaseHttp_Open

3rdParty/StormLib/src/FileStream.cpp:623–716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

621}
622
623static bool BaseHttp_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD dwStreamFlags)
624{
625#ifdef PLATFORM_WINDOWS
626
627 HINTERNET hRequest;
628 DWORD dwTemp = 0;
629
630 // Keep compiler happy
631 dwStreamFlags = dwStreamFlags;
632
633 // Don't connect to the internet
634 if(!InternetGetConnectedState(&dwTemp, 0))
635 return false;
636
637 // Initiate the connection to the internet
638 pStream->Base.Http.hInternet = InternetOpen(_T("StormLib HTTP MPQ reader"),
639 INTERNET_OPEN_TYPE_PRECONFIG,
640 NULL,
641 NULL,
642 0);
643 if(pStream->Base.Http.hInternet != NULL)
644 {
645 TCHAR szServerName[MAX_PATH];
646 DWORD dwFlags = INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_UI | INTERNET_FLAG_NO_CACHE_WRITE;
647
648 // Initiate connection with the server
649 szFileName = BaseHttp_ExtractServerName(szFileName, szServerName);
650 pStream->Base.Http.hConnect = InternetConnect(pStream->Base.Http.hInternet,
651 szServerName,
652 INTERNET_DEFAULT_HTTP_PORT,
653 NULL,
654 NULL,
655 INTERNET_SERVICE_HTTP,
656 dwFlags,
657 0);
658 if(pStream->Base.Http.hConnect != NULL)
659 {
660 // Open HTTP request to the file
661 hRequest = HttpOpenRequest(pStream->Base.Http.hConnect, _T("GET"), szFileName, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
662 if(hRequest != NULL)
663 {
664 if(HttpSendRequest(hRequest, NULL, 0, NULL, 0))
665 {
666 ULONGLONG FileTime = 0;
667 DWORD dwFileSize = 0;
668 DWORD dwDataSize;
669 DWORD dwIndex = 0;
670
671 // Check if the MPQ has Last Modified field
672 dwDataSize = sizeof(ULONGLONG);
673 if(HttpQueryInfo(hRequest, HTTP_QUERY_LAST_MODIFIED | HTTP_QUERY_FLAG_SYSTEMTIME, &FileTime, &dwDataSize, &dwIndex))
674 pStream->Base.Http.FileTime = FileTime;
675
676 // Verify if the server supports random access
677 dwDataSize = sizeof(DWORD);
678 if(HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwFileSize, &dwDataSize, &dwIndex))
679 {
680 if(dwFileSize != 0)

Callers

nothing calls this directly

Calls 2

SetLastErrorFunction · 0.85

Tested by

no test coverage detected