combine Http_DescribeError and Platform_DescribeError code for windows

This commit is contained in:
UnknownShadow200 2020-11-19 01:13:22 +11:00
parent 05bc88da4b
commit ed9f30493e
3 changed files with 12 additions and 17 deletions

View File

@ -640,13 +640,6 @@ static void Http_BackendFree(void) {
#define UNICODE
#define _UNICODE
#endif
#ifdef UNICODE
#define Platform_DecodeString(dst, src, len) String_AppendUtf16(dst, (cc_unichar*)(src), (len) * 2)
#else
#define Platform_DecodeString(dst, src, len) String_DecodeCP1252(dst, (cc_uint8*)(src), len)
#endif
#include <windows.h>
#include <wininet.h>
static HINTERNET hInternet;
@ -745,13 +738,7 @@ static cc_result HttpCache_Lookup(struct HttpCacheEntry* e) {
}
cc_bool Http_DescribeError(cc_result res, cc_string* dst) {
TCHAR chars[600];
res = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
GetModuleHandle(TEXT("wininet.dll")), res, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), chars, 600, NULL);
if (!res) return false;
Platform_DecodeString(dst, chars, res);
return true;
return Platform_DescribeErrorExt(res, dst, GetModuleHandle(TEXT("wininet.dll")));
}
static void Http_BackendInit(void) {

View File

@ -1614,15 +1614,22 @@ cc_result Platform_Decrypt(const cc_string* key, const void* data, int len, cc_s
return 0;
}
cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
cc_bool Platform_DescribeErrorExt(cc_result res, cc_string* dst, void* lib) {
TCHAR chars[NATIVE_STR_LEN];
res = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, res, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), chars, NATIVE_STR_LEN, NULL);
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
if (lib) flags |= FORMAT_MESSAGE_FROM_HMODULE;
res = FormatMessage(flags, lib, res, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
chars, NATIVE_STR_LEN, NULL);
if (!res) return false;
Platform_DecodeString(dst, chars, res);
return true;
}
cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
return Platform_DescribeErrorExt(res, dst, NULL);
}
#elif defined CC_BUILD_POSIX
int Platform_ConvertString(void* data, const cc_string* src) {
cc_uint8* dst = (cc_uint8*)data;

View File

@ -54,6 +54,7 @@ cc_result Platform_Decrypt(const cc_string* key, const void* data, int len, cc_s
/* NOTE: This is for general functions like file I/O. If a more specific
describe exists (e.g. Http_DescribeError), that should be preferred. */
cc_bool Platform_DescribeError(cc_result res, cc_string* dst);
cc_bool Platform_DescribeErrorExt(cc_result res, cc_string* dst, void* lib);
/* Starts the game with the given arguments. */
CC_API cc_result Process_StartGame(const cc_string* args);