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