author | Darkvater |
Tue, 28 Nov 2006 19:58:13 +0000 | |
changeset 5168 | 10a8dc9788d7 |
parent 5167 | 2b9d61386688 |
child 5218 | aae5f36a5256 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1885
diff
changeset
|
4 |
#include "openttd.h" |
1302 | 5 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2162
diff
changeset
|
6 |
#include "functions.h" |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
7 |
#include "macros.h" |
2162
c1ded3bd3d0c
(svn r2672) Move saving/loading related declarations to saveload.h
tron
parents:
2160
diff
changeset
|
8 |
#include "saveload.h" |
1317
f382f1b439c7
(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
|
9 |
#include "string.h" |
0 | 10 |
#include "gfx.h" |
11 |
#include "window.h" |
|
12 |
#include <windows.h> |
|
13 |
#include <winnt.h> |
|
14 |
#include <wininet.h> |
|
15 |
#include <io.h> |
|
16 |
#include <fcntl.h> |
|
2160 | 17 |
#include "variables.h" |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
18 |
#include "win32.h" |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
19 |
#include "fios.h" // opendir/readdir/closedir |
4210
2c1a58c727ed
(svn r5698) - Fix [r5697]: don't remove ctype include for win32.c; needed for toupper...ugh
Darkvater
parents:
4209
diff
changeset
|
20 |
#include <ctype.h> |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
21 |
#include <tchar.h> |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
22 |
#include <errno.h> |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
23 |
#include <sys/types.h> |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
24 |
#include <sys/stat.h> |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
25 |
|
0 | 26 |
static bool _has_console; |
27 |
||
3394
78963d9c1022
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
28 |
#if defined(__MINGW32__) |
78963d9c1022
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
29 |
#include <stdint.h> |
78963d9c1022
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
30 |
#endif |
0 | 31 |
|
2208 | 32 |
static bool cursor_visible = true; |
33 |
||
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
34 |
bool MyShowCursor(bool show) |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
35 |
{ |
2209 | 36 |
if (cursor_visible == show) return show; |
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
37 |
|
2209 | 38 |
cursor_visible = show; |
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
39 |
ShowCursor(show); |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
40 |
|
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
41 |
return !show; |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
42 |
} |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
43 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
44 |
/** Helper function needed by dynamically loading libraries |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
45 |
* XXX: Hurray for MS only having an ANSI GetProcAddress function |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
46 |
* on normal windows and no Wide version except for in Windows Mobile/CE */ |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
47 |
bool LoadLibraryList(Function proc[], const char *dll) |
0 | 48 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
49 |
while (*dll != '\0') { |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
50 |
HMODULE lib; |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
51 |
lib = LoadLibrary(MB_TO_WIDE(dll)); |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
52 |
|
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
53 |
if (lib == NULL) return false; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
54 |
for (;;) { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
55 |
FARPROC p; |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
56 |
|
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
57 |
while (*dll++ != '\0'); |
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
58 |
if (*dll == '\0') break; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
59 |
#if defined(WINCE) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
60 |
p = GetProcAddress(lib, MB_TO_WIDE(dll); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
61 |
#else |
0 | 62 |
p = GetProcAddress(lib, dll); |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
63 |
#endif |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
64 |
if (p == NULL) return false; |
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
65 |
*proc++ = (Function)p; |
0 | 66 |
} |
67 |
dll++; |
|
68 |
} |
|
69 |
return true; |
|
70 |
} |
|
71 |
||
796 | 72 |
#ifdef _MSC_VER |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
73 |
static const char *_exception_string = NULL; |
2428
b2e4fb6665d0
(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
|
74 |
#endif |
0 | 75 |
|
76 |
void ShowOSErrorBox(const char *buf) |
|
77 |
{ |
|
78 |
MyShowCursor(true); |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
79 |
MessageBox(GetActiveWindow(), MB_TO_WIDE(buf), _T("Error!"), MB_ICONSTOP); |
0 | 80 |
|
81 |
// if exception tracker is enabled, we crash here to let the exception handler handle it. |
|
82 |
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG) |
|
83 |
if (*buf == '!') { |
|
84 |
_exception_string = buf; |
|
85 |
*(byte*)0 = 0; |
|
86 |
} |
|
87 |
#endif |
|
88 |
} |
|
89 |
||
2428
b2e4fb6665d0
(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
|
90 |
#ifdef _MSC_VER |
b2e4fb6665d0
(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
|
91 |
|
b2e4fb6665d0
(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
|
92 |
static void *_safe_esp; |
b2e4fb6665d0
(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 |
static char *_crash_msg; |
b2e4fb6665d0
(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 |
static bool _expanded; |
b2e4fb6665d0
(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 bool _did_emerg_save; |
b2e4fb6665d0
(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 int _ident; |
b2e4fb6665d0
(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 |
|
0 | 98 |
typedef struct DebugFileInfo { |
99 |
uint32 size; |
|
100 |
uint32 crc32; |
|
101 |
SYSTEMTIME file_time; |
|
102 |
} DebugFileInfo; |
|
103 |
||
104 |
static uint32 *_crc_table; |
|
105 |
||
106 |
static void MakeCRCTable(uint32 *table) { |
|
107 |
uint32 crc, poly = 0xEDB88320L; |
|
2026 | 108 |
int i; |
109 |
int j; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
110 |
|
0 | 111 |
_crc_table = table; |
112 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
113 |
for (i = 0; i != 256; i++) { |
0 | 114 |
crc = i; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
115 |
for (j = 8; j != 0; j--) { |
4078
4530dde1a8a9
(svn r5393) CodeChange : Little typo correction. Nothing spectacular. Only broke in MSVC
belugas
parents:
4077
diff
changeset
|
116 |
crc = (crc & 1 ? (crc >> 1) ^ poly : crc >> 1); |
0 | 117 |
} |
118 |
table[i] = crc; |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
static uint32 CalcCRC(byte *data, uint size, uint32 crc) { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
123 |
for (; size > 0; size--) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
124 |
crc = ((crc >> 8) & 0x00FFFFFF) ^ _crc_table[(crc ^ *data++) & 0xFF]; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
125 |
} |
0 | 126 |
return crc; |
127 |
} |
|
128 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
129 |
static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename) |
0 | 130 |
{ |
131 |
memset(dfi, 0, sizeof(dfi)); |
|
132 |
||
133 |
{ |
|
134 |
HANDLE file; |
|
135 |
byte buffer[1024]; |
|
136 |
DWORD numread; |
|
137 |
uint32 filesize = 0; |
|
138 |
FILETIME write_time; |
|
139 |
uint32 crc = (uint32)-1; |
|
140 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
141 |
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
142 |
OPEN_EXISTING, 0, 0); |
0 | 143 |
if (file != INVALID_HANDLE_VALUE) { |
2952 | 144 |
for (;;) { |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
145 |
if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
146 |
numread == 0) |
0 | 147 |
break; |
148 |
filesize += numread; |
|
149 |
crc = CalcCRC(buffer, numread, crc); |
|
150 |
} |
|
151 |
dfi->size = filesize; |
|
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 |
|
0 | 154 |
if (GetFileTime(file, NULL, NULL, &write_time)) { |
155 |
FileTimeToSystemTime(&write_time, &dfi->file_time); |
|
156 |
} |
|
157 |
CloseHandle(file); |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
||
163 |
static char *PrintModuleInfo(char *output, HMODULE mod) |
|
164 |
{ |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
165 |
TCHAR buffer[MAX_PATH]; |
0 | 166 |
DebugFileInfo dfi; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
167 |
|
0 | 168 |
GetModuleFileName(mod, buffer, MAX_PATH); |
169 |
GetFileInfo(&dfi, buffer); |
|
2458
c95808cd2ac9
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2428
diff
changeset
|
170 |
output += sprintf(output, " %-20s handle: %p size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n", |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
171 |
WIDE_TO_MB(buffer), |
0 | 172 |
mod, |
173 |
dfi.size, |
|
174 |
dfi.crc32, |
|
175 |
dfi.file_time.wYear, |
|
176 |
dfi.file_time.wMonth, |
|
177 |
dfi.file_time.wDay, |
|
178 |
dfi.file_time.wHour, |
|
179 |
dfi.file_time.wMinute, |
|
180 |
dfi.file_time.wSecond |
|
181 |
); |
|
182 |
return output; |
|
183 |
} |
|
184 |
||
185 |
static char *PrintModuleList(char *output) |
|
186 |
{ |
|
187 |
BOOL (WINAPI *EnumProcessModules)(HANDLE,HMODULE*,DWORD,LPDWORD); |
|
188 |
HANDLE proc; |
|
189 |
HMODULE modules[100]; |
|
190 |
DWORD needed; |
|
191 |
BOOL res; |
|
192 |
int count,i; |
|
193 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
194 |
if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0\0")) { |
0 | 195 |
proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); |
196 |
if (proc) { |
|
197 |
res = EnumProcessModules(proc, modules, sizeof(modules), &needed); |
|
198 |
CloseHandle(proc); |
|
199 |
if (res) { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
200 |
count = |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
201 |
min(needed / sizeof(HMODULE), lengthof(modules)); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
202 |
for (i = 0; i != count; i++) |
0 | 203 |
output = PrintModuleInfo(output, modules[i]); |
204 |
return output; |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
output = PrintModuleInfo(output, NULL); |
|
209 |
return output; |
|
210 |
} |
|
211 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
212 |
static const TCHAR _crash_desc[] = |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
213 |
_T("A serious fault condition occured in the game. The game will shut down.\n") |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
214 |
_T("Press \"Submit report\" to send crash information to the developers. ") |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
215 |
_T("This will greatly help debugging. ") |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
216 |
_T("The information contained in the report is displayed below.\n") |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
217 |
_T("Press \"Emergency save\" to attempt saving the game."); |
0 | 218 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
219 |
static const TCHAR _save_succeeded[] = |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
220 |
_T("Emergency save succeeded.\n") |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
221 |
_T("Be aware that critical parts of the internal game state may have become ") |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
222 |
_T("corrupted. The saved game is not guaranteed to work."); |
0 | 223 |
|
1881
023a134a4b12
(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 |
static bool EmergencySave(void) |
023a134a4b12
(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 |
{ |
023a134a4b12
(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 |
SaveOrLoad("crash.sav", SL_SAVE); |
023a134a4b12
(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
|
227 |
return true; |
023a134a4b12
(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
|
228 |
} |
0 | 229 |
|
230 |
typedef struct { |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
231 |
HINTERNET (WINAPI *InternetOpen)(LPCTSTR,DWORD, LPCTSTR, LPCTSTR, DWORD); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
232 |
HINTERNET (WINAPI *InternetConnect)(HINTERNET, LPCTSTR, INTERNET_PORT, LPCTSTR, LPCTSTR, DWORD, DWORD, DWORD); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
233 |
HINTERNET (WINAPI *HttpOpenRequest)(HINTERNET, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR *, DWORD, DWORD); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
234 |
BOOL (WINAPI *HttpSendRequest)(HINTERNET, LPCTSTR, DWORD, LPVOID, DWORD); |
0 | 235 |
BOOL (WINAPI *InternetCloseHandle)(HINTERNET); |
236 |
BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD); |
|
237 |
} WinInetProcs; |
|
238 |
||
239 |
#define M(x) x "\0" |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
240 |
#if defined(UNICODE) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
241 |
# define W(x) x "W" |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
242 |
#else |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
243 |
# define W(x) x "A" |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
244 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
245 |
static const char wininet_files[] = |
0 | 246 |
M("wininet.dll") |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
247 |
M(W("InternetOpen")) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
248 |
M(W("InternetConnect")) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
249 |
M(W("HttpOpenRequest")) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
250 |
M(W("HttpSendRequest")) |
0 | 251 |
M("InternetCloseHandle") |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
252 |
M(W("HttpQueryInfo")) |
0 | 253 |
M(""); |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
254 |
#undef W |
0 | 255 |
#undef M |
256 |
||
257 |
static WinInetProcs _wininet; |
|
258 |
||
259 |
||
5168
10a8dc9788d7
(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
10a8dc9788d7
(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
10a8dc9788d7
(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]; |
10a8dc9788d7
(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
10a8dc9788d7
(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
10a8dc9788d7
(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 ); |
10a8dc9788d7
(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
10a8dc9788d7
(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); |
10a8dc9788d7
(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
10a8dc9788d7
(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); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
277 |
|
10a8dc9788d7
(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); |
10a8dc9788d7
(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; } |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
280 |
|
10a8dc9788d7
(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
10a8dc9788d7
(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
10a8dc9788d7
(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
10a8dc9788d7
(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 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
329 |
static const TCHAR * const _expand_texts[] = {_T("S&how report >>"), _T("&Hide report <<") }; |
0 | 330 |
|
331 |
static void SetWndSize(HWND wnd, int mode) |
|
332 |
{ |
|
333 |
RECT r,r2; |
|
334 |
int offs; |
|
335 |
||
336 |
GetWindowRect(wnd, &r); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
337 |
|
0 | 338 |
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
|
339 |
|
0 | 340 |
if (mode >= 0) { |
341 |
GetWindowRect(GetDlgItem(wnd, 11), &r2); |
|
342 |
offs = r2.bottom - r2.top + 10; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
343 |
if (!mode) offs = -offs; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
344 |
SetWindowPos(wnd, HWND_TOPMOST, 0, 0, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
345 |
r.right - r.left, r.bottom - r.top + offs, SWP_NOMOVE | SWP_NOZORDER); |
0 | 346 |
} else { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
347 |
SetWindowPos(wnd, HWND_TOPMOST, |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
348 |
(GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
349 |
(GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2, |
0 | 350 |
0, 0, SWP_NOSIZE); |
351 |
} |
|
352 |
} |
|
353 |
||
354 |
static bool DoEmergencySave(HWND wnd) |
|
355 |
{ |
|
356 |
bool b = false; |
|
357 |
||
358 |
EnableWindow(GetDlgItem(wnd, 13), FALSE); |
|
359 |
_did_emerg_save = true; |
|
360 |
__try { |
|
361 |
b = EmergencySave(); |
|
362 |
} __except (1) {} |
|
363 |
return b; |
|
364 |
} |
|
365 |
||
2458
c95808cd2ac9
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2428
diff
changeset
|
366 |
static INT_PTR CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam) |
0 | 367 |
{ |
2952 | 368 |
switch (msg) { |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
369 |
case WM_INITDIALOG: { |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
370 |
#if defined(UNICODE) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
371 |
# define crash_msg crash_msgW |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
372 |
TCHAR crash_msgW[8096]; |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
373 |
MultiByteToWideChar(CP_ACP, 0, _crash_msg, -1, crash_msgW, lengthof(crash_msgW)); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
374 |
#else |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
375 |
# define crash_msg _crash_msg |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
376 |
#endif |
0 | 377 |
SetDlgItemText(wnd, 10, _crash_desc); |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
378 |
SetDlgItemText(wnd, 11, crash_msg); |
0 | 379 |
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE); |
380 |
SetWndSize(wnd, -1); |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
381 |
} return TRUE; |
0 | 382 |
case WM_COMMAND: |
2952 | 383 |
switch (wParam) { |
0 | 384 |
case 12: // Close |
385 |
ExitProcess(0); |
|
386 |
case 13: { // Emergency save |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
387 |
if (DoEmergencySave(wnd)) { |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
388 |
MessageBox(wnd, _save_succeeded, _T("Save successful"), MB_ICONINFORMATION); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
389 |
} else { |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
390 |
MessageBox(wnd, _T("Save failed"), _T("Save failed"), MB_ICONINFORMATION); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
391 |
} |
0 | 392 |
break; |
393 |
} |
|
394 |
case 14: { // Submit crash report |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
395 |
const TCHAR *s; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
396 |
|
0 | 397 |
SetCursor(LoadCursor(NULL, IDC_WAIT)); |
398 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
399 |
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), _T("")); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
400 |
if (s != NULL) { |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
401 |
MessageBox(wnd, s, _T("Error"), MB_ICONSTOP); |
0 | 402 |
break; |
403 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
404 |
|
0 | 405 |
// try to submit emergency savegame |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
406 |
if (_did_emerg_save || DoEmergencySave(wnd)) SubmitFile(wnd, _T("crash.sav")); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
407 |
|
0 | 408 |
// try to submit the autosaved game |
409 |
if (_opt.autosave) { |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
410 |
TCHAR buf[40]; |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
411 |
_sntprintf(buf, lengthof(buf), _T("autosave%d.sav"), (_autosave_ctr - 1) & 3); |
0 | 412 |
SubmitFile(wnd, buf); |
413 |
} |
|
414 |
EnableWindow(GetDlgItem(wnd, 14), FALSE); |
|
415 |
SetCursor(LoadCursor(NULL, IDC_ARROW)); |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
416 |
MessageBox(wnd, _T("Crash report submitted. Thank you."), _T("Crash Report"), MB_ICONINFORMATION); |
0 | 417 |
break; |
418 |
} |
|
419 |
case 15: // Expand |
|
420 |
_expanded ^= 1; |
|
421 |
SetWndSize(wnd, _expanded); |
|
422 |
break; |
|
423 |
} |
|
424 |
return TRUE; |
|
425 |
case WM_CLOSE: |
|
426 |
ExitProcess(0); |
|
427 |
} |
|
428 |
||
429 |
return FALSE; |
|
430 |
} |
|
431 |
||
1102
316643e34104
(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
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
439 |
extern bool CloseConsoleLogIfActive(void); |
1023
8df956881058
(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
2f2e12688e97
(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
10a8dc9788d7
(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
8073826fe82d
(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 |
||
452 |
MakeCRCTable(alloca(256 * sizeof(uint32))); |
|
453 |
_crash_msg = output = LocalAlloc(LMEM_FIXED, 8192); |
|
454 |
||
455 |
{ |
|
456 |
SYSTEMTIME time; |
|
457 |
GetLocalTime(&time); |
|
5168
10a8dc9788d7
(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
1bc9b3024d0d
(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
2f2e12688e97
(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
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
472 |
if (_exception_string) |
8073826fe82d
(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
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
475 |
#ifdef _M_AMD64 |
dffcca243dbc
(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" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
477 |
"Registers:\r\n" |
dffcca243dbc
(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" |
dffcca243dbc
(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" |
dffcca243dbc
(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" |
dffcca243dbc
(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" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
482 |
"RIP: %.16llX EFLAGS: %.8X\r\n" |
dffcca243dbc
(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", |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
484 |
ep->ExceptionRecord->ExceptionCode, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
485 |
ep->ExceptionRecord->ExceptionAddress, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
486 |
ep->ContextRecord->Rax, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
487 |
ep->ContextRecord->Rbx, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
488 |
ep->ContextRecord->Rcx, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
489 |
ep->ContextRecord->Rdx, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
490 |
ep->ContextRecord->Rsi, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
491 |
ep->ContextRecord->Rdi, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
492 |
ep->ContextRecord->Rbp, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
493 |
ep->ContextRecord->Rsp, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
494 |
ep->ContextRecord->R8, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
495 |
ep->ContextRecord->R9, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
496 |
ep->ContextRecord->R10, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
497 |
ep->ContextRecord->R11, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
498 |
ep->ContextRecord->R12, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
499 |
ep->ContextRecord->R13, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
500 |
ep->ContextRecord->R14, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
501 |
ep->ContextRecord->R15, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
502 |
ep->ContextRecord->Rip, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
503 |
ep->ContextRecord->EFlags |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
504 |
); |
dffcca243dbc
(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
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
525 |
#endif |
0 | 526 |
|
527 |
{ |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
528 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
529 |
byte *b = (byte*)ep->ContextRecord->Rip; |
dffcca243dbc
(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
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
532 |
#endif |
0 | 533 |
int i; |
1468
8073826fe82d
(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
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
550 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
551 |
uint32 *b = (uint32*)ep->ContextRecord->Rsp; |
dffcca243dbc
(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
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
554 |
#endif |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
555 |
for (j = 0; j != 24; j++) { |
8073826fe82d
(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
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
576 |
" Windows version %d.%d %d %s\r\n", |
8073826fe82d
(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
10a8dc9788d7
(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
8df956881058
(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 */ |
8df956881058
(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(); |
8df956881058
(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
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
593 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
594 |
ep->ContextRecord->Rip = (DWORD64)Handler2; |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
595 |
ep->ContextRecord->Rsp = (DWORD64)_safe_esp; |
dffcca243dbc
(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
dffcca243dbc
(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
8df956881058
(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 |
|
8df956881058
(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 |
|
8df956881058
(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
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
607 |
static void Win32InitializeExceptions(void) |
0 | 608 |
{ |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
609 |
#ifdef _M_AMD64 |
3341
b8febc9509d7
(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
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
611 |
_safe_esp = _get_save_esp(); |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
612 |
#else |
0 | 613 |
_asm { |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
614 |
mov _safe_esp, esp |
0 | 615 |
} |
2482
dffcca243dbc
(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
b8febc9509d7
(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
384c7451e3bb
(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 |
384c7451e3bb
(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 |
384c7451e3bb
(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� */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
625 |
|
384c7451e3bb
(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. |
384c7451e3bb
(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. |
4224
4471b359da52
(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
|
628 |
* To guarantee reentrancy, we fall back to malloc if the instance is |
4218
384c7451e3bb
(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 |
384c7451e3bb
(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). */ |
384c7451e3bb
(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; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
632 |
static bool _global_dir_is_in_use = false; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
633 |
|
384c7451e3bb
(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) |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
635 |
{ |
384c7451e3bb
(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; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
637 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
638 |
if (_global_dir_is_in_use) { |
4224
4471b359da52
(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
|
639 |
d = calloc(1, sizeof(*d)); |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
640 |
} else { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
641 |
_global_dir_is_in_use = true; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
642 |
d = &_global_dir; |
4224
4471b359da52
(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
|
643 |
memset(d, 0, sizeof(*d)); |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
644 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
645 |
return d; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
646 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
647 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
648 |
static inline void dir_free(DIR *d) |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
649 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
650 |
if (d == &_global_dir) { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
651 |
_global_dir_is_in_use = false; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
652 |
} else { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
653 |
free(d); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
654 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
655 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
656 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
657 |
DIR *opendir(const char *path) |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
658 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
659 |
DIR *d; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
660 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
661 |
DWORD fa = GetFileAttributesW(OTTD2FS(path)); |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
662 |
|
4224
4471b359da52
(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 |
if ((fa != INVALID_FILE_ATTRIBUTES) && (fa & FILE_ATTRIBUTE_DIRECTORY)) { |
4471b359da52
(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 |
d = dir_calloc(); |
4471b359da52
(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
|
665 |
if (d != NULL) { |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
666 |
char search_path[MAX_PATH]; |
4224
4471b359da52
(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 |
/* build search path for FindFirstFile */ |
4471b359da52
(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
|
668 |
snprintf(search_path, lengthof(search_path), "%s" PATHSEP "*", path); |
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
669 |
d->hFind = FindFirstFileW(OTTD2FS(search_path), &d->fd); |
4224
4471b359da52
(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 |
|
4471b359da52
(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 |
if (d->hFind != INVALID_HANDLE_VALUE || |
4471b359da52
(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 |
GetLastError() == ERROR_NO_MORE_FILES) { // the directory is empty |
4471b359da52
(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->ent.dir = d; |
4471b359da52
(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 |
d->at_first_entry = true; |
4471b359da52
(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 |
} else { |
4471b359da52
(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 |
dir_free(d); |
4471b359da52
(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 |
d = NULL; |
4471b359da52
(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 |
} |
4471b359da52
(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 |
} else { |
4471b359da52
(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 |
errno = ENOMEM; |
4471b359da52
(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 |
} |
4471b359da52
(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 |
} else { |
4471b359da52
(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 |
/* path not found or not a directory */ |
4471b359da52
(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
|
684 |
d = NULL; |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
685 |
errno = ENOENT; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
686 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
687 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
688 |
SetErrorMode(sem); // restore previous setting |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
689 |
return d; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
690 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
691 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
692 |
struct dirent *readdir(DIR *d) |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
693 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
694 |
DWORD prev_err = GetLastError(); // avoid polluting last error |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
695 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
696 |
if (d->at_first_entry) { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
697 |
/* the directory was empty when opened */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
698 |
if (d->hFind == INVALID_HANDLE_VALUE) return NULL; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
699 |
d->at_first_entry = false; |
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
700 |
} else if (!FindNextFileW(d->hFind, &d->fd)) { // determine cause and bail |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
701 |
if (GetLastError() == ERROR_NO_MORE_FILES) SetLastError(prev_err); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
702 |
return NULL; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
703 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
704 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
705 |
/* This entry has passed all checks; return information about it. |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
706 |
* (note: d_name is a pointer; see struct dirent definition) */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
707 |
d->ent.d_name = d->fd.cFileName; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
708 |
return &d->ent; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
709 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
710 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
711 |
int closedir(DIR *d) |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
712 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
713 |
FindClose(d->hFind); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
714 |
dir_free(d); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
715 |
return 0; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
716 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
717 |
|
4221
bb06fe8dcce2
(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
|
718 |
bool FiosIsRoot(const char *file) |
0 | 719 |
{ |
4221
bb06fe8dcce2
(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
|
720 |
return file[3] == '\0'; // C:\... |
0 | 721 |
} |
722 |
||
4221
bb06fe8dcce2
(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
|
723 |
void FiosGetDrives(void) |
0 | 724 |
{ |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
725 |
TCHAR drives[256]; |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
726 |
const TCHAR *s; |
0 | 727 |
|
4221
bb06fe8dcce2
(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 |
GetLogicalDriveStrings(sizeof(drives), drives); |
bb06fe8dcce2
(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 |
for (s = drives; *s != '\0';) { |
bb06fe8dcce2
(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 |
FiosItem *fios = FiosAlloc(); |
bb06fe8dcce2
(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->type = FIOS_TYPE_DRIVE; |
bb06fe8dcce2
(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
|
732 |
fios->mtime = 0; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
733 |
snprintf(fios->name, lengthof(fios->name), "%c:", s[0] & 0xFF); |
4221
bb06fe8dcce2
(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 |
ttd_strlcpy(fios->title, fios->name, lengthof(fios->title)); |
bb06fe8dcce2
(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
|
735 |
while (*s++ != '\0'); |
0 | 736 |
} |
737 |
} |
|
738 |
||
4221
bb06fe8dcce2
(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
|
739 |
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) |
0 | 740 |
{ |
4245
59697b49326e
(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
|
741 |
// hectonanoseconds between Windows and POSIX epoch |
4247
00cdac3de8e9
(svn r5836) - Silence a warning on mingw. Thanks glx.
Darkvater
parents:
4245
diff
changeset
|
742 |
static const int64 posix_epoch_hns = 0x019DB1DED53E8000LL; |
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
743 |
const WIN32_FIND_DATAW *fd = &ent->dir->fd; |
4224
4471b359da52
(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
|
744 |
if (fd->dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) return false; |
0 | 745 |
|
4224
4471b359da52
(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
|
746 |
sb->st_size = ((uint64) fd->nFileSizeHigh << 32) + fd->nFileSizeLow; |
4245
59697b49326e
(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 |
/* UTC FILETIME to seconds-since-1970 UTC |
59697b49326e
(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 |
* we just have to subtract POSIX epoch and scale down to units of seconds. |
59697b49326e
(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 |
* http://www.gamedev.net/community/forums/topic.asp?topic_id=294070&whichpage=1� |
59697b49326e
(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 |
* XXX - not entirely correct, since filetimes on FAT aren't UTC but local, |
59697b49326e
(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 |
* this won't entirely be correct, but we use the time only for comparsion. */ |
59697b49326e
(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
|
752 |
sb->st_mtime = (time_t)((*(uint64*)&fd->ftLastWriteTime - posix_epoch_hns) / 1E7); |
4221
bb06fe8dcce2
(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
|
753 |
sb->st_mode = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG; |
4224
4471b359da52
(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
|
754 |
|
4221
bb06fe8dcce2
(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
|
755 |
return true; |
0 | 756 |
} |
757 |
||
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
758 |
bool FiosGetDiskFreeSpace(const char *path, uint32 *tot) |
0 | 759 |
{ |
1596
c1c439a2d5b2
(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
|
760 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
761 |
bool retval = false; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
762 |
TCHAR root[4]; |
0 | 763 |
DWORD spc, bps, nfc, tnc; |
1596
c1c439a2d5b2
(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
|
764 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
765 |
_sntprintf(root, lengthof(root), _T("%c:") _T(PATHSEP), path[0]); |
1596
c1c439a2d5b2
(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 |
if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) { |
c1c439a2d5b2
(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
|
767 |
*tot = ((spc * bps) * (uint64)nfc) >> 20; |
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
768 |
retval = true; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
769 |
} |
1596
c1c439a2d5b2
(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 |
|
c1c439a2d5b2
(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
|
771 |
SetErrorMode(sem); // reset previous setting |
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
772 |
return retval; |
0 | 773 |
} |
774 |
||
775 |
static int ParseCommandLine(char *line, char **argv, int max_argc) |
|
776 |
{ |
|
777 |
int n = 0; |
|
778 |
||
779 |
do { |
|
780 |
// skip whitespace |
|
781 |
while (*line == ' ' || *line == '\t') |
|
782 |
line++; |
|
783 |
||
784 |
// end? |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
785 |
if (*line == '\0') |
0 | 786 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
787 |
|
0 | 788 |
// special handling when quoted |
789 |
if (*line == '"') { |
|
790 |
argv[n++] = ++line; |
|
791 |
while (*line != '"') { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
792 |
if (*line == '\0') return n; |
0 | 793 |
line++; |
794 |
} |
|
795 |
} else { |
|
796 |
argv[n++] = line; |
|
797 |
while (*line != ' ' && *line != '\t') { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
798 |
if (*line == '\0') return n; |
0 | 799 |
line++; |
800 |
} |
|
801 |
} |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
802 |
*line++ = '\0'; |
0 | 803 |
} while (n != max_argc); |
804 |
||
805 |
return n; |
|
806 |
} |
|
807 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
808 |
void CreateConsole(void) |
0 | 809 |
{ |
810 |
HANDLE hand; |
|
811 |
CONSOLE_SCREEN_BUFFER_INFO coninfo; |
|
812 |
||
813 |
if (_has_console) return; |
|
814 |
||
815 |
_has_console = true; |
|
816 |
||
4572
e6e17d286de7
(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
|
817 |
AllocConsole(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
818 |
|
0 | 819 |
hand = GetStdHandle(STD_OUTPUT_HANDLE); |
820 |
GetConsoleScreenBufferInfo(hand, &coninfo); |
|
821 |
coninfo.dwSize.Y = 500; |
|
822 |
SetConsoleScreenBufferSize(hand, coninfo.dwSize); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
823 |
|
0 | 824 |
// redirect unbuffered STDIN, STDOUT, STDERR to the console |
2172 | 825 |
#if !defined(__CYGWIN__) |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
826 |
*stdout = *_fdopen( _open_osfhandle((intptr_t)hand, _O_TEXT), "w" ); |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
827 |
*stdin = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" ); |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
828 |
*stderr = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); |
0 | 829 |
#else |
830 |
// open_osfhandle is not in cygwin |
|
831 |
*stdout = *fdopen(1, "w" ); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
832 |
*stdin = *fdopen(0, "r" ); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
833 |
*stderr = *fdopen(2, "w" ); |
0 | 834 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
835 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
836 |
setvbuf(stdin, NULL, _IONBF, 0); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
837 |
setvbuf(stdout, NULL, _IONBF, 0); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
838 |
setvbuf(stderr, NULL, _IONBF, 0); |
0 | 839 |
} |
840 |
||
841 |
void ShowInfo(const char *str) |
|
842 |
{ |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
843 |
if (_has_console) { |
0 | 844 |
puts(str); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
845 |
} else { |
0 | 846 |
bool old; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
847 |
|
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); |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
852 |
if (MessageBox(GetActiveWindow(), MB_TO_WIDE(str), _T("OpenTTD"), MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) { |
0 | 853 |
CreateConsole(); |
854 |
} |
|
855 |
MyShowCursor(old); |
|
856 |
} |
|
857 |
} |
|
858 |
||
2428
b2e4fb6665d0
(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__ |
b2e4fb6665d0
(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) */ |
b2e4fb6665d0
(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 |
b2e4fb6665d0
(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 |
b2e4fb6665d0
(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 |
b2e4fb6665d0
(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 |
b2e4fb6665d0
(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); |
b2e4fb6665d0
(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 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
868 |
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
869 |
LPTSTR lpCmdLine, int nCmdShow) |
0 | 870 |
{ |
871 |
int argc; |
|
872 |
char *argv[64]; // max 64 command line arguments |
|
873 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
874 |
#if defined(UNICODE) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
875 |
/* We need to backup the command line (arguments) because the pointer |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
876 |
* of FS2OTTD() is only temporary */ |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
877 |
char cmdline[MAX_PATH]; |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
878 |
ttd_strlcpy(cmdline, FS2OTTD(GetCommandLine()), sizeof(cmdline)); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
879 |
#else |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
880 |
char *cmdline = GetCommandLine(); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
881 |
#endif |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
882 |
|
0 | 883 |
#if defined(_DEBUG) |
884 |
CreateConsole(); |
|
885 |
#endif |
|
886 |
||
2428
b2e4fb6665d0
(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
|
887 |
_set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox |
0 | 888 |
|
889 |
// setup random seed to something quite random |
|
4369
02b9ab2cf501
(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
|
890 |
_random_seeds[1][0] = _random_seeds[0][0] = GetTickCount(); |
02b9ab2cf501
(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
|
891 |
_random_seeds[1][1] = _random_seeds[0][1] = _random_seeds[0][0] * 0x1234567; |
2073 | 892 |
SeedMT(_random_seeds[0][0]); |
0 | 893 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
894 |
argc = ParseCommandLine(cmdline, argv, lengthof(argv)); |
0 | 895 |
|
896 |
#if defined(WIN32_EXCEPTION_TRACKER) |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
897 |
Win32InitializeExceptions(); |
0 | 898 |
#endif |
899 |
||
900 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
901 |
_try { |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
902 |
LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep); |
0 | 903 |
#endif |
904 |
ttd_main(argc, argv); |
|
905 |
||
906 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
907 |
} _except (ExceptionHandler(_exception_info())) {} |
|
908 |
#endif |
|
909 |
||
910 |
return 0; |
|
911 |
} |
|
912 |
||
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
913 |
void DeterminePaths(void) |
0 | 914 |
{ |
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
915 |
char *s, *cfg; |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
916 |
wchar_t path[MAX_PATH]; |
0 | 917 |
|
918 |
_path.personal_dir = _path.game_data_dir = cfg = malloc(MAX_PATH); |
|
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
919 |
GetCurrentDirectoryW(MAX_PATH - 1, path); |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
920 |
WideCharToMultiByte(CP_UTF8, 0, path, -1, cfg, MAX_PATH, NULL, NULL); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
921 |
|
2559
08e648022cb0
(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
|
922 |
cfg[0] = toupper(cfg[0]); |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
923 |
s = strchr(cfg, '\0'); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
924 |
if (s[-1] != '\\') strcpy(s, "\\"); |
0 | 925 |
|
926 |
_path.save_dir = str_fmt("%ssave", cfg); |
|
927 |
_path.autosave_dir = str_fmt("%s\\autosave", _path.save_dir); |
|
928 |
_path.scenario_dir = str_fmt("%sscenario", cfg); |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
929 |
_path.heightmap_dir = str_fmt("%sscenario\\heightmap", cfg); |
0 | 930 |
_path.gm_dir = str_fmt("%sgm\\", cfg); |
931 |
_path.data_dir = str_fmt("%sdata\\", cfg); |
|
932 |
_path.lang_dir = str_fmt("%slang\\", cfg); |
|
933 |
||
1482
46a8146adecf
(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
|
934 |
if (_config_file == NULL) |
46a8146adecf
(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
|
935 |
_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir); |
46a8146adecf
(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
|
936 |
|
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
915
diff
changeset
|
937 |
_highscore_file = str_fmt("%shs.dat", _path.personal_dir); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
698
diff
changeset
|
938 |
_log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
0 | 939 |
|
940 |
// make (auto)save and scenario folder |
|
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
941 |
CreateDirectoryW(OTTD2FS(_path.save_dir), NULL); |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
942 |
CreateDirectoryW(OTTD2FS(_path.autosave_dir), NULL); |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
943 |
CreateDirectoryW(OTTD2FS(_path.scenario_dir), NULL); |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
944 |
CreateDirectoryW(OTTD2FS(_path.heightmap_dir), NULL); |
0 | 945 |
} |
946 |
||
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
947 |
/** |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
948 |
* Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
949 |
* and append this up to the maximum length (either absolute or screenlength). If maxlength |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
950 |
* is zero, we don't care about the screenlength but only about the physical length of the string |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
951 |
* @param tb @Textbuf type to be changed |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
952 |
* @return Return true on successfull change of Textbuf, or false otherwise |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
953 |
*/ |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
954 |
bool InsertTextBufferClipboard(Textbuf *tb) |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
955 |
{ |
5108
dc67d70b5a45
(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
|
956 |
HGLOBAL cbuf; |
dc67d70b5a45
(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
|
957 |
char utf8_buf[512]; |
dc67d70b5a45
(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
|
958 |
const char *ptr; |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
959 |
|
5108
dc67d70b5a45
(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
|
960 |
WChar c; |
dc67d70b5a45
(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
|
961 |
uint16 width, length; |
dc67d70b5a45
(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
|
962 |
|
dc67d70b5a45
(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
|
963 |
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { |
dc67d70b5a45
(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
|
964 |
int bytec; |
dc67d70b5a45
(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
|
965 |
|
dc67d70b5a45
(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
|
966 |
OpenClipboard(NULL); |
dc67d70b5a45
(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
|
967 |
cbuf = GetClipboardData(CF_UNICODETEXT); |
dc67d70b5a45
(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
|
968 |
|
dc67d70b5a45
(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
|
969 |
ptr = GlobalLock(cbuf); |
dc67d70b5a45
(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
|
970 |
bytec = WideCharToMultiByte(CP_UTF8, 0, (wchar_t*)ptr, -1, utf8_buf, lengthof(utf8_buf), NULL, NULL); |
dc67d70b5a45
(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
|
971 |
GlobalUnlock(cbuf); |
dc67d70b5a45
(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
|
972 |
CloseClipboard(); |
dc67d70b5a45
(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
|
973 |
|
dc67d70b5a45
(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
|
974 |
if (bytec == 0) { |
dc67d70b5a45
(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
|
975 |
DEBUG(misc, 0) ("[utf8] Error converting '%s'. Errno %d", ptr, GetLastError()); |
dc67d70b5a45
(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
|
976 |
return false; |
dc67d70b5a45
(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
|
977 |
} |
dc67d70b5a45
(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 |
} else if (IsClipboardFormatAvailable(CF_TEXT)) { |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
979 |
OpenClipboard(NULL); |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
980 |
cbuf = GetClipboardData(CF_TEXT); |
53a5713cf3f9
(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
dc67d70b5a45
(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 |
ptr = GlobalLock(cbuf); |
dc67d70b5a45
(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 |
ttd_strlcpy(utf8_buf, ptr, lengthof(utf8_buf)); |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
984 |
GlobalUnlock(cbuf); |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
985 |
CloseClipboard(); |
5108
dc67d70b5a45
(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
|
986 |
} else { |
dc67d70b5a45
(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 |
return false; |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
988 |
} |
5108
dc67d70b5a45
(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 |
|
dc67d70b5a45
(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 |
width = length = 0; |
dc67d70b5a45
(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
|
991 |
|
dc67d70b5a45
(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
|
992 |
for (ptr = utf8_buf; (c = Utf8Consume(&ptr)) != '\0';) { |
dc67d70b5a45
(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 |
byte charwidth; |
dc67d70b5a45
(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 |
|
dc67d70b5a45
(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 |
if (!IsPrintable(c)) break; |
dc67d70b5a45
(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
|
996 |
if (tb->length + length >= tb->maxlength - 1) break; |
dc67d70b5a45
(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 |
charwidth = GetCharacterWidth(FS_NORMAL, c); |
dc67d70b5a45
(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
|
998 |
|
dc67d70b5a45
(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
|
999 |
if (tb->maxwidth != 0 && width + tb->width + charwidth > tb->maxwidth) break; |
dc67d70b5a45
(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
|
1000 |
|
dc67d70b5a45
(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
|
1001 |
width += charwidth; |
dc67d70b5a45
(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 |
length += Utf8CharLen(c); |
dc67d70b5a45
(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
|
1003 |
} |
dc67d70b5a45
(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
|
1004 |
|
dc67d70b5a45
(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 |
if (length == 0) return false; |
dc67d70b5a45
(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 |
|
dc67d70b5a45
(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
|
1007 |
memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos); |
dc67d70b5a45
(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 |
memcpy(tb->buf + tb->caretpos, utf8_buf, length); |
dc67d70b5a45
(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 |
tb->width += width; |
dc67d70b5a45
(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 |
tb->caretxoffs += width; |
dc67d70b5a45
(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 |
|
dc67d70b5a45
(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 |
tb->length += length; |
dc67d70b5a45
(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 |
tb->caretpos += length; |
dc67d70b5a45
(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 |
tb->buf[tb->length] = '\0'; // terminating zero |
dc67d70b5a45
(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 |
|
dc67d70b5a45
(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 |
return true; |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1017 |
} |
1885
4ce583a5275b
(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
|
1018 |
|
2073 | 1019 |
|
1020 |
void CSleep(int milliseconds) |
|
1021 |
{ |
|
1022 |
Sleep(milliseconds); |
|
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
1023 |
} |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1024 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1025 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1026 |
// Utility function to get the current timestamp in milliseconds |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1027 |
// Useful for profiling |
2139 | 1028 |
int64 GetTS(void) |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1029 |
{ |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1030 |
static double freq; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1031 |
__int64 value; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1032 |
if (!freq) { |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1033 |
QueryPerformanceFrequency((LARGE_INTEGER*)&value); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1034 |
freq = (double)1000000 / value; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1035 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1036 |
QueryPerformanceCounter((LARGE_INTEGER*)&value); |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1037 |
return (__int64)(value * freq); |
2139 | 1038 |
} |
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1039 |
|
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1040 |
/** Convert from OpenTTD's encoding to that of the local environment |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1041 |
* First convert from UTF8 to wide-char, then to local |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1042 |
* @param name pointer to a valid string that will be converted |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1043 |
* @return pointer to a new stringbuffer that contains the converted string */ |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1044 |
const wchar_t *OTTD2FS(const char *name) |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1045 |
{ |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1046 |
static wchar_t ucs2_buf[MAX_PATH]; |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1047 |
int len; |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1048 |
|
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1049 |
len = MultiByteToWideChar(CP_UTF8, 0, name, -1, ucs2_buf, lengthof(ucs2_buf)); |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1050 |
if (len == 0) { |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1051 |
DEBUG(misc, 0) ("[utf8] Error converting '%s'. Errno %d", name, GetLastError()); |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1052 |
return L""; |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1053 |
} |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1054 |
|
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1055 |
return (const wchar_t*)ucs2_buf; |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1056 |
} |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1057 |
|
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1058 |
/** Convert to OpenTTD's encoding from that of the local environment |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1059 |
* @param name pointer to a valid string that will be converted |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1060 |
* @return pointer to a new stringbuffer that contains the converted string */ |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1061 |
const char *FS2OTTD(const wchar_t *name) |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1062 |
{ |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1063 |
static char utf8_buf[512]; |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1064 |
int len; |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1065 |
|
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1066 |
len = WideCharToMultiByte(CP_UTF8, 0, name, -1, utf8_buf, lengthof(utf8_buf), NULL, NULL); |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1067 |
if (len == 0) { |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1068 |
DEBUG(misc, 0) ("[utf8] Error converting string. Errno %d", GetLastError()); |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1069 |
return ""; |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1070 |
} |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1071 |
|
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1072 |
return (const char*)utf8_buf; |
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1073 |
} |