src/win32.cpp
branchcustombridgeheads
changeset 5650 aefc131bf5ce
parent 5649 55c8267c933f
equal deleted inserted replaced
5649:55c8267c933f 5650:aefc131bf5ce
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 #include "stdafx.h"
     3 #include "stdafx.h"
       
     4 #include "hal.h"
     4 #include "openttd.h"
     5 #include "openttd.h"
     5 #include "debug.h"
     6 #include "debug.h"
     6 #include "functions.h"
     7 #include "functions.h"
     7 #include "macros.h"
     8 #include "macros.h"
       
     9 #include "helpers.hpp"
     8 #include "saveload.h"
    10 #include "saveload.h"
     9 #include "string.h"
    11 #include "string.h"
    10 #include "gfx.h"
    12 #include "gfx.h"
    11 #include "window.h"
    13 #include "window.h"
    12 #include <windows.h>
    14 #include <windows.h>
   445 	if (had_exception) ExitProcess(0);
   447 	if (had_exception) ExitProcess(0);
   446 	had_exception = true;
   448 	had_exception = true;
   447 
   449 
   448 	_ident = GetTickCount(); // something pretty unique
   450 	_ident = GetTickCount(); // something pretty unique
   449 
   451 
   450 	MakeCRCTable(alloca(256 * sizeof(uint32)));
   452 	MakeCRCTable((uint32*)alloca(256 * sizeof(uint32)));
   451 	_crash_msg = output = LocalAlloc(LMEM_FIXED, 8192);
   453 	_crash_msg = output = (char*)LocalAlloc(LMEM_FIXED, 8192);
   452 
   454 
   453 	{
   455 	{
   454 		SYSTEMTIME time;
   456 		SYSTEMTIME time;
   455 		GetLocalTime(&time);
   457 		GetLocalTime(&time);
   456 		output += sprintf(output,
   458 		output += sprintf(output,
   632 static inline DIR *dir_calloc(void)
   634 static inline DIR *dir_calloc(void)
   633 {
   635 {
   634 	DIR *d;
   636 	DIR *d;
   635 
   637 
   636 	if (_global_dir_is_in_use) {
   638 	if (_global_dir_is_in_use) {
   637 		d = calloc(1, sizeof(*d));
   639 		CallocT(&d, 1);
   638 	} else {
   640 	} else {
   639 		_global_dir_is_in_use = true;
   641 		_global_dir_is_in_use = true;
   640 		d = &_global_dir;
   642 		d = &_global_dir;
   641 		memset(d, 0, sizeof(*d));
   643 		memset(d, 0, sizeof(*d));
   642 	}
   644 	}
   909 void DeterminePaths(void)
   911 void DeterminePaths(void)
   910 {
   912 {
   911 	char *s, *cfg;
   913 	char *s, *cfg;
   912 	wchar_t path[MAX_PATH];
   914 	wchar_t path[MAX_PATH];
   913 
   915 
   914 	_paths.personal_dir = _paths.game_data_dir = cfg = malloc(MAX_PATH);
   916 	_paths.personal_dir = _paths.game_data_dir = cfg = (char*)malloc(MAX_PATH);
   915 	GetCurrentDirectoryW(MAX_PATH - 1, path);
   917 	GetCurrentDirectoryW(MAX_PATH - 1, path);
   916 	convert_from_fs(path, cfg, MAX_PATH);
   918 	convert_from_fs(path, cfg, MAX_PATH);
   917 
   919 
   918 	cfg[0] = toupper(cfg[0]);
   920 	cfg[0] = toupper(cfg[0]);
   919 	s = strchr(cfg, '\0');
   921 	s = strchr(cfg, '\0');
   960 		const char *ret;
   962 		const char *ret;
   961 
   963 
   962 		OpenClipboard(NULL);
   964 		OpenClipboard(NULL);
   963 		cbuf = GetClipboardData(CF_UNICODETEXT);
   965 		cbuf = GetClipboardData(CF_UNICODETEXT);
   964 
   966 
   965 		ptr = GlobalLock(cbuf);
   967 		ptr = (const char*)GlobalLock(cbuf);
   966 		ret = convert_from_fs((wchar_t*)ptr, utf8_buf, lengthof(utf8_buf));
   968 		ret = convert_from_fs((wchar_t*)ptr, utf8_buf, lengthof(utf8_buf));
   967 		GlobalUnlock(cbuf);
   969 		GlobalUnlock(cbuf);
   968 		CloseClipboard();
   970 		CloseClipboard();
   969 
   971 
   970 		if (*ret == '\0') return false;
   972 		if (*ret == '\0') return false;
   971 	} else if (IsClipboardFormatAvailable(CF_TEXT)) {
   973 	} else if (IsClipboardFormatAvailable(CF_TEXT)) {
   972 		OpenClipboard(NULL);
   974 		OpenClipboard(NULL);
   973 		cbuf = GetClipboardData(CF_TEXT);
   975 		cbuf = GetClipboardData(CF_TEXT);
   974 
   976 
   975 		ptr = GlobalLock(cbuf);
   977 		ptr = (const char*)GlobalLock(cbuf);
   976 		ttd_strlcpy(utf8_buf, ptr, lengthof(utf8_buf));
   978 		ttd_strlcpy(utf8_buf, ptr, lengthof(utf8_buf));
   977 		GlobalUnlock(cbuf);
   979 		GlobalUnlock(cbuf);
   978 		CloseClipboard();
   980 		CloseClipboard();
   979 	} else {
   981 	} else {
   980 		return false;
   982 		return false;