author | miham |
Wed, 17 Aug 2005 12:30:07 +0000 | |
changeset 2349 | df02d0ffb588 |
parent 2338 | 8b953706648a |
child 2428 | b2e4fb6665d0 |
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" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
424
diff
changeset
|
11 |
#include "table/strings.h" |
0 | 12 |
#include "gfx.h" |
13 |
#include "window.h" |
|
14 |
#include <windows.h> |
|
15 |
#include <winnt.h> |
|
16 |
#include <wininet.h> |
|
17 |
#include <io.h> |
|
18 |
#include <fcntl.h> |
|
2160 | 19 |
#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
|
20 |
#include "win32.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
|
21 |
|
0 | 22 |
static bool _has_console; |
23 |
||
796 | 24 |
#if defined(__MINGW32__) || defined(__CYGWIN__) |
0 | 25 |
#define __TIMESTAMP__ __DATE__ __TIME__ |
26 |
#endif |
|
27 |
||
28 |
||
2208 | 29 |
static bool cursor_visible = true; |
30 |
||
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
31 |
bool MyShowCursor(bool show) |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
32 |
{ |
2209 | 33 |
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
|
34 |
|
2209 | 35 |
cursor_visible = show; |
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
36 |
ShowCursor(show); |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
37 |
|
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
38 |
return !show; |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
39 |
} |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
40 |
|
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
41 |
|
0 | 42 |
// 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
|
43 |
bool LoadLibraryList(Function proc[], const char* dll) |
0 | 44 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
|
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
48 |
if (lib == NULL) return false; |
0 | 49 |
while (true) { |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
50 |
FARPROC p; |
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
51 |
|
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
52 |
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
|
53 |
if (*dll == '\0') break; |
0 | 54 |
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
|
55 |
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
|
56 |
*proc++ = (Function)p; |
0 | 57 |
} |
58 |
dll++; |
|
59 |
} |
|
60 |
return true; |
|
61 |
} |
|
62 |
||
796 | 63 |
#ifdef _MSC_VER |
64 |
||
0 | 65 |
static const char *_exception_string; |
66 |
static void *_safe_esp; |
|
67 |
static char *_crash_msg; |
|
68 |
static bool _expanded; |
|
69 |
static bool _did_emerg_save; |
|
70 |
static int _ident; |
|
71 |
||
72 |
void ShowOSErrorBox(const char *buf) |
|
73 |
{ |
|
74 |
MyShowCursor(true); |
|
75 |
MessageBoxA(GetActiveWindow(), buf, "Error!", MB_ICONSTOP); |
|
76 |
||
77 |
// if exception tracker is enabled, we crash here to let the exception handler handle it. |
|
78 |
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG) |
|
79 |
if (*buf == '!') { |
|
80 |
_exception_string = buf; |
|
81 |
*(byte*)0 = 0; |
|
82 |
} |
|
83 |
#endif |
|
84 |
} |
|
85 |
||
86 |
typedef struct DebugFileInfo { |
|
87 |
uint32 size; |
|
88 |
uint32 crc32; |
|
89 |
SYSTEMTIME file_time; |
|
90 |
} DebugFileInfo; |
|
91 |
||
92 |
static uint32 *_crc_table; |
|
93 |
||
94 |
static void MakeCRCTable(uint32 *table) { |
|
95 |
uint32 crc, poly = 0xEDB88320L; |
|
2026 | 96 |
int i; |
97 |
int j; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
98 |
|
0 | 99 |
_crc_table = table; |
100 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
101 |
for (i = 0; i != 256; i++) { |
0 | 102 |
crc = i; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
103 |
for (j = 8; j != 0; j--) { |
0 | 104 |
if (crc & 1) |
105 |
crc = (crc >> 1) ^ poly; |
|
106 |
else |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
107 |
crc >>= 1; |
0 | 108 |
} |
109 |
table[i] = crc; |
|
110 |
} |
|
111 |
} |
|
112 |
||
113 |
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
|
114 |
for (; size > 0; size--) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
115 |
crc = ((crc >> 8) & 0x00FFFFFF) ^ _crc_table[(crc ^ *data++) & 0xFF]; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
116 |
} |
0 | 117 |
return crc; |
118 |
} |
|
119 |
||
120 |
static void GetFileInfo(DebugFileInfo *dfi, const char *filename) |
|
121 |
{ |
|
122 |
memset(dfi, 0, sizeof(dfi)); |
|
123 |
||
124 |
{ |
|
125 |
HANDLE file; |
|
126 |
byte buffer[1024]; |
|
127 |
DWORD numread; |
|
128 |
uint32 filesize = 0; |
|
129 |
FILETIME write_time; |
|
130 |
uint32 crc = (uint32)-1; |
|
131 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
132 |
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
133 |
OPEN_EXISTING, 0, 0); |
0 | 134 |
if (file != INVALID_HANDLE_VALUE) { |
135 |
while(true) { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
136 |
if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
137 |
numread == 0) |
0 | 138 |
break; |
139 |
filesize += numread; |
|
140 |
crc = CalcCRC(buffer, numread, crc); |
|
141 |
} |
|
142 |
dfi->size = filesize; |
|
143 |
dfi->crc32 = crc ^ (uint32)-1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
144 |
|
0 | 145 |
if (GetFileTime(file, NULL, NULL, &write_time)) { |
146 |
FileTimeToSystemTime(&write_time, &dfi->file_time); |
|
147 |
} |
|
148 |
CloseHandle(file); |
|
149 |
} |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
||
154 |
static char *PrintModuleInfo(char *output, HMODULE mod) |
|
155 |
{ |
|
318
65ebd0cab39b
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
306
diff
changeset
|
156 |
char buffer[MAX_PATH]; |
0 | 157 |
DebugFileInfo dfi; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
158 |
|
0 | 159 |
GetModuleFileName(mod, buffer, MAX_PATH); |
160 |
GetFileInfo(&dfi, buffer); |
|
161 |
output += sprintf(output, " %-20s handle: %.8X size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n", |
|
162 |
buffer, |
|
163 |
mod, |
|
164 |
dfi.size, |
|
165 |
dfi.crc32, |
|
166 |
dfi.file_time.wYear, |
|
167 |
dfi.file_time.wMonth, |
|
168 |
dfi.file_time.wDay, |
|
169 |
dfi.file_time.wHour, |
|
170 |
dfi.file_time.wMinute, |
|
171 |
dfi.file_time.wSecond |
|
172 |
); |
|
173 |
return output; |
|
174 |
} |
|
175 |
||
176 |
static char *PrintModuleList(char *output) |
|
177 |
{ |
|
178 |
BOOL (WINAPI *EnumProcessModules)(HANDLE,HMODULE*,DWORD,LPDWORD); |
|
179 |
HANDLE proc; |
|
180 |
HMODULE modules[100]; |
|
181 |
DWORD needed; |
|
182 |
BOOL res; |
|
183 |
int count,i; |
|
184 |
||
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
185 |
if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0")) { |
0 | 186 |
proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); |
187 |
if (proc) { |
|
188 |
res = EnumProcessModules(proc, modules, sizeof(modules), &needed); |
|
189 |
CloseHandle(proc); |
|
190 |
if (res) { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
191 |
count = |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
192 |
min(needed / sizeof(HMODULE), lengthof(modules)); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
193 |
for (i = 0; i != count; i++) |
0 | 194 |
output = PrintModuleInfo(output, modules[i]); |
195 |
return output; |
|
196 |
} |
|
197 |
} |
|
198 |
} |
|
199 |
output = PrintModuleInfo(output, NULL); |
|
200 |
return output; |
|
201 |
} |
|
202 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
203 |
static const char _crash_desc[] = |
0 | 204 |
"A serious fault condition occured in the game. The game will shut down.\n" |
205 |
"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
|
206 |
"This will greatly help debugging. " |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
207 |
"The information contained in the report is displayed below.\n" |
0 | 208 |
"Press \"Emergency save\" to attempt saving the game."; |
209 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
210 |
static const char _save_succeeded[] = |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
211 |
"Emergency save succeeded.\n" |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
212 |
"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
|
213 |
"corrupted. The saved game is not guaranteed to work."; |
0 | 214 |
|
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
|
215 |
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
|
216 |
{ |
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
|
217 |
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
|
218 |
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
|
219 |
} |
0 | 220 |
|
221 |
typedef struct { |
|
222 |
HINTERNET (WINAPI *InternetOpenA)(LPCSTR,DWORD, LPCSTR, LPCSTR, DWORD); |
|
223 |
HINTERNET (WINAPI *InternetConnectA)(HINTERNET, LPCSTR, INTERNET_PORT, LPCSTR, LPCSTR, DWORD, DWORD, DWORD); |
|
224 |
HINTERNET (WINAPI *HttpOpenRequestA)(HINTERNET, LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPCSTR *, DWORD, DWORD); |
|
225 |
BOOL (WINAPI *HttpSendRequestA)(HINTERNET, LPCSTR, DWORD, LPVOID, DWORD); |
|
226 |
BOOL (WINAPI *InternetCloseHandle)(HINTERNET); |
|
227 |
BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD); |
|
228 |
} WinInetProcs; |
|
229 |
||
230 |
#define M(x) x "\0" |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
231 |
static const char wininet_files[] = |
0 | 232 |
M("wininet.dll") |
233 |
M("InternetOpenA") |
|
234 |
M("InternetConnectA") |
|
235 |
M("HttpOpenRequestA") |
|
236 |
M("HttpSendRequestA") |
|
237 |
M("InternetCloseHandle") |
|
238 |
M("HttpQueryInfoA") |
|
239 |
M(""); |
|
240 |
#undef M |
|
241 |
||
242 |
static WinInetProcs _wininet; |
|
243 |
||
244 |
||
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
245 |
static const char *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const char *arg) |
0 | 246 |
{ |
247 |
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
|
248 |
const char *err = NULL; |
0 | 249 |
DWORD code, len; |
250 |
static char buf[100]; |
|
251 |
char buff[100]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
252 |
|
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
253 |
if (_wininet.InternetOpen == NULL && !LoadLibraryList((Function*)&_wininet, wininet_files)) return "can't load wininet.dll"; |
0 | 254 |
|
1957
2a4aa85373c3
(svn r2463) - Fix: partly revert the strncat madness and update nightly script (invisible) to correctly insert date.
Darkvater
parents:
1953
diff
changeset
|
255 |
inet = _wininet.InternetOpen("OTTD", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); |
0 | 256 |
if (inet == NULL) { err = "internetopen failed"; goto error1; } |
257 |
||
258 |
conn = _wininet.InternetConnect(inet, "openttd.com", INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0); |
|
259 |
if (conn == NULL) { err = "internetconnect failed"; goto error2; } |
|
260 |
||
261 |
sprintf(buff, "/crash.php?file=%s&ident=%d", arg, _ident); |
|
262 |
||
263 |
http = _wininet.HttpOpenRequest(conn, "POST", buff, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE , 0); |
|
264 |
if (http == NULL) { err = "httpopenrequest failed"; goto error3; } |
|
265 |
||
266 |
if (!_wininet.HttpSendRequest(http, "Content-type: application/binary", -1, msg, msglen)) { err = "httpsendrequest failed"; goto error4; } |
|
267 |
||
268 |
len = sizeof(code); |
|
269 |
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
|
270 |
|
0 | 271 |
if (code != 200) { |
272 |
int l = sprintf(buf, "Server said: %d ", code); |
|
273 |
len = sizeof(buf) - l; |
|
274 |
_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_TEXT, buf + l, &len, 0); |
|
275 |
err = buf; |
|
276 |
} |
|
277 |
||
278 |
error4: |
|
279 |
_wininet.InternetCloseHandle(http); |
|
280 |
error3: |
|
281 |
_wininet.InternetCloseHandle(conn); |
|
282 |
error2: |
|
283 |
_wininet.InternetCloseHandle(inet); |
|
284 |
error1: |
|
285 |
return err; |
|
286 |
} |
|
287 |
||
288 |
static void SubmitFile(HWND wnd, const char *file) |
|
289 |
{ |
|
290 |
HANDLE h; |
|
291 |
unsigned long size; |
|
292 |
unsigned long read; |
|
293 |
void *mem; |
|
294 |
||
295 |
h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
|
296 |
if (h == NULL) return; |
|
297 |
||
298 |
size = GetFileSize(h, NULL); |
|
299 |
if (size > 500000) goto error1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
300 |
|
0 | 301 |
mem = malloc(size); |
302 |
if (mem == NULL) goto error1; |
|
303 |
||
304 |
if (!ReadFile(h, mem, size, &read, NULL) || read != size) goto error2; |
|
305 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
306 |
SubmitCrashReport(wnd, mem, size, file); |
0 | 307 |
|
308 |
error2: |
|
309 |
free(mem); |
|
310 |
error1: |
|
311 |
CloseHandle(h); |
|
312 |
} |
|
313 |
||
314 |
static const char * const _expand_texts[] = {"S&how report >>", "&Hide report <<" }; |
|
315 |
||
316 |
static void SetWndSize(HWND wnd, int mode) |
|
317 |
{ |
|
318 |
RECT r,r2; |
|
319 |
int offs; |
|
320 |
||
321 |
GetWindowRect(wnd, &r); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
322 |
|
0 | 323 |
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
|
324 |
|
0 | 325 |
if (mode >= 0) { |
326 |
GetWindowRect(GetDlgItem(wnd, 11), &r2); |
|
327 |
offs = r2.bottom - r2.top + 10; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
328 |
if (!mode) offs = -offs; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
329 |
SetWindowPos(wnd, HWND_TOPMOST, 0, 0, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
330 |
r.right - r.left, r.bottom - r.top + offs, SWP_NOMOVE | SWP_NOZORDER); |
0 | 331 |
} else { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
332 |
SetWindowPos(wnd, HWND_TOPMOST, |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
333 |
(GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
334 |
(GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2, |
0 | 335 |
0, 0, SWP_NOSIZE); |
336 |
} |
|
337 |
} |
|
338 |
||
339 |
static bool DoEmergencySave(HWND wnd) |
|
340 |
{ |
|
341 |
bool b = false; |
|
342 |
||
343 |
EnableWindow(GetDlgItem(wnd, 13), FALSE); |
|
344 |
_did_emerg_save = true; |
|
345 |
__try { |
|
346 |
b = EmergencySave(); |
|
347 |
} __except (1) {} |
|
348 |
return b; |
|
349 |
} |
|
350 |
||
351 |
static BOOL CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam) |
|
352 |
{ |
|
353 |
switch(msg) { |
|
354 |
case WM_INITDIALOG: |
|
355 |
SetDlgItemText(wnd, 10, _crash_desc); |
|
356 |
SetDlgItemText(wnd, 11, _crash_msg); |
|
357 |
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE); |
|
358 |
SetWndSize(wnd, -1); |
|
359 |
return TRUE; |
|
360 |
case WM_COMMAND: |
|
361 |
switch(wParam) { |
|
362 |
case 12: // Close |
|
363 |
ExitProcess(0); |
|
364 |
case 13: { // Emergency save |
|
365 |
if (DoEmergencySave(wnd)) |
|
366 |
MessageBoxA(wnd, _save_succeeded, "Save successful", MB_ICONINFORMATION); |
|
367 |
else |
|
368 |
MessageBoxA(wnd, "Save failed", "Save failed", MB_ICONINFORMATION); |
|
369 |
break; |
|
370 |
} |
|
371 |
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
|
372 |
const char *s; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
373 |
|
0 | 374 |
SetCursor(LoadCursor(NULL, IDC_WAIT)); |
375 |
||
376 |
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), ""); |
|
377 |
if (s) { |
|
378 |
MessageBoxA(wnd, s, "Error", MB_ICONSTOP); |
|
379 |
break; |
|
380 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
381 |
|
0 | 382 |
// try to submit emergency savegame |
383 |
if (_did_emerg_save || DoEmergencySave(wnd)) { |
|
384 |
SubmitFile(wnd, "crash.sav"); |
|
385 |
} |
|
386 |
// try to submit the autosaved game |
|
387 |
if (_opt.autosave) { |
|
388 |
char buf[40]; |
|
389 |
sprintf(buf, "autosave%d.sav", (_autosave_ctr - 1) & 3); |
|
390 |
SubmitFile(wnd, buf); |
|
391 |
} |
|
392 |
EnableWindow(GetDlgItem(wnd, 14), FALSE); |
|
393 |
SetCursor(LoadCursor(NULL, IDC_ARROW)); |
|
394 |
MessageBoxA(wnd, "Crash report submitted. Thank you.", "Crash Report", MB_ICONINFORMATION); |
|
395 |
break; |
|
396 |
} |
|
397 |
case 15: // Expand |
|
398 |
_expanded ^= 1; |
|
399 |
SetWndSize(wnd, _expanded); |
|
400 |
break; |
|
401 |
} |
|
402 |
return TRUE; |
|
403 |
case WM_CLOSE: |
|
404 |
ExitProcess(0); |
|
405 |
} |
|
406 |
||
407 |
return FALSE; |
|
408 |
} |
|
409 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
410 |
static void Handler2(void) |
0 | 411 |
{ |
412 |
ShowCursor(TRUE); |
|
413 |
ShowWindow(GetActiveWindow(), FALSE); |
|
414 |
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(100), NULL, CrashDialogFunc); |
|
415 |
} |
|
416 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
417 |
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
|
418 |
|
0 | 419 |
static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) |
420 |
{ |
|
421 |
char *output; |
|
422 |
static bool had_exception; |
|
423 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
424 |
if (had_exception) ExitProcess(0); |
0 | 425 |
had_exception = true; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
426 |
|
0 | 427 |
_ident = GetTickCount(); // something pretty unique |
428 |
||
429 |
MakeCRCTable(alloca(256 * sizeof(uint32))); |
|
430 |
_crash_msg = output = LocalAlloc(LMEM_FIXED, 8192); |
|
431 |
||
432 |
{ |
|
433 |
SYSTEMTIME time; |
|
434 |
GetLocalTime(&time); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
435 |
output += sprintf(output, |
0 | 436 |
"*** OpenTTD Crash Report ***\r\n" |
437 |
"Date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n" |
|
438 |
"Build: %s built on " __TIMESTAMP__ "\r\n", |
|
439 |
time.wYear, |
|
440 |
time.wMonth, |
|
441 |
time.wDay, |
|
442 |
time.wHour, |
|
443 |
time.wMinute, |
|
444 |
time.wSecond, |
|
445 |
"???" |
|
446 |
); |
|
447 |
} |
|
448 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
449 |
if (_exception_string) |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
450 |
output += sprintf(output, "Reason: %s\r\n", _exception_string); |
0 | 451 |
|
452 |
output += sprintf(output, "Exception %.8X at %.8X\r\n" |
|
453 |
"Registers:\r\n" |
|
454 |
" EAX: %.8X EBX: %.8X ECX: %.8X EDX: %.8X\r\n" |
|
455 |
" ESI: %.8X EDI: %.8X EBP: %.8X ESP: %.8X\r\n" |
|
456 |
" EIP: %.8X EFLAGS: %.8X\r\n" |
|
457 |
"\r\nBytes at CS:EIP:\r\n", |
|
458 |
ep->ExceptionRecord->ExceptionCode, |
|
459 |
ep->ExceptionRecord->ExceptionAddress, |
|
460 |
ep->ContextRecord->Eax, |
|
461 |
ep->ContextRecord->Ebx, |
|
462 |
ep->ContextRecord->Ecx, |
|
463 |
ep->ContextRecord->Edx, |
|
464 |
ep->ContextRecord->Esi, |
|
465 |
ep->ContextRecord->Edi, |
|
466 |
ep->ContextRecord->Ebp, |
|
467 |
ep->ContextRecord->Esp, |
|
468 |
ep->ContextRecord->Eip, |
|
469 |
ep->ContextRecord->EFlags |
|
470 |
); |
|
471 |
||
472 |
{ |
|
473 |
byte *b = (byte*)ep->ContextRecord->Eip; |
|
474 |
int i; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
475 |
for (i = 0; i != 24; i++) { |
0 | 476 |
if (IsBadReadPtr(b, 1)) { |
477 |
output += sprintf(output, " ??"); // OCR: WAS: , 0); |
|
478 |
} else { |
|
479 |
output += sprintf(output, " %.2X", *b); |
|
480 |
} |
|
481 |
b++; |
|
482 |
} |
|
483 |
output += sprintf(output, |
|
484 |
"\r\n" |
|
485 |
"\r\nStack trace: \r\n" |
|
486 |
); |
|
487 |
} |
|
488 |
||
489 |
{ |
|
490 |
int i,j; |
|
491 |
uint32 *b = (uint32*)ep->ContextRecord->Esp; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
492 |
for (j = 0; j != 24; j++) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
493 |
for (i = 0; i != 8; i++) { |
0 | 494 |
if (IsBadReadPtr(b,sizeof(uint32))) { |
495 |
output += sprintf(output, " ????????"); //OCR: WAS - , 0); |
|
496 |
} else { |
|
497 |
output += sprintf(output, " %.8X", *b); |
|
498 |
} |
|
499 |
b++; |
|
500 |
} |
|
501 |
output += sprintf(output, "\r\n"); |
|
502 |
} |
|
503 |
} |
|
504 |
||
505 |
output += sprintf(output, "\r\nModule information:\r\n"); |
|
506 |
output = PrintModuleList(output); |
|
507 |
||
508 |
{ |
|
509 |
OSVERSIONINFO os; |
|
510 |
os.dwOSVersionInfoSize = sizeof(os); |
|
511 |
GetVersionEx(&os); |
|
512 |
output += sprintf(output, "\r\nSystem information:\r\n" |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
513 |
" Windows version %d.%d %d %s\r\n", |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
514 |
os.dwMajorVersion, os.dwMinorVersion, os.dwBuildNumber, os.szCSDVersion); |
0 | 515 |
} |
516 |
||
517 |
{ |
|
518 |
HANDLE file = CreateFile("crash.log", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); |
|
519 |
DWORD num_written; |
|
520 |
if (file != INVALID_HANDLE_VALUE) { |
|
521 |
WriteFile(file, _crash_msg, output - _crash_msg, &num_written, NULL); |
|
522 |
CloseHandle(file); |
|
523 |
} |
|
524 |
} |
|
525 |
||
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
|
526 |
/* 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
|
527 |
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
|
528 |
|
0 | 529 |
if (_safe_esp) { |
530 |
ep->ContextRecord->Eip = (DWORD)Handler2; |
|
531 |
ep->ContextRecord->Esp = (DWORD)_safe_esp; |
|
532 |
return EXCEPTION_CONTINUE_EXECUTION; |
|
533 |
} |
|
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
|
534 |
|
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
|
535 |
|
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
|
536 |
return EXCEPTION_EXECUTE_HANDLER; |
0 | 537 |
} |
538 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
539 |
static void Win32InitializeExceptions(void) |
0 | 540 |
{ |
541 |
_asm { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
542 |
mov _safe_esp, esp |
0 | 543 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
544 |
|
0 | 545 |
SetUnhandledExceptionFilter(ExceptionHandler); |
546 |
} |
|
796 | 547 |
#else |
548 |
/* Get rid of unused variable warnings.. ShowOSErrorBox |
|
915 | 549 |
* is now used twice, once in MSVC, and once in all other Win |
796 | 550 |
* compilers (cygwin, mingw, etc.) */ |
551 |
void ShowOSErrorBox(const char *buf) |
|
552 |
{ |
|
553 |
MyShowCursor(true); |
|
554 |
MessageBoxA(GetActiveWindow(), buf, "Error!", MB_ICONSTOP); |
|
555 |
} |
|
0 | 556 |
#endif |
557 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
558 |
#ifndef __MINGW32__ |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
559 |
static inline int strcasecmp(const char* s1, const char* s2) |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
560 |
{ |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
561 |
return stricmp(s1, s2); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
562 |
} |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
563 |
#endif |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
564 |
|
0 | 565 |
static char *_fios_path; |
566 |
static char *_fios_save_path; |
|
567 |
static char *_fios_scn_path; |
|
568 |
static FiosItem *_fios_items; |
|
569 |
static int _fios_count, _fios_alloc; |
|
570 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
571 |
static FiosItem *FiosAlloc(void) |
0 | 572 |
{ |
573 |
if (_fios_count == _fios_alloc) { |
|
574 |
_fios_alloc += 256; |
|
575 |
_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem)); |
|
576 |
} |
|
577 |
return &_fios_items[_fios_count++]; |
|
578 |
} |
|
579 |
||
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
|
580 |
static HANDLE MyFindFirstFile(const char *path, const char *file, WIN32_FIND_DATA *fd) |
0 | 581 |
{ |
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
|
582 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
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
|
583 |
HANDLE h; |
0 | 584 |
char paths[MAX_PATH]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
585 |
|
0 | 586 |
sprintf(paths, "%s\\%s", path, file); |
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
|
587 |
h = FindFirstFile(paths, fd); |
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
|
588 |
|
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
|
589 |
SetErrorMode(sem); // restore previous setting |
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
|
590 |
return h; |
0 | 591 |
} |
592 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
593 |
int CDECL compare_FiosItems(const void *a, const void *b) |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
594 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
595 |
const FiosItem *da = (const FiosItem *)a; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
596 |
const FiosItem *db = (const FiosItem *)b; |
0 | 597 |
int r; |
598 |
||
599 |
if (_savegame_sort_order < 2) // sort by date |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
600 |
r = da->mtime < db->mtime ? -1 : 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
601 |
else |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
602 |
r = strcasecmp(da->title, db->title); |
0 | 603 |
|
604 |
if (_savegame_sort_order & 1) r = -r; |
|
605 |
return r; |
|
606 |
} |
|
607 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
608 |
|
0 | 609 |
// Get a list of savegames |
610 |
FiosItem *FiosGetSavegameList(int *num, int mode) |
|
611 |
{ |
|
612 |
WIN32_FIND_DATA fd; |
|
613 |
HANDLE h; |
|
614 |
FiosItem *fios; |
|
615 |
int sort_start; |
|
616 |
||
617 |
if (_fios_save_path == NULL) { |
|
618 |
_fios_save_path = malloc(MAX_PATH); |
|
619 |
strcpy(_fios_save_path, _path.save_dir); |
|
620 |
} |
|
621 |
||
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
622 |
_fios_path = _fios_save_path; |
0 | 623 |
|
624 |
// Parent directory, only if not of the type C:\. |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
625 |
if (_fios_path[3] != '\0') { |
0 | 626 |
fios = FiosAlloc(); |
627 |
fios->type = FIOS_TYPE_PARENT; |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
628 |
fios->mtime = 0; |
1572
6d0111113f0b
(svn r2076) Set the name for the parent directory to ".."
tron
parents:
1548
diff
changeset
|
629 |
strcpy(fios->name, ".."); |
0 | 630 |
strcpy(fios->title, ".. (Parent directory)"); |
631 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
632 |
|
0 | 633 |
// Show subdirectories first |
634 |
h = MyFindFirstFile(_fios_path, "*.*", &fd); |
|
635 |
if (h != INVALID_HANDLE_VALUE) { |
|
636 |
do { |
|
637 |
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
638 |
strcmp(fd.cFileName, ".") != 0 && |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
639 |
strcmp(fd.cFileName, "..") != 0) { |
0 | 640 |
fios = FiosAlloc(); |
641 |
fios->type = FIOS_TYPE_DIR; |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
642 |
fios->mtime = 0; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
643 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
644 |
snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName); |
0 | 645 |
} |
646 |
} while (FindNextFile(h, &fd)); |
|
647 |
FindClose(h); |
|
648 |
} |
|
649 |
||
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
650 |
{ |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
651 |
/* XXX ugly global variables ... */ |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
652 |
byte order = _savegame_sort_order; |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
653 |
_savegame_sort_order = 2; // sort ascending by name |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
654 |
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems); |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
655 |
_savegame_sort_order = order; |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
656 |
} |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
657 |
|
0 | 658 |
// this is where to start sorting |
659 |
sort_start = _fios_count; |
|
660 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
661 |
/* Show savegame files |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
662 |
* .SAV OpenTTD saved game |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
663 |
* .SS1 Transport Tycoon Deluxe preset game |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
664 |
* .SV1 Transport Tycoon Deluxe (Patch) saved game |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
665 |
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game |
0 | 666 |
*/ |
667 |
h = MyFindFirstFile(_fios_path, "*.*", &fd); |
|
668 |
if (h != INVALID_HANDLE_VALUE) { |
|
669 |
do { |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
670 |
char *t; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
671 |
|
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
672 |
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
673 |
|
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
674 |
t = strrchr(fd.cFileName, '.'); |
2338 | 675 |
if (t == NULL) continue; |
676 |
||
677 |
if (strcasecmp(t, ".sav") == 0) { // OpenTTD |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
678 |
fios = FiosAlloc(); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
679 |
fios->type = FIOS_TYPE_FILE; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
680 |
fios->mtime = *(uint64*)&fd.ftLastWriteTime; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
681 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
682 |
|
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
683 |
*t = '\0'; // strip extension |
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
684 |
ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title)); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
685 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { |
2338 | 686 |
if (strcasecmp(t, ".ss1") == 0 || |
687 |
strcasecmp(t, ".sv1") == 0 || |
|
688 |
strcasecmp(t, ".sv2") == 0) { // TTDLX(Patch) |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
689 |
char buf[MAX_PATH]; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
690 |
|
0 | 691 |
fios = FiosAlloc(); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
692 |
fios->type = FIOS_TYPE_OLDFILE; |
0 | 693 |
fios->mtime = *(uint64*)&fd.ftLastWriteTime; |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
694 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
0 | 695 |
sprintf(buf, "%s\\%s", _fios_path, fd.cFileName); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
696 |
GetOldSaveGameName(fios->title, buf); |
0 | 697 |
} |
698 |
} |
|
699 |
} while (FindNextFile(h, &fd)); |
|
700 |
FindClose(h); |
|
701 |
} |
|
702 |
||
703 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
|
704 |
||
705 |
// Drives |
|
706 |
{ |
|
707 |
char drives[256]; |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
708 |
const char *s; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
709 |
|
0 | 710 |
GetLogicalDriveStrings(sizeof(drives), drives); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
711 |
for (s = drives; *s != '\0';) { |
0 | 712 |
fios = FiosAlloc(); |
713 |
fios->type = FIOS_TYPE_DRIVE; |
|
1580 | 714 |
sprintf(fios->name, "%c:", s[0]); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
715 |
sprintf(fios->title, "%c:", s[0]); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
716 |
while (*s++ != '\0') {} |
0 | 717 |
} |
718 |
} |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
719 |
|
0 | 720 |
*num = _fios_count; |
721 |
return _fios_items; |
|
722 |
} |
|
723 |
||
724 |
// Get a list of scenarios |
|
725 |
FiosItem *FiosGetScenarioList(int *num, int mode) |
|
726 |
{ |
|
727 |
FiosItem *fios; |
|
728 |
WIN32_FIND_DATA fd; |
|
729 |
HANDLE h; |
|
730 |
int sort_start; |
|
731 |
||
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
732 |
if (_fios_scn_path == NULL) { |
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
733 |
_fios_scn_path = malloc(MAX_PATH); |
0 | 734 |
strcpy(_fios_scn_path, _path.scenario_dir); |
735 |
} |
|
736 |
||
737 |
_fios_path = _fios_scn_path; |
|
738 |
||
739 |
// Parent directory, only if not of the type C:\. |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
740 |
if (_fios_path[3] != '\0' && mode != SLD_NEW_GAME) { |
0 | 741 |
fios = FiosAlloc(); |
742 |
fios->type = FIOS_TYPE_PARENT; |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
743 |
fios->mtime = 0; |
0 | 744 |
strcpy(fios->title, ".. (Parent directory)"); |
745 |
} |
|
746 |
||
747 |
// Show subdirectories first |
|
748 |
h = MyFindFirstFile(_fios_scn_path, "*.*", &fd); |
|
749 |
if (h != INVALID_HANDLE_VALUE && mode != SLD_NEW_GAME) { |
|
750 |
do { |
|
751 |
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
752 |
strcmp(fd.cFileName, ".") != 0 && |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
753 |
strcmp(fd.cFileName, "..") != 0) { |
0 | 754 |
fios = FiosAlloc(); |
755 |
fios->type = FIOS_TYPE_DIR; |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
756 |
fios->mtime = 0; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
757 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
758 |
snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName); |
0 | 759 |
} |
760 |
} while (FindNextFile(h, &fd)); |
|
761 |
FindClose(h); |
|
762 |
} |
|
763 |
||
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
764 |
{ |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
765 |
/* XXX ugly global variables ... */ |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
766 |
byte order = _savegame_sort_order; |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
767 |
_savegame_sort_order = 2; // sort ascending by name |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
768 |
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems); |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
769 |
_savegame_sort_order = order; |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
770 |
} |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
771 |
|
0 | 772 |
// this is where to start sorting |
773 |
sort_start = _fios_count; |
|
774 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
775 |
/* Show scenario files |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
776 |
* .SCN OpenTTD style scenario file |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
777 |
* .SV0 Transport Tycoon Deluxe (Patch) scenario |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
778 |
* .SS0 Transport Tycoon Deluxe preset scenario |
0 | 779 |
*/ |
780 |
h = MyFindFirstFile(_fios_scn_path, "*.*", &fd); |
|
781 |
if (h != INVALID_HANDLE_VALUE) { |
|
782 |
do { |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
783 |
char *t; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
784 |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
785 |
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) continue; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
786 |
|
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
787 |
t = strrchr(fd.cFileName, '.'); |
2338 | 788 |
if (t == NULL) continue; |
789 |
||
790 |
if (strcasecmp(t, ".scn") == 0) { // OpenTTD |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
791 |
fios = FiosAlloc(); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
792 |
fios->type = FIOS_TYPE_SCENARIO; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
793 |
fios->mtime = *(uint64*)&fd.ftLastWriteTime; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
794 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
795 |
|
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
796 |
*t = '\0'; // strip extension |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
797 |
ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title)); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
798 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
799 |
mode == SLD_NEW_GAME) { |
2338 | 800 |
if (strcasecmp(t, ".sv0") == 0 || |
801 |
strcasecmp(t, ".ss0") == 0) { // TTDLX(Patch) |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
802 |
char buf[MAX_PATH]; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
803 |
|
0 | 804 |
fios = FiosAlloc(); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
805 |
fios->type = FIOS_TYPE_OLD_SCENARIO; |
0 | 806 |
fios->mtime = *(uint64*)&fd.ftLastWriteTime; |
807 |
sprintf(buf, "%s\\%s", _fios_path, fd.cFileName); |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
808 |
GetOldScenarioGameName(fios->title, buf); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
809 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
0 | 810 |
} |
811 |
} |
|
812 |
} while (FindNextFile(h, &fd)); |
|
813 |
FindClose(h); |
|
814 |
} |
|
815 |
||
816 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
|
817 |
||
818 |
// Drives |
|
819 |
if (mode != SLD_NEW_GAME) { |
|
820 |
char drives[256]; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
821 |
const char *s; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
822 |
|
0 | 823 |
GetLogicalDriveStrings(sizeof(drives), drives); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
824 |
for (s = drives; *s != '\0';) { |
0 | 825 |
fios = FiosAlloc(); |
826 |
fios->type = FIOS_TYPE_DRIVE; |
|
1580 | 827 |
sprintf(fios->name, "%c:", s[0]); |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
828 |
sprintf(fios->title, "%c:", s[0]); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
829 |
while (*s++ != '\0') {} |
0 | 830 |
} |
831 |
} |
|
832 |
||
833 |
*num = _fios_count; |
|
834 |
return _fios_items; |
|
835 |
} |
|
836 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
837 |
|
0 | 838 |
// Free the list of savegames |
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
839 |
void FiosFreeSavegameList(void) |
0 | 840 |
{ |
841 |
free(_fios_items); |
|
842 |
_fios_items = NULL; |
|
843 |
_fios_alloc = _fios_count = 0; |
|
844 |
} |
|
845 |
||
846 |
// Browse to |
|
847 |
char *FiosBrowseTo(const FiosItem *item) |
|
848 |
{ |
|
849 |
char *path = _fios_path; |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
850 |
char *s; |
0 | 851 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
852 |
switch (item->type) { |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
853 |
case FIOS_TYPE_DRIVE: |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
854 |
sprintf(path, "%c:\\", item->title[0]); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
855 |
break; |
0 | 856 |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
857 |
case FIOS_TYPE_PARENT: |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
858 |
s = strrchr(path, '\\'); |
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
859 |
if (s != path + 2) |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
860 |
s[0] = '\0'; |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
861 |
else |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
862 |
s[1] = '\0'; |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
863 |
break; |
0 | 864 |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
865 |
case FIOS_TYPE_DIR: |
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2285
diff
changeset
|
866 |
if (path[3] != '\0') strcat(path, "\\"); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
867 |
strcat(path, item->name); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
868 |
break; |
0 | 869 |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
870 |
case FIOS_TYPE_FILE: |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
871 |
case FIOS_TYPE_OLDFILE: |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
872 |
case FIOS_TYPE_SCENARIO: |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
873 |
case FIOS_TYPE_OLD_SCENARIO: { |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
874 |
static char str_buffr[512]; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
875 |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
876 |
sprintf(str_buffr, "%s\\%s", path, item->name); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
877 |
return str_buffr; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
878 |
} |
0 | 879 |
} |
880 |
||
881 |
return NULL; |
|
882 |
} |
|
883 |
||
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
|
884 |
/** |
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
|
885 |
* Get descriptive texts. Returns the path and free space |
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
|
886 |
* left on the device |
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
|
887 |
* @param path string describing the path |
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
|
888 |
* @param tfs total free space in megabytes, optional (can be NULL) |
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
|
889 |
* @return StringID describing the path (free space or failure) |
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
|
890 |
*/ |
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
|
891 |
StringID FiosGetDescText(const char **path, uint32 *tot) |
0 | 892 |
{ |
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
|
893 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
0 | 894 |
char root[4]; |
895 |
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
|
896 |
StringID sid; |
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
|
897 |
|
0 | 898 |
*path = _fios_path; |
899 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
900 |
sprintf(root, "%c:\\", _fios_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
|
901 |
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
|
902 |
*tot = ((spc * bps) * (uint64)nfc) >> 20; |
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
|
903 |
sid = STR_4005_BYTES_FREE; |
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
|
904 |
} else |
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
|
905 |
sid = STR_4006_UNABLE_TO_READ_DRIVE; |
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
|
906 |
|
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
|
907 |
SetErrorMode(sem); // reset previous setting |
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
|
908 |
return sid; |
0 | 909 |
} |
910 |
||
911 |
void FiosMakeSavegameName(char *buf, const char *name) |
|
912 |
{ |
|
1508
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
913 |
const char* extension; |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
914 |
const char* period; |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
915 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
916 |
if (_game_mode == GM_EDITOR) |
1508
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
917 |
extension = ".scn"; |
0 | 918 |
else |
1508
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
919 |
extension = ".sav"; |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
920 |
|
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
921 |
// Don't append the extension, if it is already there |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
922 |
period = strrchr(name, '.'); |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
923 |
if (period != NULL && strcasecmp(period, extension) == 0) extension = ""; |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
924 |
|
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
925 |
sprintf(buf, "%s\\%s%s", _fios_path, name, extension); |
0 | 926 |
} |
927 |
||
2255
ddcaf9e333ff
(svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents:
2211
diff
changeset
|
928 |
bool FiosDelete(const char *name) |
0 | 929 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
930 |
char path[512]; |
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
931 |
|
1495
c8a61d136f26
(svn r1999) r1990 broke savegame deletion, fix that [1161729]
tron
parents:
1486
diff
changeset
|
932 |
snprintf(path, lengthof(path), "%s\\%s", _fios_path, name); |
2255
ddcaf9e333ff
(svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents:
2211
diff
changeset
|
933 |
return DeleteFile(path) != 0; |
0 | 934 |
} |
935 |
||
936 |
bool FileExists(const char *filename) |
|
937 |
{ |
|
938 |
HANDLE hand = CreateFile(filename, 0, 0, NULL, OPEN_EXISTING, 0, NULL); |
|
939 |
if (hand == INVALID_HANDLE_VALUE) return false; |
|
940 |
CloseHandle(hand); |
|
941 |
return true; |
|
942 |
} |
|
943 |
||
944 |
static int CDECL LanguageCompareFunc(const void *a, const void *b) |
|
945 |
{ |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
206
diff
changeset
|
946 |
return strcmp(*(const char* const *)a, *(const char* const *)b); |
0 | 947 |
} |
948 |
||
949 |
int GetLanguageList(char **languages, int max) |
|
950 |
{ |
|
951 |
HANDLE hand; |
|
952 |
int num = 0; |
|
953 |
char filedir[MAX_PATH]; |
|
954 |
WIN32_FIND_DATA fd; |
|
955 |
sprintf(filedir, "%s*.lng", _path.lang_dir); |
|
956 |
||
957 |
hand = FindFirstFile(filedir, &fd); |
|
958 |
if (hand != INVALID_HANDLE_VALUE) { |
|
959 |
do { |
|
960 |
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
|
961 |
languages[num++] = strdup(fd.cFileName); |
|
962 |
if (num == max) break; |
|
963 |
} |
|
964 |
} while (FindNextFile(hand, &fd)); |
|
965 |
FindClose(hand); |
|
966 |
} |
|
967 |
||
968 |
qsort(languages, num, sizeof(char*), LanguageCompareFunc); |
|
969 |
return num; |
|
970 |
} |
|
971 |
||
972 |
static int ParseCommandLine(char *line, char **argv, int max_argc) |
|
973 |
{ |
|
974 |
int n = 0; |
|
975 |
||
976 |
do { |
|
977 |
// skip whitespace |
|
978 |
while (*line == ' ' || *line == '\t') |
|
979 |
line++; |
|
980 |
||
981 |
// end? |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
982 |
if (*line == '\0') |
0 | 983 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
984 |
|
0 | 985 |
// special handling when quoted |
986 |
if (*line == '"') { |
|
987 |
argv[n++] = ++line; |
|
988 |
while (*line != '"') { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
989 |
if (*line == '\0') return n; |
0 | 990 |
line++; |
991 |
} |
|
992 |
} else { |
|
993 |
argv[n++] = line; |
|
994 |
while (*line != ' ' && *line != '\t') { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
995 |
if (*line == '\0') return n; |
0 | 996 |
line++; |
997 |
} |
|
998 |
} |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
999 |
*line++ = '\0'; |
0 | 1000 |
} while (n != max_argc); |
1001 |
||
1002 |
return n; |
|
1003 |
} |
|
1004 |
||
1005 |
||
1006 |
#if defined(_MSC_VER) |
|
2091
97197b795fe6
(svn r2601) Fix: Added TIC,TOC macros do be able to do profiling easier.
ludde
parents:
2073
diff
changeset
|
1007 |
uint32 _declspec(naked) rdtsc(void) |
0 | 1008 |
{ |
1009 |
_asm { |
|
1010 |
rdtsc |
|
1011 |
ret |
|
1012 |
} |
|
1013 |
} |
|
1014 |
#endif |
|
1015 |
||
1102
316643e34104
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
1016 |
void CreateConsole(void) |
0 | 1017 |
{ |
1018 |
HANDLE hand; |
|
1019 |
CONSOLE_SCREEN_BUFFER_INFO coninfo; |
|
1020 |
||
1021 |
if (_has_console) return; |
|
1022 |
||
1023 |
_has_console = true; |
|
1024 |
||
1025 |
AllocConsole(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1026 |
|
0 | 1027 |
hand = GetStdHandle(STD_OUTPUT_HANDLE); |
1028 |
GetConsoleScreenBufferInfo(hand, &coninfo); |
|
1029 |
coninfo.dwSize.Y = 500; |
|
1030 |
SetConsoleScreenBufferSize(hand, coninfo.dwSize); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1031 |
|
0 | 1032 |
// redirect unbuffered STDIN, STDOUT, STDERR to the console |
2172 | 1033 |
#if !defined(__CYGWIN__) |
0 | 1034 |
*stdout = *_fdopen( _open_osfhandle((long)hand, _O_TEXT), "w" ); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1035 |
*stdin = *_fdopen(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" ); |
0 | 1036 |
*stderr = *_fdopen(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); |
1037 |
#else |
|
1038 |
// open_osfhandle is not in cygwin |
|
1039 |
*stdout = *fdopen(1, "w" ); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1040 |
*stdin = *fdopen(0, "r" ); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1041 |
*stderr = *fdopen(2, "w" ); |
0 | 1042 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1043 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1044 |
setvbuf(stdin, NULL, _IONBF, 0); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1045 |
setvbuf(stdout, NULL, _IONBF, 0); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1046 |
setvbuf(stderr, NULL, _IONBF, 0); |
0 | 1047 |
} |
1048 |
||
1049 |
void ShowInfo(const char *str) |
|
1050 |
{ |
|
1051 |
if (_has_console) |
|
1052 |
puts(str); |
|
1053 |
else { |
|
1054 |
bool old; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1055 |
|
0 | 1056 |
ReleaseCapture(); |
1057 |
_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
|
1058 |
|
0 | 1059 |
old = MyShowCursor(true); |
1060 |
if (MessageBoxA(GetActiveWindow(), str, "OpenTTD", MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) { |
|
1061 |
CreateConsole(); |
|
1062 |
} |
|
1063 |
MyShowCursor(old); |
|
1064 |
} |
|
1065 |
} |
|
1066 |
||
1067 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1068 |
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1069 |
LPTSTR lpCmdLine, int nCmdShow) |
0 | 1070 |
{ |
1071 |
int argc; |
|
1072 |
char *argv[64]; // max 64 command line arguments |
|
1073 |
||
1074 |
#if defined(_DEBUG) |
|
1075 |
CreateConsole(); |
|
1076 |
#endif |
|
1077 |
||
1078 |
// make sure we have an autosave folder - Done in DeterminePaths |
|
1079 |
// CreateDirectory("autosave", NULL); |
|
1080 |
||
1081 |
// setup random seed to something quite random |
|
1082 |
#if defined(_MSC_VER) |
|
1083 |
{ |
|
1084 |
uint64 seed = rdtsc(); |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2139
diff
changeset
|
1085 |
_random_seeds[0][0] = GB(seed, 0, 32); |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2139
diff
changeset
|
1086 |
_random_seeds[0][1] = GB(seed, 32, 32); |
0 | 1087 |
} |
1088 |
#else |
|
206 | 1089 |
_random_seeds[0][0] = GetTickCount(); |
1090 |
_random_seeds[0][1] = _random_seeds[0][0] * 0x1234567; |
|
0 | 1091 |
#endif |
2073 | 1092 |
SeedMT(_random_seeds[0][0]); |
0 | 1093 |
|
1094 |
argc = ParseCommandLine(GetCommandLine(), argv, lengthof(argv)); |
|
1095 |
||
1096 |
#if defined(WIN32_EXCEPTION_TRACKER) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1097 |
{ |
0 | 1098 |
Win32InitializeExceptions(); |
1099 |
} |
|
1100 |
#endif |
|
1101 |
||
1102 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
1103 |
_try { |
|
1104 |
uint32 _stdcall ExceptionHandler(void *ep); |
|
1105 |
#endif |
|
1106 |
ttd_main(argc, argv); |
|
1107 |
||
1108 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
1109 |
} _except (ExceptionHandler(_exception_info())) {} |
|
1110 |
#endif |
|
1111 |
||
1112 |
return 0; |
|
1113 |
} |
|
1114 |
||
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
|
1115 |
void DeterminePaths(void) |
0 | 1116 |
{ |
1117 |
char *s; |
|
1118 |
char *cfg; |
|
1119 |
||
1120 |
_path.personal_dir = _path.game_data_dir = cfg = malloc(MAX_PATH); |
|
1121 |
GetCurrentDirectory(MAX_PATH - 1, cfg); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1122 |
|
0 | 1123 |
|
1124 |
s = strchr(cfg, 0); |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1125 |
if (s[-1] != '\\') strcpy(s, "\\"); |
0 | 1126 |
|
1127 |
_path.save_dir = str_fmt("%ssave", cfg); |
|
1128 |
_path.autosave_dir = str_fmt("%s\\autosave", _path.save_dir); |
|
1129 |
_path.scenario_dir = str_fmt("%sscenario", cfg); |
|
1130 |
_path.gm_dir = str_fmt("%sgm\\", cfg); |
|
1131 |
_path.data_dir = str_fmt("%sdata\\", cfg); |
|
1132 |
_path.lang_dir = str_fmt("%slang\\", cfg); |
|
1133 |
||
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
|
1134 |
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
|
1135 |
_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
|
1136 |
|
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
|
1137 |
_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
|
1138 |
_log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
0 | 1139 |
|
1140 |
// make (auto)save and scenario folder |
|
1141 |
CreateDirectory(_path.save_dir, NULL); |
|
1142 |
CreateDirectory(_path.autosave_dir, NULL); |
|
1143 |
CreateDirectory(_path.scenario_dir, NULL); |
|
1144 |
} |
|
1145 |
||
1022
9ea8ee93d6a9
(svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents:
983
diff
changeset
|
1146 |
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
|
1147 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1148 |
va_list ap; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1149 |
int ret; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1150 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1151 |
va_start(ap, format); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1152 |
ret = vsnprintf(str, size, format, ap); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1153 |
va_end(ap); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1154 |
return ret; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1155 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1156 |
|
1022
9ea8ee93d6a9
(svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents:
983
diff
changeset
|
1157 |
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
|
1158 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1159 |
int ret; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1160 |
ret = _vsnprintf(str, size, format, ap); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1161 |
if (ret < 0) str[size - 1] = '\0'; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1162 |
return ret; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1163 |
} |
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
|
1164 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1165 |
/** |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1166 |
* 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
|
1167 |
* 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
|
1168 |
* 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
|
1169 |
* @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
|
1170 |
* @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
|
1171 |
*/ |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1172 |
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
|
1173 |
{ |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1174 |
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
|
1175 |
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
|
1176 |
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
|
1177 |
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
|
1178 |
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
|
1179 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1180 |
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
|
1181 |
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
|
1182 |
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
|
1183 |
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
|
1184 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1185 |
for (; IsValidAsciiChar(*dataptr) && (tb->length + length) < tb->maxlength - 1 && |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1186 |
(tb->maxwidth == 0 || width + tb->width + GetCharacterWidth((byte)*dataptr) <= tb->maxwidth); 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
|
1187 |
width += GetCharacterWidth((byte)*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
|
1188 |
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
|
1189 |
} |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1190 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1191 |
if (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
|
1192 |
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
|
1193 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1194 |
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
|
1195 |
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
|
1196 |
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
|
1197 |
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
|
1198 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1199 |
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
|
1200 |
tb->caretpos += 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
|
1201 |
tb->buf[tb->length + 1] = '\0'; // terminating zero |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1202 |
|
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1203 |
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
|
1204 |
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
|
1205 |
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
|
1206 |
} |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1207 |
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
|
1208 |
} |
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
|
1209 |
|
2073 | 1210 |
|
1211 |
void CSleep(int milliseconds) |
|
1212 |
{ |
|
1213 |
Sleep(milliseconds); |
|
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
1214 |
} |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1215 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1216 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1217 |
// 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
|
1218 |
// Useful for profiling |
2139 | 1219 |
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
|
1220 |
{ |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1221 |
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
|
1222 |
__int64 value; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1223 |
if (!freq) { |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1224 |
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
|
1225 |
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
|
1226 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1227 |
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
|
1228 |
return (__int64)(value * freq); |
2139 | 1229 |
} |