mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
API exclusively.
This commit is contained in:
parent
4e71091137
commit
d8d210056d
@ -64,6 +64,7 @@ static void DedicatedSignalHandler(int sig)
|
|||||||
#include <windows.h> /* GetTickCount */
|
#include <windows.h> /* GetTickCount */
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <tchar.h>
|
||||||
static HANDLE _hInputReady, _hWaitForInputHandling;
|
static HANDLE _hInputReady, _hWaitForInputHandling;
|
||||||
static HANDLE _hThread; // Thread to close
|
static HANDLE _hThread; // Thread to close
|
||||||
static char _win_console_thread_buffer[200];
|
static char _win_console_thread_buffer[200];
|
||||||
@ -121,10 +122,10 @@ static const char *DedicatedVideoStart(const char * const *parm)
|
|||||||
_debug_misc_level = 0;
|
_debug_misc_level = 0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// For win32 we need to allocate an console (debug mode does the same)
|
// For win32 we need to allocate a console (debug mode does the same)
|
||||||
CreateConsole();
|
CreateConsole();
|
||||||
CreateWindowsConsoleThread();
|
CreateWindowsConsoleThread();
|
||||||
SetConsoleTitle("OpenTTD Dedicated Server");
|
SetConsoleTitle(_T("OpenTTD Dedicated Server"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __OS2__
|
#ifdef __OS2__
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "../window.h"
|
#include "../window.h"
|
||||||
#include "win32_v.h"
|
#include "win32_v.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
HWND main_wnd;
|
HWND main_wnd;
|
||||||
@ -517,7 +518,7 @@ static void RegisterWndClass(void)
|
|||||||
LoadCursor(NULL, IDC_ARROW),
|
LoadCursor(NULL, IDC_ARROW),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
"OTTD"
|
_T("OTTD")
|
||||||
};
|
};
|
||||||
|
|
||||||
registered = true;
|
registered = true;
|
||||||
@ -588,11 +589,11 @@ static void MakeWindow(bool full_screen)
|
|||||||
SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
||||||
} else {
|
} else {
|
||||||
extern const char _openttd_revision[];
|
extern const char _openttd_revision[];
|
||||||
char Windowtitle[50];
|
TCHAR Windowtitle[50];
|
||||||
|
|
||||||
snprintf(Windowtitle, lengthof(Windowtitle), "OpenTTD %s", _openttd_revision);
|
_sntprintf(Windowtitle, sizeof(Windowtitle), _T("OpenTTD %s"), MB_TO_WIDE(_openttd_revision));
|
||||||
|
|
||||||
_wnd.main_wnd = CreateWindow("OTTD", Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
|
_wnd.main_wnd = CreateWindow(_T("OTTD"), Windowtitle, style, x, y, w, h, 0, 0, GetModuleHandle(NULL), 0);
|
||||||
if (_wnd.main_wnd == NULL) error("CreateWindow failed");
|
if (_wnd.main_wnd == NULL) error("CreateWindow failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
174
win32.c
174
win32.c
@ -18,6 +18,7 @@
|
|||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
#include "fios.h" // opendir/readdir/closedir
|
#include "fios.h" // opendir/readdir/closedir
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <tchar.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -40,12 +41,14 @@ bool MyShowCursor(bool show)
|
|||||||
return !show;
|
return !show;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Helper function needed by dynamically loading libraries
|
||||||
// Helper function needed by dynamically loading SDL
|
* XXX: Hurray for MS only having an ANSI GetProcAddress function
|
||||||
|
* on normal windows and no Wide version except for in Windows Mobile/CE */
|
||||||
bool LoadLibraryList(Function proc[], const char *dll)
|
bool LoadLibraryList(Function proc[], const char *dll)
|
||||||
{
|
{
|
||||||
while (*dll != '\0') {
|
while (*dll != '\0') {
|
||||||
HMODULE lib = LoadLibrary(dll);
|
HMODULE lib;
|
||||||
|
lib = LoadLibrary(MB_TO_WIDE(dll));
|
||||||
|
|
||||||
if (lib == NULL) return false;
|
if (lib == NULL) return false;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -53,7 +56,11 @@ bool LoadLibraryList(Function proc[], const char* dll)
|
|||||||
|
|
||||||
while (*dll++ != '\0');
|
while (*dll++ != '\0');
|
||||||
if (*dll == '\0') break;
|
if (*dll == '\0') break;
|
||||||
|
#if defined(WINCE)
|
||||||
|
p = GetProcAddress(lib, MB_TO_WIDE(dll);
|
||||||
|
#else
|
||||||
p = GetProcAddress(lib, dll);
|
p = GetProcAddress(lib, dll);
|
||||||
|
#endif
|
||||||
if (p == NULL) return false;
|
if (p == NULL) return false;
|
||||||
*proc++ = (Function)p;
|
*proc++ = (Function)p;
|
||||||
}
|
}
|
||||||
@ -63,13 +70,13 @@ bool LoadLibraryList(Function proc[], const char* dll)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
static const char *_exception_string;
|
static const char *_exception_string = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ShowOSErrorBox(const char *buf)
|
void ShowOSErrorBox(const char *buf)
|
||||||
{
|
{
|
||||||
MyShowCursor(true);
|
MyShowCursor(true);
|
||||||
MessageBoxA(GetActiveWindow(), buf, "Error!", MB_ICONSTOP);
|
MessageBox(GetActiveWindow(), MB_TO_WIDE(buf), _T("Error!"), MB_ICONSTOP);
|
||||||
|
|
||||||
// if exception tracker is enabled, we crash here to let the exception handler handle it.
|
// if exception tracker is enabled, we crash here to let the exception handler handle it.
|
||||||
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG)
|
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG)
|
||||||
@ -119,7 +126,7 @@ static uint32 CalcCRC(byte *data, uint size, uint32 crc) {
|
|||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GetFileInfo(DebugFileInfo *dfi, const char *filename)
|
static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename)
|
||||||
{
|
{
|
||||||
memset(dfi, 0, sizeof(dfi));
|
memset(dfi, 0, sizeof(dfi));
|
||||||
|
|
||||||
@ -155,13 +162,13 @@ static void GetFileInfo(DebugFileInfo *dfi, const char *filename)
|
|||||||
|
|
||||||
static char *PrintModuleInfo(char *output, HMODULE mod)
|
static char *PrintModuleInfo(char *output, HMODULE mod)
|
||||||
{
|
{
|
||||||
char buffer[MAX_PATH];
|
TCHAR buffer[MAX_PATH];
|
||||||
DebugFileInfo dfi;
|
DebugFileInfo dfi;
|
||||||
|
|
||||||
GetModuleFileName(mod, buffer, MAX_PATH);
|
GetModuleFileName(mod, buffer, MAX_PATH);
|
||||||
GetFileInfo(&dfi, buffer);
|
GetFileInfo(&dfi, buffer);
|
||||||
output += sprintf(output, " %-20s handle: %p size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n",
|
output += sprintf(output, " %-20s handle: %p size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n",
|
||||||
buffer,
|
WIDE_TO_MB(buffer),
|
||||||
mod,
|
mod,
|
||||||
dfi.size,
|
dfi.size,
|
||||||
dfi.crc32,
|
dfi.crc32,
|
||||||
@ -184,7 +191,7 @@ static char *PrintModuleList(char *output)
|
|||||||
BOOL res;
|
BOOL res;
|
||||||
int count,i;
|
int count,i;
|
||||||
|
|
||||||
if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0")) {
|
if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0\0")) {
|
||||||
proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
|
proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
|
||||||
if (proc) {
|
if (proc) {
|
||||||
res = EnumProcessModules(proc, modules, sizeof(modules), &needed);
|
res = EnumProcessModules(proc, modules, sizeof(modules), &needed);
|
||||||
@ -202,17 +209,17 @@ static char *PrintModuleList(char *output)
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char _crash_desc[] =
|
static const TCHAR _crash_desc[] =
|
||||||
"A serious fault condition occured in the game. The game will shut down.\n"
|
_T("A serious fault condition occured in the game. The game will shut down.\n")
|
||||||
"Press \"Submit report\" to send crash information to the developers. "
|
_T("Press \"Submit report\" to send crash information to the developers. ")
|
||||||
"This will greatly help debugging. "
|
_T("This will greatly help debugging. ")
|
||||||
"The information contained in the report is displayed below.\n"
|
_T("The information contained in the report is displayed below.\n")
|
||||||
"Press \"Emergency save\" to attempt saving the game.";
|
_T("Press \"Emergency save\" to attempt saving the game.");
|
||||||
|
|
||||||
static const char _save_succeeded[] =
|
static const TCHAR _save_succeeded[] =
|
||||||
"Emergency save succeeded.\n"
|
_T("Emergency save succeeded.\n")
|
||||||
"Be aware that critical parts of the internal game state may have become "
|
_T("Be aware that critical parts of the internal game state may have become ")
|
||||||
"corrupted. The saved game is not guaranteed to work.";
|
_T("corrupted. The saved game is not guaranteed to work.");
|
||||||
|
|
||||||
static bool EmergencySave(void)
|
static bool EmergencySave(void)
|
||||||
{
|
{
|
||||||
@ -221,57 +228,63 @@ static bool EmergencySave(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
HINTERNET (WINAPI *InternetOpenA)(LPCSTR,DWORD, LPCSTR, LPCSTR, DWORD);
|
HINTERNET (WINAPI *InternetOpen)(LPCTSTR,DWORD, LPCTSTR, LPCTSTR, DWORD);
|
||||||
HINTERNET (WINAPI *InternetConnectA)(HINTERNET, LPCSTR, INTERNET_PORT, LPCSTR, LPCSTR, DWORD, DWORD, DWORD);
|
HINTERNET (WINAPI *InternetConnect)(HINTERNET, LPCTSTR, INTERNET_PORT, LPCTSTR, LPCTSTR, DWORD, DWORD, DWORD);
|
||||||
HINTERNET (WINAPI *HttpOpenRequestA)(HINTERNET, LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPCSTR *, DWORD, DWORD);
|
HINTERNET (WINAPI *HttpOpenRequest)(HINTERNET, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR *, DWORD, DWORD);
|
||||||
BOOL (WINAPI *HttpSendRequestA)(HINTERNET, LPCSTR, DWORD, LPVOID, DWORD);
|
BOOL (WINAPI *HttpSendRequest)(HINTERNET, LPCTSTR, DWORD, LPVOID, DWORD);
|
||||||
BOOL (WINAPI *InternetCloseHandle)(HINTERNET);
|
BOOL (WINAPI *InternetCloseHandle)(HINTERNET);
|
||||||
BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD);
|
BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD);
|
||||||
} WinInetProcs;
|
} WinInetProcs;
|
||||||
|
|
||||||
#define M(x) x "\0"
|
#define M(x) x "\0"
|
||||||
|
#if defined(UNICODE)
|
||||||
|
# define W(x) x "W"
|
||||||
|
#else
|
||||||
|
# define W(x) x "A"
|
||||||
|
#endif
|
||||||
static const char wininet_files[] =
|
static const char wininet_files[] =
|
||||||
M("wininet.dll")
|
M("wininet.dll")
|
||||||
M("InternetOpenA")
|
M(W("InternetOpen"))
|
||||||
M("InternetConnectA")
|
M(W("InternetConnect"))
|
||||||
M("HttpOpenRequestA")
|
M(W("HttpOpenRequest"))
|
||||||
M("HttpSendRequestA")
|
M(W("HttpSendRequest"))
|
||||||
M("InternetCloseHandle")
|
M("InternetCloseHandle")
|
||||||
M("HttpQueryInfoA")
|
M(W("HttpQueryInfo"))
|
||||||
M("");
|
M("");
|
||||||
|
#undef W
|
||||||
#undef M
|
#undef M
|
||||||
|
|
||||||
static WinInetProcs _wininet;
|
static WinInetProcs _wininet;
|
||||||
|
|
||||||
|
|
||||||
static const char *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const char *arg)
|
static const TCHAR *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const TCHAR *arg)
|
||||||
{
|
{
|
||||||
HINTERNET inet, conn, http;
|
HINTERNET inet, conn, http;
|
||||||
const char *err = NULL;
|
const TCHAR *err = NULL;
|
||||||
DWORD code, len;
|
DWORD code, len;
|
||||||
static char buf[100];
|
static TCHAR buf[100];
|
||||||
char buff[100];
|
TCHAR buff[100];
|
||||||
|
|
||||||
if (_wininet.InternetOpen == NULL && !LoadLibraryList((Function*)&_wininet, wininet_files)) return "can't load wininet.dll";
|
if (_wininet.InternetOpen == NULL && !LoadLibraryList((Function*)&_wininet, wininet_files)) return _T("can't load wininet.dll");
|
||||||
|
|
||||||
inet = _wininet.InternetOpen("OTTD", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
|
inet = _wininet.InternetOpen(_T("OTTD"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
|
||||||
if (inet == NULL) { err = "internetopen failed"; goto error1; }
|
if (inet == NULL) { err = _T("internetopen failed"); goto error1; }
|
||||||
|
|
||||||
conn = _wininet.InternetConnect(inet, "openttd.com", INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0);
|
conn = _wininet.InternetConnect(inet, _T("www.openttd.org"), INTERNET_DEFAULT_HTTP_PORT, _T(""), _T(""), INTERNET_SERVICE_HTTP, 0, 0);
|
||||||
if (conn == NULL) { err = "internetconnect failed"; goto error2; }
|
if (conn == NULL) { err = _T("internetconnect failed"); goto error2; }
|
||||||
|
|
||||||
sprintf(buff, "/crash.php?file=%s&ident=%d", arg, _ident);
|
_sntprintf(buff, lengthof(buff), _T("/crash.php?file=%s&ident=%d"), arg, _ident);
|
||||||
|
|
||||||
http = _wininet.HttpOpenRequest(conn, "POST", buff, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE , 0);
|
http = _wininet.HttpOpenRequest(conn, _T("POST"), buff, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE , 0);
|
||||||
if (http == NULL) { err = "httpopenrequest failed"; goto error3; }
|
if (http == NULL) { err = _T("httpopenrequest failed"); goto error3; }
|
||||||
|
|
||||||
if (!_wininet.HttpSendRequest(http, "Content-type: application/binary", -1, msg, (DWORD)msglen)) { err = "httpsendrequest failed"; goto error4; }
|
if (!_wininet.HttpSendRequest(http, _T("Content-type: application/binary"), -1, msg, (DWORD)msglen)) { err = _T("httpsendrequest failed"); goto error4; }
|
||||||
|
|
||||||
len = sizeof(code);
|
len = sizeof(code);
|
||||||
if (!_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &len, 0)) { err = "httpqueryinfo failed"; goto error4; }
|
if (!_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &len, 0)) { err = _T("httpqueryinfo failed"); goto error4; }
|
||||||
|
|
||||||
if (code != 200) {
|
if (code != 200) {
|
||||||
int l = sprintf(buf, "Server said: %d ", code);
|
int l = _sntprintf(buf, lengthof(buf), _T("Server said: %d "), code);
|
||||||
len = sizeof(buf) - l;
|
len = sizeof(buf) - l;
|
||||||
_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_TEXT, buf + l, &len, 0);
|
_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_TEXT, buf + l, &len, 0);
|
||||||
err = buf;
|
err = buf;
|
||||||
@ -287,7 +300,7 @@ error1:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SubmitFile(HWND wnd, const char *file)
|
static void SubmitFile(HWND wnd, const TCHAR *file)
|
||||||
{
|
{
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
@ -313,7 +326,7 @@ error1:
|
|||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * const _expand_texts[] = {"S&how report >>", "&Hide report <<" };
|
static const TCHAR * const _expand_texts[] = {_T("S&how report >>"), _T("&Hide report <<") };
|
||||||
|
|
||||||
static void SetWndSize(HWND wnd, int mode)
|
static void SetWndSize(HWND wnd, int mode)
|
||||||
{
|
{
|
||||||
@ -353,48 +366,54 @@ static bool DoEmergencySave(HWND wnd)
|
|||||||
static INT_PTR CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam)
|
static INT_PTR CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam)
|
||||||
{
|
{
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG: {
|
||||||
|
#if defined(UNICODE)
|
||||||
|
# define crash_msg crash_msgW
|
||||||
|
TCHAR crash_msgW[8096];
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, _crash_msg, -1, crash_msgW, lengthof(crash_msgW));
|
||||||
|
#else
|
||||||
|
# define crash_msg _crash_msg
|
||||||
|
#endif
|
||||||
SetDlgItemText(wnd, 10, _crash_desc);
|
SetDlgItemText(wnd, 10, _crash_desc);
|
||||||
SetDlgItemText(wnd, 11, _crash_msg);
|
SetDlgItemText(wnd, 11, crash_msg);
|
||||||
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE);
|
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE);
|
||||||
SetWndSize(wnd, -1);
|
SetWndSize(wnd, -1);
|
||||||
return TRUE;
|
} return TRUE;
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
switch (wParam) {
|
switch (wParam) {
|
||||||
case 12: // Close
|
case 12: // Close
|
||||||
ExitProcess(0);
|
ExitProcess(0);
|
||||||
case 13: { // Emergency save
|
case 13: { // Emergency save
|
||||||
if (DoEmergencySave(wnd)) {
|
if (DoEmergencySave(wnd)) {
|
||||||
MessageBoxA(wnd, _save_succeeded, "Save successful", MB_ICONINFORMATION);
|
MessageBox(wnd, _save_succeeded, _T("Save successful"), MB_ICONINFORMATION);
|
||||||
} else {
|
} else {
|
||||||
MessageBoxA(wnd, "Save failed", "Save failed", MB_ICONINFORMATION);
|
MessageBox(wnd, _T("Save failed"), _T("Save failed"), MB_ICONINFORMATION);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 14: { // Submit crash report
|
case 14: { // Submit crash report
|
||||||
const char *s;
|
const TCHAR *s;
|
||||||
|
|
||||||
SetCursor(LoadCursor(NULL, IDC_WAIT));
|
SetCursor(LoadCursor(NULL, IDC_WAIT));
|
||||||
|
|
||||||
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), "");
|
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), _T(""));
|
||||||
if (s) {
|
if (s != NULL) {
|
||||||
MessageBoxA(wnd, s, "Error", MB_ICONSTOP);
|
MessageBox(wnd, s, _T("Error"), MB_ICONSTOP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to submit emergency savegame
|
// try to submit emergency savegame
|
||||||
if (_did_emerg_save || DoEmergencySave(wnd)) {
|
if (_did_emerg_save || DoEmergencySave(wnd)) SubmitFile(wnd, _T("crash.sav"));
|
||||||
SubmitFile(wnd, "crash.sav");
|
|
||||||
}
|
|
||||||
// try to submit the autosaved game
|
// try to submit the autosaved game
|
||||||
if (_opt.autosave) {
|
if (_opt.autosave) {
|
||||||
char buf[40];
|
TCHAR buf[40];
|
||||||
sprintf(buf, "autosave%d.sav", (_autosave_ctr - 1) & 3);
|
_sntprintf(buf, lengthof(buf), _T("autosave%d.sav"), (_autosave_ctr - 1) & 3);
|
||||||
SubmitFile(wnd, buf);
|
SubmitFile(wnd, buf);
|
||||||
}
|
}
|
||||||
EnableWindow(GetDlgItem(wnd, 14), FALSE);
|
EnableWindow(GetDlgItem(wnd, 14), FALSE);
|
||||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||||
MessageBoxA(wnd, "Crash report submitted. Thank you.", "Crash Report", MB_ICONINFORMATION);
|
MessageBox(wnd, _T("Crash report submitted. Thank you."), _T("Crash Report"), MB_ICONINFORMATION);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 15: // Expand
|
case 15: // Expand
|
||||||
@ -423,7 +442,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
|||||||
{
|
{
|
||||||
extern const char _openttd_revision[];
|
extern const char _openttd_revision[];
|
||||||
char *output;
|
char *output;
|
||||||
static bool had_exception;
|
static bool had_exception = false;
|
||||||
|
|
||||||
if (had_exception) ExitProcess(0);
|
if (had_exception) ExitProcess(0);
|
||||||
had_exception = true;
|
had_exception = true;
|
||||||
@ -436,7 +455,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
|||||||
{
|
{
|
||||||
SYSTEMTIME time;
|
SYSTEMTIME time;
|
||||||
GetLocalTime(&time);
|
GetLocalTime(&time);
|
||||||
output += snprintf(output, 8192,
|
output += sprintf(output,
|
||||||
"*** OpenTTD Crash Report ***\r\n"
|
"*** OpenTTD Crash Report ***\r\n"
|
||||||
"Date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n"
|
"Date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n"
|
||||||
"Build: %s built on " __DATE__ " " __TIME__ "\r\n",
|
"Build: %s built on " __DATE__ " " __TIME__ "\r\n",
|
||||||
@ -559,7 +578,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
HANDLE file = CreateFile("crash.log", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
HANDLE file = CreateFile(_T("crash.log"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
||||||
DWORD num_written;
|
DWORD num_written;
|
||||||
if (file != INVALID_HANDLE_VALUE) {
|
if (file != INVALID_HANDLE_VALUE) {
|
||||||
WriteFile(file, _crash_msg, output - _crash_msg, &num_written, NULL);
|
WriteFile(file, _crash_msg, output - _crash_msg, &num_written, NULL);
|
||||||
@ -703,15 +722,15 @@ bool FiosIsRoot(const char *file)
|
|||||||
|
|
||||||
void FiosGetDrives(void)
|
void FiosGetDrives(void)
|
||||||
{
|
{
|
||||||
char drives[256];
|
TCHAR drives[256];
|
||||||
const char *s;
|
const TCHAR *s;
|
||||||
|
|
||||||
GetLogicalDriveStrings(sizeof(drives), drives);
|
GetLogicalDriveStrings(sizeof(drives), drives);
|
||||||
for (s = drives; *s != '\0';) {
|
for (s = drives; *s != '\0';) {
|
||||||
FiosItem *fios = FiosAlloc();
|
FiosItem *fios = FiosAlloc();
|
||||||
fios->type = FIOS_TYPE_DRIVE;
|
fios->type = FIOS_TYPE_DRIVE;
|
||||||
fios->mtime = 0;
|
fios->mtime = 0;
|
||||||
snprintf(fios->name, lengthof(fios->name), "%c:", s[0]);
|
snprintf(fios->name, lengthof(fios->name), "%c:", s[0] & 0xFF);
|
||||||
ttd_strlcpy(fios->title, fios->name, lengthof(fios->title));
|
ttd_strlcpy(fios->title, fios->name, lengthof(fios->title));
|
||||||
while (*s++ != '\0');
|
while (*s++ != '\0');
|
||||||
}
|
}
|
||||||
@ -740,10 +759,10 @@ bool FiosGetDiskFreeSpace(const char *path, uint32 *tot)
|
|||||||
{
|
{
|
||||||
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box
|
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
char root[4];
|
TCHAR root[4];
|
||||||
DWORD spc, bps, nfc, tnc;
|
DWORD spc, bps, nfc, tnc;
|
||||||
|
|
||||||
snprintf(root, lengthof(root), "%c:" PATHSEP, path[0]);
|
_sntprintf(root, lengthof(root), _T("%c:") _T(PATHSEP), path[0]);
|
||||||
if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
|
if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
|
||||||
*tot = ((spc * bps) * (uint64)nfc) >> 20;
|
*tot = ((spc * bps) * (uint64)nfc) >> 20;
|
||||||
retval = true;
|
retval = true;
|
||||||
@ -830,7 +849,7 @@ void ShowInfo(const char *str)
|
|||||||
_left_button_clicked =_left_button_down = false;
|
_left_button_clicked =_left_button_down = false;
|
||||||
|
|
||||||
old = MyShowCursor(true);
|
old = MyShowCursor(true);
|
||||||
if (MessageBoxA(GetActiveWindow(), str, "OpenTTD", MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) {
|
if (MessageBox(GetActiveWindow(), MB_TO_WIDE(str), _T("OpenTTD"), MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) {
|
||||||
CreateConsole();
|
CreateConsole();
|
||||||
}
|
}
|
||||||
MyShowCursor(old);
|
MyShowCursor(old);
|
||||||
@ -846,12 +865,21 @@ void ShowInfo(const char *str)
|
|||||||
int _set_error_mode(int);
|
int _set_error_mode(int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
LPTSTR lpCmdLine, int nCmdShow)
|
LPTSTR lpCmdLine, int nCmdShow)
|
||||||
{
|
{
|
||||||
int argc;
|
int argc;
|
||||||
char *argv[64]; // max 64 command line arguments
|
char *argv[64]; // max 64 command line arguments
|
||||||
|
|
||||||
|
#if defined(UNICODE)
|
||||||
|
/* We need to backup the command line (arguments) because the pointer
|
||||||
|
* of FS2OTTD() is only temporary */
|
||||||
|
char cmdline[MAX_PATH];
|
||||||
|
ttd_strlcpy(cmdline, FS2OTTD(GetCommandLine()), sizeof(cmdline));
|
||||||
|
#else
|
||||||
|
char *cmdline = GetCommandLine();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
CreateConsole();
|
CreateConsole();
|
||||||
#endif
|
#endif
|
||||||
@ -863,17 +891,15 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||||||
_random_seeds[1][1] = _random_seeds[0][1] = _random_seeds[0][0] * 0x1234567;
|
_random_seeds[1][1] = _random_seeds[0][1] = _random_seeds[0][0] * 0x1234567;
|
||||||
SeedMT(_random_seeds[0][0]);
|
SeedMT(_random_seeds[0][0]);
|
||||||
|
|
||||||
argc = ParseCommandLine(GetCommandLine(), argv, lengthof(argv));
|
argc = ParseCommandLine(cmdline, argv, lengthof(argv));
|
||||||
|
|
||||||
#if defined(WIN32_EXCEPTION_TRACKER)
|
#if defined(WIN32_EXCEPTION_TRACKER)
|
||||||
{
|
|
||||||
Win32InitializeExceptions();
|
Win32InitializeExceptions();
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG)
|
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG)
|
||||||
_try {
|
_try {
|
||||||
uint32 _stdcall ExceptionHandler(void *ep);
|
LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep);
|
||||||
#endif
|
#endif
|
||||||
ttd_main(argc, argv);
|
ttd_main(argc, argv);
|
||||||
|
|
||||||
|
8
win32.h
8
win32.h
@ -8,4 +8,12 @@ bool MyShowCursor(bool show);
|
|||||||
typedef void (*Function)(int);
|
typedef void (*Function)(int);
|
||||||
bool LoadLibraryList(Function proc[], const char *dll);
|
bool LoadLibraryList(Function proc[], const char *dll);
|
||||||
|
|
||||||
|
#if defined(UNICODE)
|
||||||
|
# define MB_TO_WIDE(x) OTTD2FS(x)
|
||||||
|
# define WIDE_TO_MB(x) FS2OTTD(x)
|
||||||
|
#else
|
||||||
|
# define MB_TO_WIDE(x) (x)
|
||||||
|
# define WIDE_TO_MB(x) (x)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* WIN32_H */
|
#endif /* WIN32_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user