author | rubidium |
Tue, 22 Jan 2008 21:00:30 +0000 | |
branch | NewGRF_ports |
changeset 6872 | 1c4a4a609f85 |
parent 6871 | 5a9dc001e1ad |
child 10242 | 52b4a9006029 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6415
diff
changeset
|
3 |
/** @file win32.cpp Implementation of MS Windows system calls */ |
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6415
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1885
diff
changeset
|
6 |
#include "openttd.h" |
1302 | 7 |
#include "debug.h" |
2162
c1ded3bd3d0c
(svn r2672) Move saving/loading related declarations to saveload.h
tron
parents:
2160
diff
changeset
|
8 |
#include "saveload.h" |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
9 |
#include "gfx_func.h" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
10 |
#include "textbuf_gui.h" |
6624
554e5aee6c3f
(svn r9129) -Codechange: unify parts of DeterminePaths.
rubidium
parents:
6602
diff
changeset
|
11 |
#include "fileio.h" |
0 | 12 |
#include <windows.h> |
13 |
#include <winnt.h> |
|
14 |
#include <wininet.h> |
|
15 |
#include <io.h> |
|
16 |
#include <fcntl.h> |
|
5304
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
17 |
#include <shlobj.h> // SHGetFolderPath |
2160 | 18 |
#include "variables.h" |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
19 |
#include "win32.h" |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
20 |
#include "fios.h" // opendir/readdir/closedir |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
21 |
#include "fileio.h" |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
22 |
#include "core/alloc_func.hpp" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
23 |
#include "functions.h" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
24 |
#include "core/random_func.hpp" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
25 |
#include "core/bitmath_func.hpp" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
26 |
#include "string_func.h" |
4210
2c1a58c727ed
(svn r5698) - Fix [r5697]: don't remove ctype include for win32.c; needed for toupper...ugh
Darkvater
parents:
4209
diff
changeset
|
27 |
#include <ctype.h> |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
28 |
#include <tchar.h> |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
29 |
#include <errno.h> |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
30 |
#include <sys/types.h> |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
31 |
#include <sys/stat.h> |
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
32 |
#if defined(_MSC_VER) && !defined(WINCE) |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
33 |
#include <dbghelp.h> |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
34 |
#endif |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
35 |
|
0 | 36 |
static bool _has_console; |
37 |
||
3394
78963d9c1022
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
38 |
#if defined(__MINGW32__) |
78963d9c1022
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
39 |
#include <stdint.h> |
78963d9c1022
(svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents:
3341
diff
changeset
|
40 |
#endif |
0 | 41 |
|
2208 | 42 |
static bool cursor_visible = true; |
43 |
||
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
44 |
bool MyShowCursor(bool show) |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
45 |
{ |
2209 | 46 |
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
|
47 |
|
2209 | 48 |
cursor_visible = show; |
2207
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
49 |
ShowCursor(show); |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
50 |
|
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
51 |
return !show; |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
52 |
} |
40c928fbde8a
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents:
2195
diff
changeset
|
53 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
54 |
/** Helper function needed by dynamically loading libraries |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
55 |
* XXX: Hurray for MS only having an ANSI GetProcAddress function |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
56 |
* on normal windows and no Wide version except for in Windows Mobile/CE */ |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
57 |
bool LoadLibraryList(Function proc[], const char *dll) |
0 | 58 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
59 |
while (*dll != '\0') { |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
60 |
HMODULE lib; |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
61 |
lib = LoadLibrary(MB_TO_WIDE(dll)); |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
62 |
|
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
63 |
if (lib == NULL) return false; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
64 |
for (;;) { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
65 |
FARPROC p; |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
66 |
|
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
67 |
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
|
68 |
if (*dll == '\0') break; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
69 |
#if defined(WINCE) |
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
70 |
p = GetProcAddress(lib, MB_TO_WIDE(dll)); |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
71 |
#else |
0 | 72 |
p = GetProcAddress(lib, dll); |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
73 |
#endif |
2183
6fba9150225b
(svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents:
2177
diff
changeset
|
74 |
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
|
75 |
*proc++ = (Function)p; |
0 | 76 |
} |
77 |
dll++; |
|
78 |
} |
|
79 |
return true; |
|
80 |
} |
|
81 |
||
796 | 82 |
#ifdef _MSC_VER |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
83 |
static const char *_exception_string = NULL; |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
84 |
void SetExceptionString(const char *s, ...) |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
85 |
{ |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
86 |
va_list va; |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
87 |
char buf[512]; |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
88 |
|
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
89 |
va_start(va, s); |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
90 |
vsnprintf(buf, lengthof(buf), s, va); |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
91 |
va_end(va); |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
92 |
|
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
93 |
_exception_string = strdup(buf); |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
94 |
} |
2428
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
95 |
#endif |
0 | 96 |
|
97 |
void ShowOSErrorBox(const char *buf) |
|
98 |
{ |
|
99 |
MyShowCursor(true); |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
100 |
MessageBox(GetActiveWindow(), MB_TO_WIDE(buf), _T("Error!"), MB_ICONSTOP); |
0 | 101 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
102 |
/* if exception tracker is enabled, we crash here to let the exception handler handle it. */ |
0 | 103 |
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG) |
104 |
if (*buf == '!') { |
|
105 |
_exception_string = buf; |
|
106 |
*(byte*)0 = 0; |
|
107 |
} |
|
108 |
#endif |
|
109 |
} |
|
110 |
||
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
111 |
#if defined(_MSC_VER) && !defined(WINCE) |
2428
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
112 |
|
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
113 |
static void *_safe_esp; |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
114 |
static char *_crash_msg; |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
115 |
static bool _expanded; |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
116 |
static bool _did_emerg_save; |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
117 |
static int _ident; |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
118 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
119 |
struct DebugFileInfo { |
0 | 120 |
uint32 size; |
121 |
uint32 crc32; |
|
122 |
SYSTEMTIME file_time; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
123 |
}; |
0 | 124 |
|
125 |
static uint32 *_crc_table; |
|
126 |
||
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
127 |
static void MakeCRCTable(uint32 *table) |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
128 |
{ |
0 | 129 |
uint32 crc, poly = 0xEDB88320L; |
2026 | 130 |
int i; |
131 |
int j; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
132 |
|
0 | 133 |
_crc_table = table; |
134 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
135 |
for (i = 0; i != 256; i++) { |
0 | 136 |
crc = i; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
137 |
for (j = 8; j != 0; j--) { |
4078
4530dde1a8a9
(svn r5393) CodeChange : Little typo correction. Nothing spectacular. Only broke in MSVC
belugas
parents:
4077
diff
changeset
|
138 |
crc = (crc & 1 ? (crc >> 1) ^ poly : crc >> 1); |
0 | 139 |
} |
140 |
table[i] = crc; |
|
141 |
} |
|
142 |
} |
|
143 |
||
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
144 |
static uint32 CalcCRC(byte *data, uint size, uint32 crc) |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
145 |
{ |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
146 |
for (; size > 0; size--) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
147 |
crc = ((crc >> 8) & 0x00FFFFFF) ^ _crc_table[(crc ^ *data++) & 0xFF]; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
148 |
} |
0 | 149 |
return crc; |
150 |
} |
|
151 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
152 |
static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename) |
0 | 153 |
{ |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
154 |
HANDLE file; |
0 | 155 |
memset(dfi, 0, sizeof(dfi)); |
156 |
||
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
157 |
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
158 |
if (file != INVALID_HANDLE_VALUE) { |
0 | 159 |
byte buffer[1024]; |
160 |
DWORD numread; |
|
161 |
uint32 filesize = 0; |
|
162 |
FILETIME write_time; |
|
163 |
uint32 crc = (uint32)-1; |
|
164 |
||
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
165 |
for (;;) { |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
166 |
if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || numread == 0) |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
167 |
break; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
168 |
filesize += numread; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
169 |
crc = CalcCRC(buffer, numread, crc); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
170 |
} |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
171 |
dfi->size = filesize; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
172 |
dfi->crc32 = crc ^ (uint32)-1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
173 |
|
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
174 |
if (GetFileTime(file, NULL, NULL, &write_time)) { |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
175 |
FileTimeToSystemTime(&write_time, &dfi->file_time); |
0 | 176 |
} |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
177 |
CloseHandle(file); |
0 | 178 |
} |
179 |
} |
|
180 |
||
181 |
||
182 |
static char *PrintModuleInfo(char *output, HMODULE mod) |
|
183 |
{ |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
184 |
TCHAR buffer[MAX_PATH]; |
0 | 185 |
DebugFileInfo dfi; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
186 |
|
0 | 187 |
GetModuleFileName(mod, buffer, MAX_PATH); |
188 |
GetFileInfo(&dfi, buffer); |
|
2458
c95808cd2ac9
(svn r2984) Use adequate types, this should aid portability a bit
tron
parents:
2428
diff
changeset
|
189 |
output += sprintf(output, " %-20s handle: %p size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n", |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
190 |
WIDE_TO_MB(buffer), |
0 | 191 |
mod, |
192 |
dfi.size, |
|
193 |
dfi.crc32, |
|
194 |
dfi.file_time.wYear, |
|
195 |
dfi.file_time.wMonth, |
|
196 |
dfi.file_time.wDay, |
|
197 |
dfi.file_time.wHour, |
|
198 |
dfi.file_time.wMinute, |
|
199 |
dfi.file_time.wSecond |
|
200 |
); |
|
201 |
return output; |
|
202 |
} |
|
203 |
||
204 |
static char *PrintModuleList(char *output) |
|
205 |
{ |
|
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
206 |
BOOL (WINAPI *EnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD); |
0 | 207 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
208 |
if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0\0")) { |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
209 |
HMODULE modules[100]; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
210 |
DWORD needed; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
211 |
BOOL res; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
212 |
int count, i; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
213 |
|
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
214 |
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
215 |
if (proc != NULL) { |
0 | 216 |
res = EnumProcessModules(proc, modules, sizeof(modules), &needed); |
217 |
CloseHandle(proc); |
|
218 |
if (res) { |
|
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
219 |
count = min(needed / sizeof(HMODULE), lengthof(modules)); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
220 |
|
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
221 |
for (i = 0; i != count; i++) output = PrintModuleInfo(output, modules[i]); |
0 | 222 |
return output; |
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
output = PrintModuleInfo(output, NULL); |
|
227 |
return output; |
|
228 |
} |
|
229 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
230 |
static const TCHAR _crash_desc[] = |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
231 |
_T("A serious fault condition occured in the game. The game will shut down.\n") |
5781
1ddb0f889d2c
(svn r7843) -Codechange (r7840): left out word 'file' making crash-text look un-english-ish.
Darkvater
parents:
5780
diff
changeset
|
232 |
_T("Please send the crash information and the crash.dmp file (if any) to the developers.\n") |
5780
5756767879f9
(svn r7840) -Codechange: Change the crash window a bit. Tell about Flyspray and crash.dmp. Remove
Darkvater
parents:
5726
diff
changeset
|
233 |
_T("This will greatly help debugging. The correct place to do this is http://bugs.openttd.org. ") |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
234 |
_T("The information contained in the report is displayed below.\n") |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
235 |
_T("Press \"Emergency save\" to attempt saving the game."); |
0 | 236 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
237 |
static const TCHAR _save_succeeded[] = |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
238 |
_T("Emergency save succeeded.\n") |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
239 |
_T("Be aware that critical parts of the internal game state may have become ") |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
240 |
_T("corrupted. The saved game is not guaranteed to work."); |
0 | 241 |
|
6573 | 242 |
static bool EmergencySave() |
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
|
243 |
{ |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
244 |
SaveOrLoad("crash.sav", SL_SAVE, BASE_DIR); |
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
|
245 |
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
|
246 |
} |
0 | 247 |
|
5311
9a20c2d925da
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
248 |
/* Disable the crash-save submit code as it's not used */ |
9a20c2d925da
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
249 |
#if 0 |
9a20c2d925da
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
250 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
251 |
struct WinInetProcs { |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
252 |
HINTERNET (WINAPI *InternetOpen)(LPCTSTR,DWORD, LPCTSTR, LPCTSTR, DWORD); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
253 |
HINTERNET (WINAPI *InternetConnect)(HINTERNET, LPCTSTR, INTERNET_PORT, LPCTSTR, LPCTSTR, DWORD, DWORD, DWORD); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
254 |
HINTERNET (WINAPI *HttpOpenRequest)(HINTERNET, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR *, DWORD, DWORD); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
255 |
BOOL (WINAPI *HttpSendRequest)(HINTERNET, LPCTSTR, DWORD, LPVOID, DWORD); |
0 | 256 |
BOOL (WINAPI *InternetCloseHandle)(HINTERNET); |
257 |
BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD); |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
258 |
}; |
0 | 259 |
|
260 |
#define M(x) x "\0" |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
261 |
#if defined(UNICODE) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
262 |
# define W(x) x "W" |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
263 |
#else |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
264 |
# define W(x) x "A" |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
265 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
266 |
static const char wininet_files[] = |
0 | 267 |
M("wininet.dll") |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
268 |
M(W("InternetOpen")) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
269 |
M(W("InternetConnect")) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
270 |
M(W("HttpOpenRequest")) |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
271 |
M(W("HttpSendRequest")) |
0 | 272 |
M("InternetCloseHandle") |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
273 |
M(W("HttpQueryInfo")) |
0 | 274 |
M(""); |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
275 |
#undef W |
0 | 276 |
#undef M |
277 |
||
278 |
static WinInetProcs _wininet; |
|
279 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
280 |
static const TCHAR *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const TCHAR *arg) |
0 | 281 |
{ |
282 |
HINTERNET inet, conn, http; |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
283 |
const TCHAR *err = NULL; |
0 | 284 |
DWORD code, len; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
285 |
static TCHAR buf[100]; |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
286 |
TCHAR buff[100]; |
0 | 287 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
288 |
if (_wininet.InternetOpen == NULL && !LoadLibraryList((Function*)&_wininet, wininet_files)) return _T("can't load wininet.dll"); |
0 | 289 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
290 |
inet = _wininet.InternetOpen(_T("OTTD"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
291 |
if (inet == NULL) { err = _T("internetopen failed"); goto error1; } |
0 | 292 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
293 |
conn = _wininet.InternetConnect(inet, _T("www.openttd.org"), INTERNET_DEFAULT_HTTP_PORT, _T(""), _T(""), INTERNET_SERVICE_HTTP, 0, 0); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
294 |
if (conn == NULL) { err = _T("internetconnect failed"); goto error2; } |
0 | 295 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
296 |
_sntprintf(buff, lengthof(buff), _T("/crash.php?file=%s&ident=%d"), arg, _ident); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
297 |
|
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
298 |
http = _wininet.HttpOpenRequest(conn, _T("POST"), buff, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE , 0); |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
299 |
if (http == NULL) { err = _T("httpopenrequest failed"); goto error3; } |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
300 |
|
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
301 |
if (!_wininet.HttpSendRequest(http, _T("Content-type: application/binary"), -1, msg, (DWORD)msglen)) { err = _T("httpsendrequest failed"); goto error4; } |
0 | 302 |
|
303 |
len = sizeof(code); |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
304 |
if (!_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &len, 0)) { err = _T("httpqueryinfo failed"); goto error4; } |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
305 |
|
0 | 306 |
if (code != 200) { |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
307 |
int l = _sntprintf(buf, lengthof(buf), _T("Server said: %d "), code); |
0 | 308 |
len = sizeof(buf) - l; |
309 |
_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_TEXT, buf + l, &len, 0); |
|
310 |
err = buf; |
|
311 |
} |
|
312 |
||
313 |
error4: |
|
314 |
_wininet.InternetCloseHandle(http); |
|
315 |
error3: |
|
316 |
_wininet.InternetCloseHandle(conn); |
|
317 |
error2: |
|
318 |
_wininet.InternetCloseHandle(inet); |
|
319 |
error1: |
|
320 |
return err; |
|
321 |
} |
|
322 |
||
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
323 |
static void SubmitFile(HWND wnd, const TCHAR *file) |
0 | 324 |
{ |
325 |
HANDLE h; |
|
326 |
unsigned long size; |
|
327 |
unsigned long read; |
|
328 |
void *mem; |
|
329 |
||
330 |
h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
|
331 |
if (h == NULL) return; |
|
332 |
||
333 |
size = GetFileSize(h, NULL); |
|
334 |
if (size > 500000) goto error1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
335 |
|
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
336 |
mem = MallocT<byte>(size); |
0 | 337 |
if (mem == NULL) goto error1; |
338 |
||
339 |
if (!ReadFile(h, mem, size, &read, NULL) || read != size) goto error2; |
|
340 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
341 |
SubmitCrashReport(wnd, mem, size, file); |
0 | 342 |
|
343 |
error2: |
|
344 |
free(mem); |
|
345 |
error1: |
|
346 |
CloseHandle(h); |
|
347 |
} |
|
348 |
||
5311
9a20c2d925da
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
349 |
#endif /* Disabled crash-submit procedures */ |
9a20c2d925da
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
350 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
351 |
static const TCHAR * const _expand_texts[] = {_T("S&how report >>"), _T("&Hide report <<") }; |
0 | 352 |
|
353 |
static void SetWndSize(HWND wnd, int mode) |
|
354 |
{ |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
355 |
RECT r, r2; |
0 | 356 |
int offs; |
357 |
||
358 |
GetWindowRect(wnd, &r); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
359 |
|
0 | 360 |
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
|
361 |
|
0 | 362 |
if (mode >= 0) { |
363 |
GetWindowRect(GetDlgItem(wnd, 11), &r2); |
|
364 |
offs = r2.bottom - r2.top + 10; |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
365 |
if (!mode) offs = -offs; |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
366 |
SetWindowPos(wnd, HWND_TOPMOST, 0, 0, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
367 |
r.right - r.left, r.bottom - r.top + offs, SWP_NOMOVE | SWP_NOZORDER); |
0 | 368 |
} else { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
369 |
SetWindowPos(wnd, HWND_TOPMOST, |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
370 |
(GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2, |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
371 |
(GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2, |
0 | 372 |
0, 0, SWP_NOSIZE); |
373 |
} |
|
374 |
} |
|
375 |
||
376 |
static bool DoEmergencySave(HWND wnd) |
|
377 |
{ |
|
378 |
bool b = false; |
|
379 |
||
380 |
EnableWindow(GetDlgItem(wnd, 13), FALSE); |
|
381 |
_did_emerg_save = true; |
|
382 |
__try { |
|
383 |
b = EmergencySave(); |
|
384 |
} __except (1) {} |
|
385 |
return b; |
|
386 |
} |
|
387 |
||
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
388 |
static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) |
0 | 389 |
{ |
2952 | 390 |
switch (msg) { |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
391 |
case WM_INITDIALOG: { |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
392 |
#if defined(UNICODE) |
5312
884ebccbd847
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
393 |
/* We need to put the crash-log in a seperate buffer because the default |
5973
1a4cc06c6c64
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5925
diff
changeset
|
394 |
* buffer in MB_TO_WIDE is not large enough (512 chars) */ |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
395 |
wchar_t crash_msgW[8096]; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
396 |
#endif |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
397 |
SetDlgItemText(wnd, 10, _crash_desc); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
398 |
SetDlgItemText(wnd, 11, MB_TO_WIDE_BUFFER(_crash_msg, crash_msgW, lengthof(crash_msgW))); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
399 |
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
400 |
SetWndSize(wnd, -1); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
401 |
} return TRUE; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
402 |
case WM_COMMAND: |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
403 |
switch (wParam) { |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
404 |
case 12: /* Close */ |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
405 |
ExitProcess(0); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
406 |
case 13: /* Emergency save */ |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
407 |
if (DoEmergencySave(wnd)) { |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
408 |
MessageBox(wnd, _save_succeeded, _T("Save successful"), MB_ICONINFORMATION); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
409 |
} else { |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
410 |
MessageBox(wnd, _T("Save failed"), _T("Save failed"), MB_ICONINFORMATION); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
411 |
} |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
412 |
break; |
5311
9a20c2d925da
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
413 |
/* Disable the crash-save submit code as it's not used */ |
9a20c2d925da
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
414 |
#if 0 |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
415 |
case 14: { /* Submit crash report */ |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
416 |
const TCHAR *s; |
0 | 417 |
|
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
418 |
SetCursor(LoadCursor(NULL, IDC_WAIT)); |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
419 |
|
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
420 |
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), _T("")); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
421 |
if (s != NULL) { |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
422 |
MessageBox(wnd, s, _T("Error"), MB_ICONSTOP); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
423 |
break; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
424 |
} |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
425 |
|
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
426 |
// try to submit emergency savegame |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
427 |
if (_did_emerg_save || DoEmergencySave(wnd)) SubmitFile(wnd, _T("crash.sav")); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
428 |
|
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
429 |
// try to submit the autosaved game |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
430 |
if (_opt.autosave) { |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
431 |
TCHAR buf[40]; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
432 |
_sntprintf(buf, lengthof(buf), _T("autosave%d.sav"), (_autosave_ctr - 1) & 3); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
433 |
SubmitFile(wnd, buf); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
434 |
} |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
435 |
EnableWindow(GetDlgItem(wnd, 14), FALSE); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
436 |
SetCursor(LoadCursor(NULL, IDC_ARROW)); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
437 |
MessageBox(wnd, _T("Crash report submitted. Thank you."), _T("Crash Report"), MB_ICONINFORMATION); |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
438 |
} break; |
5311
9a20c2d925da
(svn r7467) -Cleanup: [win32] Disable the submit-savegame-on-crash code as we (webserver)
Darkvater
parents:
5310
diff
changeset
|
439 |
#endif /* Disabled crash-submit procedures */ |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
440 |
case 15: /* Expand window to show crash-message */ |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
441 |
_expanded ^= 1; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
442 |
SetWndSize(wnd, _expanded); |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
443 |
break; |
0 | 444 |
} |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
445 |
return TRUE; |
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
446 |
case WM_CLOSE: ExitProcess(0); |
0 | 447 |
} |
448 |
||
449 |
return FALSE; |
|
450 |
} |
|
451 |
||
6573 | 452 |
static void Handler2() |
0 | 453 |
{ |
454 |
ShowCursor(TRUE); |
|
455 |
ShowWindow(GetActiveWindow(), FALSE); |
|
456 |
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(100), NULL, CrashDialogFunc); |
|
457 |
} |
|
458 |
||
6573 | 459 |
extern bool CloseConsoleLogIfActive(); |
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
|
460 |
|
0 | 461 |
static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) |
462 |
{ |
|
3204
2f2e12688e97
(svn r3872) - [win32] Show the revision in crash.txt and enable the button to show the crash text in the crash-window
Darkvater
parents:
2952
diff
changeset
|
463 |
extern const char _openttd_revision[]; |
0 | 464 |
char *output; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
465 |
static bool had_exception = false; |
0 | 466 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
467 |
if (had_exception) ExitProcess(0); |
0 | 468 |
had_exception = true; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
469 |
|
0 | 470 |
_ident = GetTickCount(); // something pretty unique |
471 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
472 |
MakeCRCTable((uint32*)alloca(256 * sizeof(uint32))); |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
473 |
_crash_msg = output = (char*)LocalAlloc(LMEM_FIXED, 8192); |
0 | 474 |
|
475 |
{ |
|
476 |
SYSTEMTIME time; |
|
477 |
GetLocalTime(&time); |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
478 |
output += sprintf(output, |
0 | 479 |
"*** OpenTTD Crash Report ***\r\n" |
480 |
"Date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n" |
|
4236
1bc9b3024d0d
(svn r5801) - Codechange: The exception dialog showed the last modification-date of win32.c instead of the last compilation-date. Use __DATE__ __TIME__ instead of __TIMESTAMP__; only affected windows not built with mingw/cygwin.
Darkvater
parents:
4224
diff
changeset
|
481 |
"Build: %s built on " __DATE__ " " __TIME__ "\r\n", |
0 | 482 |
time.wYear, |
483 |
time.wMonth, |
|
484 |
time.wDay, |
|
485 |
time.wHour, |
|
486 |
time.wMinute, |
|
487 |
time.wSecond, |
|
3204
2f2e12688e97
(svn r3872) - [win32] Show the revision in crash.txt and enable the button to show the crash text in the crash-window
Darkvater
parents:
2952
diff
changeset
|
488 |
_openttd_revision |
0 | 489 |
); |
490 |
} |
|
491 |
||
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
492 |
if (_exception_string) |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
493 |
output += sprintf(output, "Reason: %s\r\n", _exception_string); |
0 | 494 |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
495 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
496 |
output += sprintf(output, "Exception %.8X at %.16IX\r\n" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
497 |
"Registers:\r\n" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
498 |
"RAX: %.16llX RBX: %.16llX RCX: %.16llX RDX: %.16llX\r\n" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
499 |
"RSI: %.16llX RDI: %.16llX RBP: %.16llX RSP: %.16llX\r\n" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
500 |
"R8: %.16llX R9: %.16llX R10: %.16llX R11: %.16llX\r\n" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
501 |
"R12: %.16llX R13: %.16llX R14: %.16llX R15: %.16llX\r\n" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
502 |
"RIP: %.16llX EFLAGS: %.8X\r\n" |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
503 |
"\r\nBytes at CS:RIP:\r\n", |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
504 |
ep->ExceptionRecord->ExceptionCode, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
505 |
ep->ExceptionRecord->ExceptionAddress, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
506 |
ep->ContextRecord->Rax, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
507 |
ep->ContextRecord->Rbx, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
508 |
ep->ContextRecord->Rcx, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
509 |
ep->ContextRecord->Rdx, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
510 |
ep->ContextRecord->Rsi, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
511 |
ep->ContextRecord->Rdi, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
512 |
ep->ContextRecord->Rbp, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
513 |
ep->ContextRecord->Rsp, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
514 |
ep->ContextRecord->R8, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
515 |
ep->ContextRecord->R9, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
516 |
ep->ContextRecord->R10, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
517 |
ep->ContextRecord->R11, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
518 |
ep->ContextRecord->R12, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
519 |
ep->ContextRecord->R13, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
520 |
ep->ContextRecord->R14, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
521 |
ep->ContextRecord->R15, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
522 |
ep->ContextRecord->Rip, |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
523 |
ep->ContextRecord->EFlags |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
524 |
); |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
525 |
#else |
0 | 526 |
output += sprintf(output, "Exception %.8X at %.8X\r\n" |
527 |
"Registers:\r\n" |
|
528 |
" EAX: %.8X EBX: %.8X ECX: %.8X EDX: %.8X\r\n" |
|
529 |
" ESI: %.8X EDI: %.8X EBP: %.8X ESP: %.8X\r\n" |
|
530 |
" EIP: %.8X EFLAGS: %.8X\r\n" |
|
531 |
"\r\nBytes at CS:EIP:\r\n", |
|
532 |
ep->ExceptionRecord->ExceptionCode, |
|
533 |
ep->ExceptionRecord->ExceptionAddress, |
|
534 |
ep->ContextRecord->Eax, |
|
535 |
ep->ContextRecord->Ebx, |
|
536 |
ep->ContextRecord->Ecx, |
|
537 |
ep->ContextRecord->Edx, |
|
538 |
ep->ContextRecord->Esi, |
|
539 |
ep->ContextRecord->Edi, |
|
540 |
ep->ContextRecord->Ebp, |
|
541 |
ep->ContextRecord->Esp, |
|
542 |
ep->ContextRecord->Eip, |
|
543 |
ep->ContextRecord->EFlags |
|
544 |
); |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
545 |
#endif |
0 | 546 |
|
547 |
{ |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
548 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
549 |
byte *b = (byte*)ep->ContextRecord->Rip; |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
550 |
#else |
0 | 551 |
byte *b = (byte*)ep->ContextRecord->Eip; |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
552 |
#endif |
0 | 553 |
int i; |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
554 |
for (i = 0; i != 24; i++) { |
0 | 555 |
if (IsBadReadPtr(b, 1)) { |
556 |
output += sprintf(output, " ??"); // OCR: WAS: , 0); |
|
557 |
} else { |
|
558 |
output += sprintf(output, " %.2X", *b); |
|
559 |
} |
|
560 |
b++; |
|
561 |
} |
|
562 |
output += sprintf(output, |
|
563 |
"\r\n" |
|
564 |
"\r\nStack trace: \r\n" |
|
565 |
); |
|
566 |
} |
|
567 |
||
568 |
{ |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
569 |
int i, j; |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
570 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
571 |
uint32 *b = (uint32*)ep->ContextRecord->Rsp; |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
572 |
#else |
0 | 573 |
uint32 *b = (uint32*)ep->ContextRecord->Esp; |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
574 |
#endif |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
575 |
for (j = 0; j != 24; j++) { |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
576 |
for (i = 0; i != 8; i++) { |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
577 |
if (IsBadReadPtr(b, sizeof(uint32))) { |
0 | 578 |
output += sprintf(output, " ????????"); //OCR: WAS - , 0); |
579 |
} else { |
|
580 |
output += sprintf(output, " %.8X", *b); |
|
581 |
} |
|
582 |
b++; |
|
583 |
} |
|
584 |
output += sprintf(output, "\r\n"); |
|
585 |
} |
|
586 |
} |
|
587 |
||
588 |
output += sprintf(output, "\r\nModule information:\r\n"); |
|
589 |
output = PrintModuleList(output); |
|
590 |
||
591 |
{ |
|
592 |
OSVERSIONINFO os; |
|
593 |
os.dwOSVersionInfoSize = sizeof(os); |
|
594 |
GetVersionEx(&os); |
|
595 |
output += sprintf(output, "\r\nSystem information:\r\n" |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
596 |
" Windows version %d.%d %d %s\r\n", |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
597 |
os.dwMajorVersion, os.dwMinorVersion, os.dwBuildNumber, os.szCSDVersion); |
0 | 598 |
} |
599 |
||
600 |
{ |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
601 |
HANDLE file = CreateFile(_T("crash.log"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); |
0 | 602 |
DWORD num_written; |
603 |
if (file != INVALID_HANDLE_VALUE) { |
|
604 |
WriteFile(file, _crash_msg, output - _crash_msg, &num_written, NULL); |
|
605 |
CloseHandle(file); |
|
606 |
} |
|
607 |
} |
|
608 |
||
6868
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
609 |
#if !defined(_DEBUG) |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
610 |
HMODULE dbghelp = LoadLibrary(_T("dbghelp.dll")); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
611 |
if (dbghelp != NULL) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
612 |
typedef BOOL (WINAPI *MiniDumpWriteDump_t)(HANDLE, DWORD, HANDLE, |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
613 |
MINIDUMP_TYPE, |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
614 |
CONST PMINIDUMP_EXCEPTION_INFORMATION, |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
615 |
CONST PMINIDUMP_USER_STREAM_INFORMATION, |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
616 |
CONST PMINIDUMP_CALLBACK_INFORMATION); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
617 |
MiniDumpWriteDump_t funcMiniDumpWriteDump = (MiniDumpWriteDump_t)GetProcAddress(dbghelp, "MiniDumpWriteDump"); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
618 |
if (funcMiniDumpWriteDump != NULL) { |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
619 |
HANDLE file = CreateFile(_T("crash.dmp"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
620 |
HANDLE proc = GetCurrentProcess(); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
621 |
DWORD procid = GetCurrentProcessId(); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
622 |
MINIDUMP_EXCEPTION_INFORMATION mdei; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
623 |
MINIDUMP_USER_STREAM userstream; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
624 |
MINIDUMP_USER_STREAM_INFORMATION musi; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
625 |
char msg[] = "****** Built on " __DATE__ " " __TIME__ ". ******"; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
626 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
627 |
userstream.Type = LastReservedStream + 1; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
628 |
userstream.Buffer = msg; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
629 |
userstream.BufferSize = sizeof(msg); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
630 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
631 |
musi.UserStreamCount = 1; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
632 |
musi.UserStreamArray = &userstream; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
633 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
634 |
mdei.ThreadId = GetCurrentThreadId(); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
635 |
mdei.ExceptionPointers = ep; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
636 |
mdei.ClientPointers = false; |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
637 |
|
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
638 |
funcMiniDumpWriteDump(proc, procid, file, MiniDumpWithDataSegs, &mdei, &musi, NULL); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
639 |
} |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
640 |
FreeLibrary(dbghelp); |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
641 |
} |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
642 |
#endif |
7eb395287b3d
(svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents:
6800
diff
changeset
|
643 |
|
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
|
644 |
/* 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
|
645 |
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
|
646 |
|
0 | 647 |
if (_safe_esp) { |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
648 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
649 |
ep->ContextRecord->Rip = (DWORD64)Handler2; |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
650 |
ep->ContextRecord->Rsp = (DWORD64)_safe_esp; |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
651 |
#else |
0 | 652 |
ep->ContextRecord->Eip = (DWORD)Handler2; |
653 |
ep->ContextRecord->Esp = (DWORD)_safe_esp; |
|
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
654 |
#endif |
0 | 655 |
return EXCEPTION_CONTINUE_EXECUTION; |
656 |
} |
|
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
|
657 |
|
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
|
658 |
|
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
|
659 |
return EXCEPTION_EXECUTE_HANDLER; |
0 | 660 |
} |
661 |
||
6497
b7170a1ffb33
(svn r8933) -Fix [Win64]: rdtsc now uses intrinsic on VC8 (michi_cc)
KUDr
parents:
6491
diff
changeset
|
662 |
#ifdef _M_AMD64 |
6573 | 663 |
extern "C" void *_get_save_esp(); |
6497
b7170a1ffb33
(svn r8933) -Fix [Win64]: rdtsc now uses intrinsic on VC8 (michi_cc)
KUDr
parents:
6491
diff
changeset
|
664 |
#endif |
b7170a1ffb33
(svn r8933) -Fix [Win64]: rdtsc now uses intrinsic on VC8 (michi_cc)
KUDr
parents:
6491
diff
changeset
|
665 |
|
6573 | 666 |
static void Win32InitializeExceptions() |
0 | 667 |
{ |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
668 |
#ifdef _M_AMD64 |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
669 |
_safe_esp = _get_save_esp(); |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
670 |
#else |
0 | 671 |
_asm { |
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
672 |
mov _safe_esp, esp |
0 | 673 |
} |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
674 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
675 |
|
0 | 676 |
SetUnhandledExceptionFilter(ExceptionHandler); |
677 |
} |
|
3341
b8febc9509d7
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
3340
diff
changeset
|
678 |
#endif /* _MSC_VER */ |
0 | 679 |
|
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
680 |
/* Code below for windows version of opendir/readdir/closedir copied and |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
681 |
* modified from Jan Wassenberg's GPL implementation posted over at |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
682 |
* http://www.gamedev.net/community/forums/topic.asp?topic_id=364584&whichpage=1� */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
683 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
684 |
/* suballocator - satisfies most requests with a reusable static instance. |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
685 |
* this avoids hundreds of alloc/free which would fragment the heap. |
6142
3afbecfa23a7
(svn r8508) -Codechange (r5762): [win32] Use an atomic operation to query and set the value of _global_dir_is_in_use for opendir etc to guarantee concurrency.
Darkvater
parents:
6009
diff
changeset
|
686 |
* To guarantee concurrency, we fall back to malloc if the instance is |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
687 |
* already in use (it's important to avoid suprises since this is such a |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
688 |
* low-level routine). */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
689 |
static DIR _global_dir; |
6142
3afbecfa23a7
(svn r8508) -Codechange (r5762): [win32] Use an atomic operation to query and set the value of _global_dir_is_in_use for opendir etc to guarantee concurrency.
Darkvater
parents:
6009
diff
changeset
|
690 |
static LONG _global_dir_is_in_use = false; |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
691 |
|
6573 | 692 |
static inline DIR *dir_calloc() |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
693 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
694 |
DIR *d; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
695 |
|
6142
3afbecfa23a7
(svn r8508) -Codechange (r5762): [win32] Use an atomic operation to query and set the value of _global_dir_is_in_use for opendir etc to guarantee concurrency.
Darkvater
parents:
6009
diff
changeset
|
696 |
if (InterlockedExchange(&_global_dir_is_in_use, true) == (LONG)true) { |
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
697 |
d = CallocT<DIR>(1); |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
698 |
} else { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
699 |
d = &_global_dir; |
4224
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
700 |
memset(d, 0, sizeof(*d)); |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
701 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
702 |
return d; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
703 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
704 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
705 |
static inline void dir_free(DIR *d) |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
706 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
707 |
if (d == &_global_dir) { |
6142
3afbecfa23a7
(svn r8508) -Codechange (r5762): [win32] Use an atomic operation to query and set the value of _global_dir_is_in_use for opendir etc to guarantee concurrency.
Darkvater
parents:
6009
diff
changeset
|
708 |
_global_dir_is_in_use = (LONG)false; |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
709 |
} else { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
710 |
free(d); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
711 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
712 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
713 |
|
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
714 |
DIR *opendir(const TCHAR *path) |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
715 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
716 |
DIR *d; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
717 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
718 |
DWORD fa = GetFileAttributes(path); |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
719 |
|
4224
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
720 |
if ((fa != INVALID_FILE_ATTRIBUTES) && (fa & FILE_ATTRIBUTE_DIRECTORY)) { |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
721 |
d = dir_calloc(); |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
722 |
if (d != NULL) { |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
723 |
TCHAR search_path[MAX_PATH]; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
724 |
bool slash = path[_tcslen(path) - 1] == '\\'; |
6491
f93251621d20
(svn r8919) -Regression (UTF8) (try #2): Win9x is very picky about trailing slashes in paths, so C:\\* will not work (but C:\Windows\\* does; go figure). Thanks glx for pointing it out and for the initial fix.
Darkvater
parents:
6450
diff
changeset
|
725 |
|
f93251621d20
(svn r8919) -Regression (UTF8) (try #2): Win9x is very picky about trailing slashes in paths, so C:\\* will not work (but C:\Windows\\* does; go figure). Thanks glx for pointing it out and for the initial fix.
Darkvater
parents:
6450
diff
changeset
|
726 |
/* build search path for FindFirstFile, try not to append additional slashes |
f93251621d20
(svn r8919) -Regression (UTF8) (try #2): Win9x is very picky about trailing slashes in paths, so C:\\* will not work (but C:\Windows\\* does; go figure). Thanks glx for pointing it out and for the initial fix.
Darkvater
parents:
6450
diff
changeset
|
727 |
* as it throws Win9x off its groove for root directories */ |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
728 |
_sntprintf(search_path, lengthof(search_path), _T("%s%s*"), path, slash ? _T("") : _T("\\")); |
6415
c802d76a67fd
(svn r8824) -Fix (r8821): don't use MSVC2005 runtime library-only _snwprintf_s function, but use 'insecure/deprecated' version and zero-terminate string ourselves. Thanks for testing glx.
Darkvater
parents:
6412
diff
changeset
|
729 |
*lastof(search_path) = '\0'; |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
730 |
d->hFind = FindFirstFile(search_path, &d->fd); |
4224
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
731 |
|
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
732 |
if (d->hFind != INVALID_HANDLE_VALUE || |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
733 |
GetLastError() == ERROR_NO_MORE_FILES) { // the directory is empty |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
734 |
d->ent.dir = d; |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
735 |
d->at_first_entry = true; |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
736 |
} else { |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
737 |
dir_free(d); |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
738 |
d = NULL; |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
739 |
} |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
740 |
} else { |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
741 |
errno = ENOMEM; |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
742 |
} |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
743 |
} else { |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
744 |
/* path not found or not a directory */ |
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
745 |
d = NULL; |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
746 |
errno = ENOENT; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
747 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
748 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
749 |
SetErrorMode(sem); // restore previous setting |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
750 |
return d; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
751 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
752 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
753 |
struct dirent *readdir(DIR *d) |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
754 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
755 |
DWORD prev_err = GetLastError(); // avoid polluting last error |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
756 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
757 |
if (d->at_first_entry) { |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
758 |
/* the directory was empty when opened */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
759 |
if (d->hFind == INVALID_HANDLE_VALUE) return NULL; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
760 |
d->at_first_entry = false; |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
761 |
} else if (!FindNextFile(d->hFind, &d->fd)) { // determine cause and bail |
4218
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
762 |
if (GetLastError() == ERROR_NO_MORE_FILES) SetLastError(prev_err); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
763 |
return NULL; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
764 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
765 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
766 |
/* This entry has passed all checks; return information about it. |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
767 |
* (note: d_name is a pointer; see struct dirent definition) */ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
768 |
d->ent.d_name = d->fd.cFileName; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
769 |
return &d->ent; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
770 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
771 |
|
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
772 |
int closedir(DIR *d) |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
773 |
{ |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
774 |
FindClose(d->hFind); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
775 |
dir_free(d); |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
776 |
return 0; |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
777 |
} |
384c7451e3bb
(svn r5762) - Codechange: Implementation of POSIX-style opendir/readdir/closedir functions for windows using FindFirstFile/FindNextFile/FindClose.
Darkvater
parents:
4210
diff
changeset
|
778 |
|
4221
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
779 |
bool FiosIsRoot(const char *file) |
0 | 780 |
{ |
4221
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
781 |
return file[3] == '\0'; // C:\... |
0 | 782 |
} |
783 |
||
6573 | 784 |
void FiosGetDrives() |
0 | 785 |
{ |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
786 |
#if defined(WINCE) |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
787 |
/* WinCE only knows one drive: / */ |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
788 |
FiosItem *fios = FiosAlloc(); |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
789 |
fios->type = FIOS_TYPE_DRIVE; |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
790 |
fios->mtime = 0; |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
791 |
snprintf(fios->name, lengthof(fios->name), PATHSEP ""); |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
792 |
ttd_strlcpy(fios->title, fios->name, lengthof(fios->title)); |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
793 |
#else |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
794 |
TCHAR drives[256]; |
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
795 |
const TCHAR *s; |
0 | 796 |
|
4221
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
797 |
GetLogicalDriveStrings(sizeof(drives), drives); |
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
798 |
for (s = drives; *s != '\0';) { |
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
799 |
FiosItem *fios = FiosAlloc(); |
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
800 |
fios->type = FIOS_TYPE_DRIVE; |
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
801 |
fios->mtime = 0; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
802 |
snprintf(fios->name, lengthof(fios->name), "%c:", s[0] & 0xFF); |
4221
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
803 |
ttd_strlcpy(fios->title, fios->name, lengthof(fios->title)); |
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
804 |
while (*s++ != '\0'); |
0 | 805 |
} |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
806 |
#endif |
0 | 807 |
} |
808 |
||
4221
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
809 |
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) |
0 | 810 |
{ |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
811 |
/* hectonanoseconds between Windows and POSIX epoch */ |
4247
00cdac3de8e9
(svn r5836) - Silence a warning on mingw. Thanks glx.
Darkvater
parents:
4245
diff
changeset
|
812 |
static const int64 posix_epoch_hns = 0x019DB1DED53E8000LL; |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
813 |
const WIN32_FIND_DATA *fd = &ent->dir->fd; |
0 | 814 |
|
4224
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
815 |
sb->st_size = ((uint64) fd->nFileSizeHigh << 32) + fd->nFileSizeLow; |
4245
59697b49326e
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
816 |
/* UTC FILETIME to seconds-since-1970 UTC |
59697b49326e
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
817 |
* we just have to subtract POSIX epoch and scale down to units of seconds. |
59697b49326e
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
818 |
* http://www.gamedev.net/community/forums/topic.asp?topic_id=294070&whichpage=1� |
59697b49326e
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
819 |
* XXX - not entirely correct, since filetimes on FAT aren't UTC but local, |
59697b49326e
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
820 |
* this won't entirely be correct, but we use the time only for comparsion. */ |
59697b49326e
(svn r5831) - Fix (r5765): regression regarding windows filetimes. st->st_mtime's type time_t is only 64bit on windows64, so we need to convert it.
Darkvater
parents:
4236
diff
changeset
|
821 |
sb->st_mtime = (time_t)((*(uint64*)&fd->ftLastWriteTime - posix_epoch_hns) / 1E7); |
4221
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
822 |
sb->st_mode = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG; |
4224
4471b359da52
(svn r5769) - Fix (r5762): fix some mistakes in the opendir code and filesize calculation. Thanks to Tron for noticing (and fixing).
Darkvater
parents:
4223
diff
changeset
|
823 |
|
4221
bb06fe8dcce2
(svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents:
4220
diff
changeset
|
824 |
return true; |
0 | 825 |
} |
826 |
||
6566
a780a47d6af3
(svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents:
6521
diff
changeset
|
827 |
bool FiosIsHiddenFile(const struct dirent *ent) |
a780a47d6af3
(svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents:
6521
diff
changeset
|
828 |
{ |
a780a47d6af3
(svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents:
6521
diff
changeset
|
829 |
return (ent->dir->fd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0; |
a780a47d6af3
(svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents:
6521
diff
changeset
|
830 |
} |
a780a47d6af3
(svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents:
6521
diff
changeset
|
831 |
|
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
832 |
bool FiosGetDiskFreeSpace(const char *path, uint32 *tot) |
0 | 833 |
{ |
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
|
834 |
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box |
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
835 |
bool retval = false; |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
836 |
TCHAR root[4]; |
0 | 837 |
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
|
838 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
839 |
_sntprintf(root, lengthof(root), _T("%c:") _T(PATHSEP), path[0]); |
1596
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1582
diff
changeset
|
840 |
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
|
841 |
*tot = ((spc * bps) * (uint64)nfc) >> 20; |
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
842 |
retval = true; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
843 |
} |
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
|
844 |
|
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
|
845 |
SetErrorMode(sem); // reset previous setting |
4222
951fbf19b1ad
(svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents:
4221
diff
changeset
|
846 |
return retval; |
0 | 847 |
} |
848 |
||
849 |
static int ParseCommandLine(char *line, char **argv, int max_argc) |
|
850 |
{ |
|
851 |
int n = 0; |
|
852 |
||
853 |
do { |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
854 |
/* skip whitespace */ |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
855 |
while (*line == ' ' || *line == '\t') line++; |
0 | 856 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
857 |
/* end? */ |
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
858 |
if (*line == '\0') break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
859 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
860 |
/* special handling when quoted */ |
0 | 861 |
if (*line == '"') { |
862 |
argv[n++] = ++line; |
|
863 |
while (*line != '"') { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
864 |
if (*line == '\0') return n; |
0 | 865 |
line++; |
866 |
} |
|
867 |
} else { |
|
868 |
argv[n++] = line; |
|
869 |
while (*line != ' ' && *line != '\t') { |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
870 |
if (*line == '\0') return n; |
0 | 871 |
line++; |
872 |
} |
|
873 |
} |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
874 |
*line++ = '\0'; |
0 | 875 |
} while (n != max_argc); |
876 |
||
877 |
return n; |
|
878 |
} |
|
879 |
||
6573 | 880 |
void CreateConsole() |
0 | 881 |
{ |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
882 |
#if defined(WINCE) |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
883 |
/* WinCE doesn't support console stuff */ |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
884 |
#else |
0 | 885 |
HANDLE hand; |
886 |
CONSOLE_SCREEN_BUFFER_INFO coninfo; |
|
887 |
||
888 |
if (_has_console) return; |
|
889 |
_has_console = true; |
|
890 |
||
4572
e6e17d286de7
(svn r6421) -Revert r6420: The dedicated server's console actually needs to work. It misses half the input at the moment. Sorry, too hasty commit.
Darkvater
parents:
4571
diff
changeset
|
891 |
AllocConsole(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
892 |
|
0 | 893 |
hand = GetStdHandle(STD_OUTPUT_HANDLE); |
894 |
GetConsoleScreenBufferInfo(hand, &coninfo); |
|
895 |
coninfo.dwSize.Y = 500; |
|
896 |
SetConsoleScreenBufferSize(hand, coninfo.dwSize); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
897 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
898 |
/* redirect unbuffered STDIN, STDOUT, STDERR to the console */ |
2172 | 899 |
#if !defined(__CYGWIN__) |
2482
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
900 |
*stdout = *_fdopen( _open_osfhandle((intptr_t)hand, _O_TEXT), "w" ); |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
901 |
*stdin = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" ); |
dffcca243dbc
(svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents:
2458
diff
changeset
|
902 |
*stderr = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); |
0 | 903 |
#else |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
904 |
/* open_osfhandle is not in cygwin */ |
0 | 905 |
*stdout = *fdopen(1, "w" ); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
906 |
*stdin = *fdopen(0, "r" ); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
907 |
*stderr = *fdopen(2, "w" ); |
0 | 908 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
909 |
|
1468
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
910 |
setvbuf(stdin, NULL, _IONBF, 0); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
911 |
setvbuf(stdout, NULL, _IONBF, 0); |
8073826fe82d
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
912 |
setvbuf(stderr, NULL, _IONBF, 0); |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
913 |
#endif |
0 | 914 |
} |
915 |
||
916 |
void ShowInfo(const char *str) |
|
917 |
{ |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
918 |
if (_has_console) { |
5925
f8e678955ef1
(svn r8134) -Fix (r8013): Add a newline after the ShowInfo console output
Darkvater
parents:
5860
diff
changeset
|
919 |
fprintf(stderr, "%s\n", str); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3799
diff
changeset
|
920 |
} else { |
0 | 921 |
bool old; |
5973
1a4cc06c6c64
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5925
diff
changeset
|
922 |
#if defined(UNICODE) |
1a4cc06c6c64
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5925
diff
changeset
|
923 |
/* We need to put the text in a seperate buffer because the default |
1a4cc06c6c64
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5925
diff
changeset
|
924 |
* buffer in MB_TO_WIDE might not be large enough (512 chars) */ |
1a4cc06c6c64
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5925
diff
changeset
|
925 |
wchar_t help_msgW[4096]; |
1a4cc06c6c64
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5925
diff
changeset
|
926 |
#endif |
0 | 927 |
ReleaseCapture(); |
928 |
_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
|
929 |
|
0 | 930 |
old = MyShowCursor(true); |
5973
1a4cc06c6c64
(svn r8239) -Regression (r7278): Help window was empty for UNICODE builds
Darkvater
parents:
5925
diff
changeset
|
931 |
if (MessageBox(GetActiveWindow(), MB_TO_WIDE_BUFFER(str, help_msgW, lengthof(help_msgW)), _T("OpenTTD"), MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) { |
0 | 932 |
CreateConsole(); |
933 |
} |
|
934 |
MyShowCursor(old); |
|
935 |
} |
|
936 |
} |
|
937 |
||
2428
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
938 |
#ifdef __MINGW32__ |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
939 |
/* _set_error_mode() constants&function (do not exist in mingw headers) */ |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
940 |
#define _OUT_TO_DEFAULT 0 |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
941 |
#define _OUT_TO_STDERR 1 |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
942 |
#define _OUT_TO_MSGBOX 2 |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
943 |
#define _REPORT_ERRMODE 3 |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
944 |
int _set_error_mode(int); |
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
945 |
#endif |
0 | 946 |
|
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
947 |
#if defined(WINCE) |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
948 |
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
949 |
#else |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
950 |
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
951 |
#endif |
0 | 952 |
{ |
953 |
int argc; |
|
954 |
char *argv[64]; // max 64 command line arguments |
|
5312
884ebccbd847
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
955 |
char *cmdline; |
0 | 956 |
|
6602
391adb618a4c
(svn r9085) -Codechange/Fix: [win32] Move the initialisation of _codepage (non-UNICODE) to winMain as a dedicated server, or different video driver will not have a win32 messageloop.
Darkvater
parents:
6601
diff
changeset
|
957 |
#if !defined(UNICODE) |
391adb618a4c
(svn r9085) -Codechange/Fix: [win32] Move the initialisation of _codepage (non-UNICODE) to winMain as a dedicated server, or different video driver will not have a win32 messageloop.
Darkvater
parents:
6601
diff
changeset
|
958 |
_codepage = GetACP(); // get system codepage as some kind of a default |
391adb618a4c
(svn r9085) -Codechange/Fix: [win32] Move the initialisation of _codepage (non-UNICODE) to winMain as a dedicated server, or different video driver will not have a win32 messageloop.
Darkvater
parents:
6601
diff
changeset
|
959 |
#endif /* UNICODE */ |
391adb618a4c
(svn r9085) -Codechange/Fix: [win32] Move the initialisation of _codepage (non-UNICODE) to winMain as a dedicated server, or different video driver will not have a win32 messageloop.
Darkvater
parents:
6601
diff
changeset
|
960 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
961 |
#if defined(UNICODE) |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
962 |
|
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
963 |
#if !defined(WINCE) |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
964 |
/* Check if a win9x user started the win32 version */ |
6871
5a9dc001e1ad
(svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents:
6870
diff
changeset
|
965 |
if (HasBit(GetVersion(), 31)) error("This version of OpenTTD doesn't run on windows 95/98/ME.\nPlease download the win9x binary and try again."); |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
966 |
#endif |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
967 |
|
5312
884ebccbd847
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
968 |
/* For UNICODE we need to convert the commandline to char* _AND_ |
884ebccbd847
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
969 |
* save it because argv[] points into this buffer and thus needs to |
884ebccbd847
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
970 |
* be available between subsequent calls to FS2OTTD() */ |
884ebccbd847
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
971 |
char cmdlinebuf[MAX_PATH]; |
6602
391adb618a4c
(svn r9085) -Codechange/Fix: [win32] Move the initialisation of _codepage (non-UNICODE) to winMain as a dedicated server, or different video driver will not have a win32 messageloop.
Darkvater
parents:
6601
diff
changeset
|
972 |
#endif /* UNICODE */ |
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
973 |
|
5312
884ebccbd847
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
974 |
cmdline = WIDE_TO_MB_BUFFER(GetCommandLine(), cmdlinebuf, lengthof(cmdlinebuf)); |
884ebccbd847
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
975 |
|
0 | 976 |
#if defined(_DEBUG) |
977 |
CreateConsole(); |
|
978 |
#endif |
|
979 |
||
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
980 |
#if !defined(WINCE) |
2428
b2e4fb6665d0
(svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents:
2338
diff
changeset
|
981 |
_set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
982 |
#endif |
0 | 983 |
|
5310
3ce198917af0
(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.
Darkvater
parents:
5304
diff
changeset
|
984 |
/* setup random seed to something quite random */ |
6871
5a9dc001e1ad
(svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents:
6870
diff
changeset
|
985 |
SetRandomSeed(GetTickCount()); |
0 | 986 |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
987 |
argc = ParseCommandLine(cmdline, argv, lengthof(argv)); |
0 | 988 |
|
989 |
#if defined(WIN32_EXCEPTION_TRACKER) |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
990 |
Win32InitializeExceptions(); |
0 | 991 |
#endif |
992 |
||
993 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
994 |
_try { |
|
5168
10a8dc9788d7
(svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents:
5167
diff
changeset
|
995 |
LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep); |
0 | 996 |
#endif |
997 |
ttd_main(argc, argv); |
|
998 |
||
999 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
1000 |
} _except (ExceptionHandler(_exception_info())) {} |
|
1001 |
#endif |
|
1002 |
||
1003 |
return 0; |
|
1004 |
} |
|
1005 |
||
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1006 |
#if defined(WINCE) |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1007 |
void GetCurrentDirectoryW(int length, wchar_t *path) |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1008 |
{ |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1009 |
/* Get the name of this module */ |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1010 |
GetModuleFileName(NULL, path, length); |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1011 |
|
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1012 |
/* Remove the executable name, this we call CurrentDir */ |
6450
1c2016673250
(svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents:
6443
diff
changeset
|
1013 |
wchar_t *pDest = wcsrchr(path, '\\'); |
6009
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1014 |
if (pDest != NULL) { |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1015 |
int result = pDest - path + 1; |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1016 |
path[result] = '\0'; |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1017 |
} |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1018 |
} |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1019 |
#endif |
cf31b0e5c696
(svn r8309) [WinCE] -Fix: WinCE doesn't know resolution changing
truelight
parents:
5973
diff
changeset
|
1020 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1021 |
char *getcwd(char *buf, size_t size) |
0 | 1022 |
{ |
6800
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
1023 |
#if defined(WINCE) |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
1024 |
TCHAR path[MAX_PATH]; |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
1025 |
GetModuleFileName(NULL, path, MAX_PATH); |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
1026 |
convert_from_fs(path, buf, size); |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
1027 |
/* GetModuleFileName returns dir with file, so remove everything behind latest '\\' */ |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
1028 |
char *p = strrchr(buf, '\\'); |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
1029 |
if (p != NULL) *p = '\0'; |
6c09e1e86fcb
(svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents:
6743
diff
changeset
|
1030 |
#elif defined(UNICODE) |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1031 |
TCHAR path[MAX_PATH]; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1032 |
GetCurrentDirectory(MAX_PATH - 1, path); |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1033 |
convert_from_fs(path, buf, size); |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1034 |
#else |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1035 |
GetCurrentDirectory(size, buf); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1036 |
#endif |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1037 |
return buf; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1038 |
} |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1039 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1040 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1041 |
void DetermineBasePaths(const char *exe) |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1042 |
{ |
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1043 |
extern void ScanForTarFiles(); |
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1044 |
char tmp[MAX_PATH]; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1045 |
TCHAR path[MAX_PATH]; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1046 |
#ifdef WITH_PERSONAL_DIR |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1047 |
SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1048 |
strncpy(tmp, WIDE_TO_MB_BUFFER(path, tmp, lengthof(tmp)), lengthof(tmp)); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1049 |
AppendPathSeparator(tmp, MAX_PATH); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1050 |
ttd_strlcat(tmp, PERSONAL_DIR, MAX_PATH); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1051 |
AppendPathSeparator(tmp, MAX_PATH); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1052 |
_searchpaths[SP_PERSONAL_DIR] = strdup(tmp); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1053 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1054 |
SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS, NULL, SHGFP_TYPE_CURRENT, path); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1055 |
strncpy(tmp, WIDE_TO_MB_BUFFER(path, tmp, lengthof(tmp)), lengthof(tmp)); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1056 |
AppendPathSeparator(tmp, MAX_PATH); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1057 |
ttd_strlcat(tmp, PERSONAL_DIR, MAX_PATH); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1058 |
AppendPathSeparator(tmp, MAX_PATH); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1059 |
_searchpaths[SP_SHARED_DIR] = strdup(tmp); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1060 |
#else |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1061 |
_searchpaths[SP_PERSONAL_DIR] = NULL; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1062 |
_searchpaths[SP_SHARED_DIR] = NULL; |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1063 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1064 |
|
6720
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1065 |
/* Get the path to working directory of OpenTTD */ |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1066 |
getcwd(tmp, lengthof(tmp)); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1067 |
AppendPathSeparator(tmp, MAX_PATH); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1068 |
_searchpaths[SP_WORKING_DIR] = strdup(tmp); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1069 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1070 |
if (!GetModuleFileName(NULL, path, lengthof(path))) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1071 |
DEBUG(misc, 0, "GetModuleFileName failed (%d)\n", GetLastError()); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1072 |
_searchpaths[SP_BINARY_DIR] = NULL; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1073 |
} else { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1074 |
TCHAR exec_dir[MAX_PATH]; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1075 |
_tcsncpy(path, MB_TO_WIDE_BUFFER(exe, path, lengthof(path)), lengthof(path)); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1076 |
if (!GetFullPathName(path, lengthof(exec_dir), exec_dir, NULL)) { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1077 |
DEBUG(misc, 0, "GetFullPathName failed (%d)\n", GetLastError()); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1078 |
_searchpaths[SP_BINARY_DIR] = NULL; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1079 |
} else { |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1080 |
strncpy(tmp, WIDE_TO_MB_BUFFER(exec_dir, tmp, lengthof(tmp)), lengthof(tmp)); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1081 |
char *s = strrchr(tmp, PATHSEPCHAR); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1082 |
*(s + 1) = '\0'; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1083 |
_searchpaths[SP_BINARY_DIR] = strdup(tmp); |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1084 |
} |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1085 |
} |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1086 |
|
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1087 |
_searchpaths[SP_INSTALLATION_DIR] = NULL; |
35756db7e577
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents:
6719
diff
changeset
|
1088 |
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL; |
6870
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1089 |
|
ca3fd1fbe311
(svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents:
6868
diff
changeset
|
1090 |
ScanForTarFiles(); |
0 | 1091 |
} |
1092 |
||
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
|
1093 |
/** |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1094 |
* 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
|
1095 |
* 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
|
1096 |
* is zero, we don't care about the screenlength but only about the physical length of the string |
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
1097 |
* @param tb Textbuf type to be changed |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1098 |
* @return true on successful change of Textbuf, or false otherwise |
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
|
1099 |
*/ |
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1100 |
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
|
1101 |
{ |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1102 |
HGLOBAL cbuf; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1103 |
char utf8_buf[512]; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1104 |
const char *ptr; |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1105 |
|
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1106 |
WChar c; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1107 |
uint16 width, length; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1108 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1109 |
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1110 |
OpenClipboard(NULL); |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1111 |
cbuf = GetClipboardData(CF_UNICODETEXT); |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1112 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1113 |
ptr = (const char*)GlobalLock(cbuf); |
6601
2fce875cc53b
(svn r9084) -Fix: [win9x] Clipboard paste for Windows95 (doesn't have CF_UNICODETEXT) correctly converts the input to the current locale.
Darkvater
parents:
6577
diff
changeset
|
1114 |
const char *ret = convert_from_fs((wchar_t*)ptr, utf8_buf, lengthof(utf8_buf)); |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1115 |
GlobalUnlock(cbuf); |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1116 |
CloseClipboard(); |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1117 |
|
5312
884ebccbd847
(svn r7468) -Codechange: [win32] Add some comments to MB/WIDE_TO_WIDE/MB_[BUFFER] macros and
Darkvater
parents:
5311
diff
changeset
|
1118 |
if (*ret == '\0') return false; |
6601
2fce875cc53b
(svn r9084) -Fix: [win9x] Clipboard paste for Windows95 (doesn't have CF_UNICODETEXT) correctly converts the input to the current locale.
Darkvater
parents:
6577
diff
changeset
|
1119 |
#if !defined(UNICODE) |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1120 |
} else if (IsClipboardFormatAvailable(CF_TEXT)) { |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1121 |
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
|
1122 |
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
|
1123 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1124 |
ptr = (const char*)GlobalLock(cbuf); |
6601
2fce875cc53b
(svn r9084) -Fix: [win9x] Clipboard paste for Windows95 (doesn't have CF_UNICODETEXT) correctly converts the input to the current locale.
Darkvater
parents:
6577
diff
changeset
|
1125 |
ttd_strlcpy(utf8_buf, FS2OTTD(ptr), lengthof(utf8_buf)); |
2fce875cc53b
(svn r9084) -Fix: [win9x] Clipboard paste for Windows95 (doesn't have CF_UNICODETEXT) correctly converts the input to the current locale.
Darkvater
parents:
6577
diff
changeset
|
1126 |
|
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
|
1127 |
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
|
1128 |
CloseClipboard(); |
6601
2fce875cc53b
(svn r9084) -Fix: [win9x] Clipboard paste for Windows95 (doesn't have CF_UNICODETEXT) correctly converts the input to the current locale.
Darkvater
parents:
6577
diff
changeset
|
1129 |
#endif /* UNICODE */ |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1130 |
} else { |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1131 |
return false; |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1132 |
} |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1133 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1134 |
width = length = 0; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1135 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1136 |
for (ptr = utf8_buf; (c = Utf8Consume(&ptr)) != '\0';) { |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1137 |
if (!IsPrintable(c)) break; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1138 |
|
6521
424429c0fb68
(svn r8975) -Regression: [win32] Possible buffer overflow if unicode text is pasted into an input box and needs trimming. The last character was wrongly assumed to be of length 1 (tb->maxlength - 1), while a unicode character can be up to 4 long.
Darkvater
parents:
6497
diff
changeset
|
1139 |
size_t len = Utf8CharLen(c); |
424429c0fb68
(svn r8975) -Regression: [win32] Possible buffer overflow if unicode text is pasted into an input box and needs trimming. The last character was wrongly assumed to be of length 1 (tb->maxlength - 1), while a unicode character can be up to 4 long.
Darkvater
parents:
6497
diff
changeset
|
1140 |
if (tb->length + length >= tb->maxlength - (uint16)len) break; |
424429c0fb68
(svn r8975) -Regression: [win32] Possible buffer overflow if unicode text is pasted into an input box and needs trimming. The last character was wrongly assumed to be of length 1 (tb->maxlength - 1), while a unicode character can be up to 4 long.
Darkvater
parents:
6497
diff
changeset
|
1141 |
|
424429c0fb68
(svn r8975) -Regression: [win32] Possible buffer overflow if unicode text is pasted into an input box and needs trimming. The last character was wrongly assumed to be of length 1 (tb->maxlength - 1), while a unicode character can be up to 4 long.
Darkvater
parents:
6497
diff
changeset
|
1142 |
byte charwidth = GetCharacterWidth(FS_NORMAL, c); |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1143 |
if (tb->maxwidth != 0 && width + tb->width + charwidth > tb->maxwidth) break; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1144 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1145 |
width += charwidth; |
6521
424429c0fb68
(svn r8975) -Regression: [win32] Possible buffer overflow if unicode text is pasted into an input box and needs trimming. The last character was wrongly assumed to be of length 1 (tb->maxlength - 1), while a unicode character can be up to 4 long.
Darkvater
parents:
6497
diff
changeset
|
1146 |
length += len; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1147 |
} |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1148 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1149 |
if (length == 0) return false; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1150 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1151 |
memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos); |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1152 |
memcpy(tb->buf + tb->caretpos, utf8_buf, length); |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1153 |
tb->width += width; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1154 |
tb->caretxoffs += width; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1155 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1156 |
tb->length += length; |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1157 |
tb->caretpos += length; |
6521
424429c0fb68
(svn r8975) -Regression: [win32] Possible buffer overflow if unicode text is pasted into an input box and needs trimming. The last character was wrongly assumed to be of length 1 (tb->maxlength - 1), while a unicode character can be up to 4 long.
Darkvater
parents:
6497
diff
changeset
|
1158 |
assert(tb->length < tb->maxlength); |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1159 |
tb->buf[tb->length] = '\0'; // terminating zero |
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1160 |
|
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4572
diff
changeset
|
1161 |
return true; |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
1162 |
} |
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
|
1163 |
|
2073 | 1164 |
|
1165 |
void CSleep(int milliseconds) |
|
1166 |
{ |
|
1167 |
Sleep(milliseconds); |
|
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2091
diff
changeset
|
1168 |
} |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1169 |
|
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1170 |
|
6719
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
1171 |
/** Utility function to get the current timestamp in milliseconds |
4cc327ad39d5
(svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents:
6643
diff
changeset
|
1172 |
* Useful for profiling */ |
6573 | 1173 |
int64 GetTS() |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1174 |
{ |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1175 |
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
|
1176 |
__int64 value; |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1177 |
if (!freq) { |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1178 |
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
|
1179 |
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
|
1180 |
} |
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2099
diff
changeset
|
1181 |
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
|
1182 |
return (__int64)(value * freq); |
2139 | 1183 |
} |
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1184 |
|
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1185 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1186 |
/** |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1187 |
* Convert to OpenTTD's encoding from that of the local environment. |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1188 |
* When the project is built in UNICODE, the system codepage is irrelevant and |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1189 |
* the input string is wide. In ANSI mode, the string is in the |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1190 |
* local codepage which we'll convert to wide-char, and then to UTF-8. |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1191 |
* OpenTTD internal encoding is UTF8. |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1192 |
* The returned value's contents can only be guaranteed until the next call to |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1193 |
* this function. So if the value is needed for anything else, use convert_from_fs |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1194 |
* @param name pointer to a valid string that will be converted (local, or wide) |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1195 |
* @return pointer to the converted string; if failed string is of zero-length |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1196 |
* @see the current code-page comes from video\win32_v.cpp, event-notification |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1197 |
* WM_INPUTLANGCHANGE */ |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1198 |
const char *FS2OTTD(const TCHAR *name) |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1199 |
{ |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1200 |
static char utf8_buf[512]; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1201 |
#if defined(UNICODE) |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1202 |
return convert_from_fs(name, utf8_buf, lengthof(utf8_buf)); |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1203 |
#else |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1204 |
char *s = utf8_buf; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1205 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1206 |
for (; *name != '\0'; name++) { |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1207 |
wchar_t w; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1208 |
int len = MultiByteToWideChar(_codepage, 0, name, 1, &w, 1); |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1209 |
if (len != 1) { |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1210 |
DEBUG(misc, 0, "[utf8] M2W error converting '%c'. Errno %d", *name, GetLastError()); |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1211 |
continue; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1212 |
} |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1213 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1214 |
if (s + Utf8CharLen(w) >= lastof(utf8_buf)) break; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1215 |
s += Utf8Encode(s, w); |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1216 |
} |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1217 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1218 |
*s = '\0'; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1219 |
return utf8_buf; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1220 |
#endif /* UNICODE */ |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1221 |
} |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1222 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1223 |
/** |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1224 |
* Convert from OpenTTD's encoding to that of the local environment. |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1225 |
* When the project is built in UNICODE the system codepage is irrelevant and |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1226 |
* the converted string is wide. In ANSI mode, the UTF8 string is converted |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1227 |
* to multi-byte. |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1228 |
* OpenTTD internal encoding is UTF8. |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1229 |
* The returned value's contents can only be guaranteed until the next call to |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1230 |
* this function. So if the value is needed for anything else, use convert_from_fs |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1231 |
* @param name pointer to a valid string that will be converted (UTF8) |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1232 |
* @return pointer to the converted string; if failed string is of zero-length |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1233 |
* @see the current code-page comes from video\win32_v.cpp, event-notification |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1234 |
* WM_INPUTLANGCHANGE */ |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1235 |
const TCHAR *OTTD2FS(const char *name) |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1236 |
{ |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1237 |
static TCHAR system_buf[512]; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1238 |
#if defined(UNICODE) |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1239 |
return convert_to_fs(name, system_buf, lengthof(system_buf)); |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1240 |
#else |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1241 |
char *s = system_buf; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1242 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1243 |
for (WChar c; (c = Utf8Consume(&name)) != '\0';) { |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1244 |
if (s >= lastof(system_buf)) break; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1245 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1246 |
char mb; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1247 |
int len = WideCharToMultiByte(_codepage, 0, (wchar_t*)&c, 1, &mb, 1, NULL, NULL); |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1248 |
if (len != 1) { |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1249 |
DEBUG(misc, 0, "[utf8] W2M error converting '0x%X'. Errno %d", c, GetLastError()); |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1250 |
continue; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1251 |
} |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1252 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1253 |
*s++ = mb; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1254 |
} |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1255 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1256 |
*s = '\0'; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1257 |
return system_buf; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1258 |
#endif /* UNICODE */ |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1259 |
} |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1260 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1261 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1262 |
/** Convert to OpenTTD's encoding from that of the environment in |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1263 |
* UNICODE. OpenTTD encoding is UTF8, local is wide |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1264 |
* @param name pointer to a valid string that will be converted |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1265 |
* @param utf8_buf pointer to a valid buffer that will receive the converted string |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1266 |
* @param buflen length in characters of the receiving buffer |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1267 |
* @return pointer to utf8_buf. If conversion fails the string is of zero-length */ |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1268 |
char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen) |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1269 |
{ |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1270 |
int len = WideCharToMultiByte(CP_UTF8, 0, name, -1, utf8_buf, buflen, NULL, NULL); |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1271 |
if (len == 0) { |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1272 |
DEBUG(misc, 0, "[utf8] W2M error converting wide-string. Errno %d", GetLastError()); |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1273 |
utf8_buf[0] = '\0'; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1274 |
} |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1275 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1276 |
return utf8_buf; |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1277 |
} |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1278 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1279 |
|
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1280 |
/** Convert from OpenTTD's encoding to that of the environment in |
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1281 |
* UNICODE. OpenTTD encoding is UTF8, local is wide |
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5120
diff
changeset
|
1282 |
* @param name pointer to a valid string that will be converted |
5218
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1283 |
* @param utf16_buf pointer to a valid wide-char buffer that will receive the |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1284 |
* converted string |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1285 |
* @param buflen length in wide characters of the receiving buffer |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1286 |
* @return pointer to utf16_buf. If conversion fails the string is of zero-length */ |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1287 |
wchar_t *convert_to_fs(const char *name, wchar_t *utf16_buf, size_t buflen) |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1288 |
{ |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1289 |
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, utf16_buf, buflen); |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1290 |
if (len == 0) { |
6577
ee768d653dd0
(svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents:
6574
diff
changeset
|
1291 |
DEBUG(misc, 0, "[utf8] M2W error converting '%s'. Errno %d", name, GetLastError()); |
5218
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1292 |
utf16_buf[0] = '\0'; |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1293 |
} |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1294 |
|
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1295 |
return utf16_buf; |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1296 |
} |
aae5f36a5256
(svn r7333) -Codechange: [win32] Extend the OTTD2FS and FS2OTTD functions to also accept conversions
Darkvater
parents:
5168
diff
changeset
|
1297 |
|
5304
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1298 |
/** Our very own SHGetFolderPath function for support of windows operating |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1299 |
* systems that don't have this function (eg Win9x, etc.). We try using the |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1300 |
* native function, and if that doesn't exist we will try a more crude approach |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1301 |
* of environment variables and hope for the best */ |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1302 |
HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath) |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1303 |
{ |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1304 |
static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = NULL; |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1305 |
static bool first_time = true; |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1306 |
|
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1307 |
/* We only try to load the library one time; if it fails, it fails */ |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1308 |
if (first_time) { |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1309 |
#if defined(UNICODE) |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1310 |
# define W(x) x "W" |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1311 |
#else |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1312 |
# define W(x) x "A" |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1313 |
#endif |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1314 |
if (!LoadLibraryList((Function*)&SHGetFolderPath, "SHFolder.dll\0" W("SHGetFolderPath") "\0\0")) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5336
diff
changeset
|
1315 |
DEBUG(misc, 0, "Unable to load " W("SHGetFolderPath") "from SHFolder.dll"); |
5304
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1316 |
} |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1317 |
#undef W |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1318 |
first_time = false; |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1319 |
} |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1320 |
|
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1321 |
if (SHGetFolderPath != NULL) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath); |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1322 |
|
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1323 |
/* SHGetFolderPath doesn't exist, try a more conservative approach, |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1324 |
* eg environment variables. This is only included for legacy modes |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1325 |
* MSDN says: that 'pszPath' is a "Pointer to a null-terminated string of |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1326 |
* length MAX_PATH which will receive the path" so let's assume that |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1327 |
* Windows 95 with Internet Explorer 5.0, Windows 98 with Internet Explorer 5.0, |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1328 |
* Windows 98 Second Edition (SE), Windows NT 4.0 with Internet Explorer 5.0, |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1329 |
* Windows NT 4.0 with Service Pack 4 (SP4) */ |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1330 |
{ |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1331 |
DWORD ret; |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1332 |
switch (csidl) { |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1333 |
case CSIDL_FONTS: /* Get the system font path, eg %WINDIR%\Fonts */ |
5336
2588c9b8cd9f
(svn r7500) -Fix (r7460): GetEnvironmentVariable and strncat take the number of characters and
Darkvater
parents:
5312
diff
changeset
|
1334 |
ret = GetEnvironmentVariable(_T("WINDIR"), pszPath, MAX_PATH); |
5304
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1335 |
if (ret == 0) break; |
5336
2588c9b8cd9f
(svn r7500) -Fix (r7460): GetEnvironmentVariable and strncat take the number of characters and
Darkvater
parents:
5312
diff
changeset
|
1336 |
_tcsncat(pszPath, _T("\\Fonts"), MAX_PATH); |
5304
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1337 |
|
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1338 |
return (HRESULT)0; |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1339 |
break; |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1340 |
/* XXX - other types to go here when needed... */ |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1341 |
} |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1342 |
} |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1343 |
|
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1344 |
return E_INVALIDARG; |
50daae4d7d38
(svn r7460) -Fix (r7337): [win32] If the underlying OS didn't have support for SHGetFolderPath the
Darkvater
parents:
5296
diff
changeset
|
1345 |
} |
6743
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1346 |
|
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1347 |
/** Determine the current user's locale. */ |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1348 |
const char *GetCurrentLocale(const char *) |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1349 |
{ |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1350 |
char lang[9], country[9]; |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1351 |
if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, lang, lengthof(lang)) == 0 || |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1352 |
GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, country, lengthof(country)) == 0) { |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1353 |
/* Unable to retrieve the locale. */ |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1354 |
return NULL; |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1355 |
} |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1356 |
/* Format it as 'en_us'. */ |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1357 |
static char retbuf[6] = {lang[0], lang[1], '_', country[0], country[1], 0}; |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1358 |
return retbuf; |
cabfaa4a0295
(svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents:
6720
diff
changeset
|
1359 |
} |