MCPcopy Create free account
hub / github.com/DentonW/DevIL / ILAPIENTRY ilutWinLoadUrl

Function ILAPIENTRY ilutWinLoadUrl

DevIL/src-ILUT/src/ilut_win32.cpp:766–852  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764#if !defined(_WIN32_WCE) && !(defined(_WIN32) && defined(__GNUC__))
765#define BUFFSIZE 8192 // Change to suit the efficiency.
766ILboolean ILAPIENTRY ilutWinLoadUrl(ILstring Url)
767{
768 HINTERNET Handle, UrlHandle;
769 DWORD BytesRead = 0, Context = 1;
770 ILubyte Buff[BUFFSIZE], *Buffer, *TempBuff;
771 ILuint BufferSize = 0, i;
772 ILboolean Is404 = IL_TRUE;
773 char Buffer404[] = { '<', 'h', 't', 'm', 'l', '>' };
774
775 Buffer = (ILubyte*)ialloc(0);
776 if (Buffer == NULL) {
777 return IL_FALSE;
778 }
779
780 Handle = InternetOpen(IL_TEXT("Developer's Image Library"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
781 if (Handle == NULL) {
782 ifree(Buffer);
783 ilSetError(ILUT_COULD_NOT_OPEN_FILE);
784 return IL_FALSE;
785 }
786
787 // Try again if fails the first time, loading only from the cache.
788 UrlHandle = InternetOpenUrl(Handle, Url, NULL, 0, 0, Context);
789 if (UrlHandle == NULL) {
790 InternetCloseHandle(Handle);
791 Handle = InternetOpen(IL_TEXT("Developer's Image Library"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_FROM_CACHE);
792 if (Handle == NULL) {
793 ifree(Buffer);
794 ilSetError(ILUT_COULD_NOT_OPEN_FILE);
795 return IL_FALSE;
796 }
797 UrlHandle = InternetOpenUrl(Handle, Url, NULL, 0, 0, Context);
798 if (UrlHandle == NULL) {
799 ifree(Buffer);
800 InternetCloseHandle(Handle);
801 ilSetError(ILUT_COULD_NOT_OPEN_FILE);
802 return IL_FALSE;
803 }
804 }
805
806 do {
807 if (!InternetReadFile(UrlHandle, Buff, BUFFSIZE, &BytesRead)) {
808 InternetCloseHandle(UrlHandle);
809 InternetCloseHandle(Handle);
810 ifree(Buffer);
811 ilSetError(ILUT_COULD_NOT_OPEN_FILE);
812 return IL_FALSE;
813 }
814
815 TempBuff = (ILubyte*)ialloc(BufferSize + BytesRead);
816 if (TempBuff == NULL) {
817 ifree(Buffer);
818 return IL_FALSE;
819 }
820
821 memcpy(TempBuff, Buffer, BufferSize);
822 memcpy(TempBuff + BufferSize, Buff, BytesRead);
823 ifree(Buffer);

Callers

nothing calls this directly

Calls 1

ilSetErrorFunction · 0.85

Tested by

no test coverage detected