More work on asyncdownloader

This commit is contained in:
UnknownShadow200 2018-05-06 13:58:27 +10:00
parent 0d5fb926aa
commit aa62d7d43f
4 changed files with 50 additions and 5 deletions

View File

@ -345,7 +345,7 @@ void Bitmap_DecodePng(Bitmap* bmp, Stream* stream) {
if (Stream_ReadU8(stream) != 0) ErrorHandler_Fail("PNG filter method must be ADAPTIVE");
if (Stream_ReadU8(stream) != 0) ErrorHandler_Fail("PNG interlacing not supported");
static UInt32 samplesPerPixel[7] = { 1,0,3,1,2,0,4 };
static UInt32 samplesPerPixel[7] = { 1, 0, 3, 1, 2, 0, 4 };
bytesPerPixel = ((samplesPerPixel[col] * bitsPerSample) + 7) >> 3;
scanlineSize = ((samplesPerPixel[col] * bitsPerSample * bmp->Width) + 7) >> 3;
scanlineBytes = scanlineSize + 1; /* Add 1 byte for filter byte of each scanline */

View File

@ -8,6 +8,7 @@
*/
typedef struct DrawTextArgs_ DrawTextArgs;
typedef struct Bitmap_ Bitmap;
typedef struct AsyncRequest_ AsyncRequest;
extern UInt8* Platform_NewLine; /* Newline for text */
extern UInt8 Platform_DirectorySeparator;
@ -86,4 +87,10 @@ ReturnCode Platform_SocketWrite(void* socket, UInt8* buffer, UInt32 count, UInt3
ReturnCode Platform_SocketClose(void* socket);
ReturnCode Platform_SocketAvailable(void* socket, UInt32* available);
ReturnCode Platform_SocketSelectRead(void* socket, Int32 microseconds, bool* success);
void Platform_HttpInit(void);
ReturnCode Platform_HttpMakeRequest(AsyncRequest* request, void** handle);
ReturnCode Platform_HttpGetRequestData(AsyncRequest* request, void* handle);
ReturnCode Platform_HttpFreeRequest(void* handle);
ReturnCode Platform_HttpFree(void);
#endif

View File

@ -10,11 +10,21 @@
#include "Constants.h"
#include "Game.h"
#include "Funcs.h"
#include "AsyncDownloader.h"
int main(void) {
ErrorHandler_Init("client.log");
Platform_Init();
/*Platform_HttpInit();
AsyncRequest req = { 0 };
String url = String_FromEmptyArray(req.URL);
String_AppendConst(&url, "http://static.classicube.net/skins/UnknownShadow200.png");
void* reqHandle = NULL;
ReturnCode ret = Platform_HttpMakeRequest(&req, &reqHandle);
ReturnCode ret2 = Platform_HttpFreeRequest(reqHandle);
ReturnCode ret3 = Platform_HttpFree();*/
String maps = String_FromConst("maps");
if (!Platform_DirectoryExists(&maps)) {
ReturnCode result = Platform_DirectoryCreate(&maps);
@ -48,8 +58,8 @@ int main(void) {
}
String title = String_FromConst(PROGRAM_APP_NAME);
String rawArgs = Platform_GetCommandLineArgs();
// rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
String rawArgs = Platform_GetCommandLineArgs();
rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
//rawArgs = String_FromReadonly("UnknownShadow200");
String args[5]; UInt32 argsCount = Array_Elems(args);

View File

@ -5,6 +5,7 @@
#include "ErrorHandler.h"
#include "Drawer2D.h"
#include "Funcs.h"
#include "AsyncDownloader.h"
#define WIN32_LEAN_AND_MEAN
#define NOSERVICE
#define NOMCX
@ -13,8 +14,10 @@
#include <stdlib.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <WinInet.h>
#pragma comment(lib, "ws2_32.lib")
#pragma comment (lib, "Wininet.lib")
HDC hdc;
HANDLE heap;
bool stopwatch_highResolution;
@ -269,8 +272,7 @@ ReturnCode Platform_FileWrite(void* file, UInt8* buffer, UInt32 count, UInt32* b
}
ReturnCode Platform_FileClose(void* file) {
BOOL success = CloseHandle((HANDLE)file);
return success ? 0 : GetLastError();
return CloseHandle((HANDLE)file) ? 0 : GetLastError();
}
ReturnCode Platform_FileSeek(void* file, Int32 offset, Int32 seekType) {
@ -593,4 +595,30 @@ ReturnCode Platform_SocketSelectRead(void* socket, Int32 microseconds, bool* suc
} else {
*success = args[0] != 0; return 0;
}
}
HINTERNET hInternet;
void Platform_HttpInit(void) {
/* TODO: Should we use INTERNET_OPEN_TYPE_PRECONFIG instead? */
hInternet = InternetOpenA(PROGRAM_APP_NAME, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (hInternet == NULL) ErrorHandler_FailWithCode(GetLastError(), "Failed to init WinINet");
}
ReturnCode Platform_HttpMakeRequest(AsyncRequest* request, void** handle) {
String url = String_FromRawArray(request->URL);
*handle = InternetOpenUrlA(hInternet, url.buffer, NULL, 0,
INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_UI | INTERNET_FLAG_RELOAD, NULL);
return *handle == NULL ? GetLastError() : 0;
}
ReturnCode Platform_HttpGetRequestData(AsyncRequest* request, void* handle) {
}
ReturnCode Platform_HttpFreeRequest(void* handle) {
return InternetCloseHandle(handle) ? 0 : GetLastError();
}
ReturnCode Platform_HttpFree(void) {
return InternetCloseHandle(hInternet) ? 0 : GetLastError();
}