author | Darkvater |
Sat, 05 Aug 2006 00:53:09 +0000 | |
changeset 4222 | 951fbf19b1ad |
parent 4221 | bb06fe8dcce2 |
child 4223 | 0f9535dda7ed |
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" |
2211 | 7 |
#include "hal.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
|
8 |
#include "macros.h" |
2162
c1ded3bd3d0c
(svn r2672) Move saving/loading related declarations to saveload.h
tron
parents:
2160
diff
changeset
|
9 |
#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
|
10 |
#include "string.h" |
0 | 11 |
#include "gfx.h" |
12 |
#include "window.h" |
|
13 |
#include <windows.h> |
|
14 |
#include <winnt.h> |
|
15 |
#include <wininet.h> |
|
16 |
#include <io.h> |
|
17 |
#include <fcntl.h> |
|
2160 | 18 |
#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
|
19 |
#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
|
20 |
#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
|
21 |
#include <ctype.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 |
||
796 | 28 |
#if defined(__MINGW32__) || defined(__CYGWIN__) |
0 | 29 |
#define __TIMESTAMP__ __DATE__ __TIME__ |
30 |
#endif |
|
31 |
||
3394
78963d9c1022
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
32 |
#if defined(__MINGW32__) |
78963d9c1022
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
33 |
#include <stdint.h> |
78963d9c1022
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
34 |
#endif |
0 | 35 |
|
2208 | 36 |
static bool cursor_visible = true; |
37 |
||
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
38 |
bool MyShowCursor(bool show) |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
39 |
{ |
2209 | 40 |
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
|
41 |
|
2209 | 42 |
cursor_visible = show; |
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
43 |
ShowCursor(show); |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
44 |
|
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
45 |
return !show; |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
46 |
} |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
47 |
|
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
48 |
|
0 | 49 |
// Helper function needed by dynamically loading SDL |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
50 |
bool LoadLibraryList(Function proc[], const char* dll) |
0 | 51 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
52 |
while (*dll != '\0') { |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
53 |
HMODULE lib = LoadLibrary(dll); |
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
54 |
|
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
55 |
if (lib == NULL) return false; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
56 |
for (;;) { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
57 |
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
|
58 |
|
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
59 |
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
|
60 |
if (*dll == '\0') break; |
0 | 61 |
p = GetProcAddress(lib, dll); |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
62 |
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
|
63 |
*proc++ = (Function)p; |
0 | 64 |
} |
65 |
dll++; |
|
66 |
} |
|
67 |
return true; |
|
68 |
} |
|
69 |
||
796 | 70 |
#ifdef _MSC_VER |
0 | 71 |
static const char *_exception_string; |
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
|
72 |
#endif |
0 | 73 |
|
74 |
void ShowOSErrorBox(const char *buf) |
|
75 |
{ |
|
76 |
MyShowCursor(true); |
|
77 |
MessageBoxA(GetActiveWindow(), buf, "Error!", MB_ICONSTOP); |
|
78 |
||
79 |
// if exception tracker is enabled, we crash here to let the exception handler handle it. |
|
80 |
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG) |
|
81 |
if (*buf == '!') { |
|
82 |
_exception_string = buf; |
|
83 |
*(byte*)0 = 0; |
|
84 |
} |
|
85 |
#endif |
|
86 |
} |
|
87 |
||
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
|
88 |
#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
|
89 |
|
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 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
|
0 | 96 |
typedef struct DebugFileInfo { |
97 |
uint32 size; |
|
98 |
uint32 crc32; |
|
99 |
SYSTEMTIME file_time; |
|
100 |
} DebugFileInfo; |
|
101 |
||
102 |
static uint32 *_crc_table; |
|
103 |
||
104 |
static void MakeCRCTable(uint32 *table) { |
|
105 |
uint32 crc, poly = 0xEDB88320L; |
|
2026 | 106 |
int i; |
107 |
int j; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
108 |
|
0 | 109 |
_crc_table = table; |
110 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
111 |
for (i = 0; i != 256; i++) { |
0 | 112 |
crc = i; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
113 |
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
|
114 |
crc = (crc & 1 ? (crc >> 1) ^ poly : crc >> 1); |
0 | 115 |
} |
116 |
table[i] = crc; |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
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
|
121 |
for (; size > 0; size--) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
122 |
crc = ((crc >> 8) & 0x00FFFFFF) ^ _crc_table[(crc ^ *data++) & 0xFF]; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
123 |
} |
0 | 124 |
return crc; |
125 |
} |
|
126 |
||
127 |
static void GetFileInfo(DebugFileInfo *dfi, const char *filename) |
|
128 |
{ |
|
129 |
memset(dfi, 0, sizeof(dfi)); |
|
130 |
||
131 |
{ |
|
132 |
HANDLE file; |
|
133 |
byte buffer[1024]; |
|
134 |
DWORD numread; |
|
135 |
uint32 filesize = 0; |
|
136 |
FILETIME write_time; |
|
137 |
uint32 crc = (uint32)-1; |
|
138 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
139 |
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
140 |
OPEN_EXISTING, 0, 0); |
0 | 141 |
if (file != INVALID_HANDLE_VALUE) { |
2952 | 142 |
for (;;) { |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
143 |
if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
144 |
numread == 0) |
0 | 145 |
break; |
146 |
filesize += numread; |
|
147 |
crc = CalcCRC(buffer, numread, crc); |
|
148 |
} |
|
149 |
dfi->size = filesize; |
|
150 |
dfi->crc32 = crc ^ (uint32)-1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
151 |
|
0 | 152 |
if (GetFileTime(file, NULL, NULL, &write_time)) { |
153 |
FileTimeToSystemTime(&write_time, &dfi->file_time); |
|
154 |
} |
|
155 |
CloseHandle(file); |
|
156 |
} |
|
157 |
} |
|
158 |
} |
|
159 |
||
160 |
||
161 |
static char *PrintModuleInfo(char *output, HMODULE mod) |
|
162 |
{ |
|
318
65ebd0cab39b
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
306
diff
changeset
|
163 |
char buffer[MAX_PATH]; |
0 | 164 |
DebugFileInfo dfi; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
165 |
|
0 | 166 |
GetModuleFileName(mod, buffer, MAX_PATH); |
167 |
GetFileInfo(&dfi, buffer); |
|
2458
c95808cd2ac9
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2428
diff
changeset
|
168 |
output += sprintf(output, " %-20s handle: %p size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n", |
0 | 169 |
buffer, |
170 |
mod, |
|
171 |
dfi.size, |
|
172 |
dfi.crc32, |
|
173 |
dfi.file_time.wYear, |
|
174 |
dfi.file_time.wMonth, |
|
175 |
dfi.file_time.wDay, |
|
176 |
dfi.file_time.wHour, |
|
177 |
dfi.file_time.wMinute, |
|
178 |
dfi.file_time.wSecond |
|
179 |
); |
|
180 |
return output; |
|
181 |
} |
|
182 |
||
183 |
static char *PrintModuleList(char *output) |
|
184 |
{ |
|
185 |
BOOL (WINAPI *EnumProcessModules)(HANDLE,HMODULE*,DWORD,LPDWORD); |
|
186 |
HANDLE proc; |
|
187 |
HMODULE modules[100]; |
|
188 |
DWORD needed; |
|
189 |
BOOL res; |
|
190 |
int count,i; |
|
191 |
||
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
192 |
if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0")) { |
0 | 193 |
proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); |
194 |
if (proc) { |
|
195 |
res = EnumProcessModules(proc, modules, sizeof(modules), &needed); |
|
196 |
CloseHandle(proc); |
|
197 |
if (res) { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
198 |
count = |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
199 |
min(needed / sizeof(HMODULE), lengthof(modules)); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
200 |
for (i = 0; i != count; i++) |
0 | 201 |
output = PrintModuleInfo(output, modules[i]); |
202 |
return output; |
|
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
output = PrintModuleInfo(output, NULL); |
|
207 |
return output; |
|
208 |
} |
|
209 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
210 |
static const char _crash_desc[] = |
0 | 211 |
"A serious fault condition occured in the game. The game will shut down.\n" |
212 |
"Press \"Submit report\" to send crash information to the developers. " |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
213 |
"This will greatly help debugging. " |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
214 |
"The information contained in the report is displayed below.\n" |
0 | 215 |
"Press \"Emergency save\" to attempt saving the game."; |
216 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
217 |
static const char _save_succeeded[] = |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
218 |
"Emergency save succeeded.\n" |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
219 |
"Be aware that critical parts of the internal game state may have become " |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
220 |
"corrupted. The saved game is not guaranteed to work."; |
0 | 221 |
|
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
|
222 |
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
|
223 |
{ |
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 |
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
|
225 |
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
|
226 |
} |
0 | 227 |
|
228 |
typedef struct { |
|
229 |
HINTERNET (WINAPI *InternetOpenA)(LPCSTR,DWORD, LPCSTR, LPCSTR, DWORD); |
|
230 |
HINTERNET (WINAPI *InternetConnectA)(HINTERNET, LPCSTR, INTERNET_PORT, LPCSTR, LPCSTR, DWORD, DWORD, DWORD); |
|
231 |
HINTERNET (WINAPI *HttpOpenRequestA)(HINTERNET, LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPCSTR *, DWORD, DWORD); |
|
232 |
BOOL (WINAPI *HttpSendRequestA)(HINTERNET, LPCSTR, DWORD, LPVOID, DWORD); |
|
233 |
BOOL (WINAPI *InternetCloseHandle)(HINTERNET); |
|
234 |
BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD); |
|
235 |
} WinInetProcs; |
|
236 |
||
237 |
#define M(x) x "\0" |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
238 |
static const char wininet_files[] = |
0 | 239 |
M("wininet.dll") |
240 |
M("InternetOpenA") |
|
241 |
M("InternetConnectA") |
|
242 |
M("HttpOpenRequestA") |
|
243 |
M("HttpSendRequestA") |
|
244 |
M("InternetCloseHandle") |
|
245 |
M("HttpQueryInfoA") |
|
246 |
M(""); |
|
247 |
#undef M |
|
248 |
||
249 |
static WinInetProcs _wininet; |
|
250 |
||
251 |
||
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
252 |
static const char *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const char *arg) |
0 | 253 |
{ |
254 |
HINTERNET inet, conn, http; |
|
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
255 |
const char *err = NULL; |
0 | 256 |
DWORD code, len; |
257 |
static char buf[100]; |
|
258 |
char buff[100]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
259 |
|
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
260 |
if (_wininet.InternetOpen == NULL && !LoadLibraryList((Function*)&_wininet, wininet_files)) return "can't load wininet.dll"; |
0 | 261 |
|
1957
2a4aa85373c3
(svn r2463) - Fix: partly revert the strncat madness and update nightly script (invisible) to correctly insert date.
Darkvater
parents:
1953
diff
changeset
|
262 |
inet = _wininet.InternetOpen("OTTD", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); |
0 | 263 |
if (inet == NULL) { err = "internetopen failed"; goto error1; } |
264 |
||
265 |
conn = _wininet.InternetConnect(inet, "openttd.com", INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0); |
|
266 |
if (conn == NULL) { err = "internetconnect failed"; goto error2; } |
|
267 |
||
268 |
sprintf(buff, "/crash.php?file=%s&ident=%d", arg, _ident); |
|
269 |
||
270 |
http = _wininet.HttpOpenRequest(conn, "POST", buff, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE , 0); |
|
271 |
if (http == NULL) { err = "httpopenrequest failed"; goto error3; } |
|
272 |
||
273 |
if (!_wininet.HttpSendRequest(http, "Content-type: application/binary", -1, msg, msglen)) { err = "httpsendrequest failed"; goto error4; } |
|
274 |
||
275 |
len = sizeof(code); |
|
276 |
if (!_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &len, 0)) { err = "httpqueryinfo failed"; goto error4; } |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
277 |
|
0 | 278 |
if (code != 200) { |
279 |
int l = sprintf(buf, "Server said: %d ", code); |
|
280 |
len = sizeof(buf) - l; |
|
281 |
_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_TEXT, buf + l, &len, 0); |
|
282 |
err = buf; |
|
283 |
} |
|
284 |
||
285 |
error4: |
|
286 |
_wininet.InternetCloseHandle(http); |
|
287 |
error3: |
|
288 |
_wininet.InternetCloseHandle(conn); |
|
289 |
error2: |
|
290 |
_wininet.InternetCloseHandle(inet); |
|
291 |
error1: |
|
292 |
return err; |
|
293 |
} |
|
294 |
||
295 |
static void SubmitFile(HWND wnd, const char *file) |
|
296 |
{ |
|
297 |
HANDLE h; |
|
298 |
unsigned long size; |
|
299 |
unsigned long read; |
|
300 |
void *mem; |
|
301 |
||
302 |
h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
|
303 |
if (h == NULL) return; |
|
304 |
||
305 |
size = GetFileSize(h, NULL); |
|
306 |
if (size > 500000) goto error1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
307 |
|
0 | 308 |
mem = malloc(size); |
309 |
if (mem == NULL) goto error1; |
|
310 |
||
311 |
if (!ReadFile(h, mem, size, &read, NULL) || read != size) goto error2; |
|
312 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
313 |
SubmitCrashReport(wnd, mem, size, file); |
0 | 314 |
|
315 |
error2: |
|
316 |
free(mem); |
|
317 |
error1: |
|
318 |
CloseHandle(h); |
|
319 |
} |
|
320 |
||
321 |
static const char * const _expand_texts[] = {"S&how report >>", "&Hide report <<" }; |
|
322 |
||
323 |
static void SetWndSize(HWND wnd, int mode) |
|
324 |
{ |
|
325 |
RECT r,r2; |
|
326 |
int offs; |
|
327 |
||
328 |
GetWindowRect(wnd, &r); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
329 |
|
0 | 330 |
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
|
331 |
|
0 | 332 |
if (mode >= 0) { |
333 |
GetWindowRect(GetDlgItem(wnd, 11), &r2); |
|
334 |
offs = r2.bottom - r2.top + 10; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
335 |
if (!mode) offs = -offs; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
336 |
SetWindowPos(wnd, HWND_TOPMOST, 0, 0, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
337 |
r.right - r.left, r.bottom - r.top + offs, SWP_NOMOVE | SWP_NOZORDER); |
0 | 338 |
} else { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
339 |
SetWindowPos(wnd, HWND_TOPMOST, |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
340 |
(GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
341 |
(GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2, |
0 | 342 |
0, 0, SWP_NOSIZE); |
343 |
} |
|
344 |
} |
|
345 |
||
346 |
static bool DoEmergencySave(HWND wnd) |
|
347 |
{ |
|
348 |
bool b = false; |
|
349 |
||
350 |
EnableWindow(GetDlgItem(wnd, 13), FALSE); |
|
351 |
_did_emerg_save = true; |
|
352 |
__try { |
|
353 |
b = EmergencySave(); |
|
354 |
} __except (1) {} |
|
355 |
return b; |
|
356 |
} |
|
357 |
||
2458
c95808cd2ac9
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2428
diff
changeset
|
358 |
static INT_PTR CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam) |
0 | 359 |
{ |
2952 | 360 |
switch (msg) { |
0 | 361 |
case WM_INITDIALOG: |
362 |
SetDlgItemText(wnd, 10, _crash_desc); |
|
363 |
SetDlgItemText(wnd, 11, _crash_msg); |
|
364 |
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE); |
|
365 |
SetWndSize(wnd, -1); |
|
366 |
return TRUE; |
|
367 |
case WM_COMMAND: |
|
2952 | 368 |
switch (wParam) { |
0 | 369 |
case 12: // Close |
370 |
ExitProcess(0); |
|
371 |
case 13: { // Emergency save |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
372 |
if (DoEmergencySave(wnd)) { |
0 | 373 |
MessageBoxA(wnd, _save_succeeded, "Save successful", MB_ICONINFORMATION); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
374 |
} else { |
0 | 375 |
MessageBoxA(wnd, "Save failed", "Save failed", MB_ICONINFORMATION); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
376 |
} |
0 | 377 |
break; |
378 |
} |
|
379 |
case 14: { // Submit crash report |
|
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
380 |
const char *s; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
381 |
|
0 | 382 |
SetCursor(LoadCursor(NULL, IDC_WAIT)); |
383 |
||
384 |
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), ""); |
|
385 |
if (s) { |
|
386 |
MessageBoxA(wnd, s, "Error", MB_ICONSTOP); |
|
387 |
break; |
|
388 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
389 |
|
0 | 390 |
// try to submit emergency savegame |
391 |
if (_did_emerg_save || DoEmergencySave(wnd)) { |
|
392 |
SubmitFile(wnd, "crash.sav"); |
|
393 |
} |
|
394 |
// try to submit the autosaved game |
|
395 |
if (_opt.autosave) { |
|
396 |
char buf[40]; |
|
397 |
sprintf(buf, "autosave%d.sav", (_autosave_ctr - 1) & 3); |
|
398 |
SubmitFile(wnd, buf); |
|
399 |
} |
|
400 |
EnableWindow(GetDlgItem(wnd, 14), FALSE); |
|
401 |
SetCursor(LoadCursor(NULL, IDC_ARROW)); |
|
402 |
MessageBoxA(wnd, "Crash report submitted. Thank you.", "Crash Report", MB_ICONINFORMATION); |
|
403 |
break; |
|
404 |
} |
|
405 |
case 15: // Expand |
|
406 |
_expanded ^= 1; |
|
407 |
SetWndSize(wnd, _expanded); |
|
408 |
break; |
|
409 |
} |
|
410 |
return TRUE; |
|
411 |
case WM_CLOSE: |
|
412 |
ExitProcess(0); |
|
413 |
} |
|
414 |
||
415 |
return FALSE; |
|
416 |
} |
|
417 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
418 |
static void Handler2(void) |
0 | 419 |
{ |
420 |
ShowCursor(TRUE); |
|
421 |
ShowWindow(GetActiveWindow(), FALSE); |
|
422 |
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(100), NULL, CrashDialogFunc); |
|
423 |
} |
|
424 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
425 |
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
|
426 |
|
0 | 427 |
static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) |
428 |
{ |
|
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
|
429 |
extern const char _openttd_revision[]; |
0 | 430 |
char *output; |
431 |
static bool had_exception; |
|
432 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
433 |
if (had_exception) ExitProcess(0); |
0 | 434 |
had_exception = true; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
435 |
|
0 | 436 |
_ident = GetTickCount(); // something pretty unique |
437 |
||
438 |
MakeCRCTable(alloca(256 * sizeof(uint32))); |
|
439 |
_crash_msg = output = LocalAlloc(LMEM_FIXED, 8192); |
|
440 |
||
441 |
{ |
|
442 |
SYSTEMTIME time; |
|
443 |
GetLocalTime(&time); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
444 |
output += sprintf(output, |
0 | 445 |
"*** OpenTTD Crash Report ***\r\n" |
446 |
"Date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n" |
|
447 |
"Build: %s built on " __TIMESTAMP__ "\r\n", |
|
448 |
time.wYear, |
|
449 |
time.wMonth, |
|
450 |
time.wDay, |
|
451 |
time.wHour, |
|
452 |
time.wMinute, |
|
453 |
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
|
454 |
_openttd_revision |
0 | 455 |
); |
456 |
} |
|
457 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
458 |
if (_exception_string) |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
459 |
output += sprintf(output, "Reason: %s\r\n", _exception_string); |
0 | 460 |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
461 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
462 |
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
|
463 |
"Registers:\r\n" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
464 |
"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
|
465 |
"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
|
466 |
"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
|
467 |
"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
|
468 |
"RIP: %.16llX EFLAGS: %.8X\r\n" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
469 |
"\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
|
470 |
ep->ExceptionRecord->ExceptionCode, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
471 |
ep->ExceptionRecord->ExceptionAddress, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
472 |
ep->ContextRecord->Rax, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
473 |
ep->ContextRecord->Rbx, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
474 |
ep->ContextRecord->Rcx, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
475 |
ep->ContextRecord->Rdx, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
476 |
ep->ContextRecord->Rsi, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
477 |
ep->ContextRecord->Rdi, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
478 |
ep->ContextRecord->Rbp, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
479 |
ep->ContextRecord->Rsp, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
480 |
ep->ContextRecord->R8, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
481 |
ep->ContextRecord->R9, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
482 |
ep->ContextRecord->R10, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
483 |
ep->ContextRecord->R11, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
484 |
ep->ContextRecord->R12, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
485 |
ep->ContextRecord->R13, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
486 |
ep->ContextRecord->R14, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
487 |
ep->ContextRecord->R15, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
488 |
ep->ContextRecord->Rip, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
489 |
ep->ContextRecord->EFlags |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
490 |
); |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
491 |
#else |
0 | 492 |
output += sprintf(output, "Exception %.8X at %.8X\r\n" |
493 |
"Registers:\r\n" |
|
494 |
" EAX: %.8X EBX: %.8X ECX: %.8X EDX: %.8X\r\n" |
|
495 |
" ESI: %.8X EDI: %.8X EBP: %.8X ESP: %.8X\r\n" |
|
496 |
" EIP: %.8X EFLAGS: %.8X\r\n" |
|
497 |
"\r\nBytes at CS:EIP:\r\n", |
|
498 |
ep->ExceptionRecord->ExceptionCode, |
|
499 |
ep->ExceptionRecord->ExceptionAddress, |
|
500 |
ep->ContextRecord->Eax, |
|
501 |
ep->ContextRecord->Ebx, |
|
502 |
ep->ContextRecord->Ecx, |
|
503 |
ep->ContextRecord->Edx, |
|
504 |
ep->ContextRecord->Esi, |
|
505 |
ep->ContextRecord->Edi, |
|
506 |
ep->ContextRecord->Ebp, |
|
507 |
ep->ContextRecord->Esp, |
|
508 |
ep->ContextRecord->Eip, |
|
509 |
ep->ContextRecord->EFlags |
|
510 |
); |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
511 |
#endif |
0 | 512 |
|
513 |
{ |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
514 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
515 |
byte *b = (byte*)ep->ContextRecord->Rip; |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
516 |
#else |
0 | 517 |
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
|
518 |
#endif |
0 | 519 |
int i; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
520 |
for (i = 0; i != 24; i++) { |
0 | 521 |
if (IsBadReadPtr(b, 1)) { |
522 |
output += sprintf(output, " ??"); // OCR: WAS: , 0); |
|
523 |
} else { |
|
524 |
output += sprintf(output, " %.2X", *b); |
|
525 |
} |
|
526 |
b++; |
|
527 |
} |
|
528 |
output += sprintf(output, |
|
529 |
"\r\n" |
|
530 |
"\r\nStack trace: \r\n" |
|
531 |
); |
|
532 |
} |
|
533 |
||
534 |
{ |
|
535 |
int i,j; |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
536 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
537 |
uint32 *b = (uint32*)ep->ContextRecord->Rsp; |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
538 |
#else |
0 | 539 |
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
|
540 |
#endif |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
541 |
for (j = 0; j != 24; j++) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
542 |
for (i = 0; i != 8; i++) { |
0 | 543 |
if (IsBadReadPtr(b,sizeof(uint32))) { |
544 |
output += sprintf(output, " ????????"); //OCR: WAS - , 0); |
|
545 |
} else { |
|
546 |
output += sprintf(output, " %.8X", *b); |
|
547 |
} |
|
548 |
b++; |
|
549 |
} |
|
550 |
output += sprintf(output, "\r\n"); |
|
551 |
} |
|
552 |
} |
|
553 |
||
554 |
output += sprintf(output, "\r\nModule information:\r\n"); |
|
555 |
output = PrintModuleList(output); |
|
556 |
||
557 |
{ |
|
558 |
OSVERSIONINFO os; |
|
559 |
os.dwOSVersionInfoSize = sizeof(os); |
|
560 |
GetVersionEx(&os); |
|
561 |
output += sprintf(output, "\r\nSystem information:\r\n" |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
562 |
" Windows version %d.%d %d %s\r\n", |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
563 |
os.dwMajorVersion, os.dwMinorVersion, os.dwBuildNumber, os.szCSDVersion); |
0 | 564 |
} |
565 |
||
566 |
{ |
|
567 |
HANDLE file = CreateFile("crash.log", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); |
|
568 |
DWORD num_written; |
|
569 |
if (file != INVALID_HANDLE_VALUE) { |
|
570 |
WriteFile(file, _crash_msg, output - _crash_msg, &num_written, NULL); |
|
571 |
CloseHandle(file); |
|
572 |
} |
|
573 |
} |
|
574 |
||
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
|
575 |
/* 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
|
576 |
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
|
577 |
|
0 | 578 |
if (_safe_esp) { |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
579 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
580 |
ep->ContextRecord->Rip = (DWORD64)Handler2; |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
581 |
ep->ContextRecord->Rsp = (DWORD64)_safe_esp; |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
582 |
#else |
0 | 583 |
ep->ContextRecord->Eip = (DWORD)Handler2; |
584 |
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
|
585 |
#endif |
0 | 586 |
return EXCEPTION_CONTINUE_EXECUTION; |
587 |
} |
|
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
|
588 |
|
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 |
|
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 |
return EXCEPTION_EXECUTE_HANDLER; |
0 | 591 |
} |
592 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
593 |
static void Win32InitializeExceptions(void) |
0 | 594 |
{ |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
595 |
#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
|
596 |
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
|
597 |
_safe_esp = _get_save_esp(); |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
598 |
#else |
0 | 599 |
_asm { |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
600 |
mov _safe_esp, esp |
0 | 601 |
} |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
602 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
603 |
|
0 | 604 |
SetUnhandledExceptionFilter(ExceptionHandler); |
605 |
} |
|
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
|
606 |
#endif /* _MSC_VER */ |
0 | 607 |
|
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
608 |
/* 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
|
609 |
* 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
|
610 |
* 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
|
611 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
612 |
/* 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
|
613 |
* this avoids hundreds of alloc/free which would fragment the heap. |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
614 |
* To guarantee thread-safety, we fall back to malloc if the instance is |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
615 |
* 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
|
616 |
* 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
|
617 |
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
|
618 |
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
|
619 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
620 |
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
|
621 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
622 |
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
|
623 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
624 |
if (_global_dir_is_in_use) { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
625 |
d = calloc(1, sizeof(DIR)); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
626 |
} else { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
627 |
_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
|
628 |
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
|
629 |
memset(d, 0, sizeof(DIR)); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
630 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
631 |
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
|
632 |
} |
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 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
|
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 |
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
|
637 |
_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
|
638 |
} else { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
639 |
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
|
640 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
641 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
642 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
643 |
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
|
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 |
char search_path[MAX_PATH]; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
646 |
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
|
647 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
648 |
DWORD fa = GetFileAttributes(path); |
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 |
/* not a directory or path not found */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
651 |
if (fa == INVALID_FILE_ATTRIBUTES || (fa & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
652 |
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
|
653 |
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
|
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 |
d = dir_calloc(); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
657 |
if (d == NULL) { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
658 |
errno = ENOMEM; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
659 |
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
|
660 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
661 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
662 |
/* build search path for FindFirstFile */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
663 |
snprintf(search_path, lengthof(search_path), "%s" PATHSEP "*", path); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
664 |
d->hFind = FindFirstFile(search_path, &d->fd); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
665 |
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
|
666 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
667 |
if (d->hFind == INVALID_HANDLE_VALUE) { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
668 |
/* not an error - the directory is just empty */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
669 |
if (GetLastError() == ERROR_NO_MORE_FILES) 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
|
670 |
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
|
671 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
672 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
673 |
d->ent.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
|
674 |
d->at_first_entry = true; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
675 |
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
|
676 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
677 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
678 |
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
|
679 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
680 |
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
|
681 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
682 |
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
|
683 |
/* 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
|
684 |
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
|
685 |
d->at_first_entry = false; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
686 |
goto already_have_file; |
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 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
689 |
/* Go until the end of directory or until a valid entry was found */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
690 |
if (!FindNextFile(d->hFind, &d->fd)) { // determine cause and bail |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
691 |
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
|
692 |
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
|
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 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
695 |
already_have_file: |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
696 |
/* 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
|
697 |
* (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
|
698 |
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
|
699 |
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
|
700 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
701 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
702 |
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
|
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 |
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
|
705 |
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
|
706 |
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
|
707 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
708 |
|
4220
86ca889037b3
(svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
4219
diff
changeset
|
709 |
extern char *_fios_path; |
86ca889037b3
(svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
4219
diff
changeset
|
710 |
extern FiosItem *_fios_items; |
86ca889037b3
(svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
4219
diff
changeset
|
711 |
extern int _fios_count, _fios_alloc; |
0 | 712 |
|
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
|
713 |
bool FiosIsRoot(const char *file) |
0 | 714 |
{ |
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
|
715 |
return file[3] == '\0'; // C:\... |
0 | 716 |
} |
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 |
void FiosGetDrives(void) |
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 |
char drives[256]; |
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
|
721 |
const char *s; |
0 | 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 |
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
|
724 |
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
|
725 |
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
|
726 |
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
|
727 |
fios->mtime = 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
|
728 |
snprintf(fios->name, lengthof(fios->name), "%c:", 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
|
729 |
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
|
730 |
while (*s++ != '\0'); |
0 | 731 |
} |
732 |
} |
|
733 |
||
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 |
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) |
0 | 735 |
{ |
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
|
736 |
const WIN32_FIND_DATA *fd = &ent->dir->fd; |
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
|
737 |
if ((fd->dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0) return false; |
0 | 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 |
sb->st_size = (fd->nFileSizeHigh * MAXDWORD+1) + fd->nFileSizeLow; |
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
|
740 |
sb->st_mtime = (fd->ftLastWriteTime.dwHighDateTime * MAXDWORD+1) + fd->ftLastWriteTime.dwLowDateTime; |
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
|
741 |
sb->st_mode = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG; |
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
|
742 |
return true; |
0 | 743 |
} |
744 |
||
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
745 |
bool FiosGetDiskFreeSpace(const char *path, uint32 *tot) |
0 | 746 |
{ |
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
|
747 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
748 |
bool retval = false; |
0 | 749 |
char root[4]; |
750 |
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
|
751 |
|
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
752 |
snprintf(root, lengthof(root), "%c:" 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
|
753 |
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
|
754 |
*tot = ((spc * bps) * (uint64)nfc) >> 20; |
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
755 |
retval = true; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
756 |
} |
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
|
757 |
|
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
|
758 |
SetErrorMode(sem); // reset previous setting |
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
759 |
return retval; |
0 | 760 |
} |
761 |
||
762 |
static int ParseCommandLine(char *line, char **argv, int max_argc) |
|
763 |
{ |
|
764 |
int n = 0; |
|
765 |
||
766 |
do { |
|
767 |
// skip whitespace |
|
768 |
while (*line == ' ' || *line == '\t') |
|
769 |
line++; |
|
770 |
||
771 |
// end? |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
772 |
if (*line == '\0') |
0 | 773 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
774 |
|
0 | 775 |
// special handling when quoted |
776 |
if (*line == '"') { |
|
777 |
argv[n++] = ++line; |
|
778 |
while (*line != '"') { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
779 |
if (*line == '\0') return n; |
0 | 780 |
line++; |
781 |
} |
|
782 |
} else { |
|
783 |
argv[n++] = line; |
|
784 |
while (*line != ' ' && *line != '\t') { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
785 |
if (*line == '\0') return n; |
0 | 786 |
line++; |
787 |
} |
|
788 |
} |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
789 |
*line++ = '\0'; |
0 | 790 |
} while (n != max_argc); |
791 |
||
792 |
return n; |
|
793 |
} |
|
794 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
795 |
void CreateConsole(void) |
0 | 796 |
{ |
797 |
HANDLE hand; |
|
798 |
CONSOLE_SCREEN_BUFFER_INFO coninfo; |
|
799 |
||
800 |
if (_has_console) return; |
|
801 |
||
802 |
_has_console = true; |
|
803 |
||
804 |
AllocConsole(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
805 |
|
0 | 806 |
hand = GetStdHandle(STD_OUTPUT_HANDLE); |
807 |
GetConsoleScreenBufferInfo(hand, &coninfo); |
|
808 |
coninfo.dwSize.Y = 500; |
|
809 |
SetConsoleScreenBufferSize(hand, coninfo.dwSize); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
810 |
|
0 | 811 |
// redirect unbuffered STDIN, STDOUT, STDERR to the console |
2172 | 812 |
#if !defined(__CYGWIN__) |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
813 |
*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
|
814 |
*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
|
815 |
*stderr = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); |
0 | 816 |
#else |
817 |
// open_osfhandle is not in cygwin |
|
818 |
*stdout = *fdopen(1, "w" ); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
819 |
*stdin = *fdopen(0, "r" ); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
820 |
*stderr = *fdopen(2, "w" ); |
0 | 821 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
822 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
823 |
setvbuf(stdin, NULL, _IONBF, 0); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
824 |
setvbuf(stdout, NULL, _IONBF, 0); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
825 |
setvbuf(stderr, NULL, _IONBF, 0); |
0 | 826 |
} |
827 |
||
828 |
void ShowInfo(const char *str) |
|
829 |
{ |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
830 |
if (_has_console) { |
0 | 831 |
puts(str); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
832 |
} else { |
0 | 833 |
bool old; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
834 |
|
0 | 835 |
ReleaseCapture(); |
836 |
_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
|
837 |
|
0 | 838 |
old = MyShowCursor(true); |
839 |
if (MessageBoxA(GetActiveWindow(), str, "OpenTTD", MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) { |
|
840 |
CreateConsole(); |
|
841 |
} |
|
842 |
MyShowCursor(old); |
|
843 |
} |
|
844 |
} |
|
845 |
||
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
|
846 |
#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
|
847 |
/* _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
|
848 |
#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
|
849 |
#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
|
850 |
#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
|
851 |
#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
|
852 |
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
|
853 |
#endif |
0 | 854 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
855 |
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
856 |
LPTSTR lpCmdLine, int nCmdShow) |
0 | 857 |
{ |
858 |
int argc; |
|
859 |
char *argv[64]; // max 64 command line arguments |
|
860 |
||
861 |
#if defined(_DEBUG) |
|
862 |
CreateConsole(); |
|
863 |
#endif |
|
864 |
||
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
|
865 |
_set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox |
0 | 866 |
|
867 |
// setup random seed to something quite random |
|
206 | 868 |
_random_seeds[0][0] = GetTickCount(); |
869 |
_random_seeds[0][1] = _random_seeds[0][0] * 0x1234567; |
|
2073 | 870 |
SeedMT(_random_seeds[0][0]); |
0 | 871 |
|
872 |
argc = ParseCommandLine(GetCommandLine(), argv, lengthof(argv)); |
|
873 |
||
874 |
#if defined(WIN32_EXCEPTION_TRACKER) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
875 |
{ |
0 | 876 |
Win32InitializeExceptions(); |
877 |
} |
|
878 |
#endif |
|
879 |
||
880 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
881 |
_try { |
|
882 |
uint32 _stdcall ExceptionHandler(void *ep); |
|
883 |
#endif |
|
884 |
ttd_main(argc, argv); |
|
885 |
||
886 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
887 |
} _except (ExceptionHandler(_exception_info())) {} |
|
888 |
#endif |
|
889 |
||
890 |
return 0; |
|
891 |
} |
|
892 |
||
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
|
893 |
void DeterminePaths(void) |
0 | 894 |
{ |
895 |
char *s; |
|
896 |
char *cfg; |
|
897 |
||
898 |
_path.personal_dir = _path.game_data_dir = cfg = malloc(MAX_PATH); |
|
899 |
GetCurrentDirectory(MAX_PATH - 1, cfg); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
900 |
|
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
|
901 |
cfg[0] = toupper(cfg[0]); |
0 | 902 |
s = strchr(cfg, 0); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
903 |
if (s[-1] != '\\') strcpy(s, "\\"); |
0 | 904 |
|
905 |
_path.save_dir = str_fmt("%ssave", cfg); |
|
906 |
_path.autosave_dir = str_fmt("%s\\autosave", _path.save_dir); |
|
907 |
_path.scenario_dir = str_fmt("%sscenario", cfg); |
|
908 |
_path.gm_dir = str_fmt("%sgm\\", cfg); |
|
909 |
_path.data_dir = str_fmt("%sdata\\", cfg); |
|
910 |
_path.lang_dir = str_fmt("%slang\\", cfg); |
|
911 |
||
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
|
912 |
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
|
913 |
_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
|
914 |
|
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
|
915 |
_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
|
916 |
_log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
0 | 917 |
|
918 |
// make (auto)save and scenario folder |
|
919 |
CreateDirectory(_path.save_dir, NULL); |
|
920 |
CreateDirectory(_path.autosave_dir, NULL); |
|
921 |
CreateDirectory(_path.scenario_dir, NULL); |
|
922 |
} |
|
923 |
||
1022
9ea8ee93d6a9
(svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents:
983
diff
changeset
|
924 |
int CDECL snprintf(char *str, size_t size, const char *format, ...) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
925 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
926 |
va_list ap; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
927 |
int ret; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
928 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
929 |
va_start(ap, format); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
930 |
ret = vsnprintf(str, size, format, ap); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
931 |
va_end(ap); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
932 |
return ret; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
933 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
934 |
|
2764
6225ab46af43
(svn r3309) Cygwin doesn't define _MSC_VER; check it exists before basing decisions on its value.
peter1138
parents:
2639
diff
changeset
|
935 |
#ifdef _MSC_VER |
1022
9ea8ee93d6a9
(svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents:
983
diff
changeset
|
936 |
int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
937 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
938 |
int ret; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
939 |
ret = _vsnprintf(str, size, format, ap); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
940 |
if (ret < 0) str[size - 1] = '\0'; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
941 |
return ret; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
942 |
} |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
943 |
#endif |
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
|
944 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
945 |
/** |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
946 |
* 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
|
947 |
* 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
|
948 |
* 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
|
949 |
* @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
|
950 |
* @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
|
951 |
*/ |
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 |
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
|
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 |
if (IsClipboardFormatAvailable(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
|
955 |
HGLOBAL 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
|
956 |
const byte *data, *dataptr; |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
957 |
uint16 width = 0; |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
958 |
uint16 length = 0; |
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 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
960 |
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
|
961 |
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
|
962 |
data = GlobalLock(cbuf); // clipboard data |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
963 |
dataptr = data; |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
964 |
|
3458
d3a6ddfa6784
(svn r4301) - Fix: the maxlength parameter of Textbuf is supposed to be the size of the buffer (so length of string + '\0'), but in the code it was a mix of both. It didn't cause any problems though, only an occasionaly one-less character than allowed. (thanks Tron for noticing)
Darkvater
parents:
3394
diff
changeset
|
965 |
for (; IsValidAsciiChar(*dataptr) && (tb->length + length) < (tb->maxlength - 1) && |
3799
7f989f09828d
(svn r4807) - Fix: win32 compilation was broken by r4802
glx
parents:
3649
diff
changeset
|
966 |
(tb->maxwidth == 0 || width + tb->width + GetCharacterWidth(FS_NORMAL, (byte)*dataptr) <= tb->maxwidth); dataptr++) { |
7f989f09828d
(svn r4807) - Fix: win32 compilation was broken by r4802
glx
parents:
3649
diff
changeset
|
967 |
width += GetCharacterWidth(FS_NORMAL, (byte)*dataptr); |
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
|
968 |
length++; |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
969 |
} |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
970 |
|
3458
d3a6ddfa6784
(svn r4301) - Fix: the maxlength parameter of Textbuf is supposed to be the size of the buffer (so length of string + '\0'), but in the code it was a mix of both. It didn't cause any problems though, only an occasionaly one-less character than allowed. (thanks Tron for noticing)
Darkvater
parents:
3394
diff
changeset
|
971 |
if (length == 0) 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
|
972 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
973 |
memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos); |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
974 |
memcpy(tb->buf + tb->caretpos, data, length); |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
975 |
tb->width += width; |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
976 |
tb->caretxoffs += width; |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
977 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
978 |
tb->length += length; |
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 |
tb->caretpos += length; |
3458
d3a6ddfa6784
(svn r4301) - Fix: the maxlength parameter of Textbuf is supposed to be the size of the buffer (so length of string + '\0'), but in the code it was a mix of both. It didn't cause any problems though, only an occasionaly one-less character than allowed. (thanks Tron for noticing)
Darkvater
parents:
3394
diff
changeset
|
980 |
tb->buf[tb->length] = '\0'; // terminating zero |
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
|
981 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
982 |
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
|
983 |
CloseClipboard(); |
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 |
return true; |
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 |
} |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
986 |
return false; |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
987 |
} |
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
|
988 |
|
2073 | 989 |
|
990 |
void CSleep(int milliseconds) |
|
991 |
{ |
|
992 |
Sleep(milliseconds); |
|
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
993 |
} |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
994 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
995 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
996 |
// 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
|
997 |
// Useful for profiling |
2139 | 998 |
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
|
999 |
{ |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1000 |
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
|
1001 |
__int64 value; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1002 |
if (!freq) { |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1003 |
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
|
1004 |
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
|
1005 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1006 |
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
|
1007 |
return (__int64)(value * freq); |
2139 | 1008 |
} |