author | rubidium |
Thu, 01 Feb 2007 15:49:12 +0000 | |
changeset 5893 | 7e431a4abebb |
parent 5891 | 9601f4469a37 |
child 6086 | 37ea367a54e6 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
4 |
#include "hal.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1885
diff
changeset
|
5 |
#include "openttd.h" |
1302 | 6 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2162
diff
changeset
|
7 |
#include "functions.h" |
2171
60334c9ca477
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
8 |
#include "macros.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
9 |
#include "helpers.hpp" |
2162
b98e430ffd10
(svn r2672) Move saving/loading related declarations to saveload.h
tron
parents:
2160
diff
changeset
|
10 |
#include "saveload.h" |
1317
3c90086ff34f
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1302
diff
changeset
|
11 |
#include "string.h" |
0 | 12 |
#include "gfx.h" |
13 |
#include "window.h" |
|
14 |
#include <windows.h> |
|
15 |
#include <winnt.h> |
|
16 |
#include <wininet.h> |
|
17 |
#include <io.h> |
|
18 |
#include <fcntl.h> |
|
5304
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
19 |
#include <shlobj.h> // SHGetFolderPath |
2160 | 20 |
#include "variables.h" |
2183
b88b90aba8bc
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
21 |
#include "win32.h" |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
22 |
#include "fios.h" // opendir/readdir/closedir |
4210
654309f99970
(svn r5698) - Fix [r5697]: don't remove ctype include for win32.c; needed for toupper...ugh
Darkvater
parents:
4209
diff
changeset
|
23 |
#include <ctype.h> |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
24 |
#include <tchar.h> |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
25 |
#include <errno.h> |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
26 |
#include <sys/types.h> |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
27 |
#include <sys/stat.h> |
2171
60334c9ca477
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
28 |
|
0 | 29 |
static bool _has_console; |
30 |
||
3394
f8a308a11171
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
31 |
#if defined(__MINGW32__) |
f8a308a11171
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
32 |
#include <stdint.h> |
f8a308a11171
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
33 |
#endif |
0 | 34 |
|
2208 | 35 |
static bool cursor_visible = true; |
36 |
||
2207
be1ef1e1fc58
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
37 |
bool MyShowCursor(bool show) |
be1ef1e1fc58
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
38 |
{ |
2209 | 39 |
if (cursor_visible == show) return show; |
2207
be1ef1e1fc58
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
40 |
|
2209 | 41 |
cursor_visible = show; |
2207
be1ef1e1fc58
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
42 |
ShowCursor(show); |
be1ef1e1fc58
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
43 |
|
be1ef1e1fc58
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
44 |
return !show; |
be1ef1e1fc58
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
45 |
} |
be1ef1e1fc58
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
46 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
47 |
/** Helper function needed by dynamically loading libraries |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
48 |
* XXX: Hurray for MS only having an ANSI GetProcAddress function |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
49 |
* on normal windows and no Wide version except for in Windows Mobile/CE */ |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
50 |
bool LoadLibraryList(Function proc[], const char *dll) |
0 | 51 |
{ |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
52 |
while (*dll != '\0') { |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
53 |
HMODULE lib; |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
54 |
lib = LoadLibrary(MB_TO_WIDE(dll)); |
2183
b88b90aba8bc
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
55 |
|
b88b90aba8bc
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
56 |
if (lib == NULL) return false; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
57 |
for (;;) { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
58 |
FARPROC p; |
2183
b88b90aba8bc
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
59 |
|
b88b90aba8bc
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
60 |
while (*dll++ != '\0'); |
b88b90aba8bc
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
61 |
if (*dll == '\0') break; |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
62 |
#if defined(WINCE) |
5758
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
63 |
p = GetProcAddress(lib, MB_TO_WIDE(dll)); |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
64 |
#else |
0 | 65 |
p = GetProcAddress(lib, dll); |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
66 |
#endif |
2183
b88b90aba8bc
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
67 |
if (p == NULL) return false; |
b88b90aba8bc
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
68 |
*proc++ = (Function)p; |
0 | 69 |
} |
70 |
dll++; |
|
71 |
} |
|
72 |
return true; |
|
73 |
} |
|
74 |
||
796 | 75 |
#ifdef _MSC_VER |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
76 |
static const char *_exception_string = NULL; |
2428
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
77 |
#endif |
0 | 78 |
|
79 |
void ShowOSErrorBox(const char *buf) |
|
80 |
{ |
|
81 |
MyShowCursor(true); |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
82 |
MessageBox(GetActiveWindow(), MB_TO_WIDE(buf), _T("Error!"), MB_ICONSTOP); |
0 | 83 |
|
84 |
// if exception tracker is enabled, we crash here to let the exception handler handle it. |
|
85 |
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG) |
|
86 |
if (*buf == '!') { |
|
87 |
_exception_string = buf; |
|
88 |
*(byte*)0 = 0; |
|
89 |
} |
|
90 |
#endif |
|
91 |
} |
|
92 |
||
2428
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
93 |
#ifdef _MSC_VER |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
94 |
|
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
95 |
static void *_safe_esp; |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
96 |
static char *_crash_msg; |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
97 |
static bool _expanded; |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
98 |
static bool _did_emerg_save; |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
99 |
static int _ident; |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
100 |
|
0 | 101 |
typedef struct DebugFileInfo { |
102 |
uint32 size; |
|
103 |
uint32 crc32; |
|
104 |
SYSTEMTIME file_time; |
|
105 |
} DebugFileInfo; |
|
106 |
||
107 |
static uint32 *_crc_table; |
|
108 |
||
109 |
static void MakeCRCTable(uint32 *table) { |
|
110 |
uint32 crc, poly = 0xEDB88320L; |
|
2026 | 111 |
int i; |
112 |
int j; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
113 |
|
0 | 114 |
_crc_table = table; |
115 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
116 |
for (i = 0; i != 256; i++) { |
0 | 117 |
crc = i; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
118 |
for (j = 8; j != 0; j--) { |
4078
7a8f56da0af0
(svn r5393) CodeChange : Little typo correction. Nothing spectacular. Only broke in MSVC
belugas
parents:
4077
diff
changeset
|
119 |
crc = (crc & 1 ? (crc >> 1) ^ poly : crc >> 1); |
0 | 120 |
} |
121 |
table[i] = crc; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
static uint32 CalcCRC(byte *data, uint size, uint32 crc) { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
126 |
for (; size > 0; size--) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
127 |
crc = ((crc >> 8) & 0x00FFFFFF) ^ _crc_table[(crc ^ *data++) & 0xFF]; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
128 |
} |
0 | 129 |
return crc; |
130 |
} |
|
131 |
||
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
132 |
static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename) |
0 | 133 |
{ |
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
134 |
HANDLE file; |
0 | 135 |
memset(dfi, 0, sizeof(dfi)); |
136 |
||
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
137 |
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
138 |
if (file != INVALID_HANDLE_VALUE) { |
0 | 139 |
byte buffer[1024]; |
140 |
DWORD numread; |
|
141 |
uint32 filesize = 0; |
|
142 |
FILETIME write_time; |
|
143 |
uint32 crc = (uint32)-1; |
|
144 |
||
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
145 |
for (;;) { |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
146 |
if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || numread == 0) |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
147 |
break; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
148 |
filesize += numread; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
149 |
crc = CalcCRC(buffer, numread, crc); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
150 |
} |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
151 |
dfi->size = filesize; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
152 |
dfi->crc32 = crc ^ (uint32)-1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
153 |
|
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
154 |
if (GetFileTime(file, NULL, NULL, &write_time)) { |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
155 |
FileTimeToSystemTime(&write_time, &dfi->file_time); |
0 | 156 |
} |
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
157 |
CloseHandle(file); |
0 | 158 |
} |
159 |
} |
|
160 |
||
161 |
||
162 |
static char *PrintModuleInfo(char *output, HMODULE mod) |
|
163 |
{ |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
164 |
TCHAR buffer[MAX_PATH]; |
0 | 165 |
DebugFileInfo dfi; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
166 |
|
0 | 167 |
GetModuleFileName(mod, buffer, MAX_PATH); |
168 |
GetFileInfo(&dfi, buffer); |
|
2458
dbaf5dffbb28
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2428
diff
changeset
|
169 |
output += sprintf(output, " %-20s handle: %p size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n", |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
170 |
WIDE_TO_MB(buffer), |
0 | 171 |
mod, |
172 |
dfi.size, |
|
173 |
dfi.crc32, |
|
174 |
dfi.file_time.wYear, |
|
175 |
dfi.file_time.wMonth, |
|
176 |
dfi.file_time.wDay, |
|
177 |
dfi.file_time.wHour, |
|
178 |
dfi.file_time.wMinute, |
|
179 |
dfi.file_time.wSecond |
|
180 |
); |
|
181 |
return output; |
|
182 |
} |
|
183 |
||
184 |
static char *PrintModuleList(char *output) |
|
185 |
{ |
|
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
186 |
BOOL (WINAPI *EnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD); |
0 | 187 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
188 |
if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0\0")) { |
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
189 |
HMODULE modules[100]; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
190 |
DWORD needed; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
191 |
BOOL res; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
192 |
int count, i; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
193 |
|
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
194 |
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
195 |
if (proc != NULL) { |
0 | 196 |
res = EnumProcessModules(proc, modules, sizeof(modules), &needed); |
197 |
CloseHandle(proc); |
|
198 |
if (res) { |
|
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
199 |
count = min(needed / sizeof(HMODULE), lengthof(modules)); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
200 |
|
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
201 |
for (i = 0; i != count; i++) output = PrintModuleInfo(output, modules[i]); |
0 | 202 |
return output; |
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
output = PrintModuleInfo(output, NULL); |
|
207 |
return output; |
|
208 |
} |
|
209 |
||
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
210 |
static const TCHAR _crash_desc[] = |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
211 |
_T("A serious fault condition occured in the game. The game will shut down.\n") |
5530
24c52cff1a34
(svn r7843) -Codechange (r7840): left out word 'file' making crash-text look un-english-ish.
Darkvater
parents:
5529
diff
changeset
|
212 |
_T("Please send the crash information and the crash.dmp file (if any) to the developers.\n") |
5529
25e90c3f693d
(svn r7840) -Codechange: Change the crash window a bit. Tell about Flyspray and crash.dmp. Remove
Darkvater
parents:
5475
diff
changeset
|
213 |
_T("This will greatly help debugging. The correct place to do this is http://bugs.openttd.org. ") |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
214 |
_T("The information contained in the report is displayed below.\n") |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
215 |
_T("Press \"Emergency save\" to attempt saving the game."); |
0 | 216 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
217 |
static const TCHAR _save_succeeded[] = |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
218 |
_T("Emergency save succeeded.\n") |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
219 |
_T("Be aware that critical parts of the internal game state may have become ") |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
220 |
_T("corrupted. The saved game is not guaranteed to work."); |
0 | 221 |
|
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1829
diff
changeset
|
222 |
static bool EmergencySave(void) |
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1829
diff
changeset
|
223 |
{ |
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1829
diff
changeset
|
224 |
SaveOrLoad("crash.sav", SL_SAVE); |
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1829
diff
changeset
|
225 |
return true; |
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1829
diff
changeset
|
226 |
} |
0 | 227 |
|
5311
109d82ecab59
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
228 |
/* Disable the crash-save submit code as it's not used */ |
109d82ecab59
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
229 |
#if 0 |
109d82ecab59
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
230 |
|
0 | 231 |
typedef struct { |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
232 |
HINTERNET (WINAPI *InternetOpen)(LPCTSTR,DWORD, LPCTSTR, LPCTSTR, DWORD); |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
233 |
HINTERNET (WINAPI *InternetConnect)(HINTERNET, LPCTSTR, INTERNET_PORT, LPCTSTR, LPCTSTR, DWORD, DWORD, DWORD); |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
234 |
HINTERNET (WINAPI *HttpOpenRequest)(HINTERNET, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR *, DWORD, DWORD); |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
235 |
BOOL (WINAPI *HttpSendRequest)(HINTERNET, LPCTSTR, DWORD, LPVOID, DWORD); |
0 | 236 |
BOOL (WINAPI *InternetCloseHandle)(HINTERNET); |
237 |
BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD); |
|
238 |
} WinInetProcs; |
|
239 |
||
240 |
#define M(x) x "\0" |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
241 |
#if defined(UNICODE) |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
242 |
# define W(x) x "W" |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
243 |
#else |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
244 |
# define W(x) x "A" |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
245 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
246 |
static const char wininet_files[] = |
0 | 247 |
M("wininet.dll") |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
248 |
M(W("InternetOpen")) |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
249 |
M(W("InternetConnect")) |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
250 |
M(W("HttpOpenRequest")) |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
251 |
M(W("HttpSendRequest")) |
0 | 252 |
M("InternetCloseHandle") |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
253 |
M(W("HttpQueryInfo")) |
0 | 254 |
M(""); |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
255 |
#undef W |
0 | 256 |
#undef M |
257 |
||
258 |
static WinInetProcs _wininet; |
|
259 |
||
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
260 |
static const TCHAR *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const TCHAR *arg) |
0 | 261 |
{ |
262 |
HINTERNET inet, conn, http; |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
263 |
const TCHAR *err = NULL; |
0 | 264 |
DWORD code, len; |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
265 |
static TCHAR buf[100]; |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
266 |
TCHAR buff[100]; |
0 | 267 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
268 |
if (_wininet.InternetOpen == NULL && !LoadLibraryList((Function*)&_wininet, wininet_files)) return _T("can't load wininet.dll"); |
0 | 269 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
270 |
inet = _wininet.InternetOpen(_T("OTTD"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
271 |
if (inet == NULL) { err = _T("internetopen failed"); goto error1; } |
0 | 272 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
273 |
conn = _wininet.InternetConnect(inet, _T("www.openttd.org"), INTERNET_DEFAULT_HTTP_PORT, _T(""), _T(""), INTERNET_SERVICE_HTTP, 0, 0); |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
274 |
if (conn == NULL) { err = _T("internetconnect failed"); goto error2; } |
0 | 275 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
276 |
_sntprintf(buff, lengthof(buff), _T("/crash.php?file=%s&ident=%d"), arg, _ident); |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
277 |
|
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
278 |
http = _wininet.HttpOpenRequest(conn, _T("POST"), buff, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE , 0); |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
279 |
if (http == NULL) { err = _T("httpopenrequest failed"); goto error3; } |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
280 |
|
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
281 |
if (!_wininet.HttpSendRequest(http, _T("Content-type: application/binary"), -1, msg, (DWORD)msglen)) { err = _T("httpsendrequest failed"); goto error4; } |
0 | 282 |
|
283 |
len = sizeof(code); |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
284 |
if (!_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &len, 0)) { err = _T("httpqueryinfo failed"); goto error4; } |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
285 |
|
0 | 286 |
if (code != 200) { |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
287 |
int l = _sntprintf(buf, lengthof(buf), _T("Server said: %d "), code); |
0 | 288 |
len = sizeof(buf) - l; |
289 |
_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_TEXT, buf + l, &len, 0); |
|
290 |
err = buf; |
|
291 |
} |
|
292 |
||
293 |
error4: |
|
294 |
_wininet.InternetCloseHandle(http); |
|
295 |
error3: |
|
296 |
_wininet.InternetCloseHandle(conn); |
|
297 |
error2: |
|
298 |
_wininet.InternetCloseHandle(inet); |
|
299 |
error1: |
|
300 |
return err; |
|
301 |
} |
|
302 |
||
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
303 |
static void SubmitFile(HWND wnd, const TCHAR *file) |
0 | 304 |
{ |
305 |
HANDLE h; |
|
306 |
unsigned long size; |
|
307 |
unsigned long read; |
|
308 |
void *mem; |
|
309 |
||
310 |
h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
|
311 |
if (h == NULL) return; |
|
312 |
||
313 |
size = GetFileSize(h, NULL); |
|
314 |
if (size > 500000) goto error1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
315 |
|
0 | 316 |
mem = malloc(size); |
317 |
if (mem == NULL) goto error1; |
|
318 |
||
319 |
if (!ReadFile(h, mem, size, &read, NULL) || read != size) goto error2; |
|
320 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
321 |
SubmitCrashReport(wnd, mem, size, file); |
0 | 322 |
|
323 |
error2: |
|
324 |
free(mem); |
|
325 |
error1: |
|
326 |
CloseHandle(h); |
|
327 |
} |
|
328 |
||
5311
109d82ecab59
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
329 |
#endif /* Disabled crash-submit procedures */ |
109d82ecab59
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
330 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
331 |
static const TCHAR * const _expand_texts[] = {_T("S&how report >>"), _T("&Hide report <<") }; |
0 | 332 |
|
333 |
static void SetWndSize(HWND wnd, int mode) |
|
334 |
{ |
|
335 |
RECT r,r2; |
|
336 |
int offs; |
|
337 |
||
338 |
GetWindowRect(wnd, &r); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
339 |
|
0 | 340 |
SetDlgItemText(wnd, 15, _expand_texts[mode == 1]); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
341 |
|
0 | 342 |
if (mode >= 0) { |
343 |
GetWindowRect(GetDlgItem(wnd, 11), &r2); |
|
344 |
offs = r2.bottom - r2.top + 10; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
345 |
if (!mode) offs = -offs; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
346 |
SetWindowPos(wnd, HWND_TOPMOST, 0, 0, |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
347 |
r.right - r.left, r.bottom - r.top + offs, SWP_NOMOVE | SWP_NOZORDER); |
0 | 348 |
} else { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
349 |
SetWindowPos(wnd, HWND_TOPMOST, |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
350 |
(GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2, |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
351 |
(GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2, |
0 | 352 |
0, 0, SWP_NOSIZE); |
353 |
} |
|
354 |
} |
|
355 |
||
356 |
static bool DoEmergencySave(HWND wnd) |
|
357 |
{ |
|
358 |
bool b = false; |
|
359 |
||
360 |
EnableWindow(GetDlgItem(wnd, 13), FALSE); |
|
361 |
_did_emerg_save = true; |
|
362 |
__try { |
|
363 |
b = EmergencySave(); |
|
364 |
} __except (1) {} |
|
365 |
return b; |
|
366 |
} |
|
367 |
||
2458
dbaf5dffbb28
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2428
diff
changeset
|
368 |
static INT_PTR CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam) |
0 | 369 |
{ |
2952 | 370 |
switch (msg) { |
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
371 |
case WM_INITDIALOG: { |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
372 |
#if defined(UNICODE) |
5312
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
373 |
/* We need to put the crash-log in a seperate buffer because the default |
5722
62abdb0d0662
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5674
diff
changeset
|
374 |
* buffer in MB_TO_WIDE is not large enough (512 chars) */ |
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
375 |
wchar_t crash_msgW[8096]; |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
376 |
#endif |
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
377 |
SetDlgItemText(wnd, 10, _crash_desc); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
378 |
SetDlgItemText(wnd, 11, MB_TO_WIDE_BUFFER(_crash_msg, crash_msgW, lengthof(crash_msgW))); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
379 |
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
380 |
SetWndSize(wnd, -1); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
381 |
} return TRUE; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
382 |
case WM_COMMAND: |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
383 |
switch (wParam) { |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
384 |
case 12: /* Close */ |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
385 |
ExitProcess(0); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
386 |
case 13: /* Emergency save */ |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
387 |
if (DoEmergencySave(wnd)) { |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
388 |
MessageBox(wnd, _save_succeeded, _T("Save successful"), MB_ICONINFORMATION); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
389 |
} else { |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
390 |
MessageBox(wnd, _T("Save failed"), _T("Save failed"), MB_ICONINFORMATION); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
391 |
} |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
392 |
break; |
5311
109d82ecab59
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
393 |
/* Disable the crash-save submit code as it's not used */ |
109d82ecab59
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
394 |
#if 0 |
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
395 |
case 14: { /* Submit crash report */ |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
396 |
const TCHAR *s; |
0 | 397 |
|
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
398 |
SetCursor(LoadCursor(NULL, IDC_WAIT)); |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
399 |
|
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
400 |
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), _T("")); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
401 |
if (s != NULL) { |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
402 |
MessageBox(wnd, s, _T("Error"), MB_ICONSTOP); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
403 |
break; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
404 |
} |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
405 |
|
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
406 |
// try to submit emergency savegame |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
407 |
if (_did_emerg_save || DoEmergencySave(wnd)) SubmitFile(wnd, _T("crash.sav")); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
408 |
|
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
409 |
// try to submit the autosaved game |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
410 |
if (_opt.autosave) { |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
411 |
TCHAR buf[40]; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
412 |
_sntprintf(buf, lengthof(buf), _T("autosave%d.sav"), (_autosave_ctr - 1) & 3); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
413 |
SubmitFile(wnd, buf); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
414 |
} |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
415 |
EnableWindow(GetDlgItem(wnd, 14), FALSE); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
416 |
SetCursor(LoadCursor(NULL, IDC_ARROW)); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
417 |
MessageBox(wnd, _T("Crash report submitted. Thank you."), _T("Crash Report"), MB_ICONINFORMATION); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
418 |
} break; |
5311
109d82ecab59
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
419 |
#endif /* Disabled crash-submit procedures */ |
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
420 |
case 15: /* Expand window to show crash-message */ |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
421 |
_expanded ^= 1; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
422 |
SetWndSize(wnd, _expanded); |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
423 |
break; |
0 | 424 |
} |
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
425 |
return TRUE; |
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
426 |
case WM_CLOSE: ExitProcess(0); |
0 | 427 |
} |
428 |
||
429 |
return FALSE; |
|
430 |
} |
|
431 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
432 |
static void Handler2(void) |
0 | 433 |
{ |
434 |
ShowCursor(TRUE); |
|
435 |
ShowWindow(GetActiveWindow(), FALSE); |
|
436 |
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(100), NULL, CrashDialogFunc); |
|
437 |
} |
|
438 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
439 |
extern bool CloseConsoleLogIfActive(void); |
1023
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
440 |
|
0 | 441 |
static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) |
442 |
{ |
|
3204
1d8c8114e073
(svn r3872) - [win32] Show the revision in crash.txt and enable the button to show the crash text in the crash-window
Darkvater
parents:
2952
diff
changeset
|
443 |
extern const char _openttd_revision[]; |
0 | 444 |
char *output; |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
445 |
static bool had_exception = false; |
0 | 446 |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
447 |
if (had_exception) ExitProcess(0); |
0 | 448 |
had_exception = true; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
449 |
|
0 | 450 |
_ident = GetTickCount(); // something pretty unique |
451 |
||
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
452 |
MakeCRCTable((uint32*)alloca(256 * sizeof(uint32))); |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
453 |
_crash_msg = output = (char*)LocalAlloc(LMEM_FIXED, 8192); |
0 | 454 |
|
455 |
{ |
|
456 |
SYSTEMTIME time; |
|
457 |
GetLocalTime(&time); |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
458 |
output += sprintf(output, |
0 | 459 |
"*** OpenTTD Crash Report ***\r\n" |
460 |
"Date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n" |
|
4236
8f21cc1d7095
(svn r5801) - Codechange: The exception dialog showed the last modification-date of win32.c instead of the last compilation-date. Use __DATE__ __TIME__ instead of __TIMESTAMP__; only affected windows not built with mingw/cygwin.
Darkvater
parents:
4224
diff
changeset
|
461 |
"Build: %s built on " __DATE__ " " __TIME__ "\r\n", |
0 | 462 |
time.wYear, |
463 |
time.wMonth, |
|
464 |
time.wDay, |
|
465 |
time.wHour, |
|
466 |
time.wMinute, |
|
467 |
time.wSecond, |
|
3204
1d8c8114e073
(svn r3872) - [win32] Show the revision in crash.txt and enable the button to show the crash text in the crash-window
Darkvater
parents:
2952
diff
changeset
|
468 |
_openttd_revision |
0 | 469 |
); |
470 |
} |
|
471 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
472 |
if (_exception_string) |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
473 |
output += sprintf(output, "Reason: %s\r\n", _exception_string); |
0 | 474 |
|
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
475 |
#ifdef _M_AMD64 |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
476 |
output += sprintf(output, "Exception %.8X at %.16IX\r\n" |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
477 |
"Registers:\r\n" |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
478 |
"RAX: %.16llX RBX: %.16llX RCX: %.16llX RDX: %.16llX\r\n" |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
479 |
"RSI: %.16llX RDI: %.16llX RBP: %.16llX RSP: %.16llX\r\n" |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
480 |
"R8: %.16llX R9: %.16llX R10: %.16llX R11: %.16llX\r\n" |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
481 |
"R12: %.16llX R13: %.16llX R14: %.16llX R15: %.16llX\r\n" |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
482 |
"RIP: %.16llX EFLAGS: %.8X\r\n" |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
483 |
"\r\nBytes at CS:RIP:\r\n", |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
484 |
ep->ExceptionRecord->ExceptionCode, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
485 |
ep->ExceptionRecord->ExceptionAddress, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
486 |
ep->ContextRecord->Rax, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
487 |
ep->ContextRecord->Rbx, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
488 |
ep->ContextRecord->Rcx, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
489 |
ep->ContextRecord->Rdx, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
490 |
ep->ContextRecord->Rsi, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
491 |
ep->ContextRecord->Rdi, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
492 |
ep->ContextRecord->Rbp, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
493 |
ep->ContextRecord->Rsp, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
494 |
ep->ContextRecord->R8, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
495 |
ep->ContextRecord->R9, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
496 |
ep->ContextRecord->R10, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
497 |
ep->ContextRecord->R11, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
498 |
ep->ContextRecord->R12, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
499 |
ep->ContextRecord->R13, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
500 |
ep->ContextRecord->R14, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
501 |
ep->ContextRecord->R15, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
502 |
ep->ContextRecord->Rip, |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
503 |
ep->ContextRecord->EFlags |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
504 |
); |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
505 |
#else |
0 | 506 |
output += sprintf(output, "Exception %.8X at %.8X\r\n" |
507 |
"Registers:\r\n" |
|
508 |
" EAX: %.8X EBX: %.8X ECX: %.8X EDX: %.8X\r\n" |
|
509 |
" ESI: %.8X EDI: %.8X EBP: %.8X ESP: %.8X\r\n" |
|
510 |
" EIP: %.8X EFLAGS: %.8X\r\n" |
|
511 |
"\r\nBytes at CS:EIP:\r\n", |
|
512 |
ep->ExceptionRecord->ExceptionCode, |
|
513 |
ep->ExceptionRecord->ExceptionAddress, |
|
514 |
ep->ContextRecord->Eax, |
|
515 |
ep->ContextRecord->Ebx, |
|
516 |
ep->ContextRecord->Ecx, |
|
517 |
ep->ContextRecord->Edx, |
|
518 |
ep->ContextRecord->Esi, |
|
519 |
ep->ContextRecord->Edi, |
|
520 |
ep->ContextRecord->Ebp, |
|
521 |
ep->ContextRecord->Esp, |
|
522 |
ep->ContextRecord->Eip, |
|
523 |
ep->ContextRecord->EFlags |
|
524 |
); |
|
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
525 |
#endif |
0 | 526 |
|
527 |
{ |
|
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
528 |
#ifdef _M_AMD64 |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
529 |
byte *b = (byte*)ep->ContextRecord->Rip; |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
530 |
#else |
0 | 531 |
byte *b = (byte*)ep->ContextRecord->Eip; |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
532 |
#endif |
0 | 533 |
int i; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
534 |
for (i = 0; i != 24; i++) { |
0 | 535 |
if (IsBadReadPtr(b, 1)) { |
536 |
output += sprintf(output, " ??"); // OCR: WAS: , 0); |
|
537 |
} else { |
|
538 |
output += sprintf(output, " %.2X", *b); |
|
539 |
} |
|
540 |
b++; |
|
541 |
} |
|
542 |
output += sprintf(output, |
|
543 |
"\r\n" |
|
544 |
"\r\nStack trace: \r\n" |
|
545 |
); |
|
546 |
} |
|
547 |
||
548 |
{ |
|
549 |
int i,j; |
|
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
550 |
#ifdef _M_AMD64 |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
551 |
uint32 *b = (uint32*)ep->ContextRecord->Rsp; |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
552 |
#else |
0 | 553 |
uint32 *b = (uint32*)ep->ContextRecord->Esp; |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
554 |
#endif |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
555 |
for (j = 0; j != 24; j++) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
556 |
for (i = 0; i != 8; i++) { |
0 | 557 |
if (IsBadReadPtr(b,sizeof(uint32))) { |
558 |
output += sprintf(output, " ????????"); //OCR: WAS - , 0); |
|
559 |
} else { |
|
560 |
output += sprintf(output, " %.8X", *b); |
|
561 |
} |
|
562 |
b++; |
|
563 |
} |
|
564 |
output += sprintf(output, "\r\n"); |
|
565 |
} |
|
566 |
} |
|
567 |
||
568 |
output += sprintf(output, "\r\nModule information:\r\n"); |
|
569 |
output = PrintModuleList(output); |
|
570 |
||
571 |
{ |
|
572 |
OSVERSIONINFO os; |
|
573 |
os.dwOSVersionInfoSize = sizeof(os); |
|
574 |
GetVersionEx(&os); |
|
575 |
output += sprintf(output, "\r\nSystem information:\r\n" |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
576 |
" Windows version %d.%d %d %s\r\n", |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
577 |
os.dwMajorVersion, os.dwMinorVersion, os.dwBuildNumber, os.szCSDVersion); |
0 | 578 |
} |
579 |
||
580 |
{ |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
581 |
HANDLE file = CreateFile(_T("crash.log"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); |
0 | 582 |
DWORD num_written; |
583 |
if (file != INVALID_HANDLE_VALUE) { |
|
584 |
WriteFile(file, _crash_msg, output - _crash_msg, &num_written, NULL); |
|
585 |
CloseHandle(file); |
|
586 |
} |
|
587 |
} |
|
588 |
||
1023
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
589 |
/* Close any possible log files */ |
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
590 |
CloseConsoleLogIfActive(); |
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
591 |
|
0 | 592 |
if (_safe_esp) { |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
593 |
#ifdef _M_AMD64 |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
594 |
ep->ContextRecord->Rip = (DWORD64)Handler2; |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
595 |
ep->ContextRecord->Rsp = (DWORD64)_safe_esp; |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
596 |
#else |
0 | 597 |
ep->ContextRecord->Eip = (DWORD)Handler2; |
598 |
ep->ContextRecord->Esp = (DWORD)_safe_esp; |
|
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
599 |
#endif |
0 | 600 |
return EXCEPTION_CONTINUE_EXECUTION; |
601 |
} |
|
1023
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
602 |
|
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
603 |
|
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
604 |
return EXCEPTION_EXECUTE_HANDLER; |
0 | 605 |
} |
606 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
607 |
static void Win32InitializeExceptions(void) |
0 | 608 |
{ |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
609 |
#ifdef _M_AMD64 |
3341
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
3340
diff
changeset
|
610 |
extern void *_get_save_esp(void); |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
611 |
_safe_esp = _get_save_esp(); |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
612 |
#else |
0 | 613 |
_asm { |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
614 |
mov _safe_esp, esp |
0 | 615 |
} |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
616 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
617 |
|
0 | 618 |
SetUnhandledExceptionFilter(ExceptionHandler); |
619 |
} |
|
3341
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
3340
diff
changeset
|
620 |
#endif /* _MSC_VER */ |
0 | 621 |
|
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
622 |
/* Code below for windows version of opendir/readdir/closedir copied and |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
623 |
* modified from Jan Wassenberg's GPL implementation posted over at |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
624 |
* http://www.gamedev.net/community/forums/topic.asp?topic_id=364584&whichpage=1� */ |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
625 |
|
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
626 |
/* suballocator - satisfies most requests with a reusable static instance. |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
627 |
* this avoids hundreds of alloc/free which would fragment the heap. |
5891
9601f4469a37
(svn r8508) -Codechange (r5762): [win32] Use an atomic operation to query and set the value of _global_dir_is_in_use for opendir etc to guarantee concurrency.
Darkvater
parents:
5758
diff
changeset
|
628 |
* To guarantee concurrency, we fall back to malloc if the instance is |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
629 |
* already in use (it's important to avoid suprises since this is such a |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
630 |
* low-level routine). */ |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
631 |
static DIR _global_dir; |
5891
9601f4469a37
(svn r8508) -Codechange (r5762): [win32] Use an atomic operation to query and set the value of _global_dir_is_in_use for opendir etc to guarantee concurrency.
Darkvater
parents:
5758
diff
changeset
|
632 |
static LONG _global_dir_is_in_use = false; |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
633 |
|
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
634 |
static inline DIR *dir_calloc(void) |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
635 |
{ |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
636 |
DIR *d; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
637 |
|
5891
9601f4469a37
(svn r8508) -Codechange (r5762): [win32] Use an atomic operation to query and set the value of _global_dir_is_in_use for opendir etc to guarantee concurrency.
Darkvater
parents:
5758
diff
changeset
|
638 |
if (InterlockedExchange(&_global_dir_is_in_use, true) == (LONG)true) { |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
639 |
d = CallocT<DIR>(1); |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
640 |
} else { |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
641 |
d = &_global_dir; |
4224
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
642 |
memset(d, 0, sizeof(*d)); |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
643 |
} |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
644 |
return d; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
645 |
} |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
646 |
|
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
647 |
static inline void dir_free(DIR *d) |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
648 |
{ |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
649 |
if (d == &_global_dir) { |
5891
9601f4469a37
(svn r8508) -Codechange (r5762): [win32] Use an atomic operation to query and set the value of _global_dir_is_in_use for opendir etc to guarantee concurrency.
Darkvater
parents:
5758
diff
changeset
|
650 |
_global_dir_is_in_use = (LONG)false; |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
651 |
} else { |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
652 |
free(d); |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
653 |
} |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
654 |
} |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
655 |
|
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
656 |
DIR *opendir(const char *path) |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
657 |
{ |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
658 |
DIR *d; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
659 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
660 |
DWORD fa = GetFileAttributesW(OTTD2FS(path)); |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
661 |
|
4224
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
662 |
if ((fa != INVALID_FILE_ATTRIBUTES) && (fa & FILE_ATTRIBUTE_DIRECTORY)) { |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
663 |
d = dir_calloc(); |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
664 |
if (d != NULL) { |
5120
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
665 |
char search_path[MAX_PATH]; |
4224
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
666 |
/* build search path for FindFirstFile */ |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
667 |
snprintf(search_path, lengthof(search_path), "%s" PATHSEP "*", path); |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
668 |
d->hFind = FindFirstFileW(OTTD2FS(search_path), &d->fd); |
4224
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
669 |
|
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
670 |
if (d->hFind != INVALID_HANDLE_VALUE || |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
671 |
GetLastError() == ERROR_NO_MORE_FILES) { // the directory is empty |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
672 |
d->ent.dir = d; |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
673 |
d->at_first_entry = true; |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
674 |
} else { |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
675 |
dir_free(d); |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
676 |
d = NULL; |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
677 |
} |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
678 |
} else { |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
679 |
errno = ENOMEM; |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
680 |
} |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
681 |
} else { |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
682 |
/* path not found or not a directory */ |
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
683 |
d = NULL; |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
684 |
errno = ENOENT; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
685 |
} |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
686 |
|
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
687 |
SetErrorMode(sem); // restore previous setting |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
688 |
return d; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
689 |
} |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
690 |
|
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
691 |
struct dirent *readdir(DIR *d) |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
692 |
{ |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
693 |
DWORD prev_err = GetLastError(); // avoid polluting last error |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
694 |
|
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
695 |
if (d->at_first_entry) { |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
696 |
/* the directory was empty when opened */ |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
697 |
if (d->hFind == INVALID_HANDLE_VALUE) return NULL; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
698 |
d->at_first_entry = false; |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
699 |
} else if (!FindNextFileW(d->hFind, &d->fd)) { // determine cause and bail |
4218
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
700 |
if (GetLastError() == ERROR_NO_MORE_FILES) SetLastError(prev_err); |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
701 |
return NULL; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
702 |
} |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
703 |
|
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
704 |
/* This entry has passed all checks; return information about it. |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
705 |
* (note: d_name is a pointer; see struct dirent definition) */ |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
706 |
d->ent.d_name = d->fd.cFileName; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
707 |
return &d->ent; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
708 |
} |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
709 |
|
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
710 |
int closedir(DIR *d) |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
711 |
{ |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
712 |
FindClose(d->hFind); |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
713 |
dir_free(d); |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
714 |
return 0; |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
715 |
} |
4033c207d304
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
716 |
|
4221
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
717 |
bool FiosIsRoot(const char *file) |
0 | 718 |
{ |
4221
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
719 |
return file[3] == '\0'; // C:\... |
0 | 720 |
} |
721 |
||
4221
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
722 |
void FiosGetDrives(void) |
0 | 723 |
{ |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
724 |
TCHAR drives[256]; |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
725 |
const TCHAR *s; |
0 | 726 |
|
4221
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
727 |
GetLogicalDriveStrings(sizeof(drives), drives); |
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
728 |
for (s = drives; *s != '\0';) { |
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
729 |
FiosItem *fios = FiosAlloc(); |
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
730 |
fios->type = FIOS_TYPE_DRIVE; |
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
731 |
fios->mtime = 0; |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
732 |
snprintf(fios->name, lengthof(fios->name), "%c:", s[0] & 0xFF); |
4221
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
733 |
ttd_strlcpy(fios->title, fios->name, lengthof(fios->title)); |
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
734 |
while (*s++ != '\0'); |
0 | 735 |
} |
736 |
} |
|
737 |
||
4221
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
738 |
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) |
0 | 739 |
{ |
4245
e8d08dbda199
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
740 |
// hectonanoseconds between Windows and POSIX epoch |
4247
091fb0c37c8c
(svn r5836) - Silence a warning on mingw. Thanks glx.
Darkvater
parents:
4245
diff
changeset
|
741 |
static const int64 posix_epoch_hns = 0x019DB1DED53E8000LL; |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
742 |
const WIN32_FIND_DATAW *fd = &ent->dir->fd; |
4224
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
743 |
if (fd->dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) return false; |
0 | 744 |
|
4224
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
745 |
sb->st_size = ((uint64) fd->nFileSizeHigh << 32) + fd->nFileSizeLow; |
4245
e8d08dbda199
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
746 |
/* UTC FILETIME to seconds-since-1970 UTC |
e8d08dbda199
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
747 |
* we just have to subtract POSIX epoch and scale down to units of seconds. |
e8d08dbda199
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
748 |
* http://www.gamedev.net/community/forums/topic.asp?topic_id=294070&whichpage=1� |
e8d08dbda199
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
749 |
* XXX - not entirely correct, since filetimes on FAT aren't UTC but local, |
e8d08dbda199
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
750 |
* this won't entirely be correct, but we use the time only for comparsion. */ |
e8d08dbda199
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
751 |
sb->st_mtime = (time_t)((*(uint64*)&fd->ftLastWriteTime - posix_epoch_hns) / 1E7); |
4221
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
752 |
sb->st_mode = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG; |
4224
72c4669d95fa
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
753 |
|
4221
ff4a040f30c6
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
754 |
return true; |
0 | 755 |
} |
756 |
||
4222
36e9bd216011
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
757 |
bool FiosGetDiskFreeSpace(const char *path, uint32 *tot) |
0 | 758 |
{ |
1596
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1582
diff
changeset
|
759 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
4222
36e9bd216011
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
760 |
bool retval = false; |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
761 |
TCHAR root[4]; |
0 | 762 |
DWORD spc, bps, nfc, tnc; |
1596
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1582
diff
changeset
|
763 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
764 |
_sntprintf(root, lengthof(root), _T("%c:") _T(PATHSEP), path[0]); |
1596
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1582
diff
changeset
|
765 |
if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) { |
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1582
diff
changeset
|
766 |
*tot = ((spc * bps) * (uint64)nfc) >> 20; |
4222
36e9bd216011
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
767 |
retval = true; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
768 |
} |
1596
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1582
diff
changeset
|
769 |
|
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1582
diff
changeset
|
770 |
SetErrorMode(sem); // reset previous setting |
4222
36e9bd216011
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
771 |
return retval; |
0 | 772 |
} |
773 |
||
774 |
static int ParseCommandLine(char *line, char **argv, int max_argc) |
|
775 |
{ |
|
776 |
int n = 0; |
|
777 |
||
778 |
do { |
|
779 |
// skip whitespace |
|
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
780 |
while (*line == ' ' || *line == '\t') line++; |
0 | 781 |
|
782 |
// end? |
|
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
783 |
if (*line == '\0') break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
784 |
|
0 | 785 |
// special handling when quoted |
786 |
if (*line == '"') { |
|
787 |
argv[n++] = ++line; |
|
788 |
while (*line != '"') { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
789 |
if (*line == '\0') return n; |
0 | 790 |
line++; |
791 |
} |
|
792 |
} else { |
|
793 |
argv[n++] = line; |
|
794 |
while (*line != ' ' && *line != '\t') { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
795 |
if (*line == '\0') return n; |
0 | 796 |
line++; |
797 |
} |
|
798 |
} |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
799 |
*line++ = '\0'; |
0 | 800 |
} while (n != max_argc); |
801 |
||
802 |
return n; |
|
803 |
} |
|
804 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
805 |
void CreateConsole(void) |
0 | 806 |
{ |
807 |
HANDLE hand; |
|
808 |
CONSOLE_SCREEN_BUFFER_INFO coninfo; |
|
809 |
||
810 |
if (_has_console) return; |
|
811 |
_has_console = true; |
|
812 |
||
4572
6800fdfcd5c0
(svn r6421) -Revert r6420: The dedicated server's console actually needs to work. It misses half the input at the moment. Sorry, too hasty commit.
Darkvater
parents:
4571
diff
changeset
|
813 |
AllocConsole(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
814 |
|
0 | 815 |
hand = GetStdHandle(STD_OUTPUT_HANDLE); |
816 |
GetConsoleScreenBufferInfo(hand, &coninfo); |
|
817 |
coninfo.dwSize.Y = 500; |
|
818 |
SetConsoleScreenBufferSize(hand, coninfo.dwSize); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
819 |
|
0 | 820 |
// redirect unbuffered STDIN, STDOUT, STDERR to the console |
2172 | 821 |
#if !defined(__CYGWIN__) |
2482
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
822 |
*stdout = *_fdopen( _open_osfhandle((intptr_t)hand, _O_TEXT), "w" ); |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
823 |
*stdin = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" ); |
374f6395847d
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
824 |
*stderr = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); |
0 | 825 |
#else |
826 |
// open_osfhandle is not in cygwin |
|
827 |
*stdout = *fdopen(1, "w" ); |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
828 |
*stdin = *fdopen(0, "r" ); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
829 |
*stderr = *fdopen(2, "w" ); |
0 | 830 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
831 |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
832 |
setvbuf(stdin, NULL, _IONBF, 0); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
833 |
setvbuf(stdout, NULL, _IONBF, 0); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
834 |
setvbuf(stderr, NULL, _IONBF, 0); |
0 | 835 |
} |
836 |
||
837 |
void ShowInfo(const char *str) |
|
838 |
{ |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
839 |
if (_has_console) { |
5674
abe7d6b7b1d4
(svn r8134) -Fix (r8013): Add a newline after the ShowInfo console output
Darkvater
parents:
5609
diff
changeset
|
840 |
fprintf(stderr, "%s\n", str); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
841 |
} else { |
0 | 842 |
bool old; |
5722
62abdb0d0662
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5674
diff
changeset
|
843 |
#if defined(UNICODE) |
62abdb0d0662
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5674
diff
changeset
|
844 |
/* We need to put the text in a seperate buffer because the default |
62abdb0d0662
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5674
diff
changeset
|
845 |
* buffer in MB_TO_WIDE might not be large enough (512 chars) */ |
62abdb0d0662
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5674
diff
changeset
|
846 |
wchar_t help_msgW[4096]; |
62abdb0d0662
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5674
diff
changeset
|
847 |
#endif |
0 | 848 |
ReleaseCapture(); |
849 |
_left_button_clicked =_left_button_down = false; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
850 |
|
0 | 851 |
old = MyShowCursor(true); |
5722
62abdb0d0662
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5674
diff
changeset
|
852 |
if (MessageBox(GetActiveWindow(), MB_TO_WIDE_BUFFER(str, help_msgW, lengthof(help_msgW)), _T("OpenTTD"), MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) { |
0 | 853 |
CreateConsole(); |
854 |
} |
|
855 |
MyShowCursor(old); |
|
856 |
} |
|
857 |
} |
|
858 |
||
2428
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
859 |
#ifdef __MINGW32__ |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
860 |
/* _set_error_mode() constants&function (do not exist in mingw headers) */ |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
861 |
#define _OUT_TO_DEFAULT 0 |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
862 |
#define _OUT_TO_STDERR 1 |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
863 |
#define _OUT_TO_MSGBOX 2 |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
864 |
#define _REPORT_ERRMODE 3 |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
865 |
int _set_error_mode(int); |
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
866 |
#endif |
0 | 867 |
|
5758
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
868 |
#if defined(WINCE) |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
869 |
int APIENTRY WinMain |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
870 |
#else |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
871 |
int APIENTRY _tWinMain |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
872 |
#endif |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
873 |
(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
874 |
LPTSTR lpCmdLine, int nCmdShow) |
0 | 875 |
{ |
876 |
int argc; |
|
877 |
char *argv[64]; // max 64 command line arguments |
|
5312
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
878 |
char *cmdline; |
0 | 879 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
880 |
#if defined(UNICODE) |
5312
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
881 |
/* For UNICODE we need to convert the commandline to char* _AND_ |
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
882 |
* save it because argv[] points into this buffer and thus needs to |
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
883 |
* be available between subsequent calls to FS2OTTD() */ |
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
884 |
char cmdlinebuf[MAX_PATH]; |
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
885 |
#endif |
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
886 |
|
5312
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
887 |
cmdline = WIDE_TO_MB_BUFFER(GetCommandLine(), cmdlinebuf, lengthof(cmdlinebuf)); |
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
888 |
|
0 | 889 |
#if defined(_DEBUG) |
890 |
CreateConsole(); |
|
891 |
#endif |
|
892 |
||
2428
a27141f22960
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
893 |
_set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox |
0 | 894 |
|
5310
4bb8cfc73019
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
895 |
/* setup random seed to something quite random */ |
4369
3812b4335df9
(svn r6086) -Fix: InteractiveRandom was not seeded properly resulting in the dedicated server always generating the same map. Thanks to the #openttdcoop team for detecting.
rubidium
parents:
4321
diff
changeset
|
896 |
_random_seeds[1][0] = _random_seeds[0][0] = GetTickCount(); |
3812b4335df9
(svn r6086) -Fix: InteractiveRandom was not seeded properly resulting in the dedicated server always generating the same map. Thanks to the #openttdcoop team for detecting.
rubidium
parents:
4321
diff
changeset
|
897 |
_random_seeds[1][1] = _random_seeds[0][1] = _random_seeds[0][0] * 0x1234567; |
2073 | 898 |
SeedMT(_random_seeds[0][0]); |
0 | 899 |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
900 |
argc = ParseCommandLine(cmdline, argv, lengthof(argv)); |
0 | 901 |
|
902 |
#if defined(WIN32_EXCEPTION_TRACKER) |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
903 |
Win32InitializeExceptions(); |
0 | 904 |
#endif |
905 |
||
906 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
907 |
_try { |
|
5168
e206899169c4
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
908 |
LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep); |
0 | 909 |
#endif |
910 |
ttd_main(argc, argv); |
|
911 |
||
912 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
913 |
} _except (ExceptionHandler(_exception_info())) {} |
|
914 |
#endif |
|
915 |
||
916 |
return 0; |
|
917 |
} |
|
918 |
||
5758
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
919 |
#if defined(WINCE) |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
920 |
void GetCurrentDirectoryW(int length, wchar_t *path) |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
921 |
{ |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
922 |
wchar_t *pDest = NULL; |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
923 |
/* Get the name of this module */ |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
924 |
GetModuleFileName(NULL, path, length); |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
925 |
|
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
926 |
/* Remove the executable name, this we call CurrentDir */ |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
927 |
pDest = wcsrchr(path, '\\'); |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
928 |
if (pDest != NULL) { |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
929 |
int result = pDest - path + 1; |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
930 |
path[result] = '\0'; |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
931 |
} |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
932 |
} |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
933 |
#endif |
4b10d28b54c7
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5722
diff
changeset
|
934 |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
935 |
void DeterminePaths(void) |
0 | 936 |
{ |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
937 |
char *s, *cfg; |
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
938 |
wchar_t path[MAX_PATH]; |
0 | 939 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
940 |
_paths.personal_dir = _paths.game_data_dir = cfg = (char*)malloc(MAX_PATH); |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
941 |
GetCurrentDirectoryW(MAX_PATH - 1, path); |
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
942 |
convert_from_fs(path, cfg, MAX_PATH); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
943 |
|
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2532
diff
changeset
|
944 |
cfg[0] = toupper(cfg[0]); |
5120
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
945 |
s = strchr(cfg, '\0'); |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
946 |
if (s[-1] != '\\') strcpy(s, "\\"); |
0 | 947 |
|
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
948 |
_paths.save_dir = str_fmt("%ssave", cfg); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
949 |
_paths.autosave_dir = str_fmt("%s\\autosave", _paths.save_dir); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
950 |
_paths.scenario_dir = str_fmt("%sscenario", cfg); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
951 |
_paths.heightmap_dir = str_fmt("%sscenario\\heightmap", cfg); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
952 |
_paths.gm_dir = str_fmt("%sgm\\", cfg); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
953 |
_paths.data_dir = str_fmt("%sdata\\", cfg); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
954 |
_paths.lang_dir = str_fmt("%slang\\", cfg); |
0 | 955 |
|
1482
80e315adc3bd
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1480
diff
changeset
|
956 |
if (_config_file == NULL) |
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
957 |
_config_file = str_fmt("%sopenttd.cfg", _paths.personal_dir); |
1482
80e315adc3bd
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1480
diff
changeset
|
958 |
|
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
959 |
_highscore_file = str_fmt("%shs.dat", _paths.personal_dir); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
960 |
_log_file = str_fmt("%sopenttd.log", _paths.personal_dir); |
0 | 961 |
|
962 |
// make (auto)save and scenario folder |
|
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
963 |
CreateDirectoryW(OTTD2FS(_paths.save_dir), NULL); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
964 |
CreateDirectoryW(OTTD2FS(_paths.autosave_dir), NULL); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
965 |
CreateDirectoryW(OTTD2FS(_paths.scenario_dir), NULL); |
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5218
diff
changeset
|
966 |
CreateDirectoryW(OTTD2FS(_paths.heightmap_dir), NULL); |
0 | 967 |
} |
968 |
||
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
969 |
/** |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
970 |
* Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
971 |
* and append this up to the maximum length (either absolute or screenlength). If maxlength |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
972 |
* is zero, we don't care about the screenlength but only about the physical length of the string |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
973 |
* @param tb @Textbuf type to be changed |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
974 |
* @return Return true on successfull change of Textbuf, or false otherwise |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
975 |
*/ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
976 |
bool InsertTextBufferClipboard(Textbuf *tb) |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
977 |
{ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
978 |
HGLOBAL cbuf; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
979 |
char utf8_buf[512]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
980 |
const char *ptr; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
981 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
982 |
WChar c; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
983 |
uint16 width, length; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
984 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
985 |
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { |
5312
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
986 |
const char *ret; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
987 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
988 |
OpenClipboard(NULL); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
989 |
cbuf = GetClipboardData(CF_UNICODETEXT); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
990 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
991 |
ptr = (const char*)GlobalLock(cbuf); |
5312
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
992 |
ret = convert_from_fs((wchar_t*)ptr, utf8_buf, lengthof(utf8_buf)); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
993 |
GlobalUnlock(cbuf); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
994 |
CloseClipboard(); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
995 |
|
5312
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
996 |
if (*ret == '\0') return false; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
997 |
} else if (IsClipboardFormatAvailable(CF_TEXT)) { |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
998 |
OpenClipboard(NULL); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
999 |
cbuf = GetClipboardData(CF_TEXT); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1000 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1001 |
ptr = (const char*)GlobalLock(cbuf); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1002 |
ttd_strlcpy(utf8_buf, ptr, lengthof(utf8_buf)); |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1003 |
GlobalUnlock(cbuf); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1004 |
CloseClipboard(); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1005 |
} else { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1006 |
return false; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1007 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1008 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1009 |
width = length = 0; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1010 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1011 |
for (ptr = utf8_buf; (c = Utf8Consume(&ptr)) != '\0';) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1012 |
byte charwidth; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1013 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1014 |
if (!IsPrintable(c)) break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1015 |
if (tb->length + length >= tb->maxlength - 1) break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1016 |
charwidth = GetCharacterWidth(FS_NORMAL, c); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1017 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1018 |
if (tb->maxwidth != 0 && width + tb->width + charwidth > tb->maxwidth) break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1019 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1020 |
width += charwidth; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1021 |
length += Utf8CharLen(c); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1022 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1023 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1024 |
if (length == 0) return false; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1025 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1026 |
memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1027 |
memcpy(tb->buf + tb->caretpos, utf8_buf, length); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1028 |
tb->width += width; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1029 |
tb->caretxoffs += width; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1030 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1031 |
tb->length += length; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1032 |
tb->caretpos += length; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1033 |
tb->buf[tb->length] = '\0'; // terminating zero |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1034 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1035 |
return true; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1036 |
} |
1885
aef601001f5e
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1881
diff
changeset
|
1037 |
|
2073 | 1038 |
|
1039 |
void CSleep(int milliseconds) |
|
1040 |
{ |
|
1041 |
Sleep(milliseconds); |
|
2099
02c5a49863e9
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
1042 |
} |
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1043 |
|
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1044 |
|
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1045 |
// Utility function to get the current timestamp in milliseconds |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1046 |
// Useful for profiling |
2139 | 1047 |
int64 GetTS(void) |
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1048 |
{ |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1049 |
static double freq; |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1050 |
__int64 value; |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1051 |
if (!freq) { |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1052 |
QueryPerformanceFrequency((LARGE_INTEGER*)&value); |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1053 |
freq = (double)1000000 / value; |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1054 |
} |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1055 |
QueryPerformanceCounter((LARGE_INTEGER*)&value); |
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1056 |
return (__int64)(value * freq); |
2139 | 1057 |
} |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1058 |
|
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1059 |
/** Convert from OpenTTD's encoding to that of the local environment in |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1060 |
* UNICODE. OpenTTD encoding is UTF8, local is wide-char |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1061 |
* @param name pointer to a valid string that will be converted |
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1062 |
* @param utf16_buf pointer to a valid wide-char buffer that will receive the |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1063 |
* converted string |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1064 |
* @param buflen length in wide characters of the receiving buffer |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1065 |
* @return pointer to utf16_buf. If conversion fails the string is of zero-length */ |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1066 |
wchar_t *convert_to_fs(const char *name, wchar_t *utf16_buf, size_t buflen) |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1067 |
{ |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1068 |
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, utf16_buf, buflen); |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1069 |
if (len == 0) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5336
diff
changeset
|
1070 |
DEBUG(misc, 0, "[utf8] error converting '%s'. Errno %d", name, GetLastError()); |
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1071 |
utf16_buf[0] = '\0'; |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1072 |
} |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1073 |
|
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1074 |
return utf16_buf; |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1075 |
} |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1076 |
|
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1077 |
/** Convert from OpenTTD's encoding to that of the local environment in |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1078 |
* UNICODE. OpenTTD encoding is UTF8, local is wide-char. |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1079 |
* The returned value's contents can only be guaranteed until the next call to |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1080 |
* this function. So if the value is needed for anything else, use convert_from_fs |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1081 |
* @param name pointer to a valid string that will be converted |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1082 |
* @return pointer to the converted string; if failed string is of zero-length */ |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1083 |
const wchar_t *OTTD2FS(const char *name) |
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1084 |
{ |
5312
ce01037b54f1
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
1085 |
static wchar_t utf16_buf[512]; |
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1086 |
return convert_to_fs(name, utf16_buf, lengthof(utf16_buf)); |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1087 |
} |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1088 |
|
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1089 |
|
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1090 |
/** Convert to OpenTTD's encoding from that of the local environment in |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1091 |
* UNICODE. OpenTTD encoding is UTF8, local is wide-char |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1092 |
* @param name pointer to a valid string that will be converted |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1093 |
* @param utf8_buf pointer to a valid buffer that will receive the converted string |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1094 |
* @param buflen length in characters of the receiving buffer |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1095 |
* @return pointer to utf8_buf. If conversion fails the string is of zero-length */ |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1096 |
char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen) |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1097 |
{ |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1098 |
int len = WideCharToMultiByte(CP_UTF8, 0, name, -1, utf8_buf, buflen, NULL, NULL); |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1099 |
if (len == 0) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5336
diff
changeset
|
1100 |
DEBUG(misc, 0, "[utf8] error converting wide-string. Errno %d", GetLastError()); |
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1101 |
utf8_buf[0] = '\0'; |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1102 |
} |
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1103 |
|
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1104 |
return utf8_buf; |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1105 |
} |
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1106 |
|
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1107 |
/** Convert to OpenTTD's encoding from that of the local environment in |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1108 |
* UNICODE. OpenTTD encoding is UTF8, local is wide-char. |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1109 |
* The returned value's contents can only be guaranteed until the next call to |
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1110 |
* this function. So if the value is needed for anything else, use convert_from_fs |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1111 |
* @param name pointer to a valid string that will be converted |
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1112 |
* @return pointer to the converted string; if failed string is of zero-length */ |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1113 |
const char *FS2OTTD(const wchar_t *name) |
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1114 |
{ |
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1115 |
static char utf8_buf[512]; |
5218
bde1f7566777
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1116 |
return convert_from_fs(name, utf8_buf, lengthof(utf8_buf)); |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1117 |
} |
5304
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1118 |
|
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1119 |
/** Our very own SHGetFolderPath function for support of windows operating |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1120 |
* systems that don't have this function (eg Win9x, etc.). We try using the |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1121 |
* native function, and if that doesn't exist we will try a more crude approach |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1122 |
* of environment variables and hope for the best */ |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1123 |
HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath) |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1124 |
{ |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1125 |
static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = NULL; |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1126 |
static bool first_time = true; |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1127 |
|
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1128 |
/* We only try to load the library one time; if it fails, it fails */ |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1129 |
if (first_time) { |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1130 |
#if defined(UNICODE) |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1131 |
# define W(x) x "W" |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1132 |
#else |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1133 |
# define W(x) x "A" |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1134 |
#endif |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1135 |
if (!LoadLibraryList((Function*)&SHGetFolderPath, "SHFolder.dll\0" W("SHGetFolderPath") "\0\0")) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5336
diff
changeset
|
1136 |
DEBUG(misc, 0, "Unable to load " W("SHGetFolderPath") "from SHFolder.dll"); |
5304
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1137 |
} |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1138 |
#undef W |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1139 |
first_time = false; |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1140 |
} |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1141 |
|
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1142 |
if (SHGetFolderPath != NULL) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath); |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1143 |
|
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1144 |
/* SHGetFolderPath doesn't exist, try a more conservative approach, |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1145 |
* eg environment variables. This is only included for legacy modes |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1146 |
* MSDN says: that 'pszPath' is a "Pointer to a null-terminated string of |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1147 |
* length MAX_PATH which will receive the path" so let's assume that |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1148 |
* Windows 95 with Internet Explorer 5.0, Windows 98 with Internet Explorer 5.0, |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1149 |
* Windows 98 Second Edition (SE), Windows NT 4.0 with Internet Explorer 5.0, |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1150 |
* Windows NT 4.0 with Service Pack 4 (SP4) */ |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1151 |
{ |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1152 |
DWORD ret; |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1153 |
switch (csidl) { |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1154 |
case CSIDL_FONTS: /* Get the system font path, eg %WINDIR%\Fonts */ |
5336
f76077fef235
(svn r7500) -Fix (r7460): GetEnvironmentVariable and strncat take the number of characters and
Darkvater
parents:
5312
diff
changeset
|
1155 |
ret = GetEnvironmentVariable(_T("WINDIR"), pszPath, MAX_PATH); |
5304
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1156 |
if (ret == 0) break; |
5336
f76077fef235
(svn r7500) -Fix (r7460): GetEnvironmentVariable and strncat take the number of characters and
Darkvater
parents:
5312
diff
changeset
|
1157 |
_tcsncat(pszPath, _T("\\Fonts"), MAX_PATH); |
5304
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1158 |
|
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1159 |
return (HRESULT)0; |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1160 |
break; |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1161 |
/* XXX - other types to go here when needed... */ |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1162 |
} |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1163 |
} |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1164 |
|
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1165 |
return E_INVALIDARG; |
288359176ea1
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1166 |
} |