author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1508 | faae7585cae7 |
child 1548 | 3c73344cdcd7 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1302 | 3 |
#include "debug.h" |
1317
3c90086ff34f
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1302
diff
changeset
|
4 |
#include "string.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
424
diff
changeset
|
5 |
#include "table/strings.h" |
0 | 6 |
#include "gfx.h" |
1496
15d859a626e8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1495
diff
changeset
|
7 |
#include "mixer.h" |
0 | 8 |
#include "window.h" |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
9 |
#include "gui.h" |
0 | 10 |
#include <windows.h> |
11 |
#include <mmsystem.h> |
|
12 |
#include "hal.h" |
|
13 |
#include <winnt.h> |
|
14 |
#include <wininet.h> |
|
15 |
#include <io.h> |
|
16 |
#include <fcntl.h> |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
17 |
#include "network.h" |
0 | 18 |
|
19 |
#define SMART_PALETTE_ANIM |
|
20 |
||
21 |
static struct { |
|
22 |
HWND main_wnd; |
|
23 |
HBITMAP dib_sect; |
|
24 |
void *bitmap_bits; |
|
25 |
void *buffer_bits; |
|
26 |
void *alloced_bits; |
|
27 |
HPALETTE gdi_palette; |
|
28 |
int width,height; |
|
29 |
int width_org, height_org; |
|
30 |
bool cursor_visible; |
|
31 |
bool switch_driver; |
|
32 |
bool fullscreen; |
|
33 |
bool double_size; |
|
34 |
bool has_focus; |
|
35 |
bool running; |
|
36 |
} _wnd; |
|
37 |
||
38 |
static HINSTANCE _inst; |
|
39 |
static bool _has_console; |
|
40 |
||
796 | 41 |
#if defined(__MINGW32__) || defined(__CYGWIN__) |
0 | 42 |
#define __TIMESTAMP__ __DATE__ __TIME__ |
43 |
#endif |
|
44 |
||
45 |
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT |
|
46 |
extern const HalMusicDriver _dmusic_midi_driver; |
|
47 |
#endif |
|
48 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
49 |
static void MakePalette(void) |
0 | 50 |
{ |
51 |
LOGPALETTE *pal; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
52 |
uint i; |
0 | 53 |
byte *b; |
54 |
||
55 |
pal = alloca(sizeof(LOGPALETTE) + (256-1) * sizeof(PALETTEENTRY)); |
|
56 |
||
57 |
pal->palVersion = 0x300; |
|
58 |
pal->palNumEntries = 256; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
59 |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
60 |
for (i = 0, b = _cur_palette; i != 256; i++, b += 3) { |
0 | 61 |
pal->palPalEntry[i].peRed = b[0]; |
62 |
pal->palPalEntry[i].peGreen = b[1]; |
|
63 |
pal->palPalEntry[i].peBlue = b[2]; |
|
64 |
pal->palPalEntry[i].peFlags = 0; |
|
65 |
||
66 |
} |
|
67 |
_wnd.gdi_palette = CreatePalette(pal); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
68 |
if (_wnd.gdi_palette == NULL) |
0 | 69 |
error("CreatePalette failed!\n"); |
70 |
} |
|
71 |
||
72 |
static void UpdatePalette(HDC dc, uint start, uint count) |
|
73 |
{ |
|
74 |
RGBQUAD rgb[256]; |
|
75 |
uint i; |
|
76 |
byte *b; |
|
77 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
78 |
for (i = 0, b = _cur_palette + start * 3; i != count; i++, b += 3) { |
0 | 79 |
rgb[i].rgbRed = b[0]; |
80 |
rgb[i].rgbGreen = b[1]; |
|
81 |
rgb[i].rgbBlue = b[2]; |
|
82 |
rgb[i].rgbReserved = 0; |
|
83 |
} |
|
84 |
||
85 |
SetDIBColorTable(dc, start, count, rgb); |
|
86 |
} |
|
87 |
||
88 |
static bool MyShowCursor(bool show) |
|
89 |
{ |
|
90 |
if (_wnd.cursor_visible == show) |
|
91 |
return show; |
|
92 |
||
93 |
_wnd.cursor_visible = show; |
|
94 |
ShowCursor(show); |
|
95 |
||
96 |
return !show; |
|
97 |
} |
|
98 |
||
99 |
typedef struct { |
|
100 |
byte vk_from; |
|
101 |
byte vk_count; |
|
102 |
byte map_to; |
|
103 |
} VkMapping; |
|
104 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
105 |
#define AS(x, z) {x, 0, z} |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
106 |
#define AM(x, y, z, w) {x, y - x, z} |
0 | 107 |
|
153
3dbe2cfd7b3c
(svn r154) -Fix: some people while using MSVC don't have VK_OEM_3 defined? Or it could be Win2000/XP only
darkvater
parents:
151
diff
changeset
|
108 |
#ifndef VK_OEM_3 |
3dbe2cfd7b3c
(svn r154) -Fix: some people while using MSVC don't have VK_OEM_3 defined? Or it could be Win2000/XP only
darkvater
parents:
151
diff
changeset
|
109 |
#define VK_OEM_3 0xC0 |
3dbe2cfd7b3c
(svn r154) -Fix: some people while using MSVC don't have VK_OEM_3 defined? Or it could be Win2000/XP only
darkvater
parents:
151
diff
changeset
|
110 |
#endif |
3dbe2cfd7b3c
(svn r154) -Fix: some people while using MSVC don't have VK_OEM_3 defined? Or it could be Win2000/XP only
darkvater
parents:
151
diff
changeset
|
111 |
|
0 | 112 |
static const VkMapping _vk_mapping[] = { |
113 |
// Pageup stuff + up/down |
|
114 |
AM(VK_PRIOR,VK_DOWN, WKC_PAGEUP, WKC_DOWN), |
|
115 |
// Map letters & digits |
|
116 |
AM('A','Z','A','Z'), |
|
117 |
AM('0','9','0','9'), |
|
118 |
||
119 |
AS(VK_ESCAPE, WKC_ESC), |
|
424
a3095d8c1c6a
(svn r623) -Feature: [ 1066504 ] Pause key pauses the game
tron
parents:
394
diff
changeset
|
120 |
AS(VK_PAUSE, WKC_PAUSE), |
0 | 121 |
AS(VK_BACK, WKC_BACKSPACE), |
122 |
AM(VK_INSERT,VK_DELETE,WKC_INSERT, WKC_DELETE), |
|
123 |
||
124 |
AS(VK_SPACE, WKC_SPACE), |
|
125 |
AS(VK_RETURN, WKC_RETURN), |
|
126 |
AS(VK_TAB, WKC_TAB), |
|
127 |
||
128 |
// Function keys |
|
129 |
AM(VK_F1, VK_F12, WKC_F1, WKC_F12), |
|
130 |
||
131 |
// Numeric part. |
|
132 |
// What is the virtual keycode for numeric enter?? |
|
133 |
AM(VK_NUMPAD0,VK_NUMPAD9, WKC_NUM_0, WKC_NUM_9), |
|
134 |
AS(VK_DIVIDE, WKC_NUM_DIV), |
|
135 |
AS(VK_MULTIPLY, WKC_NUM_MUL), |
|
136 |
AS(VK_SUBTRACT, WKC_NUM_MINUS), |
|
137 |
AS(VK_ADD, WKC_NUM_PLUS), |
|
1466 | 138 |
AS(VK_DECIMAL, WKC_NUM_DECIMAL) |
0 | 139 |
}; |
140 |
||
1466 | 141 |
static uint MapWindowsKey(uint sym) |
0 | 142 |
{ |
1466 | 143 |
const VkMapping *map; |
144 |
uint key = 0; |
|
0 | 145 |
|
1466 | 146 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { |
147 |
if ((uint)(sym - map->vk_from) <= map->vk_count) { |
|
148 |
key = sym - map->vk_from + map->map_to; |
|
149 |
break; |
|
150 |
} |
|
151 |
} |
|
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
49
diff
changeset
|
152 |
|
0 | 153 |
if (GetAsyncKeyState(VK_SHIFT)<0) key |= WKC_SHIFT; |
154 |
if (GetAsyncKeyState(VK_CONTROL)<0) key |= WKC_CTRL; |
|
155 |
if (GetAsyncKeyState(VK_MENU)<0) key |= WKC_ALT; |
|
156 |
return key; |
|
157 |
} |
|
158 |
||
159 |
static void MakeWindow(bool full_screen); |
|
160 |
static bool AllocateDibSection(int w, int h); |
|
161 |
||
162 |
static void ClientSizeChanged(int w, int h) |
|
163 |
{ |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
164 |
if (_wnd.double_size) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
165 |
w /= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
166 |
h /= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
167 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
168 |
|
0 | 169 |
// allocate new dib section of the new size |
170 |
if (AllocateDibSection(w, h)) { |
|
171 |
// mark all palette colors dirty |
|
172 |
_pal_first_dirty = 0; |
|
173 |
_pal_last_dirty = 255; |
|
174 |
GameSizeChanged(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
175 |
|
0 | 176 |
// redraw screen |
177 |
if (_wnd.running) { |
|
178 |
_screen.dst_ptr = _wnd.buffer_bits; |
|
179 |
UpdateWindows(); |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
184 |
void DoExitSave(void); |
643
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
543
diff
changeset
|
185 |
|
0 | 186 |
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
187 |
{ |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
188 |
switch (msg) { |
0 | 189 |
case WM_PAINT: { |
190 |
PAINTSTRUCT ps; |
|
191 |
HDC dc,dc2; |
|
192 |
HBITMAP old_bmp; |
|
193 |
HPALETTE old_palette; |
|
194 |
BeginPaint(hwnd, &ps); |
|
195 |
dc = ps.hdc; |
|
196 |
dc2 = CreateCompatibleDC(dc); |
|
197 |
old_bmp = SelectObject(dc2, _wnd.dib_sect); |
|
198 |
old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
199 |
|
0 | 200 |
if (_pal_last_dirty != -1) { |
201 |
UpdatePalette(dc2, _pal_first_dirty, _pal_last_dirty - _pal_first_dirty + 1); |
|
202 |
_pal_last_dirty = -1; |
|
203 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
204 |
|
0 | 205 |
BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY); |
206 |
SelectPalette(dc, old_palette, TRUE); |
|
207 |
SelectObject(dc2, old_bmp); |
|
208 |
DeleteDC(dc2); |
|
209 |
EndPaint(hwnd, &ps); |
|
210 |
} |
|
211 |
return 0; |
|
212 |
||
213 |
case WM_PALETTECHANGED: |
|
214 |
if ((HWND)wParam == hwnd) |
|
215 |
return 0; |
|
216 |
// FALL THROUGH |
|
217 |
case WM_QUERYNEWPALETTE: { |
|
218 |
HDC hDC = GetWindowDC(hwnd); |
|
219 |
HPALETTE hOldPalette = SelectPalette(hDC, _wnd.gdi_palette, FALSE); |
|
220 |
UINT nChanged = RealizePalette(hDC); |
|
221 |
SelectPalette(hDC, hOldPalette, TRUE); |
|
222 |
ReleaseDC(hwnd, hDC); |
|
223 |
if (nChanged) |
|
224 |
InvalidateRect(hwnd, NULL, FALSE); |
|
225 |
return 0; |
|
226 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
227 |
|
0 | 228 |
case WM_CLOSE: |
646
9be33e10db7e
(svn r1079) -Fix: you can once again quit the game in windows by pressing ALT+F4 or the 'exit' button in the main menu.
darkvater
parents:
643
diff
changeset
|
229 |
if (_game_mode == GM_MENU) { // do not ask to quit on the main screen |
9be33e10db7e
(svn r1079) -Fix: you can once again quit the game in windows by pressing ALT+F4 or the 'exit' button in the main menu.
darkvater
parents:
643
diff
changeset
|
230 |
_exit_game = true; |
9be33e10db7e
(svn r1079) -Fix: you can once again quit the game in windows by pressing ALT+F4 or the 'exit' button in the main menu.
darkvater
parents:
643
diff
changeset
|
231 |
} else if (_patches.autosave_on_exit) { |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
232 |
DoExitSave(); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
233 |
_exit_game = true; |
643
a9c84d04eacb
(svn r1076) Feature: Patch setting to autosave the game on exit
dominik
parents:
543
diff
changeset
|
234 |
} else |
646
9be33e10db7e
(svn r1079) -Fix: you can once again quit the game in windows by pressing ALT+F4 or the 'exit' button in the main menu.
darkvater
parents:
643
diff
changeset
|
235 |
AskExitGame(); |
9be33e10db7e
(svn r1079) -Fix: you can once again quit the game in windows by pressing ALT+F4 or the 'exit' button in the main menu.
darkvater
parents:
643
diff
changeset
|
236 |
|
0 | 237 |
return 0; |
238 |
||
239 |
case WM_LBUTTONDOWN: |
|
240 |
SetCapture(hwnd); |
|
241 |
_left_button_down = true; |
|
242 |
return 0; |
|
243 |
||
244 |
case WM_LBUTTONUP: |
|
245 |
ReleaseCapture(); |
|
246 |
_left_button_down = false; |
|
247 |
_left_button_clicked = false; |
|
248 |
return 0; |
|
249 |
||
250 |
case WM_RBUTTONDOWN: |
|
251 |
SetCapture(hwnd); |
|
252 |
_right_button_down = true; |
|
253 |
_right_button_clicked = true; |
|
254 |
return 0; |
|
255 |
||
256 |
case WM_RBUTTONUP: |
|
257 |
ReleaseCapture(); |
|
258 |
_right_button_down = false; |
|
259 |
return 0; |
|
260 |
||
261 |
case WM_MOUSEMOVE: { |
|
262 |
int x = (int16)LOWORD(lParam); |
|
263 |
int y = (int16)HIWORD(lParam); |
|
264 |
POINT pt; |
|
265 |
||
266 |
if (_wnd.double_size) { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
267 |
x /= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
268 |
y /= 2; |
0 | 269 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
270 |
|
0 | 271 |
if (_cursor.fix_at) { |
272 |
int dx = x - _cursor.pos.x; |
|
273 |
int dy = y - _cursor.pos.y; |
|
274 |
if (dx != 0 || dy != 0) { |
|
275 |
_cursor.delta.x += dx; |
|
276 |
_cursor.delta.y += dy; |
|
277 |
||
278 |
pt.x = _cursor.pos.x; |
|
279 |
pt.y = _cursor.pos.y; |
|
280 |
||
281 |
if (_wnd.double_size) { |
|
282 |
pt.x *= 2; |
|
283 |
pt.y *= 2; |
|
284 |
} |
|
285 |
ClientToScreen(hwnd, &pt); |
|
286 |
SetCursorPos(pt.x, pt.y); |
|
287 |
} |
|
288 |
} else { |
|
289 |
_cursor.delta.x += x - _cursor.pos.x; |
|
290 |
_cursor.delta.y += y - _cursor.pos.y; |
|
291 |
_cursor.pos.x = x; |
|
292 |
_cursor.pos.y = y; |
|
293 |
_cursor.dirty = true; |
|
294 |
} |
|
295 |
MyShowCursor(false); |
|
296 |
return 0; |
|
297 |
} |
|
298 |
||
394
675c52a63cb6
(svn r586) -Fix: [1066114] Code error in win32.c Thanks Shai
darkvater
parents:
318
diff
changeset
|
299 |
case WM_KEYDOWN: { |
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
49
diff
changeset
|
300 |
// this is the rewritten ascii input function |
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
49
diff
changeset
|
301 |
// it disables windows deadkey handling --> more linux like :D |
394
675c52a63cb6
(svn r586) -Fix: [1066114] Code error in win32.c Thanks Shai
darkvater
parents:
318
diff
changeset
|
302 |
unsigned short w = 0; |
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
49
diff
changeset
|
303 |
int r = 0; |
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
49
diff
changeset
|
304 |
byte ks[256]; |
394
675c52a63cb6
(svn r586) -Fix: [1066114] Code error in win32.c Thanks Shai
darkvater
parents:
318
diff
changeset
|
305 |
unsigned int scan = 0; |
719
0a8479b52125
(svn r1171) Fix: Console hotkey works again on keyboards where this key is a deadkey.
dominik
parents:
704
diff
changeset
|
306 |
uint16 scancode = (( lParam & 0xFF0000 ) >> 16 ); |
0a8479b52125
(svn r1171) Fix: Console hotkey works again on keyboards where this key is a deadkey.
dominik
parents:
704
diff
changeset
|
307 |
|
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
49
diff
changeset
|
308 |
GetKeyboardState(ks); |
394
675c52a63cb6
(svn r586) -Fix: [1066114] Code error in win32.c Thanks Shai
darkvater
parents:
318
diff
changeset
|
309 |
r = ToAscii(wParam, scan, ks, &w, 0); |
675c52a63cb6
(svn r586) -Fix: [1066114] Code error in win32.c Thanks Shai
darkvater
parents:
318
diff
changeset
|
310 |
if (r == 0) w = 0; // no translation was possible |
135
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
49
diff
changeset
|
311 |
|
638fb31434eb
(svn r136) -Feature/Fix: Console Rev #2 and WKC_BACKQUOTE this patch adds new features to the ingame console and inserts a new keymanagement for windows pcs... (sign_de)
darkvater
parents:
49
diff
changeset
|
312 |
_pressed_key = w | MapWindowsKey(wParam) << 16; |
394
675c52a63cb6
(svn r586) -Fix: [1066114] Code error in win32.c Thanks Shai
darkvater
parents:
318
diff
changeset
|
313 |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
314 |
if (scancode == 41) |
719
0a8479b52125
(svn r1171) Fix: Console hotkey works again on keyboards where this key is a deadkey.
dominik
parents:
704
diff
changeset
|
315 |
_pressed_key = w | WKC_BACKQUOTE << 16; |
0a8479b52125
(svn r1171) Fix: Console hotkey works again on keyboards where this key is a deadkey.
dominik
parents:
704
diff
changeset
|
316 |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
317 |
if ((_pressed_key >> 16) == ('D' | WKC_CTRL) && !_wnd.fullscreen) { |
0 | 318 |
_double_size ^= 1; |
319 |
_wnd.double_size = _double_size; |
|
320 |
ClientSizeChanged(_wnd.width, _wnd.height); |
|
321 |
MarkWholeScreenDirty(); |
|
322 |
} |
|
394
675c52a63cb6
(svn r586) -Fix: [1066114] Code error in win32.c Thanks Shai
darkvater
parents:
318
diff
changeset
|
323 |
} break; |
0 | 324 |
|
325 |
||
198
0f3481fa50e1
(svn r199) -Fix: [993374] Pressing alt locks the game - sort of a bug. I hope I didn't break anything :O
darkvater
parents:
196
diff
changeset
|
326 |
case WM_SYSKEYDOWN: /* user presses F10 or Alt, both activating the title-menu */ |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
327 |
switch (wParam) { |
198
0f3481fa50e1
(svn r199) -Fix: [993374] Pressing alt locks the game - sort of a bug. I hope I didn't break anything :O
darkvater
parents:
196
diff
changeset
|
328 |
case VK_RETURN: /* Full Screen */ |
0 | 329 |
MakeWindow(!_wnd.fullscreen); |
330 |
return 0; |
|
199
10f6a586bfa6
(svn r200) -Fix: oops, ALT+F4 didn't work anymore. Fixed now.
darkvater
parents:
198
diff
changeset
|
331 |
case VK_MENU: /* Just ALT */ |
10f6a586bfa6
(svn r200) -Fix: oops, ALT+F4 didn't work anymore. Fixed now.
darkvater
parents:
198
diff
changeset
|
332 |
return 0; // do nothing |
10f6a586bfa6
(svn r200) -Fix: oops, ALT+F4 didn't work anymore. Fixed now.
darkvater
parents:
198
diff
changeset
|
333 |
default: /* ALT in combination with something else */ |
0 | 334 |
_pressed_key = MapWindowsKey(wParam) << 16; |
1480
93c8fbea364b
(svn r1984) -Fix: [1155762] Don't try to open the non-existent menu, when F10 is pressed
tron
parents:
1468
diff
changeset
|
335 |
return 0; |
0 | 336 |
} |
337 |
break; |
|
338 |
case WM_NCMOUSEMOVE: |
|
339 |
MyShowCursor(true); |
|
340 |
return 0; |
|
341 |
||
342 |
case WM_SIZE: { |
|
343 |
if (wParam != SIZE_MINIMIZED) { |
|
344 |
ClientSizeChanged(LOWORD(lParam), HIWORD(lParam)); |
|
345 |
} |
|
346 |
return 0; |
|
347 |
} |
|
348 |
case WM_SIZING: { |
|
349 |
RECT* r = (RECT*)lParam; |
|
350 |
RECT r2; |
|
351 |
int w, h; |
|
352 |
||
353 |
SetRect(&r2, 0, 0, 0, 0); |
|
354 |
AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
355 |
|
0 | 356 |
w = r->right - r->left - (r2.right - r2.left); |
357 |
h = r->bottom - r->top - (r2.bottom - r2.top); |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
358 |
if (_wnd.double_size) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
359 |
w /= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
360 |
h /= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
361 |
} |
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
362 |
w = clamp(w, 64, MAX_SCREEN_WIDTH); |
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
363 |
h = clamp(h, 64, MAX_SCREEN_HEIGHT); |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
364 |
if (_wnd.double_size) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
365 |
w *= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
366 |
h *= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
367 |
} |
0 | 368 |
SetRect(&r2, 0, 0, w, h); |
369 |
||
370 |
AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE); |
|
371 |
w = r2.right - r2.left; |
|
372 |
h = r2.bottom - r2.top; |
|
373 |
||
374 |
switch (wParam) { |
|
375 |
case WMSZ_BOTTOM: |
|
376 |
r->bottom = r->top + h; |
|
377 |
break; |
|
378 |
case WMSZ_BOTTOMLEFT: |
|
379 |
r->bottom = r->top + h; |
|
380 |
r->left = r->right - w; |
|
381 |
break; |
|
382 |
case WMSZ_BOTTOMRIGHT: |
|
383 |
r->bottom = r->top + h; |
|
384 |
r->right = r->left + w; |
|
385 |
break; |
|
386 |
case WMSZ_LEFT: |
|
387 |
r->left = r->right - w; |
|
388 |
break; |
|
389 |
case WMSZ_RIGHT: |
|
390 |
r->right = r->left + w; |
|
391 |
break; |
|
392 |
case WMSZ_TOP: |
|
393 |
r->top = r->bottom - h; |
|
394 |
break; |
|
395 |
case WMSZ_TOPLEFT: |
|
396 |
r->top = r->bottom - h; |
|
397 |
r->left = r->right - w; |
|
398 |
break; |
|
399 |
case WMSZ_TOPRIGHT: |
|
400 |
r->top = r->bottom - h; |
|
401 |
r->right = r->left + w; |
|
402 |
break; |
|
403 |
} |
|
404 |
return TRUE; |
|
405 |
} |
|
406 |
||
407 |
// needed for wheel |
|
408 |
#if !defined(WM_MOUSEWHEEL) |
|
409 |
# define WM_MOUSEWHEEL 0x020A |
|
410 |
#endif //WM_MOUSEWHEEL |
|
411 |
#if !defined(GET_WHEEL_DELTA_WPARAM) |
|
412 |
# define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD(wparam)) |
|
413 |
#endif //GET_WHEEL_DELTA_WPARAM |
|
414 |
||
415 |
case WM_MOUSEWHEEL: { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
416 |
int delta = GET_WHEEL_DELTA_WPARAM(wParam); |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
417 |
|
0 | 418 |
if (delta < 0) { |
419 |
_cursor.wheel++; |
|
420 |
} else if (delta > 0) { |
|
421 |
_cursor.wheel--; |
|
422 |
} |
|
423 |
return 0; |
|
424 |
} |
|
425 |
||
426 |
case WM_ACTIVATEAPP: |
|
427 |
_wnd.has_focus = (bool)wParam; |
|
428 |
break; |
|
429 |
} |
|
430 |
return DefWindowProc(hwnd, msg, wParam, lParam); |
|
431 |
} |
|
432 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
433 |
static void RegisterWndClass(void) |
0 | 434 |
{ |
435 |
static bool registered; |
|
436 |
if (!registered) { |
|
437 |
HINSTANCE hinst = GetModuleHandle(NULL); |
|
438 |
WNDCLASS wnd = { |
|
439 |
0, |
|
440 |
WndProcGdi, |
|
441 |
0, |
|
442 |
0, |
|
443 |
hinst, |
|
444 |
LoadIcon(hinst, MAKEINTRESOURCE(100)), |
|
445 |
LoadCursor(NULL, IDC_ARROW), |
|
446 |
0, |
|
447 |
0, |
|
448 |
"TTD" |
|
449 |
}; |
|
450 |
registered = true; |
|
451 |
if (!RegisterClass(&wnd)) |
|
452 |
error("RegisterClass failed"); |
|
453 |
} |
|
454 |
} |
|
455 |
||
659
a9733f856cd0
(svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents:
656
diff
changeset
|
456 |
extern const char _openttd_revision[]; |
a9733f856cd0
(svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents:
656
diff
changeset
|
457 |
|
0 | 458 |
static void MakeWindow(bool full_screen) |
459 |
{ |
|
460 |
_fullscreen = full_screen; |
|
461 |
||
462 |
_wnd.double_size = _double_size && !full_screen; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
463 |
|
0 | 464 |
// recreate window? |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
465 |
if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) { |
0 | 466 |
DestroyWindow(_wnd.main_wnd); |
467 |
_wnd.main_wnd = 0; |
|
468 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
469 |
|
0 | 470 |
if (full_screen) { |
471 |
DEVMODE settings; |
|
472 |
memset(&settings, 0, sizeof(DEVMODE)); |
|
473 |
settings.dmSize = sizeof(DEVMODE); |
|
474 |
settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; |
|
475 |
||
476 |
if (_fullscreen_bpp) { |
|
477 |
settings.dmBitsPerPel = _fullscreen_bpp; |
|
478 |
settings.dmFields |= DM_BITSPERPEL; |
|
479 |
} |
|
480 |
settings.dmPelsWidth = _wnd.width_org; |
|
481 |
settings.dmPelsHeight = _wnd.height_org; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
482 |
settings.dmDisplayFrequency = _display_hz; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
483 |
if (settings.dmDisplayFrequency != 0) |
0 | 484 |
settings.dmFields |= DM_DISPLAYFREQUENCY; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
485 |
if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { |
0 | 486 |
MakeWindow(false); |
487 |
return; |
|
488 |
} |
|
489 |
} else if (_wnd.fullscreen) { |
|
490 |
// restore display? |
|
491 |
ChangeDisplaySettings(NULL, 0); |
|
492 |
} |
|
493 |
||
494 |
{ |
|
495 |
RECT r; |
|
496 |
uint style; |
|
497 |
int x, y, w, h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
498 |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
499 |
_wnd.fullscreen = full_screen; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
500 |
if (_wnd.fullscreen) { |
0 | 501 |
style = WS_POPUP | WS_VISIBLE; |
502 |
SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org); |
|
503 |
} else { |
|
504 |
style = WS_OVERLAPPEDWINDOW | WS_VISIBLE; |
|
505 |
SetRect(&r, 0, 0, _wnd.width, _wnd.height); |
|
506 |
} |
|
507 |
||
508 |
AdjustWindowRect(&r, style, FALSE); |
|
509 |
w = r.right - r.left; |
|
510 |
h = r.bottom - r.top; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
511 |
x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
512 |
y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; |
0 | 513 |
|
514 |
if (_wnd.main_wnd) { |
|
515 |
SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER); |
|
516 |
} else { |
|
287
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
517 |
char Windowtitle[50] = "OpenTTD "; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
518 |
|
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
519 |
snprintf(Windowtitle, lengthof(Windowtitle), "OpenTTD %s", |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
520 |
_openttd_revision); |
659
a9733f856cd0
(svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents:
656
diff
changeset
|
521 |
|
287
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
522 |
_wnd.main_wnd = CreateWindow("TTD", Windowtitle, style, x, y, w, h, 0, 0, _inst, 0); |
0 | 523 |
if (_wnd.main_wnd == NULL) |
524 |
error("CreateWindow failed"); |
|
525 |
} |
|
526 |
} |
|
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
287
diff
changeset
|
527 |
GameSizeChanged(); // invalidate all windows, force redraw |
0 | 528 |
} |
529 |
||
530 |
static bool AllocateDibSection(int w, int h) |
|
531 |
{ |
|
532 |
BITMAPINFO *bi; |
|
533 |
HDC dc; |
|
534 |
||
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
535 |
w = clamp(w, 64, MAX_SCREEN_WIDTH); |
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
536 |
h = clamp(h, 64, MAX_SCREEN_HEIGHT); |
0 | 537 |
|
538 |
if (w == _screen.width && h == _screen.height) |
|
539 |
return false; |
|
540 |
||
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
541 |
_screen.width = w; |
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
542 |
_screen.pitch = (w + 3) & ~0x3; |
0 | 543 |
_screen.height = h; |
544 |
||
545 |
if (_wnd.alloced_bits) { |
|
546 |
free(_wnd.alloced_bits); |
|
547 |
_wnd.alloced_bits = NULL; |
|
548 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
549 |
|
0 | 550 |
bi = alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256); |
551 |
memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256); |
|
552 |
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
553 |
|
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
554 |
if (_wnd.double_size) { |
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
555 |
w = (w + 3) & ~0x3; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
556 |
_wnd.alloced_bits = _wnd.buffer_bits = malloc(w * h); |
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
557 |
w *= 2; |
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
558 |
h *= 2; |
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
559 |
} |
0 | 560 |
|
306
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
561 |
bi->bmiHeader.biWidth = _wnd.width = w; |
9ba288cacf0a
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
darkvater
parents:
298
diff
changeset
|
562 |
bi->bmiHeader.biHeight = -(_wnd.height = h); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
563 |
|
0 | 564 |
bi->bmiHeader.biPlanes = 1; |
565 |
bi->bmiHeader.biBitCount = 8; |
|
566 |
bi->bmiHeader.biCompression = BI_RGB; |
|
567 |
||
568 |
if (_wnd.dib_sect) |
|
569 |
DeleteObject(_wnd.dib_sect); |
|
570 |
||
571 |
dc = GetDC(0); |
|
572 |
_wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, &_wnd.bitmap_bits, NULL, 0); |
|
573 |
if (_wnd.dib_sect == NULL) |
|
574 |
error("CreateDIBSection failed"); |
|
575 |
ReleaseDC(0, dc); |
|
576 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
577 |
if (!_wnd.double_size) |
0 | 578 |
_wnd.buffer_bits = _wnd.bitmap_bits; |
579 |
||
580 |
return true; |
|
581 |
} |
|
582 |
||
583 |
static const uint16 default_resolutions[][2] = { |
|
1028
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
584 |
{ 640, 480}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
585 |
{ 800, 600}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
586 |
{1024, 768}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
587 |
{1152, 864}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
588 |
{1280, 800}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
589 |
{1280, 960}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
590 |
{1280, 1024}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
591 |
{1400, 1050}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
592 |
{1600, 1200}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
593 |
{1680, 1050}, |
83ffeed42391
(svn r1529) -Feature: [1090950] Adding 16:10 resolutions for mainly laptops (doode)
darkvater
parents:
1023
diff
changeset
|
594 |
{1920, 1200} |
0 | 595 |
}; |
596 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
597 |
static void FindResolutions(void) |
0 | 598 |
{ |
599 |
int i = 0, n = 0; |
|
600 |
DEVMODE dm; |
|
601 |
||
602 |
while (EnumDisplaySettings(NULL, i++, &dm)) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
603 |
if (dm.dmBitsPerPel == 8 && |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
604 |
IS_INT_INSIDE(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) && |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
605 |
IS_INT_INSIDE(dm.dmPelsHeight, 480, MAX_SCREEN_HEIGHT + 1) && ( |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
606 |
n == 0 || |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
607 |
_resolutions[n - 1][0] != dm.dmPelsWidth || |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
608 |
_resolutions[n - 1][1] != dm.dmPelsHeight |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
609 |
)) { |
0 | 610 |
_resolutions[n][0] = dm.dmPelsWidth; |
611 |
_resolutions[n][1] = dm.dmPelsHeight; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
612 |
if (++n == lengthof(_resolutions)) break; |
0 | 613 |
} |
614 |
} |
|
615 |
||
616 |
if (n == 0) { |
|
617 |
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
618 |
n = lengthof(default_resolutions); |
0 | 619 |
} |
620 |
||
621 |
_num_resolutions = n; |
|
622 |
} |
|
623 |
||
624 |
||
1301
bf64ba5b6774
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1230
diff
changeset
|
625 |
static const char *Win32GdiStart(const char * const *parm) |
0 | 626 |
{ |
627 |
memset(&_wnd, 0, sizeof(_wnd)); |
|
628 |
_wnd.cursor_visible = true; |
|
629 |
||
630 |
RegisterWndClass(); |
|
631 |
||
632 |
MakePalette(); |
|
633 |
||
634 |
FindResolutions(); |
|
635 |
||
636 |
// fullscreen uses those |
|
637 |
_wnd.width_org = _cur_resolution[0]; |
|
638 |
_wnd.height_org = _cur_resolution[1]; |
|
639 |
||
640 |
AllocateDibSection(_cur_resolution[0], _cur_resolution[1]); |
|
641 |
MarkWholeScreenDirty(); |
|
642 |
||
643 |
MakeWindow(_fullscreen); |
|
644 |
||
645 |
return NULL; |
|
646 |
} |
|
647 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
648 |
static void Win32GdiStop(void) |
0 | 649 |
{ |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
650 |
if (_wnd.fullscreen) ChangeDisplaySettings(NULL, 0); |
0 | 651 |
MyShowCursor(true); |
652 |
DeleteObject(_wnd.gdi_palette); |
|
653 |
DeleteObject(_wnd.dib_sect); |
|
654 |
DestroyWindow(_wnd.main_wnd); |
|
655 |
} |
|
656 |
||
657 |
// simple upscaler by 2 |
|
658 |
static void filter(int left, int top, int width, int height) |
|
659 |
{ |
|
660 |
uint p = _screen.pitch; |
|
661 |
byte *s = (byte*)_wnd.buffer_bits + top * p + left; |
|
662 |
byte *d = (byte*)_wnd.bitmap_bits + top * p * 4 + left * 2; |
|
663 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
664 |
for (; height > 0; height--) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
665 |
int i; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
666 |
|
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
667 |
for (i = 0; i != width; i++) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
668 |
d[i * 2] = d[i * 2 + 1] = d[i * 2 + p * 2] = d[i * 2 + 1 + p * 2] = s[i]; |
0 | 669 |
} |
670 |
s += p; |
|
671 |
d += p * 4; |
|
672 |
} |
|
673 |
} |
|
674 |
||
675 |
static void Win32GdiMakeDirty(int left, int top, int width, int height) |
|
676 |
{ |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
677 |
RECT r = { left, top, left + width, top + height }; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
678 |
|
0 | 679 |
if (_wnd.double_size) { |
680 |
filter(left, top, width, height); |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
681 |
r.left *= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
682 |
r.top *= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
683 |
r.right *= 2; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
684 |
r.bottom *= 2; |
0 | 685 |
} |
686 |
InvalidateRect(_wnd.main_wnd, &r, FALSE); |
|
687 |
} |
|
688 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
689 |
static void CheckPaletteAnim(void) |
0 | 690 |
{ |
691 |
if (_pal_last_dirty == -1) |
|
692 |
return; |
|
693 |
InvalidateRect(_wnd.main_wnd, NULL, FALSE); |
|
694 |
} |
|
695 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
696 |
static int Win32GdiMainLoop(void) |
0 | 697 |
{ |
698 |
MSG mesg; |
|
699 |
uint32 next_tick = GetTickCount() + 30, cur_ticks; |
|
700 |
||
701 |
_wnd.running = true; |
|
702 |
||
703 |
while(true) { |
|
704 |
while (PeekMessage(&mesg, NULL, 0, 0, PM_REMOVE)) { |
|
705 |
InteractiveRandom(); // randomness |
|
706 |
TranslateMessage(&mesg); |
|
707 |
DispatchMessage(&mesg); |
|
708 |
} |
|
709 |
if (_exit_game) return ML_QUIT; |
|
710 |
if (_wnd.switch_driver) return ML_SWITCHDRIVER; |
|
711 |
||
712 |
#if defined(_DEBUG) |
|
713 |
if (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0) { |
|
714 |
#else |
|
715 |
if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0) { |
|
716 |
#endif |
|
1403
aac4a4df01ac
(svn r1907) - Fix: [ 1114261 ] Speeding up when pressing ALT+TAB (Windows)
darkvater
parents:
1390
diff
changeset
|
717 |
/* Disable speeding up game with ALT+TAB (if syskey is pressed, the |
aac4a4df01ac
(svn r1907) - Fix: [ 1114261 ] Speeding up when pressing ALT+TAB (Windows)
darkvater
parents:
1390
diff
changeset
|
718 |
* real key is in the upper 16 bits (see WM_SYSKEYDOWN in WndProcGdi()) */ |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
719 |
if ((_pressed_key >> 16) & WKC_TAB && !_networking && |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
720 |
_game_mode != GM_MENU) |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
721 |
_fast_forward |= 2; |
1403
aac4a4df01ac
(svn r1907) - Fix: [ 1114261 ] Speeding up when pressing ALT+TAB (Windows)
darkvater
parents:
1390
diff
changeset
|
722 |
} else if (_fast_forward & 2) |
0 | 723 |
_fast_forward = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
724 |
|
1403
aac4a4df01ac
(svn r1907) - Fix: [ 1114261 ] Speeding up when pressing ALT+TAB (Windows)
darkvater
parents:
1390
diff
changeset
|
725 |
cur_ticks = GetTickCount(); |
0 | 726 |
if ((_fast_forward && !_pause) || cur_ticks > next_tick) |
727 |
next_tick = cur_ticks; |
|
728 |
||
729 |
if (cur_ticks == next_tick) { |
|
730 |
next_tick += 30; |
|
731 |
_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0; |
|
732 |
_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0; |
|
733 |
_dbg_screen_rect = _wnd.has_focus && GetAsyncKeyState(VK_CAPITAL)<0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
734 |
|
0 | 735 |
// determine which directional keys are down |
1230
f08094212688
(svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents:
1102
diff
changeset
|
736 |
if (_wnd.has_focus) { |
f08094212688
(svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents:
1102
diff
changeset
|
737 |
_dirkeys = |
f08094212688
(svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents:
1102
diff
changeset
|
738 |
(GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) + |
f08094212688
(svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents:
1102
diff
changeset
|
739 |
(GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) + |
f08094212688
(svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents:
1102
diff
changeset
|
740 |
(GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) + |
f08094212688
(svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents:
1102
diff
changeset
|
741 |
(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0); |
f08094212688
(svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents:
1102
diff
changeset
|
742 |
} else |
f08094212688
(svn r1734) - Fix: [ 1112253 ] hijacking of arrow keys, game also scrolled when it was out of focus (dominik)
darkvater
parents:
1102
diff
changeset
|
743 |
_dirkeys = 0; |
0 | 744 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
745 |
GameLoop(); |
0 | 746 |
_cursor.delta.x = _cursor.delta.y = 0; |
747 |
||
748 |
if (_force_full_redraw) |
|
749 |
MarkWholeScreenDirty(); |
|
750 |
||
751 |
GdiFlush(); |
|
752 |
_screen.dst_ptr = _wnd.buffer_bits; |
|
753 |
UpdateWindows(); |
|
754 |
CheckPaletteAnim(); |
|
755 |
} else { |
|
756 |
Sleep(1); |
|
757 |
GdiFlush(); |
|
758 |
_screen.dst_ptr = _wnd.buffer_bits; |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
759 |
DrawTextMessage(); |
0 | 760 |
DrawMouseCursor(); |
761 |
} |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
static bool Win32GdiChangeRes(int w, int h) |
|
766 |
{ |
|
767 |
_wnd.width = _wnd.width_org = w; |
|
768 |
_wnd.height = _wnd.height_org = h; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
769 |
|
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
287
diff
changeset
|
770 |
MakeWindow(_fullscreen); // _wnd.fullscreen screws up ingame resolution switching |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
771 |
|
0 | 772 |
return true; |
773 |
} |
|
774 |
||
775 |
const HalVideoDriver _win32_video_driver = { |
|
776 |
Win32GdiStart, |
|
777 |
Win32GdiStop, |
|
778 |
Win32GdiMakeDirty, |
|
779 |
Win32GdiMainLoop, |
|
780 |
Win32GdiChangeRes, |
|
781 |
}; |
|
782 |
||
783 |
||
784 |
/********************** |
|
785 |
* WIN32 MIDI PLAYER |
|
786 |
**********************/ |
|
787 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
788 |
static struct { |
0 | 789 |
bool stop_song; |
790 |
bool terminate; |
|
791 |
bool playing; |
|
792 |
int new_vol; |
|
793 |
HANDLE wait_obj; |
|
794 |
char start_song[260]; |
|
795 |
} _midi; |
|
796 |
||
797 |
static void Win32MidiPlaySong(const char *filename) |
|
798 |
{ |
|
799 |
strcpy(_midi.start_song, filename); |
|
800 |
_midi.playing = true; |
|
801 |
_midi.stop_song = false; |
|
802 |
SetEvent(_midi.wait_obj); |
|
803 |
} |
|
804 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
805 |
static void Win32MidiStopSong(void) |
0 | 806 |
{ |
807 |
if (_midi.playing) { |
|
808 |
_midi.stop_song = true; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
809 |
_midi.start_song[0] = '\0'; |
0 | 810 |
SetEvent(_midi.wait_obj); |
811 |
} |
|
812 |
} |
|
813 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
814 |
static bool Win32MidiIsSongPlaying(void) |
0 | 815 |
{ |
816 |
return _midi.playing; |
|
817 |
} |
|
818 |
||
819 |
static void Win32MidiSetVolume(byte vol) |
|
820 |
{ |
|
821 |
_midi.new_vol = vol; |
|
822 |
SetEvent(_midi.wait_obj); |
|
823 |
} |
|
824 |
||
825 |
static long CDECL MidiSendCommand(const char *cmd, ...) { |
|
826 |
va_list va; |
|
827 |
char buf[512]; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
828 |
|
0 | 829 |
va_start(va, cmd); |
830 |
vsprintf(buf, cmd, va); |
|
831 |
va_end(va); |
|
832 |
return mciSendStringA(buf, NULL, 0, 0); |
|
833 |
} |
|
834 |
||
835 |
static bool MidiIntPlaySong(const char *filename) |
|
836 |
{ |
|
837 |
MidiSendCommand("close all"); |
|
838 |
if (MidiSendCommand("open %s type sequencer alias song", filename) != 0) |
|
839 |
return false; |
|
840 |
||
841 |
if (MidiSendCommand("play song from 0") != 0) |
|
842 |
return false; |
|
843 |
return true; |
|
844 |
} |
|
845 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
846 |
static void MidiIntStopSong(void) |
0 | 847 |
{ |
848 |
MidiSendCommand("close all"); |
|
849 |
} |
|
850 |
||
851 |
static void MidiIntSetVolume(int vol) |
|
852 |
{ |
|
853 |
uint v = (vol * 65535 / 127); |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
854 |
midiOutSetVolume((HMIDIOUT)-1, v + (v << 16)); |
0 | 855 |
} |
856 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
857 |
static bool MidiIntIsSongPlaying(void) |
0 | 858 |
{ |
859 |
char buf[16]; |
|
860 |
mciSendStringA("status song mode", buf, sizeof(buf), 0); |
|
861 |
return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0; |
|
862 |
} |
|
863 |
||
864 |
static DWORD WINAPI MidiThread(LPVOID arg) |
|
865 |
{ |
|
866 |
_midi.wait_obj = CreateEvent(NULL, FALSE, FALSE, NULL); |
|
867 |
||
868 |
do { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
869 |
char *s; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
870 |
int vol; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
871 |
|
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
872 |
vol = _midi.new_vol; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
873 |
if (vol != -1) { |
0 | 874 |
_midi.new_vol = -1; |
875 |
MidiIntSetVolume(vol); |
|
876 |
} |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
877 |
|
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
878 |
s = _midi.start_song; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
879 |
if (s[0] != '\0') { |
0 | 880 |
_midi.playing = MidiIntPlaySong(s); |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
881 |
s[0] = '\0'; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
882 |
|
0 | 883 |
// Delay somewhat in case we don't manage to play. |
884 |
if (!_midi.playing) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
885 |
Sleep(5000); |
0 | 886 |
} |
887 |
} |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
888 |
|
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
889 |
if (_midi.stop_song && _midi.playing) { |
0 | 890 |
_midi.stop_song = false; |
891 |
_midi.playing = false; |
|
892 |
MidiIntStopSong(); |
|
893 |
} |
|
894 |
||
895 |
if (_midi.playing && !MidiIntIsSongPlaying()) |
|
896 |
_midi.playing = false; |
|
897 |
||
898 |
WaitForMultipleObjects(1, &_midi.wait_obj, FALSE, 1000); |
|
899 |
} while (!_midi.terminate); |
|
900 |
||
901 |
DeleteObject(_midi.wait_obj); |
|
902 |
return 0; |
|
903 |
} |
|
904 |
||
1301
bf64ba5b6774
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1230
diff
changeset
|
905 |
static const char *Win32MidiStart(const char * const *parm) |
0 | 906 |
{ |
907 |
DWORD threadId; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
908 |
|
0 | 909 |
memset(&_midi, 0, sizeof(_midi)); |
910 |
_midi.new_vol = -1; |
|
911 |
CreateThread(NULL, 8192, MidiThread, 0, 0, &threadId); |
|
912 |
return 0; |
|
913 |
} |
|
914 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
915 |
static void Win32MidiStop(void) |
0 | 916 |
{ |
917 |
_midi.terminate = true; |
|
918 |
SetEvent(_midi.wait_obj); |
|
919 |
} |
|
920 |
||
921 |
const HalMusicDriver _win32_music_driver = { |
|
922 |
Win32MidiStart, |
|
923 |
Win32MidiStop, |
|
924 |
Win32MidiPlaySong, |
|
925 |
Win32MidiStopSong, |
|
926 |
Win32MidiIsSongPlaying, |
|
927 |
Win32MidiSetVolume, |
|
928 |
}; |
|
929 |
||
930 |
// WIN32 Sound code. |
|
931 |
||
932 |
static HWAVEOUT _waveout; |
|
933 |
static WAVEHDR _wave_hdr[2]; |
|
934 |
static int _bufsize; |
|
935 |
static void PrepareHeader(WAVEHDR *hdr) |
|
936 |
{ |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
937 |
hdr->dwBufferLength = _bufsize * 4; |
0 | 938 |
hdr->dwFlags = 0; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
939 |
hdr->lpData = malloc(_bufsize * 4); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
940 |
if (hdr->lpData == NULL || |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
941 |
waveOutPrepareHeader(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
0 | 942 |
error("waveOutPrepareHeader failed"); |
943 |
} |
|
944 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
945 |
static void FillHeaders(void) |
0 | 946 |
{ |
947 |
WAVEHDR *hdr; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
948 |
|
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
949 |
for (hdr = _wave_hdr; hdr != endof(_wave_hdr); hdr++) { |
0 | 950 |
if (!(hdr->dwFlags & WHDR_INQUEUE)) { |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
951 |
MxMixSamples(_mixer, hdr->lpData, hdr->dwBufferLength / 4); |
0 | 952 |
if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) |
953 |
error("waveOutWrite failed"); |
|
954 |
} |
|
955 |
} |
|
956 |
} |
|
957 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
958 |
static void CALLBACK waveOutProc(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
959 |
DWORD dwParam1, DWORD dwParam2) |
0 | 960 |
{ |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
961 |
switch (uMsg) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
962 |
case WOM_DONE: |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
963 |
if (_waveout) FillHeaders(); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
964 |
break; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
965 |
|
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
966 |
default: |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
967 |
break; |
0 | 968 |
} |
969 |
} |
|
970 |
||
1301
bf64ba5b6774
(svn r1805) Teach the driver layer a few things about const correctness
tron
parents:
1230
diff
changeset
|
971 |
static const char *Win32SoundStart(const char * const *parm) |
0 | 972 |
{ |
973 |
WAVEFORMATEX wfex; |
|
974 |
int hz; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
975 |
|
0 | 976 |
_bufsize = GetDriverParamInt(parm, "bufsize", 1024); |
977 |
hz = GetDriverParamInt(parm, "hz", 11025); |
|
978 |
wfex.wFormatTag = WAVE_FORMAT_PCM; |
|
979 |
wfex.nChannels = 2; |
|
980 |
wfex.nSamplesPerSec = hz; |
|
981 |
wfex.nAvgBytesPerSec = hz*2*2; |
|
982 |
wfex.nBlockAlign = 4; |
|
983 |
wfex.wBitsPerSample = 16; |
|
984 |
if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD)&waveOutProc, 0, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) |
|
985 |
return "waveOutOpen failed"; |
|
986 |
PrepareHeader(&_wave_hdr[0]); |
|
987 |
PrepareHeader(&_wave_hdr[1]); |
|
988 |
FillHeaders(); |
|
989 |
return NULL; |
|
990 |
} |
|
991 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
992 |
static void Win32SoundStop(void) |
0 | 993 |
{ |
994 |
HWAVEOUT waveout = _waveout; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
995 |
|
0 | 996 |
_waveout = NULL; |
997 |
waveOutReset(waveout); |
|
998 |
waveOutUnprepareHeader(waveout, &_wave_hdr[0], sizeof(WAVEHDR)); |
|
999 |
waveOutUnprepareHeader(waveout, &_wave_hdr[1], sizeof(WAVEHDR)); |
|
1000 |
waveOutClose(waveout); |
|
1001 |
} |
|
1002 |
||
1003 |
const HalSoundDriver _win32_sound_driver = { |
|
1004 |
Win32SoundStart, |
|
1005 |
Win32SoundStop, |
|
1006 |
}; |
|
1007 |
||
1008 |
// Helper function needed by dynamically loading SDL |
|
1009 |
bool LoadLibraryList(void **proc, const char *dll) |
|
1010 |
{ |
|
1011 |
HMODULE lib; |
|
1012 |
void *p; |
|
1013 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1014 |
while (*dll != '\0') { |
0 | 1015 |
lib = LoadLibrary(dll); |
1016 |
if (lib == NULL) |
|
1017 |
return false; |
|
1018 |
while (true) { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1019 |
while(*dll++ != '\0'); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1020 |
if (*dll == '\0') |
0 | 1021 |
break; |
1022 |
p = GetProcAddress(lib, dll); |
|
1023 |
if (p == NULL) |
|
1024 |
return false; |
|
1025 |
*proc++ = p; |
|
1026 |
} |
|
1027 |
dll++; |
|
1028 |
} |
|
1029 |
return true; |
|
1030 |
} |
|
1031 |
||
796 | 1032 |
#ifdef _MSC_VER |
1033 |
||
0 | 1034 |
static const char *_exception_string; |
1035 |
static void *_safe_esp; |
|
1036 |
static char *_crash_msg; |
|
1037 |
static bool _expanded; |
|
1038 |
static bool _did_emerg_save; |
|
1039 |
static int _ident; |
|
1040 |
||
1041 |
void ShowOSErrorBox(const char *buf) |
|
1042 |
{ |
|
1043 |
MyShowCursor(true); |
|
1044 |
MessageBoxA(GetActiveWindow(), buf, "Error!", MB_ICONSTOP); |
|
1045 |
||
1046 |
// if exception tracker is enabled, we crash here to let the exception handler handle it. |
|
1047 |
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG) |
|
1048 |
if (*buf == '!') { |
|
1049 |
_exception_string = buf; |
|
1050 |
*(byte*)0 = 0; |
|
1051 |
} |
|
1052 |
#endif |
|
1053 |
} |
|
1054 |
||
1055 |
typedef struct DebugFileInfo { |
|
1056 |
uint32 size; |
|
1057 |
uint32 crc32; |
|
1058 |
SYSTEMTIME file_time; |
|
1059 |
} DebugFileInfo; |
|
1060 |
||
1061 |
static uint32 *_crc_table; |
|
1062 |
||
1063 |
static void MakeCRCTable(uint32 *table) { |
|
1064 |
uint32 crc, poly = 0xEDB88320L; |
|
1065 |
int i, j; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1066 |
|
0 | 1067 |
_crc_table = table; |
1068 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1069 |
for (i = 0; i != 256; i++) { |
0 | 1070 |
crc = i; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1071 |
for (j = 8; j != 0; j--) { |
0 | 1072 |
if (crc & 1) |
1073 |
crc = (crc >> 1) ^ poly; |
|
1074 |
else |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1075 |
crc >>= 1; |
0 | 1076 |
} |
1077 |
table[i] = crc; |
|
1078 |
} |
|
1079 |
} |
|
1080 |
||
1081 |
static uint32 CalcCRC(byte *data, uint size, uint32 crc) { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1082 |
for (; size > 0; size--) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1083 |
crc = ((crc >> 8) & 0x00FFFFFF) ^ _crc_table[(crc ^ *data++) & 0xFF]; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1084 |
} |
0 | 1085 |
return crc; |
1086 |
} |
|
1087 |
||
1088 |
static void GetFileInfo(DebugFileInfo *dfi, const char *filename) |
|
1089 |
{ |
|
1090 |
memset(dfi, 0, sizeof(dfi)); |
|
1091 |
||
1092 |
{ |
|
1093 |
HANDLE file; |
|
1094 |
byte buffer[1024]; |
|
1095 |
DWORD numread; |
|
1096 |
uint32 filesize = 0; |
|
1097 |
FILETIME write_time; |
|
1098 |
uint32 crc = (uint32)-1; |
|
1099 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1100 |
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1101 |
OPEN_EXISTING, 0, 0); |
0 | 1102 |
if (file != INVALID_HANDLE_VALUE) { |
1103 |
while(true) { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1104 |
if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1105 |
numread == 0) |
0 | 1106 |
break; |
1107 |
filesize += numread; |
|
1108 |
crc = CalcCRC(buffer, numread, crc); |
|
1109 |
} |
|
1110 |
dfi->size = filesize; |
|
1111 |
dfi->crc32 = crc ^ (uint32)-1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1112 |
|
0 | 1113 |
if (GetFileTime(file, NULL, NULL, &write_time)) { |
1114 |
FileTimeToSystemTime(&write_time, &dfi->file_time); |
|
1115 |
} |
|
1116 |
CloseHandle(file); |
|
1117 |
} |
|
1118 |
} |
|
1119 |
} |
|
1120 |
||
1121 |
||
1122 |
static char *PrintModuleInfo(char *output, HMODULE mod) |
|
1123 |
{ |
|
318
648afd1ab9a7
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
306
diff
changeset
|
1124 |
char buffer[MAX_PATH]; |
0 | 1125 |
DebugFileInfo dfi; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1126 |
|
0 | 1127 |
GetModuleFileName(mod, buffer, MAX_PATH); |
1128 |
GetFileInfo(&dfi, buffer); |
|
1129 |
output += sprintf(output, " %-20s handle: %.8X size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n", |
|
1130 |
buffer, |
|
1131 |
mod, |
|
1132 |
dfi.size, |
|
1133 |
dfi.crc32, |
|
1134 |
dfi.file_time.wYear, |
|
1135 |
dfi.file_time.wMonth, |
|
1136 |
dfi.file_time.wDay, |
|
1137 |
dfi.file_time.wHour, |
|
1138 |
dfi.file_time.wMinute, |
|
1139 |
dfi.file_time.wSecond |
|
1140 |
); |
|
1141 |
return output; |
|
1142 |
} |
|
1143 |
||
1144 |
static char *PrintModuleList(char *output) |
|
1145 |
{ |
|
1146 |
BOOL (WINAPI *EnumProcessModules)(HANDLE,HMODULE*,DWORD,LPDWORD); |
|
1147 |
HANDLE proc; |
|
1148 |
HMODULE modules[100]; |
|
1149 |
DWORD needed; |
|
1150 |
BOOL res; |
|
1151 |
int count,i; |
|
1152 |
||
1153 |
if (LoadLibraryList((void*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0")) { |
|
1154 |
proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); |
|
1155 |
if (proc) { |
|
1156 |
res = EnumProcessModules(proc, modules, sizeof(modules), &needed); |
|
1157 |
CloseHandle(proc); |
|
1158 |
if (res) { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1159 |
count = |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1160 |
min(needed / sizeof(HMODULE), lengthof(modules)); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1161 |
for (i = 0; i != count; i++) |
0 | 1162 |
output = PrintModuleInfo(output, modules[i]); |
1163 |
return output; |
|
1164 |
} |
|
1165 |
} |
|
1166 |
} |
|
1167 |
output = PrintModuleInfo(output, NULL); |
|
1168 |
return output; |
|
1169 |
} |
|
1170 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1171 |
static const char _crash_desc[] = |
0 | 1172 |
"A serious fault condition occured in the game. The game will shut down.\n" |
1173 |
"Press \"Submit report\" to send crash information to the developers. " |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1174 |
"This will greatly help debugging. " |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1175 |
"The information contained in the report is displayed below.\n" |
0 | 1176 |
"Press \"Emergency save\" to attempt saving the game."; |
1177 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1178 |
static const char _save_succeeded[] = |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1179 |
"Emergency save succeeded.\n" |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1180 |
"Be aware that critical parts of the internal game state may have become " |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1181 |
"corrupted. The saved game is not guaranteed to work."; |
0 | 1182 |
|
1183 |
bool EmergencySave(); |
|
1184 |
||
1185 |
||
1186 |
typedef struct { |
|
1187 |
HINTERNET (WINAPI *InternetOpenA)(LPCSTR,DWORD, LPCSTR, LPCSTR, DWORD); |
|
1188 |
HINTERNET (WINAPI *InternetConnectA)(HINTERNET, LPCSTR, INTERNET_PORT, LPCSTR, LPCSTR, DWORD, DWORD, DWORD); |
|
1189 |
HINTERNET (WINAPI *HttpOpenRequestA)(HINTERNET, LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPCSTR *, DWORD, DWORD); |
|
1190 |
BOOL (WINAPI *HttpSendRequestA)(HINTERNET, LPCSTR, DWORD, LPVOID, DWORD); |
|
1191 |
BOOL (WINAPI *InternetCloseHandle)(HINTERNET); |
|
1192 |
BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD); |
|
1193 |
} WinInetProcs; |
|
1194 |
||
1195 |
#define M(x) x "\0" |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1196 |
static const char wininet_files[] = |
0 | 1197 |
M("wininet.dll") |
1198 |
M("InternetOpenA") |
|
1199 |
M("InternetConnectA") |
|
1200 |
M("HttpOpenRequestA") |
|
1201 |
M("HttpSendRequestA") |
|
1202 |
M("InternetCloseHandle") |
|
1203 |
M("HttpQueryInfoA") |
|
1204 |
M(""); |
|
1205 |
#undef M |
|
1206 |
||
1207 |
static WinInetProcs _wininet; |
|
1208 |
||
1209 |
||
1210 |
static char *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const char *arg) |
|
1211 |
{ |
|
1212 |
HINTERNET inet, conn, http; |
|
1213 |
char *err = NULL; |
|
1214 |
DWORD code, len; |
|
1215 |
static char buf[100]; |
|
1216 |
char buff[100]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1217 |
|
0 | 1218 |
if (_wininet.InternetOpen == NULL && !LoadLibraryList((void**)&_wininet, wininet_files)) return "can't load wininet.dll"; |
1219 |
||
1220 |
inet = _wininet.InternetOpen("TTD", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); |
|
1221 |
if (inet == NULL) { err = "internetopen failed"; goto error1; } |
|
1222 |
||
1223 |
conn = _wininet.InternetConnect(inet, "openttd.com", INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0); |
|
1224 |
if (conn == NULL) { err = "internetconnect failed"; goto error2; } |
|
1225 |
||
1226 |
sprintf(buff, "/crash.php?file=%s&ident=%d", arg, _ident); |
|
1227 |
||
1228 |
http = _wininet.HttpOpenRequest(conn, "POST", buff, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE , 0); |
|
1229 |
if (http == NULL) { err = "httpopenrequest failed"; goto error3; } |
|
1230 |
||
1231 |
if (!_wininet.HttpSendRequest(http, "Content-type: application/binary", -1, msg, msglen)) { err = "httpsendrequest failed"; goto error4; } |
|
1232 |
||
1233 |
len = sizeof(code); |
|
1234 |
if (!_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &len, 0)) { err = "httpqueryinfo failed"; goto error4; } |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1235 |
|
0 | 1236 |
if (code != 200) { |
1237 |
int l = sprintf(buf, "Server said: %d ", code); |
|
1238 |
len = sizeof(buf) - l; |
|
1239 |
_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_TEXT, buf + l, &len, 0); |
|
1240 |
err = buf; |
|
1241 |
} |
|
1242 |
||
1243 |
error4: |
|
1244 |
_wininet.InternetCloseHandle(http); |
|
1245 |
error3: |
|
1246 |
_wininet.InternetCloseHandle(conn); |
|
1247 |
error2: |
|
1248 |
_wininet.InternetCloseHandle(inet); |
|
1249 |
error1: |
|
1250 |
return err; |
|
1251 |
} |
|
1252 |
||
1253 |
static void SubmitFile(HWND wnd, const char *file) |
|
1254 |
{ |
|
1255 |
HANDLE h; |
|
1256 |
unsigned long size; |
|
1257 |
unsigned long read; |
|
1258 |
void *mem; |
|
1259 |
||
1260 |
h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
|
1261 |
if (h == NULL) return; |
|
1262 |
||
1263 |
size = GetFileSize(h, NULL); |
|
1264 |
if (size > 500000) goto error1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1265 |
|
0 | 1266 |
mem = malloc(size); |
1267 |
if (mem == NULL) goto error1; |
|
1268 |
||
1269 |
if (!ReadFile(h, mem, size, &read, NULL) || read != size) goto error2; |
|
1270 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1271 |
SubmitCrashReport(wnd, mem, size, file); |
0 | 1272 |
|
1273 |
error2: |
|
1274 |
free(mem); |
|
1275 |
error1: |
|
1276 |
CloseHandle(h); |
|
1277 |
} |
|
1278 |
||
1279 |
static const char * const _expand_texts[] = {"S&how report >>", "&Hide report <<" }; |
|
1280 |
||
1281 |
static void SetWndSize(HWND wnd, int mode) |
|
1282 |
{ |
|
1283 |
RECT r,r2; |
|
1284 |
int offs; |
|
1285 |
||
1286 |
GetWindowRect(wnd, &r); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1287 |
|
0 | 1288 |
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
|
1289 |
|
0 | 1290 |
if (mode >= 0) { |
1291 |
GetWindowRect(GetDlgItem(wnd, 11), &r2); |
|
1292 |
offs = r2.bottom - r2.top + 10; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1293 |
if (!mode) offs = -offs; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1294 |
SetWindowPos(wnd, HWND_TOPMOST, 0, 0, |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1295 |
r.right - r.left, r.bottom - r.top + offs, SWP_NOMOVE | SWP_NOZORDER); |
0 | 1296 |
} else { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1297 |
SetWindowPos(wnd, HWND_TOPMOST, |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1298 |
(GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2, |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1299 |
(GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2, |
0 | 1300 |
0, 0, SWP_NOSIZE); |
1301 |
} |
|
1302 |
} |
|
1303 |
||
1304 |
static bool DoEmergencySave(HWND wnd) |
|
1305 |
{ |
|
1306 |
bool b = false; |
|
1307 |
||
1308 |
EnableWindow(GetDlgItem(wnd, 13), FALSE); |
|
1309 |
_did_emerg_save = true; |
|
1310 |
__try { |
|
1311 |
b = EmergencySave(); |
|
1312 |
} __except (1) {} |
|
1313 |
return b; |
|
1314 |
} |
|
1315 |
||
1316 |
static BOOL CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam) |
|
1317 |
{ |
|
1318 |
switch(msg) { |
|
1319 |
case WM_INITDIALOG: |
|
1320 |
SetDlgItemText(wnd, 10, _crash_desc); |
|
1321 |
SetDlgItemText(wnd, 11, _crash_msg); |
|
1322 |
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE); |
|
1323 |
SetWndSize(wnd, -1); |
|
1324 |
return TRUE; |
|
1325 |
case WM_COMMAND: |
|
1326 |
switch(wParam) { |
|
1327 |
case 12: // Close |
|
1328 |
ExitProcess(0); |
|
1329 |
case 13: { // Emergency save |
|
1330 |
if (DoEmergencySave(wnd)) |
|
1331 |
MessageBoxA(wnd, _save_succeeded, "Save successful", MB_ICONINFORMATION); |
|
1332 |
else |
|
1333 |
MessageBoxA(wnd, "Save failed", "Save failed", MB_ICONINFORMATION); |
|
1334 |
break; |
|
1335 |
} |
|
1336 |
case 14: { // Submit crash report |
|
1337 |
char *s; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1338 |
|
0 | 1339 |
SetCursor(LoadCursor(NULL, IDC_WAIT)); |
1340 |
||
1341 |
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), ""); |
|
1342 |
if (s) { |
|
1343 |
MessageBoxA(wnd, s, "Error", MB_ICONSTOP); |
|
1344 |
break; |
|
1345 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1346 |
|
0 | 1347 |
// try to submit emergency savegame |
1348 |
if (_did_emerg_save || DoEmergencySave(wnd)) { |
|
1349 |
SubmitFile(wnd, "crash.sav"); |
|
1350 |
} |
|
1351 |
// try to submit the autosaved game |
|
1352 |
if (_opt.autosave) { |
|
1353 |
char buf[40]; |
|
1354 |
sprintf(buf, "autosave%d.sav", (_autosave_ctr - 1) & 3); |
|
1355 |
SubmitFile(wnd, buf); |
|
1356 |
} |
|
1357 |
EnableWindow(GetDlgItem(wnd, 14), FALSE); |
|
1358 |
SetCursor(LoadCursor(NULL, IDC_ARROW)); |
|
1359 |
MessageBoxA(wnd, "Crash report submitted. Thank you.", "Crash Report", MB_ICONINFORMATION); |
|
1360 |
break; |
|
1361 |
} |
|
1362 |
case 15: // Expand |
|
1363 |
_expanded ^= 1; |
|
1364 |
SetWndSize(wnd, _expanded); |
|
1365 |
break; |
|
1366 |
} |
|
1367 |
return TRUE; |
|
1368 |
case WM_CLOSE: |
|
1369 |
ExitProcess(0); |
|
1370 |
} |
|
1371 |
||
1372 |
return FALSE; |
|
1373 |
} |
|
1374 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
1375 |
static void Handler2(void) |
0 | 1376 |
{ |
1377 |
ShowCursor(TRUE); |
|
1378 |
ShowWindow(GetActiveWindow(), FALSE); |
|
1379 |
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(100), NULL, CrashDialogFunc); |
|
1380 |
} |
|
1381 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
1382 |
extern bool CloseConsoleLogIfActive(void); |
1023
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
1383 |
|
0 | 1384 |
static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) |
1385 |
{ |
|
1386 |
char *output; |
|
1387 |
static bool had_exception; |
|
1388 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1389 |
if (had_exception) ExitProcess(0); |
0 | 1390 |
had_exception = true; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1391 |
|
0 | 1392 |
_ident = GetTickCount(); // something pretty unique |
1393 |
||
1394 |
MakeCRCTable(alloca(256 * sizeof(uint32))); |
|
1395 |
_crash_msg = output = LocalAlloc(LMEM_FIXED, 8192); |
|
1396 |
||
1397 |
{ |
|
1398 |
SYSTEMTIME time; |
|
1399 |
GetLocalTime(&time); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1400 |
output += sprintf(output, |
0 | 1401 |
"*** OpenTTD Crash Report ***\r\n" |
1402 |
"Date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n" |
|
1403 |
"Build: %s built on " __TIMESTAMP__ "\r\n", |
|
1404 |
time.wYear, |
|
1405 |
time.wMonth, |
|
1406 |
time.wDay, |
|
1407 |
time.wHour, |
|
1408 |
time.wMinute, |
|
1409 |
time.wSecond, |
|
1410 |
"???" |
|
1411 |
); |
|
1412 |
} |
|
1413 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1414 |
if (_exception_string) |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1415 |
output += sprintf(output, "Reason: %s\r\n", _exception_string); |
0 | 1416 |
|
1417 |
output += sprintf(output, "Exception %.8X at %.8X\r\n" |
|
1418 |
"Registers:\r\n" |
|
1419 |
" EAX: %.8X EBX: %.8X ECX: %.8X EDX: %.8X\r\n" |
|
1420 |
" ESI: %.8X EDI: %.8X EBP: %.8X ESP: %.8X\r\n" |
|
1421 |
" EIP: %.8X EFLAGS: %.8X\r\n" |
|
1422 |
"\r\nBytes at CS:EIP:\r\n", |
|
1423 |
ep->ExceptionRecord->ExceptionCode, |
|
1424 |
ep->ExceptionRecord->ExceptionAddress, |
|
1425 |
ep->ContextRecord->Eax, |
|
1426 |
ep->ContextRecord->Ebx, |
|
1427 |
ep->ContextRecord->Ecx, |
|
1428 |
ep->ContextRecord->Edx, |
|
1429 |
ep->ContextRecord->Esi, |
|
1430 |
ep->ContextRecord->Edi, |
|
1431 |
ep->ContextRecord->Ebp, |
|
1432 |
ep->ContextRecord->Esp, |
|
1433 |
ep->ContextRecord->Eip, |
|
1434 |
ep->ContextRecord->EFlags |
|
1435 |
); |
|
1436 |
||
1437 |
{ |
|
1438 |
byte *b = (byte*)ep->ContextRecord->Eip; |
|
1439 |
int i; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1440 |
for (i = 0; i != 24; i++) { |
0 | 1441 |
if (IsBadReadPtr(b, 1)) { |
1442 |
output += sprintf(output, " ??"); // OCR: WAS: , 0); |
|
1443 |
} else { |
|
1444 |
output += sprintf(output, " %.2X", *b); |
|
1445 |
} |
|
1446 |
b++; |
|
1447 |
} |
|
1448 |
output += sprintf(output, |
|
1449 |
"\r\n" |
|
1450 |
"\r\nStack trace: \r\n" |
|
1451 |
); |
|
1452 |
} |
|
1453 |
||
1454 |
{ |
|
1455 |
int i,j; |
|
1456 |
uint32 *b = (uint32*)ep->ContextRecord->Esp; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1457 |
for (j = 0; j != 24; j++) { |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1458 |
for (i = 0; i != 8; i++) { |
0 | 1459 |
if (IsBadReadPtr(b,sizeof(uint32))) { |
1460 |
output += sprintf(output, " ????????"); //OCR: WAS - , 0); |
|
1461 |
} else { |
|
1462 |
output += sprintf(output, " %.8X", *b); |
|
1463 |
} |
|
1464 |
b++; |
|
1465 |
} |
|
1466 |
output += sprintf(output, "\r\n"); |
|
1467 |
} |
|
1468 |
} |
|
1469 |
||
1470 |
output += sprintf(output, "\r\nModule information:\r\n"); |
|
1471 |
output = PrintModuleList(output); |
|
1472 |
||
1473 |
{ |
|
1474 |
OSVERSIONINFO os; |
|
1475 |
os.dwOSVersionInfoSize = sizeof(os); |
|
1476 |
GetVersionEx(&os); |
|
1477 |
output += sprintf(output, "\r\nSystem information:\r\n" |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1478 |
" Windows version %d.%d %d %s\r\n", |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1479 |
os.dwMajorVersion, os.dwMinorVersion, os.dwBuildNumber, os.szCSDVersion); |
0 | 1480 |
} |
1481 |
||
1482 |
{ |
|
1483 |
HANDLE file = CreateFile("crash.log", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); |
|
1484 |
DWORD num_written; |
|
1485 |
if (file != INVALID_HANDLE_VALUE) { |
|
1486 |
WriteFile(file, _crash_msg, output - _crash_msg, &num_written, NULL); |
|
1487 |
CloseHandle(file); |
|
1488 |
} |
|
1489 |
} |
|
1490 |
||
1023
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
1491 |
/* Close any possible log files */ |
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
1492 |
CloseConsoleLogIfActive(); |
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
1493 |
|
0 | 1494 |
if (_safe_esp) { |
1495 |
ep->ContextRecord->Eip = (DWORD)Handler2; |
|
1496 |
ep->ContextRecord->Esp = (DWORD)_safe_esp; |
|
1497 |
return EXCEPTION_CONTINUE_EXECUTION; |
|
1498 |
} |
|
1023
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
1499 |
|
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
1500 |
|
1ae7b7a78602
(svn r1524) -"Feature": when windows exception tracker is enabled (release builds) and the game crashes for any reason any active log file is closed first. This ensures the log file and ingame debug messages can be used to debug a problem. Any *nix versions are welcome
darkvater
parents:
1022
diff
changeset
|
1501 |
return EXCEPTION_EXECUTE_HANDLER; |
0 | 1502 |
} |
1503 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
1504 |
static void Win32InitializeExceptions(void) |
0 | 1505 |
{ |
1506 |
_asm { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1507 |
mov _safe_esp, esp |
0 | 1508 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1509 |
|
0 | 1510 |
SetUnhandledExceptionFilter(ExceptionHandler); |
1511 |
} |
|
796 | 1512 |
#else |
1513 |
/* Get rid of unused variable warnings.. ShowOSErrorBox |
|
915 | 1514 |
* is now used twice, once in MSVC, and once in all other Win |
796 | 1515 |
* compilers (cygwin, mingw, etc.) */ |
1516 |
void ShowOSErrorBox(const char *buf) |
|
1517 |
{ |
|
1518 |
MyShowCursor(true); |
|
1519 |
MessageBoxA(GetActiveWindow(), buf, "Error!", MB_ICONSTOP); |
|
1520 |
} |
|
0 | 1521 |
#endif |
1522 |
||
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1523 |
#ifndef __MINGW32__ |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1524 |
static inline int strcasecmp(const char* s1, const char* s2) |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1525 |
{ |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1526 |
return stricmp(s1, s2); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1527 |
} |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1528 |
#endif |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1529 |
|
0 | 1530 |
static char *_fios_path; |
1531 |
static char *_fios_save_path; |
|
1532 |
static char *_fios_scn_path; |
|
1533 |
static FiosItem *_fios_items; |
|
1534 |
static int _fios_count, _fios_alloc; |
|
1535 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
1536 |
static FiosItem *FiosAlloc(void) |
0 | 1537 |
{ |
1538 |
if (_fios_count == _fios_alloc) { |
|
1539 |
_fios_alloc += 256; |
|
1540 |
_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem)); |
|
1541 |
} |
|
1542 |
return &_fios_items[_fios_count++]; |
|
1543 |
} |
|
1544 |
||
1466 | 1545 |
static HANDLE MyFindFirstFile(const char *path, const char *file, |
1546 |
WIN32_FIND_DATA *fd) |
|
0 | 1547 |
{ |
1548 |
char paths[MAX_PATH]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1549 |
|
0 | 1550 |
sprintf(paths, "%s\\%s", path, file); |
1551 |
return FindFirstFile(paths, fd); |
|
1552 |
} |
|
1553 |
||
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1554 |
int CDECL compare_FiosItems(const void *a, const void *b) |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1555 |
{ |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1556 |
const FiosItem *da = (const FiosItem *)a; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1557 |
const FiosItem *db = (const FiosItem *)b; |
0 | 1558 |
int r; |
1559 |
||
1560 |
if (_savegame_sort_order < 2) // sort by date |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1561 |
r = da->mtime < db->mtime ? -1 : 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1562 |
else |
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1563 |
r = strcasecmp( |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1564 |
da->title[0] != '\0' ? da->title : da->name, |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1565 |
db->title[0] != '\0' ? db->title : db->name |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1566 |
); |
0 | 1567 |
|
1568 |
if (_savegame_sort_order & 1) r = -r; |
|
1569 |
return r; |
|
1570 |
} |
|
1571 |
||
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1572 |
|
0 | 1573 |
// Get a list of savegames |
1574 |
FiosItem *FiosGetSavegameList(int *num, int mode) |
|
1575 |
{ |
|
1576 |
WIN32_FIND_DATA fd; |
|
1577 |
HANDLE h; |
|
1578 |
FiosItem *fios; |
|
1579 |
int sort_start; |
|
1580 |
||
1581 |
if (_fios_save_path == NULL) { |
|
1582 |
_fios_save_path = malloc(MAX_PATH); |
|
1583 |
strcpy(_fios_save_path, _path.save_dir); |
|
1584 |
} |
|
1585 |
||
1586 |
if (_game_mode == GM_EDITOR) |
|
1587 |
_fios_path = _fios_scn_path; |
|
1588 |
else |
|
1589 |
_fios_path = _fios_save_path; |
|
1590 |
||
1591 |
// Parent directory, only if not of the type C:\. |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1592 |
if (_fios_path[3] != '\0') { |
0 | 1593 |
fios = FiosAlloc(); |
1594 |
fios->type = FIOS_TYPE_PARENT; |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1595 |
fios->mtime = 0; |
0 | 1596 |
strcpy(fios->title, ".. (Parent directory)"); |
1597 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1598 |
|
0 | 1599 |
// Show subdirectories first |
1600 |
h = MyFindFirstFile(_fios_path, "*.*", &fd); |
|
1601 |
if (h != INVALID_HANDLE_VALUE) { |
|
1602 |
do { |
|
1603 |
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1604 |
strcmp(fd.cFileName, ".") != 0 && |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1605 |
strcmp(fd.cFileName, "..") != 0) { |
0 | 1606 |
fios = FiosAlloc(); |
1607 |
fios->type = FIOS_TYPE_DIR; |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1608 |
fios->mtime = 0; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1609 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1610 |
snprintf(fios->title, lengthof(fios->title), |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1611 |
"%s\\ (Directory)", fd.cFileName); |
0 | 1612 |
} |
1613 |
} while (FindNextFile(h, &fd)); |
|
1614 |
FindClose(h); |
|
1615 |
} |
|
1616 |
||
1617 |
// this is where to start sorting |
|
1618 |
sort_start = _fios_count; |
|
1619 |
||
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1620 |
/* Show savegame files |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1621 |
* .SAV OpenTTD saved game |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1622 |
* .SS1 Transport Tycoon Deluxe preset game |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1623 |
* .SV1 Transport Tycoon Deluxe (Patch) saved game |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1624 |
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game |
0 | 1625 |
*/ |
1626 |
h = MyFindFirstFile(_fios_path, "*.*", &fd); |
|
1627 |
if (h != INVALID_HANDLE_VALUE) { |
|
1628 |
do { |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1629 |
char *t; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1630 |
|
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1631 |
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1632 |
|
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1633 |
t = strrchr(fd.cFileName, '.'); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1634 |
if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1635 |
fios = FiosAlloc(); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1636 |
fios->type = FIOS_TYPE_FILE; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1637 |
fios->mtime = *(uint64*)&fd.ftLastWriteTime; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1638 |
fios->title[0] = '\0'; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1639 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1640 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1641 |
if (t != NULL && ( |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1642 |
strcasecmp(t, ".ss1") == 0 || |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1643 |
strcasecmp(t, ".sv1") == 0 || |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1644 |
strcasecmp(t, ".sv2") == 0 |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1645 |
)) { // TTDLX(Patch) |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1646 |
char buf[MAX_PATH]; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1647 |
|
0 | 1648 |
fios = FiosAlloc(); |
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1649 |
fios->type = FIOS_TYPE_OLDFILE; |
0 | 1650 |
fios->mtime = *(uint64*)&fd.ftLastWriteTime; |
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1651 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
0 | 1652 |
sprintf(buf, "%s\\%s", _fios_path, fd.cFileName); |
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1653 |
GetOldSaveGameName(fios->title, buf); |
0 | 1654 |
} |
1655 |
} |
|
1656 |
} while (FindNextFile(h, &fd)); |
|
1657 |
FindClose(h); |
|
1658 |
} |
|
1659 |
||
1660 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
|
1661 |
||
1662 |
// Drives |
|
1663 |
{ |
|
1664 |
char drives[256]; |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1665 |
const char *s; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1666 |
|
0 | 1667 |
GetLogicalDriveStrings(sizeof(drives), drives); |
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1668 |
for (s = drives; *s != '\0';) { |
0 | 1669 |
fios = FiosAlloc(); |
1670 |
fios->type = FIOS_TYPE_DRIVE; |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1671 |
sprintf(fios->title, "%c:", s[0]); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1672 |
while (*s++ != '\0') {} |
0 | 1673 |
} |
1674 |
} |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1675 |
|
0 | 1676 |
*num = _fios_count; |
1677 |
return _fios_items; |
|
1678 |
} |
|
1679 |
||
1680 |
// Get a list of scenarios |
|
1681 |
FiosItem *FiosGetScenarioList(int *num, int mode) |
|
1682 |
{ |
|
1683 |
FiosItem *fios; |
|
1684 |
WIN32_FIND_DATA fd; |
|
1685 |
HANDLE h; |
|
1686 |
int sort_start; |
|
1687 |
||
1688 |
if (mode == SLD_NEW_GAME || _fios_scn_path == NULL) { |
|
1689 |
if (_fios_scn_path == NULL) |
|
1690 |
_fios_scn_path = malloc(MAX_PATH); |
|
1691 |
strcpy(_fios_scn_path, _path.scenario_dir); |
|
1692 |
} |
|
1693 |
||
1694 |
_fios_path = _fios_scn_path; |
|
1695 |
||
1696 |
// Parent directory, only if not of the type C:\. |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1697 |
if (_fios_path[3] != '\0' && mode != SLD_NEW_GAME) { |
0 | 1698 |
fios = FiosAlloc(); |
1699 |
fios->type = FIOS_TYPE_PARENT; |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1700 |
fios->mtime = 0; |
0 | 1701 |
strcpy(fios->title, ".. (Parent directory)"); |
1702 |
} |
|
1703 |
||
1704 |
// Show subdirectories first |
|
1705 |
h = MyFindFirstFile(_fios_scn_path, "*.*", &fd); |
|
1706 |
if (h != INVALID_HANDLE_VALUE && mode != SLD_NEW_GAME) { |
|
1707 |
do { |
|
1708 |
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1709 |
strcmp(fd.cFileName, ".") != 0 && |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1710 |
strcmp(fd.cFileName, "..") != 0) { |
0 | 1711 |
fios = FiosAlloc(); |
1712 |
fios->type = FIOS_TYPE_DIR; |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1713 |
fios->mtime = 0; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1714 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1715 |
snprintf(fios->title, lengthof(fios->title), |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1716 |
"%s\\ (Directory)", fd.cFileName); |
0 | 1717 |
} |
1718 |
} while (FindNextFile(h, &fd)); |
|
1719 |
FindClose(h); |
|
1720 |
} |
|
1721 |
||
1722 |
// this is where to start sorting |
|
1723 |
sort_start = _fios_count; |
|
1724 |
||
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1725 |
/* Show scenario files |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1726 |
* .SCN OpenTTD style scenario file |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1727 |
* .SV0 Transport Tycoon Deluxe (Patch) scenario |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1728 |
* .SS0 Transport Tycoon Deluxe preset scenario |
0 | 1729 |
*/ |
1730 |
h = MyFindFirstFile(_fios_scn_path, "*.*", &fd); |
|
1731 |
if (h != INVALID_HANDLE_VALUE) { |
|
1732 |
do { |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1733 |
char *t; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1734 |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1735 |
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) continue; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1736 |
|
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1737 |
t = strrchr(fd.cFileName, '.'); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1738 |
if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1739 |
fios = FiosAlloc(); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1740 |
fios->type = FIOS_TYPE_SCENARIO; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1741 |
fios->mtime = *(uint64*)&fd.ftLastWriteTime; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1742 |
fios->title[0] = '\0'; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1743 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1744 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1745 |
mode == SLD_NEW_GAME) { |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1746 |
if (t != NULL && ( |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1747 |
strcasecmp(t, ".sv0") == 0 || |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1748 |
strcasecmp(t, ".ss0") == 0 |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1749 |
)) { // TTDLX(Patch) |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1750 |
char buf[MAX_PATH]; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1751 |
|
0 | 1752 |
fios = FiosAlloc(); |
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1753 |
fios->type = FIOS_TYPE_OLD_SCENARIO; |
0 | 1754 |
fios->mtime = *(uint64*)&fd.ftLastWriteTime; |
1755 |
sprintf(buf, "%s\\%s", _fios_path, fd.cFileName); |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1756 |
GetOldScenarioGameName(fios->title, buf); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1757 |
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name)); |
0 | 1758 |
} |
1759 |
} |
|
1760 |
} while (FindNextFile(h, &fd)); |
|
1761 |
FindClose(h); |
|
1762 |
} |
|
1763 |
||
1764 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
|
1765 |
||
1766 |
// Drives |
|
1767 |
if (mode != SLD_NEW_GAME) { |
|
1768 |
char drives[256]; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1769 |
const char *s; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1770 |
|
0 | 1771 |
GetLogicalDriveStrings(sizeof(drives), drives); |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1772 |
for (s = drives; *s != '\0';) { |
0 | 1773 |
fios = FiosAlloc(); |
1774 |
fios->type = FIOS_TYPE_DRIVE; |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1775 |
sprintf(fios->title, "%c:", s[0]); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1776 |
while (*s++ != '\0') {} |
0 | 1777 |
} |
1778 |
} |
|
1779 |
||
1780 |
*num = _fios_count; |
|
1781 |
return _fios_items; |
|
1782 |
} |
|
1783 |
||
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1784 |
|
0 | 1785 |
// Free the list of savegames |
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
1786 |
void FiosFreeSavegameList(void) |
0 | 1787 |
{ |
1788 |
free(_fios_items); |
|
1789 |
_fios_items = NULL; |
|
1790 |
_fios_alloc = _fios_count = 0; |
|
1791 |
} |
|
1792 |
||
1793 |
// Browse to |
|
1794 |
char *FiosBrowseTo(const FiosItem *item) |
|
1795 |
{ |
|
1796 |
char *path = _fios_path; |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1797 |
char *s; |
0 | 1798 |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1799 |
switch (item->type) { |
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1800 |
case FIOS_TYPE_DRIVE: |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1801 |
sprintf(path, "%c:\\", item->title[0]); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1802 |
break; |
0 | 1803 |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1804 |
case FIOS_TYPE_PARENT: |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1805 |
s = strrchr(path, '\\'); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1806 |
if (s != NULL) *s = '\0'; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1807 |
break; |
0 | 1808 |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1809 |
case FIOS_TYPE_DIR: |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1810 |
s = strchr(item->name, '\\'); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1811 |
if (s != NULL) *s = '\0'; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1812 |
strcat(path, "\\"); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1813 |
strcat(path, item->name); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1814 |
break; |
0 | 1815 |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1816 |
case FIOS_TYPE_FILE: |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1817 |
case FIOS_TYPE_OLDFILE: |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1818 |
case FIOS_TYPE_SCENARIO: |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1819 |
case FIOS_TYPE_OLD_SCENARIO: { |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1820 |
static char str_buffr[512]; |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1821 |
|
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1822 |
sprintf(str_buffr, "%s\\%s", path, item->name); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1823 |
return str_buffr; |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
1824 |
} |
0 | 1825 |
} |
1826 |
||
1827 |
return NULL; |
|
1828 |
} |
|
1829 |
||
1830 |
// Get descriptive texts. |
|
1831 |
// Returns a path as well as a |
|
1832 |
// string describing the path. |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
206
diff
changeset
|
1833 |
StringID FiosGetDescText(const char **path) |
0 | 1834 |
{ |
1835 |
char root[4]; |
|
1836 |
DWORD spc, bps, nfc, tnc; |
|
1837 |
*path = _fios_path; |
|
1838 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1839 |
sprintf(root, "%c:\\", _fios_path[0]); |
0 | 1840 |
if (GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) { |
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1841 |
uint32 tot = ((spc * bps) * (uint64)nfc) >> 20; |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1842 |
SetDParam(0, tot); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1843 |
return STR_4005_BYTES_FREE; |
0 | 1844 |
} else { |
1845 |
return STR_4006_UNABLE_TO_READ_DRIVE; |
|
1846 |
} |
|
1847 |
} |
|
1848 |
||
1849 |
void FiosMakeSavegameName(char *buf, const char *name) |
|
1850 |
{ |
|
1508
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1851 |
const char* extension; |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1852 |
const char* period; |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1853 |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1854 |
if (_game_mode == GM_EDITOR) |
1508
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1855 |
extension = ".scn"; |
0 | 1856 |
else |
1508
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1857 |
extension = ".sav"; |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1858 |
|
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1859 |
// Don't append the extension, if it is already there |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1860 |
period = strrchr(name, '.'); |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1861 |
if (period != NULL && strcasecmp(period, extension) == 0) extension = ""; |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1862 |
|
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1496
diff
changeset
|
1863 |
sprintf(buf, "%s\\%s%s", _fios_path, name, extension); |
0 | 1864 |
} |
1865 |
||
1866 |
void FiosDelete(const char *name) |
|
1867 |
{ |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
1868 |
char path[512]; |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
1869 |
|
1495
a9e4e2b78877
(svn r1999) r1990 broke savegame deletion, fix that [1161729]
tron
parents:
1486
diff
changeset
|
1870 |
snprintf(path, lengthof(path), "%s\\%s", _fios_path, name); |
0 | 1871 |
DeleteFile(path); |
1872 |
} |
|
1873 |
||
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1874 |
#define Windows_2000 5 |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1875 |
#define Windows_NT3_51 4 |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1876 |
|
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1877 |
/* flags show the minimum required OS to use a given feature. Currently |
287
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1878 |
only dwMajorVersion and dwMinorVersion (WindowsME) are used |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1879 |
MajorVersion MinorVersion |
287
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1880 |
Windows Server 2003 5 2 dmusic |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1881 |
Windows XP 5 1 dmusic |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1882 |
Windows 2000 5 0 dmusic |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1883 |
Windows NT 4.0 4 0 win32 |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1884 |
Windows Me 4 90 dmusic |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1885 |
Windows 98 4 10 win32 |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1886 |
Windows 95 4 0 win32 |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1887 |
Windows NT 3.51 3 51 ????? |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1888 |
*/ |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1889 |
|
0 | 1890 |
const DriverDesc _video_driver_descs[] = { |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1891 |
{"null", "Null Video Driver", &_null_video_driver, 0}, |
0 | 1892 |
#if defined(WITH_SDL) |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1893 |
{"sdl", "SDL Video Driver", &_sdl_video_driver, 1}, |
0 | 1894 |
#endif |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1895 |
{"win32", "Win32 GDI Video Driver", &_win32_video_driver, Windows_NT3_51}, |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1896 |
{ "dedicated", "Dedicated Video Driver", &_dedicated_video_driver, 0}, |
1466 | 1897 |
{ NULL, NULL, NULL, 0 } |
0 | 1898 |
}; |
1899 |
||
1900 |
const DriverDesc _sound_driver_descs[] = { |
|
1901 |
{"null", "Null Sound Driver", &_null_sound_driver, 0}, |
|
1902 |
#if defined(WITH_SDL) |
|
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1903 |
{"sdl", "SDL Sound Driver", &_sdl_sound_driver, 1}, |
0 | 1904 |
#endif |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1905 |
{"win32", "Win32 WaveOut Driver", &_win32_sound_driver, Windows_NT3_51}, |
1466 | 1906 |
{ NULL, NULL, NULL, 0 } |
0 | 1907 |
}; |
1908 |
||
1909 |
const DriverDesc _music_driver_descs[] = { |
|
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1910 |
{"null", "Null Music Driver", &_null_music_driver, 0}, |
0 | 1911 |
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1912 |
{"dmusic", "DirectMusic MIDI Driver", &_dmusic_midi_driver, Windows_2000}, |
0 | 1913 |
#endif |
826 | 1914 |
// Win32 MIDI driver has higher priority than DMusic, so this one is chosen |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1915 |
{"win32", "Win32 MIDI Driver", &_win32_music_driver, Windows_NT3_51}, |
1466 | 1916 |
{ NULL, NULL, NULL, 0 } |
0 | 1917 |
}; |
1918 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
1919 |
byte GetOSVersion(void) |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1920 |
{ |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1921 |
OSVERSIONINFO osvi; |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1922 |
|
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1923 |
ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1924 |
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1925 |
|
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1926 |
if (GetVersionEx(&osvi)) { |
287
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1927 |
DEBUG(misc, 2) ("Windows Version is %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1928 |
// WinME needs directmusic too (dmusic, Windows_2000 mode), all others default to OK |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1929 |
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) { return Windows_2000;} // WinME |
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1930 |
|
121d79bcd34c
(svn r293) -Feature: Windows now shows (available) revision, release information in title bar
darkvater
parents:
223
diff
changeset
|
1931 |
return osvi.dwMajorVersion; |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1932 |
} |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1933 |
|
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1934 |
// GetVersionEx failed, but we can safely assume at least Win95/WinNT3.51 is used |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1935 |
DEBUG(misc, 0) ("Windows version retrieval failed, defaulting to level 4"); |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1936 |
return Windows_NT3_51; |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1937 |
} |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
1938 |
|
0 | 1939 |
bool FileExists(const char *filename) |
1940 |
{ |
|
1941 |
HANDLE hand = CreateFile(filename, 0, 0, NULL, OPEN_EXISTING, 0, NULL); |
|
1942 |
if (hand == INVALID_HANDLE_VALUE) return false; |
|
1943 |
CloseHandle(hand); |
|
1944 |
return true; |
|
1945 |
} |
|
1946 |
||
1947 |
static int CDECL LanguageCompareFunc(const void *a, const void *b) |
|
1948 |
{ |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
206
diff
changeset
|
1949 |
return strcmp(*(const char* const *)a, *(const char* const *)b); |
0 | 1950 |
} |
1951 |
||
1952 |
int GetLanguageList(char **languages, int max) |
|
1953 |
{ |
|
1954 |
HANDLE hand; |
|
1955 |
int num = 0; |
|
1956 |
char filedir[MAX_PATH]; |
|
1957 |
WIN32_FIND_DATA fd; |
|
1958 |
sprintf(filedir, "%s*.lng", _path.lang_dir); |
|
1959 |
||
1960 |
hand = FindFirstFile(filedir, &fd); |
|
1961 |
if (hand != INVALID_HANDLE_VALUE) { |
|
1962 |
do { |
|
1963 |
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
|
1964 |
languages[num++] = strdup(fd.cFileName); |
|
1965 |
if (num == max) break; |
|
1966 |
} |
|
1967 |
} while (FindNextFile(hand, &fd)); |
|
1968 |
FindClose(hand); |
|
1969 |
} |
|
1970 |
||
1971 |
qsort(languages, num, sizeof(char*), LanguageCompareFunc); |
|
1972 |
return num; |
|
1973 |
} |
|
1974 |
||
1975 |
static int ParseCommandLine(char *line, char **argv, int max_argc) |
|
1976 |
{ |
|
1977 |
int n = 0; |
|
1978 |
||
1979 |
do { |
|
1980 |
// skip whitespace |
|
1981 |
while (*line == ' ' || *line == '\t') |
|
1982 |
line++; |
|
1983 |
||
1984 |
// end? |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1985 |
if (*line == '\0') |
0 | 1986 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1987 |
|
0 | 1988 |
// special handling when quoted |
1989 |
if (*line == '"') { |
|
1990 |
argv[n++] = ++line; |
|
1991 |
while (*line != '"') { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1992 |
if (*line == '\0') return n; |
0 | 1993 |
line++; |
1994 |
} |
|
1995 |
} else { |
|
1996 |
argv[n++] = line; |
|
1997 |
while (*line != ' ' && *line != '\t') { |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
1998 |
if (*line == '\0') return n; |
0 | 1999 |
line++; |
2000 |
} |
|
2001 |
} |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2002 |
*line++ = '\0'; |
0 | 2003 |
} while (n != max_argc); |
2004 |
||
2005 |
return n; |
|
2006 |
} |
|
2007 |
||
2008 |
||
2009 |
#if defined(_MSC_VER) |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2010 |
static uint64 _declspec(naked) rdtsc(void) |
0 | 2011 |
{ |
2012 |
_asm { |
|
2013 |
rdtsc |
|
2014 |
ret |
|
2015 |
} |
|
2016 |
} |
|
2017 |
#endif |
|
2018 |
||
1102
998922a84f9b
(svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents:
1040
diff
changeset
|
2019 |
void CreateConsole(void) |
0 | 2020 |
{ |
2021 |
HANDLE hand; |
|
2022 |
CONSOLE_SCREEN_BUFFER_INFO coninfo; |
|
2023 |
||
2024 |
if (_has_console) return; |
|
2025 |
||
2026 |
_has_console = true; |
|
2027 |
||
2028 |
AllocConsole(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2029 |
|
0 | 2030 |
hand = GetStdHandle(STD_OUTPUT_HANDLE); |
2031 |
GetConsoleScreenBufferInfo(hand, &coninfo); |
|
2032 |
coninfo.dwSize.Y = 500; |
|
2033 |
SetConsoleScreenBufferSize(hand, coninfo.dwSize); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2034 |
|
0 | 2035 |
// redirect unbuffered STDIN, STDOUT, STDERR to the console |
2036 |
#if !defined(__CYGWIN__) |
|
2037 |
*stdout = *_fdopen( _open_osfhandle((long)hand, _O_TEXT), "w" ); |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2038 |
*stdin = *_fdopen(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" ); |
0 | 2039 |
*stderr = *_fdopen(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" ); |
2040 |
#else |
|
2041 |
// open_osfhandle is not in cygwin |
|
2042 |
*stdout = *fdopen(1, "w" ); |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2043 |
*stdin = *fdopen(0, "r" ); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2044 |
*stderr = *fdopen(2, "w" ); |
0 | 2045 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2046 |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2047 |
setvbuf(stdin, NULL, _IONBF, 0); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2048 |
setvbuf(stdout, NULL, _IONBF, 0); |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2049 |
setvbuf(stderr, NULL, _IONBF, 0); |
0 | 2050 |
} |
2051 |
||
2052 |
void ShowInfo(const char *str) |
|
2053 |
{ |
|
2054 |
if (_has_console) |
|
2055 |
puts(str); |
|
2056 |
else { |
|
2057 |
bool old; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2058 |
|
0 | 2059 |
ReleaseCapture(); |
2060 |
_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
|
2061 |
|
0 | 2062 |
old = MyShowCursor(true); |
2063 |
if (MessageBoxA(GetActiveWindow(), str, "OpenTTD", MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) { |
|
2064 |
CreateConsole(); |
|
2065 |
} |
|
2066 |
MyShowCursor(old); |
|
2067 |
} |
|
2068 |
} |
|
2069 |
||
2070 |
||
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2071 |
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2072 |
LPTSTR lpCmdLine, int nCmdShow) |
0 | 2073 |
{ |
2074 |
int argc; |
|
2075 |
char *argv[64]; // max 64 command line arguments |
|
2076 |
_inst = hInstance; |
|
2077 |
||
2078 |
#if defined(_DEBUG) |
|
2079 |
CreateConsole(); |
|
2080 |
#endif |
|
2081 |
||
2082 |
// make sure we have an autosave folder - Done in DeterminePaths |
|
2083 |
// CreateDirectory("autosave", NULL); |
|
2084 |
||
2085 |
// setup random seed to something quite random |
|
2086 |
#if defined(_MSC_VER) |
|
2087 |
{ |
|
2088 |
uint64 seed = rdtsc(); |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2089 |
_random_seeds[0][0] = seed & 0xffffffff; |
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2090 |
_random_seeds[0][1] = seed >> 32; |
0 | 2091 |
} |
2092 |
#else |
|
206 | 2093 |
_random_seeds[0][0] = GetTickCount(); |
2094 |
_random_seeds[0][1] = _random_seeds[0][0] * 0x1234567; |
|
0 | 2095 |
#endif |
2096 |
||
2097 |
argc = ParseCommandLine(GetCommandLine(), argv, lengthof(argv)); |
|
2098 |
||
2099 |
#if defined(WIN32_EXCEPTION_TRACKER) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2100 |
{ |
0 | 2101 |
Win32InitializeExceptions(); |
2102 |
} |
|
2103 |
#endif |
|
2104 |
||
2105 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
2106 |
_try { |
|
2107 |
uint32 _stdcall ExceptionHandler(void *ep); |
|
2108 |
#endif |
|
2109 |
ttd_main(argc, argv); |
|
2110 |
||
2111 |
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG) |
|
2112 |
} _except (ExceptionHandler(_exception_info())) {} |
|
2113 |
#endif |
|
2114 |
||
2115 |
return 0; |
|
2116 |
} |
|
2117 |
||
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2118 |
void DeterminePaths(void) |
0 | 2119 |
{ |
2120 |
char *s; |
|
2121 |
char *cfg; |
|
2122 |
||
2123 |
_path.personal_dir = _path.game_data_dir = cfg = malloc(MAX_PATH); |
|
2124 |
GetCurrentDirectory(MAX_PATH - 1, cfg); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2125 |
|
0 | 2126 |
|
2127 |
s = strchr(cfg, 0); |
|
1468
87ffabf776f2
(svn r1972) Several cleanups and fix some latent bugs
tron
parents:
1466
diff
changeset
|
2128 |
if (s[-1] != '\\') strcpy(s, "\\"); |
0 | 2129 |
|
2130 |
_path.save_dir = str_fmt("%ssave", cfg); |
|
2131 |
_path.autosave_dir = str_fmt("%s\\autosave", _path.save_dir); |
|
2132 |
_path.scenario_dir = str_fmt("%sscenario", cfg); |
|
2133 |
_path.gm_dir = str_fmt("%sgm\\", cfg); |
|
2134 |
_path.data_dir = str_fmt("%sdata\\", cfg); |
|
2135 |
_path.lang_dir = str_fmt("%slang\\", cfg); |
|
2136 |
||
1482
80e315adc3bd
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1480
diff
changeset
|
2137 |
if (_config_file == NULL) |
80e315adc3bd
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1480
diff
changeset
|
2138 |
_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir); |
80e315adc3bd
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1480
diff
changeset
|
2139 |
|
983
4765bf636f6b
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
915
diff
changeset
|
2140 |
_highscore_file = str_fmt("%shs.dat", _path.personal_dir); |
704
e843dd369938
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
698
diff
changeset
|
2141 |
_log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
0 | 2142 |
|
2143 |
// make (auto)save and scenario folder |
|
2144 |
CreateDirectory(_path.save_dir, NULL); |
|
2145 |
CreateDirectory(_path.autosave_dir, NULL); |
|
2146 |
CreateDirectory(_path.scenario_dir, NULL); |
|
2147 |
} |
|
2148 |
||
1022
d5ec3467d2a4
(svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents:
983
diff
changeset
|
2149 |
int CDECL snprintf(char *str, size_t size, const char *format, ...) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2150 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2151 |
va_list ap; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2152 |
int ret; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2153 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2154 |
va_start(ap, format); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2155 |
ret = vsnprintf(str, size, format, ap); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2156 |
va_end(ap); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2157 |
return ret; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2158 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2159 |
|
1022
d5ec3467d2a4
(svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents:
983
diff
changeset
|
2160 |
int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2161 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2162 |
int ret; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2163 |
ret = _vsnprintf(str, size, format, ap); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2164 |
if (ret < 0) str[size - 1] = '\0'; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2165 |
return ret; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
2166 |
} |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2167 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2168 |
/** |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2169 |
* Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2170 |
* and append this up to the maximum length (either absolute or screenlength). If maxlength |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2171 |
* is zero, we don't care about the screenlength but only about the physical length of the string |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2172 |
* @param tb @Textbuf type to be changed |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2173 |
* @return Return true on successfull change of Textbuf, or false otherwise |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2174 |
*/ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2175 |
bool InsertTextBufferClipboard(Textbuf *tb) |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2176 |
{ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2177 |
if (IsClipboardFormatAvailable(CF_TEXT)) { |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2178 |
HGLOBAL cbuf; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2179 |
const byte *data, *dataptr; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2180 |
uint16 width = 0; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2181 |
uint16 length = 0; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2182 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2183 |
OpenClipboard(NULL); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2184 |
cbuf = GetClipboardData(CF_TEXT); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2185 |
data = GlobalLock(cbuf); // clipboard data |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2186 |
dataptr = data; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2187 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2188 |
for (; IsValidAsciiChar(*dataptr) && (tb->length + length) < tb->maxlength - 1 && |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2189 |
(tb->maxwidth == 0 || width + tb->width + GetCharacterWidth((byte)*dataptr) <= tb->maxwidth); dataptr++) { |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2190 |
width += GetCharacterWidth((byte)*dataptr); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2191 |
length++; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2192 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2193 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2194 |
if (length == 0) |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2195 |
return false; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2196 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2197 |
memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2198 |
memcpy(tb->buf + tb->caretpos, data, length); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2199 |
tb->width += width; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2200 |
tb->caretxoffs += width; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2201 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2202 |
tb->length += length; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2203 |
tb->caretpos += length; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2204 |
tb->buf[tb->length + 1] = '\0'; // terminating zero |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2205 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2206 |
GlobalUnlock(cbuf); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2207 |
CloseClipboard(); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2208 |
return true; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2209 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2210 |
return false; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
2211 |
} |