mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
More work on asyncdownloader
This commit is contained in:
parent
0d5fb926aa
commit
aa62d7d43f
@ -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
|
@ -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);
|
||||
@ -49,7 +59,7 @@ int main(void) {
|
||||
|
||||
String title = String_FromConst(PROGRAM_APP_NAME);
|
||||
String rawArgs = Platform_GetCommandLineArgs();
|
||||
// rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
|
||||
rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
|
||||
//rawArgs = String_FromReadonly("UnknownShadow200");
|
||||
|
||||
String args[5]; UInt32 argsCount = Array_Elems(args);
|
||||
|
@ -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) {
|
||||
@ -594,3 +596,29 @@ ReturnCode Platform_SocketSelectRead(void* socket, Int32 microseconds, bool* suc
|
||||
*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();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user