File diff r4320:c2a7d05512a6 → r4321:baa916e5dd65
win32.c
Show inline comments
 
@@ -220,97 +220,97 @@ static bool EmergencySave(void)
 
	return true;
 
}
 

	
 
typedef struct {
 
	HINTERNET (WINAPI *InternetOpenA)(LPCSTR,DWORD, LPCSTR, LPCSTR, DWORD);
 
	HINTERNET (WINAPI *InternetConnectA)(HINTERNET, LPCSTR, INTERNET_PORT, LPCSTR, LPCSTR, DWORD, DWORD, DWORD);
 
	HINTERNET (WINAPI *HttpOpenRequestA)(HINTERNET, LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPCSTR *, DWORD, DWORD);
 
	BOOL (WINAPI *HttpSendRequestA)(HINTERNET, LPCSTR, DWORD, LPVOID, DWORD);
 
	BOOL (WINAPI *InternetCloseHandle)(HINTERNET);
 
	BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD);
 
} WinInetProcs;
 

	
 
#define M(x) x "\0"
 
static const char wininet_files[] =
 
	M("wininet.dll")
 
	M("InternetOpenA")
 
	M("InternetConnectA")
 
	M("HttpOpenRequestA")
 
	M("HttpSendRequestA")
 
	M("InternetCloseHandle")
 
	M("HttpQueryInfoA")
 
	M("");
 
#undef M
 

	
 
static WinInetProcs _wininet;
 

	
 

	
 
static const char *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const char *arg)
 
{
 
	HINTERNET inet, conn, http;
 
	const char *err = NULL;
 
	DWORD code, len;
 
	static char buf[100];
 
	char buff[100];
 

	
 
	if (_wininet.InternetOpen == NULL && !LoadLibraryList((Function*)&_wininet, wininet_files)) return "can't load wininet.dll";
 

	
 
	inet = _wininet.InternetOpen("OTTD", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
 
	if (inet == NULL) { err = "internetopen failed"; goto error1; }
 

	
 
	conn = _wininet.InternetConnect(inet, "openttd.com", INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0);
 
	if (conn == NULL) { err = "internetconnect failed"; goto error2; }
 

	
 
	sprintf(buff, "/crash.php?file=%s&ident=%d", arg, _ident);
 

	
 
	http = _wininet.HttpOpenRequest(conn, "POST", buff, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE , 0);
 
	if (http == NULL) { err = "httpopenrequest failed"; goto error3; }
 

	
 
	if (!_wininet.HttpSendRequest(http, "Content-type: application/binary", -1, msg, msglen)) { err = "httpsendrequest failed"; goto error4; }
 
	if (!_wininet.HttpSendRequest(http, "Content-type: application/binary", -1, msg, (DWORD)msglen)) { err = "httpsendrequest failed"; goto error4; }
 

	
 
	len = sizeof(code);
 
	if (!_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &len, 0)) { err = "httpqueryinfo failed"; goto error4; }
 

	
 
	if (code != 200) {
 
		int l = sprintf(buf, "Server said: %d ", code);
 
		len = sizeof(buf) - l;
 
		_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_TEXT, buf + l, &len, 0);
 
		err = buf;
 
	}
 

	
 
error4:
 
	_wininet.InternetCloseHandle(http);
 
error3:
 
	_wininet.InternetCloseHandle(conn);
 
error2:
 
	_wininet.InternetCloseHandle(inet);
 
error1:
 
	return err;
 
}
 

	
 
static void SubmitFile(HWND wnd, const char *file)
 
{
 
	HANDLE h;
 
	unsigned long size;
 
	unsigned long read;
 
	void *mem;
 

	
 
	h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
 
	if (h == NULL) return;
 

	
 
	size = GetFileSize(h, NULL);
 
	if (size > 500000) goto error1;
 

	
 
	mem = malloc(size);
 
	if (mem == NULL) goto error1;
 

	
 
	if (!ReadFile(h, mem, size, &read, NULL) || read != size) goto error2;
 

	
 
	SubmitCrashReport(wnd, mem, size, file);
 

	
 
error2:
 
	free(mem);
 
error1:
 
	CloseHandle(h);
 
}
 

	
 
static const char * const _expand_texts[] = {"S&how report >>", "&Hide report <<" };