win32.c
author Darkvater
Tue, 01 Aug 2006 19:24:29 +0000
changeset 4210 2c1a58c727ed
parent 4209 829a127ef3c6
child 4218 384c7451e3bb
permissions -rw-r--r--
(svn r5698) - Fix [r5697]: don't remove ctype include for win32.c; needed for toupper...ugh
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2184
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2184
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1885
diff changeset
     4
#include "openttd.h"
1302
1e4e3e7e23aa (svn r1806) Add missing includes (see r1803)
tron
parents: 1301
diff changeset
     5
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2162
diff changeset
     6
#include "functions.h"
2211
07a209c31e4f (svn r2729) Fix #include
tron
parents: 2210
diff changeset
     7
#include "hal.h"
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents: 2163
diff changeset
     8
#include "macros.h"
2162
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 2160
diff changeset
     9
#include "saveload.h"
1317
f382f1b439c7 (svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents: 1302
diff changeset
    10
#include "string.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 424
diff changeset
    11
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include <windows.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include <winnt.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include <wininet.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include <io.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include <fcntl.h>
2160
10a1718175af (svn r2670) Fix r2669
tron
parents: 2140
diff changeset
    19
#include "variables.h"
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    20
#include "win32.h"
4210
2c1a58c727ed (svn r5698) - Fix [r5697]: don't remove ctype include for win32.c; needed for toupper...ugh
Darkvater
parents: 4209
diff changeset
    21
#include <ctype.h>
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents: 2163
diff changeset
    22
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
static bool _has_console;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
796
42a3669a939f (svn r1266) -Fix: fix some cygwin/mingw warnings
darkvater
parents: 792
diff changeset
    25
#if defined(__MINGW32__) || defined(__CYGWIN__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
	#define __TIMESTAMP__   __DATE__ __TIME__
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
3394
78963d9c1022 (svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents: 3341
diff changeset
    29
#if defined(__MINGW32__)
78963d9c1022 (svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents: 3341
diff changeset
    30
	#include <stdint.h>
78963d9c1022 (svn r4203) - Fix compilation on mingw32 (stdint.h not included)
orudge
parents: 3341
diff changeset
    31
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
2208
ed38ba85b7e1 (svn r2726) Fix last commit
tron
parents: 2207
diff changeset
    33
static bool cursor_visible = true;
ed38ba85b7e1 (svn r2726) Fix last commit
tron
parents: 2207
diff changeset
    34
2207
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2195
diff changeset
    35
bool MyShowCursor(bool show)
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2195
diff changeset
    36
{
2209
53b1df15a9fe (svn r2727) Fix last commit, don't ask
tron
parents: 2208
diff changeset
    37
	if (cursor_visible == show) return show;
2207
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2195
diff changeset
    38
2209
53b1df15a9fe (svn r2727) Fix last commit, don't ask
tron
parents: 2208
diff changeset
    39
	cursor_visible = show;
2207
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2195
diff changeset
    40
	ShowCursor(show);
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2195
diff changeset
    41
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2195
diff changeset
    42
	return !show;
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2195
diff changeset
    43
}
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2195
diff changeset
    44
40c928fbde8a (svn r2725) Move MyShowCursor() back into win32.c, it fits better there
tron
parents: 2195
diff changeset
    45
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
// Helper function needed by dynamically loading SDL
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    47
bool LoadLibraryList(Function proc[], const char* dll)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
{
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
    49
	while (*dll != '\0') {
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    50
		HMODULE lib = LoadLibrary(dll);
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    51
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    52
		if (lib == NULL) return false;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
    53
		for (;;) {
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
    54
			FARPROC p;
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    55
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    56
			while (*dll++ != '\0');
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    57
			if (*dll == '\0') break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
			p = GetProcAddress(lib, dll);
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    59
			if (p == NULL) return false;
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
    60
			*proc++ = (Function)p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
		dll++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
796
42a3669a939f (svn r1266) -Fix: fix some cygwin/mingw warnings
darkvater
parents: 792
diff changeset
    67
#ifdef _MSC_VER
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
static const char *_exception_string;
2428
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
    69
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
void ShowOSErrorBox(const char *buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	MyShowCursor(true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	MessageBoxA(GetActiveWindow(), buf, "Error!", MB_ICONSTOP);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
// if exception tracker is enabled, we crash here to let the exception handler handle it.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
#if defined(WIN32_EXCEPTION_TRACKER) && !defined(_DEBUG)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
	if (*buf == '!') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
		_exception_string = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
		*(byte*)0 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
2428
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
    85
#ifdef _MSC_VER
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
    86
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
    87
static void *_safe_esp;
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
    88
static char *_crash_msg;
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
    89
static bool _expanded;
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
    90
static bool _did_emerg_save;
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
    91
static int _ident;
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
    92
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
typedef struct DebugFileInfo {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
	uint32 size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	uint32 crc32;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
	SYSTEMTIME file_time;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
} DebugFileInfo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
static uint32 *_crc_table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
static void MakeCRCTable(uint32 *table) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	uint32 crc, poly = 0xEDB88320L;
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1995
diff changeset
   103
	int i;
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1995
diff changeset
   104
	int j;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   105
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	_crc_table = table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   108
	for (i = 0; i != 256; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
		crc = i;
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   110
		for (j = 8; j != 0; j--) {
4078
4530dde1a8a9 (svn r5393) CodeChange : Little typo correction. Nothing spectacular. Only broke in MSVC
belugas
parents: 4077
diff changeset
   111
			crc = (crc & 1 ? (crc >> 1) ^ poly : crc >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
		table[i] = crc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
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
   118
	for (; size > 0; size--) {
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   119
		crc = ((crc >> 8) & 0x00FFFFFF) ^ _crc_table[(crc ^ *data++) & 0xFF];
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   120
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	return crc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
static void GetFileInfo(DebugFileInfo *dfi, const char *filename)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	memset(dfi, 0, sizeof(dfi));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
		HANDLE file;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
		byte buffer[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
		DWORD numread;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
		uint32 filesize = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
		FILETIME write_time;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
		uint32 crc = (uint32)-1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   136
		file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   137
			OPEN_EXISTING, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
		if (file != INVALID_HANDLE_VALUE) {
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2940
diff changeset
   139
			for (;;) {
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   140
				if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 ||
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   141
						numread == 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
				filesize += numread;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
				crc = CalcCRC(buffer, numread, crc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
			dfi->size = filesize;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
			dfi->crc32 = crc ^ (uint32)-1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   148
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
			if (GetFileTime(file, NULL, NULL, &write_time)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
				FileTimeToSystemTime(&write_time, &dfi->file_time);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
			CloseHandle(file);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
static char *PrintModuleInfo(char *output, HMODULE mod)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
{
318
65ebd0cab39b (svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents: 306
diff changeset
   160
	char buffer[MAX_PATH];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	DebugFileInfo dfi;
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   162
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	GetModuleFileName(mod, buffer, MAX_PATH);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	GetFileInfo(&dfi, buffer);
2458
c95808cd2ac9 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2428
diff changeset
   165
	output += sprintf(output, " %-20s handle: %p size: %d crc: %.8X date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n",
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
		buffer,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
		mod,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
		dfi.size,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
		dfi.crc32,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
		dfi.file_time.wYear,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
		dfi.file_time.wMonth,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
		dfi.file_time.wDay,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
		dfi.file_time.wHour,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
		dfi.file_time.wMinute,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
		dfi.file_time.wSecond
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	return output;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
static char *PrintModuleList(char *output)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	BOOL (WINAPI *EnumProcessModules)(HANDLE,HMODULE*,DWORD,LPDWORD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	HANDLE proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	HMODULE modules[100];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
	DWORD needed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	BOOL res;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	int count,i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
   189
	if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0")) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
		proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
		if (proc) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
			res = EnumProcessModules(proc, modules, sizeof(modules), &needed);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
			CloseHandle(proc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
			if (res) {
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   195
				count =
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   196
					min(needed / sizeof(HMODULE), lengthof(modules));
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   197
				for (i = 0; i != count; i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
					output = PrintModuleInfo(output, modules[i]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
				return output;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	output = PrintModuleInfo(output, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	return output;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   207
static const char _crash_desc[] =
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	"A serious fault condition occured in the game. The game will shut down.\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	"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
   210
	"This will greatly help debugging. "
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   211
	"The information contained in the report is displayed below.\n"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	"Press \"Emergency save\" to attempt saving the game.";
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   214
static const char _save_succeeded[] =
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   215
	"Emergency save succeeded.\n"
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   216
	"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
   217
	"corrupted. The saved game is not guaranteed to work.";
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
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
   219
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
   220
{
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
   221
	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
   222
	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
   223
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
typedef struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	HINTERNET (WINAPI *InternetOpenA)(LPCSTR,DWORD, LPCSTR, LPCSTR, DWORD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	HINTERNET (WINAPI *InternetConnectA)(HINTERNET, LPCSTR, INTERNET_PORT, LPCSTR, LPCSTR, DWORD, DWORD, DWORD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	HINTERNET (WINAPI *HttpOpenRequestA)(HINTERNET, LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPCSTR *, DWORD, DWORD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
	BOOL (WINAPI *HttpSendRequestA)(HINTERNET, LPCSTR, DWORD, LPVOID, DWORD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	BOOL (WINAPI *InternetCloseHandle)(HINTERNET);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	BOOL (WINAPI *HttpQueryInfo)(HINTERNET, DWORD, LPVOID, LPDWORD, LPDWORD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
} WinInetProcs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
#define M(x) x "\0"
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   235
static const char wininet_files[] =
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
	M("wininet.dll")
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
	M("InternetOpenA")
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
	M("InternetConnectA")
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
	M("HttpOpenRequestA")
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
	M("HttpSendRequestA")
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	M("InternetCloseHandle")
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	M("HttpQueryInfoA")
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	M("");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
#undef M
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
static WinInetProcs _wininet;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
   249
static const char *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const char *arg)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	HINTERNET inet, conn, http;
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
   252
	const char *err = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
	DWORD code, len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	static char buf[100];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	char buff[100];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   256
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
   257
	if (_wininet.InternetOpen == NULL && !LoadLibraryList((Function*)&_wininet, wininet_files)) return "can't load wininet.dll";
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
1957
2a4aa85373c3 (svn r2463) - Fix: partly revert the strncat madness and update nightly script (invisible) to correctly insert date.
Darkvater
parents: 1953
diff changeset
   259
	inet = _wininet.InternetOpen("OTTD", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
	if (inet == NULL) { err = "internetopen failed"; goto error1; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	conn = _wininet.InternetConnect(inet, "openttd.com", INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
	if (conn == NULL) { err = "internetconnect failed"; goto error2; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	sprintf(buff, "/crash.php?file=%s&ident=%d", arg, _ident);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	http = _wininet.HttpOpenRequest(conn, "POST", buff, NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE , 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	if (http == NULL) { err = "httpopenrequest failed"; goto error3; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
	if (!_wininet.HttpSendRequest(http, "Content-type: application/binary", -1, msg, msglen)) { err = "httpsendrequest failed"; goto error4; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
	len = sizeof(code);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	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
   274
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	if (code != 200) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
		int l = sprintf(buf, "Server said: %d ", code);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
		len = sizeof(buf) - l;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
		_wininet.HttpQueryInfo(http, HTTP_QUERY_STATUS_TEXT, buf + l, &len, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
		err = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
error4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	_wininet.InternetCloseHandle(http);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
error3:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	_wininet.InternetCloseHandle(conn);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
error2:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	_wininet.InternetCloseHandle(inet);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
error1:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	return err;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
static void SubmitFile(HWND wnd, const char *file)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
	HANDLE h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	unsigned long size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	unsigned long read;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	void *mem;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	if (h == NULL) return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
	size = GetFileSize(h, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	if (size > 500000) goto error1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   304
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	mem = malloc(size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	if (mem == NULL) goto error1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
	if (!ReadFile(h, mem, size, &read, NULL) || read != size) goto error2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   310
	SubmitCrashReport(wnd, mem, size, file);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
error2:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	free(mem);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
error1:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	CloseHandle(h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
static const char * const _expand_texts[] = {"S&how report >>", "&Hide report <<" };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
static void SetWndSize(HWND wnd, int mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
	RECT r,r2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	int offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
	GetWindowRect(wnd, &r);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   326
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	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
   328
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	if (mode >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
		GetWindowRect(GetDlgItem(wnd, 11), &r2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
		offs = r2.bottom - r2.top + 10;
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   332
		if (!mode) offs = -offs;
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   333
		SetWindowPos(wnd, HWND_TOPMOST, 0, 0,
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   334
			r.right - r.left, r.bottom - r.top + offs, SWP_NOMOVE | SWP_NOZORDER);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	} else {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   336
		SetWindowPos(wnd, HWND_TOPMOST,
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   337
			(GetSystemMetrics(SM_CXSCREEN) - (r.right - r.left)) / 2,
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   338
			(GetSystemMetrics(SM_CYSCREEN) - (r.bottom - r.top)) / 2,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
			0, 0, SWP_NOSIZE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
static bool DoEmergencySave(HWND wnd)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
	bool b = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
	EnableWindow(GetDlgItem(wnd, 13), FALSE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
	_did_emerg_save = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	__try {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
		b = EmergencySave();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	} __except (1) {}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
	return b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
2458
c95808cd2ac9 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2428
diff changeset
   355
static INT_PTR CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2940
diff changeset
   357
	switch (msg) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	case WM_INITDIALOG:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
		SetDlgItemText(wnd, 10, _crash_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
		SetDlgItemText(wnd, 11, _crash_msg);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		SetWndSize(wnd, -1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
		return TRUE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	case WM_COMMAND:
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2940
diff changeset
   365
		switch (wParam) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
		case 12: // Close
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
			ExitProcess(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
		case 13: { // Emergency save
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
   369
			if (DoEmergencySave(wnd)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
				MessageBoxA(wnd, _save_succeeded, "Save successful", MB_ICONINFORMATION);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
   371
			} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
				MessageBoxA(wnd, "Save failed", "Save failed", MB_ICONINFORMATION);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
   373
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
		case 14: { // Submit crash report
2183
6fba9150225b (svn r2697) Make compiling with SDL on Windows work again (missing #includes) and fix some warnings
tron
parents: 2177
diff changeset
   377
			const char *s;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   378
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
			SetCursor(LoadCursor(NULL, IDC_WAIT));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
			s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), "");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
			if (s) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
				MessageBoxA(wnd, s, "Error", MB_ICONSTOP);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   386
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
			// try to submit emergency savegame
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
			if (_did_emerg_save || DoEmergencySave(wnd)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
				SubmitFile(wnd, "crash.sav");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
			// try to submit the autosaved game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
			if (_opt.autosave) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
				char buf[40];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
				sprintf(buf, "autosave%d.sav", (_autosave_ctr - 1) & 3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
				SubmitFile(wnd, buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
			EnableWindow(GetDlgItem(wnd, 14), FALSE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
			SetCursor(LoadCursor(NULL, IDC_ARROW));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
			MessageBoxA(wnd, "Crash report submitted. Thank you.", "Crash Report", MB_ICONINFORMATION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
		case 15: // Expand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
			_expanded ^= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
			SetWndSize(wnd, _expanded);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
		return TRUE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
	case WM_CLOSE:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
		ExitProcess(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
	return FALSE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
1102
316643e34104 (svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents: 1040
diff changeset
   415
static void Handler2(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	ShowCursor(TRUE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
	ShowWindow(GetActiveWindow(), FALSE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(100), NULL, CrashDialogFunc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
1102
316643e34104 (svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents: 1040
diff changeset
   422
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
   423
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
{
3204
2f2e12688e97 (svn r3872) - [win32] Show the revision in crash.txt and enable the button to show the crash text in the crash-window
Darkvater
parents: 2952
diff changeset
   426
	extern const char _openttd_revision[];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	char *output;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	static bool had_exception;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   430
	if (had_exception) ExitProcess(0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
	had_exception = true;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   432
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	_ident = GetTickCount(); // something pretty unique
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
	MakeCRCTable(alloca(256 * sizeof(uint32)));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
	_crash_msg = output = LocalAlloc(LMEM_FIXED, 8192);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
		SYSTEMTIME time;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
		GetLocalTime(&time);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   441
		output += sprintf(output,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
			"*** OpenTTD Crash Report ***\r\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
			"Date: %d-%.2d-%.2d %.2d:%.2d:%.2d\r\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
			"Build: %s built on " __TIMESTAMP__ "\r\n",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
			time.wYear,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
			time.wMonth,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
			time.wDay,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
			time.wHour,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
			time.wMinute,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
			time.wSecond,
3204
2f2e12688e97 (svn r3872) - [win32] Show the revision in crash.txt and enable the button to show the crash text in the crash-window
Darkvater
parents: 2952
diff changeset
   451
			_openttd_revision
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   455
	if (_exception_string)
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   456
		output += sprintf(output, "Reason: %s\r\n", _exception_string);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   458
#ifdef _M_AMD64
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   459
	output += sprintf(output, "Exception %.8X at %.16IX\r\n"
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   460
		"Registers:\r\n"
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   461
		"RAX: %.16llX RBX: %.16llX RCX: %.16llX RDX: %.16llX\r\n"
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   462
		"RSI: %.16llX RDI: %.16llX RBP: %.16llX RSP: %.16llX\r\n"
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   463
		"R8:  %.16llX R9:  %.16llX R10: %.16llX R11: %.16llX\r\n"
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   464
		"R12: %.16llX R13: %.16llX R14: %.16llX R15: %.16llX\r\n"
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   465
		"RIP: %.16llX EFLAGS: %.8X\r\n"
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   466
		"\r\nBytes at CS:RIP:\r\n",
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   467
		ep->ExceptionRecord->ExceptionCode,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   468
		ep->ExceptionRecord->ExceptionAddress,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   469
		ep->ContextRecord->Rax,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   470
		ep->ContextRecord->Rbx,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   471
		ep->ContextRecord->Rcx,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   472
		ep->ContextRecord->Rdx,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   473
		ep->ContextRecord->Rsi,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   474
		ep->ContextRecord->Rdi,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   475
		ep->ContextRecord->Rbp,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   476
		ep->ContextRecord->Rsp,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   477
		ep->ContextRecord->R8,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   478
		ep->ContextRecord->R9,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   479
		ep->ContextRecord->R10,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   480
		ep->ContextRecord->R11,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   481
		ep->ContextRecord->R12,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   482
		ep->ContextRecord->R13,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   483
		ep->ContextRecord->R14,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   484
		ep->ContextRecord->R15,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   485
		ep->ContextRecord->Rip,
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   486
		ep->ContextRecord->EFlags
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   487
	);
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   488
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
	output += sprintf(output, "Exception %.8X at %.8X\r\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
		"Registers:\r\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
		" EAX: %.8X EBX: %.8X ECX: %.8X EDX: %.8X\r\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		" ESI: %.8X EDI: %.8X EBP: %.8X ESP: %.8X\r\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
		" EIP: %.8X EFLAGS: %.8X\r\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
		"\r\nBytes at CS:EIP:\r\n",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
		ep->ExceptionRecord->ExceptionCode,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
		ep->ExceptionRecord->ExceptionAddress,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
		ep->ContextRecord->Eax,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
		ep->ContextRecord->Ebx,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
		ep->ContextRecord->Ecx,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
		ep->ContextRecord->Edx,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
		ep->ContextRecord->Esi,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
		ep->ContextRecord->Edi,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
		ep->ContextRecord->Ebp,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
		ep->ContextRecord->Esp,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
		ep->ContextRecord->Eip,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
		ep->ContextRecord->EFlags
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	);
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   508
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
	{
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   511
#ifdef _M_AMD64
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   512
		byte *b = (byte*)ep->ContextRecord->Rip;
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   513
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
		byte *b = (byte*)ep->ContextRecord->Eip;
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   515
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
		int i;
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   517
		for (i = 0; i != 24; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
			if (IsBadReadPtr(b, 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
				output += sprintf(output, " ??"); // OCR: WAS: , 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
				output += sprintf(output, " %.2X", *b);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
			b++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
		output += sprintf(output,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
			"\r\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
			"\r\nStack trace: \r\n"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
		int i,j;
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   533
#ifdef _M_AMD64
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   534
		uint32 *b = (uint32*)ep->ContextRecord->Rsp;
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   535
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
		uint32 *b = (uint32*)ep->ContextRecord->Esp;
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   537
#endif
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   538
		for (j = 0; j != 24; j++) {
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   539
			for (i = 0; i != 8; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
				if (IsBadReadPtr(b,sizeof(uint32))) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
					output += sprintf(output, " ????????"); //OCR: WAS - , 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
					output += sprintf(output, " %.8X", *b);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
				b++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
			output += sprintf(output, "\r\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	output += sprintf(output, "\r\nModule information:\r\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	output = PrintModuleList(output);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
		OSVERSIONINFO os;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
		os.dwOSVersionInfoSize = sizeof(os);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
		GetVersionEx(&os);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
		output += sprintf(output, "\r\nSystem information:\r\n"
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   559
			" Windows version %d.%d %d %s\r\n",
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   560
			os.dwMajorVersion, os.dwMinorVersion, os.dwBuildNumber, os.szCSDVersion);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
		HANDLE file = CreateFile("crash.log", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
		DWORD num_written;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
		if (file != INVALID_HANDLE_VALUE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
			WriteFile(file, _crash_msg, output - _crash_msg, &num_written, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
			CloseHandle(file);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
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
   572
	/* 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
   573
	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
   574
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
	if (_safe_esp) {
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   576
#ifdef _M_AMD64
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   577
		ep->ContextRecord->Rip = (DWORD64)Handler2;
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   578
		ep->ContextRecord->Rsp = (DWORD64)_safe_esp;
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   579
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
		ep->ContextRecord->Eip = (DWORD)Handler2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
		ep->ContextRecord->Esp = (DWORD)_safe_esp;
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   582
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
		return EXCEPTION_CONTINUE_EXECUTION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
	}
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
   585
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
   586
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
   587
	return EXCEPTION_EXECUTE_HANDLER;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
1102
316643e34104 (svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents: 1040
diff changeset
   590
static void Win32InitializeExceptions(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
{
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   592
#ifdef _M_AMD64
3341
b8febc9509d7 (svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents: 3340
diff changeset
   593
	extern void *_get_save_esp(void);
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   594
	_safe_esp = _get_save_esp();
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   595
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
	_asm {
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   597
		mov _safe_esp, esp
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
	}
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
   599
#endif
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   600
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	SetUnhandledExceptionFilter(ExceptionHandler);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
}
3341
b8febc9509d7 (svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents: 3340
diff changeset
   603
#endif /* _MSC_VER */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
static char *_fios_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
static char *_fios_save_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
static char *_fios_scn_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
static FiosItem *_fios_items;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
static int _fios_count, _fios_alloc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
1102
316643e34104 (svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents: 1040
diff changeset
   611
static FiosItem *FiosAlloc(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	if (_fios_count == _fios_alloc) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
		_fios_alloc += 256;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
		_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
	return &_fios_items[_fios_count++];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
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
   620
static HANDLE MyFindFirstFile(const char *path, const char *file, WIN32_FIND_DATA *fd)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
{
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
   622
	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
   623
	HANDLE h;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
	char paths[MAX_PATH];
2532
971def34d311 (svn r3061) - CodeChange: revert r3056, r3057 and add a simpler fix to satisfy the needs of the absolute strict (eg. root directory is C:\ not C:)
Darkvater
parents: 2528
diff changeset
   625
	const char *s = strrchr(path, '\\');
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   626
2532
971def34d311 (svn r3061) - CodeChange: revert r3056, r3057 and add a simpler fix to satisfy the needs of the absolute strict (eg. root directory is C:\ not C:)
Darkvater
parents: 2528
diff changeset
   627
	snprintf(paths, sizeof(paths), "%s%s%s", path, (s[1] == '\0') ? "" : "\\", 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
   628
	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
   629
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
   630
	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
   631
	return h;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
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
   634
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
   635
{
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   636
	const FiosItem *da = (const FiosItem *)a;
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   637
	const FiosItem *db = (const FiosItem *)b;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	int r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
2526
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2482
diff changeset
   640
	if (_savegame_sort_order & SORT_BY_NAME) {
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2482
diff changeset
   641
		r = strcasecmp(da->title, db->title);
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2482
diff changeset
   642
	} 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
   643
		r = da->mtime < db->mtime ? -1 : 1;
2526
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2482
diff changeset
   644
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
2526
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2482
diff changeset
   646
	if (_savegame_sort_order & SORT_DESCENDING) r = -r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
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
   650
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
// Get a list of savegames
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
FiosItem *FiosGetSavegameList(int *num, int mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	WIN32_FIND_DATA fd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
	HANDLE h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
	FiosItem *fios;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
	int sort_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	if (_fios_save_path == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
		_fios_save_path = malloc(MAX_PATH);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
		strcpy(_fios_save_path, _path.save_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2091
diff changeset
   664
	_fios_path = _fios_save_path;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	// Parent directory, only if not of the type C:\.
2532
971def34d311 (svn r3061) - CodeChange: revert r3056, r3057 and add a simpler fix to satisfy the needs of the absolute strict (eg. root directory is C:\ not C:)
Darkvater
parents: 2528
diff changeset
   667
	if (_fios_path[3] != '\0') {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
		fios = FiosAlloc();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
		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
   670
		fios->mtime = 0;
1572
6d0111113f0b (svn r2076) Set the name for the parent directory to ".."
tron
parents: 1548
diff changeset
   671
		strcpy(fios->name, "..");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
		strcpy(fios->title, ".. (Parent directory)");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   674
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
	// Show subdirectories first
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
	h = MyFindFirstFile(_fios_path, "*.*", &fd);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	if (h != INVALID_HANDLE_VALUE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
			if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   680
					strcmp(fd.cFileName, ".") != 0 &&
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   681
					strcmp(fd.cFileName, "..") != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
				fios = FiosAlloc();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
				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
   684
				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
   685
				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
3329
992d1f7cb747 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3287
diff changeset
   686
				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", FS2OTTD(fd.cFileName));
2940
ce57a148333e (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2889
diff changeset
   687
				str_validate(fios->title);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
		} while (FindNextFile(h, &fd));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
		FindClose(h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
2334
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   693
	{
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   694
		/* XXX ugly global variables ... */
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   695
		byte order = _savegame_sort_order;
2526
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2482
diff changeset
   696
		_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
2334
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   697
		qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   698
		_savegame_sort_order = order;
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   699
	}
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   700
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
	// this is where to start sorting
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
	sort_start = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
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
   704
	/* 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
   705
	 * .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
   706
	 * .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
   707
	 * .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
   708
	 * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
	 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
	h = MyFindFirstFile(_fios_path, "*.*", &fd);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
	if (h != INVALID_HANDLE_VALUE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
		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
   713
			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
   714
6a31e3d7dfe3 (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   715
			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
   716
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
   717
			t = strrchr(fd.cFileName, '.');
2338
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   718
			if (t == NULL) continue;
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   719
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   720
			if (strcasecmp(t, ".sav") == 0) { // OpenTTD
1486
6a31e3d7dfe3 (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   721
				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
   722
				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
   723
				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
   724
				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2091
diff changeset
   725
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2091
diff changeset
   726
				*t = '\0'; // strip extension
3329
992d1f7cb747 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3287
diff changeset
   727
				ttd_strlcpy(fios->title, FS2OTTD(fd.cFileName), lengthof(fios->title));
2940
ce57a148333e (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2889
diff changeset
   728
				str_validate(fios->title);
1486
6a31e3d7dfe3 (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   729
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
2338
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   730
				if (strcasecmp(t, ".ss1") == 0 ||
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   731
						strcasecmp(t, ".sv1") == 0 ||
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   732
						strcasecmp(t, ".sv2") == 0) { // TTDLX(Patch)
1486
6a31e3d7dfe3 (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   733
					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
   734
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
					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
   736
					fios->type = FIOS_TYPE_OLDFILE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
					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
   738
					ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
					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
   740
					GetOldSaveGameName(fios->title, buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
		} while (FindNextFile(h, &fd));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
		FindClose(h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
	qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
	// Drives
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
		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
   752
		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
   753
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		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
   755
		for (s = drives; *s != '\0';) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
			fios = FiosAlloc();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
			fios->type = FIOS_TYPE_DRIVE;
1580
0064c283b59b (svn r2084) Set the name for drive items
tron
parents: 1572
diff changeset
   758
			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
   759
			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
   760
			while (*s++ != '\0') {}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
	}
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
   763
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
	*num = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
	return _fios_items;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
// Get a list of scenarios
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
FiosItem *FiosGetScenarioList(int *num, int mode)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
	FiosItem *fios;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	WIN32_FIND_DATA fd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	HANDLE h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
	int sort_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2091
diff changeset
   776
	if (_fios_scn_path == NULL) {
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2091
diff changeset
   777
		_fios_scn_path = malloc(MAX_PATH);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
		strcpy(_fios_scn_path, _path.scenario_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
	_fios_path = _fios_scn_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	// 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
   784
	if (_fios_path[3] != '\0' && mode != SLD_NEW_GAME) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
		fios = FiosAlloc();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
		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
   787
		fios->mtime = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
		strcpy(fios->title, ".. (Parent directory)");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
	// Show subdirectories first
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
	h = MyFindFirstFile(_fios_scn_path, "*.*", &fd);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
	if (h != INVALID_HANDLE_VALUE && mode != SLD_NEW_GAME) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
			if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   796
					strcmp(fd.cFileName, ".") != 0 &&
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   797
					strcmp(fd.cFileName, "..") != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
				fios = FiosAlloc();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
				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
   800
				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
   801
				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
3329
992d1f7cb747 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3287
diff changeset
   802
				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", FS2OTTD(fd.cFileName));
2940
ce57a148333e (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2889
diff changeset
   803
				str_validate(fios->title);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		} while (FindNextFile(h, &fd));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
		FindClose(h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
2334
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   809
	{
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   810
		/* XXX ugly global variables ... */
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   811
		byte order = _savegame_sort_order;
2526
cae4842086a9 (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2482
diff changeset
   812
		_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
2334
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   813
		qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   814
		_savegame_sort_order = order;
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   815
	}
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   816
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
	// this is where to start sorting
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
	sort_start = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
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
   820
	/* 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
   821
	 * .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
   822
	 * .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
   823
	 * .SS0 Transport Tycoon Deluxe preset scenario
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
	h = MyFindFirstFile(_fios_scn_path, "*.*", &fd);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
	if (h != INVALID_HANDLE_VALUE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
		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
   828
			char *t;
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   829
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
   830
			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
   831
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
   832
			t = strrchr(fd.cFileName, '.');
2338
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   833
			if (t == NULL) continue;
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   834
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   835
			if (strcasecmp(t, ".scn") == 0) { // OpenTTD
1486
6a31e3d7dfe3 (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   836
				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
   837
				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
   838
				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
   839
				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2091
diff changeset
   840
2334
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   841
				*t = '\0'; // strip extension
3329
992d1f7cb747 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3287
diff changeset
   842
				ttd_strlcpy(fios->title, FS2OTTD(fd.cFileName), lengthof(fios->title));
2940
ce57a148333e (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2889
diff changeset
   843
				str_validate(fios->title);
1486
6a31e3d7dfe3 (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   844
			} 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
   845
					mode == SLD_NEW_GAME) {
2338
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   846
				if (strcasecmp(t, ".sv0") == 0 ||
8b953706648a (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   847
						strcasecmp(t, ".ss0") == 0) { // TTDLX(Patch)
1486
6a31e3d7dfe3 (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   848
					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
   849
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
					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
   851
					fios->type = FIOS_TYPE_OLD_SCENARIO;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
					fios->mtime = *(uint64*)&fd.ftLastWriteTime;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
					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
   854
					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
   855
					ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
		} while (FindNextFile(h, &fd));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
		FindClose(h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
	// Drives
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
	if (mode != SLD_NEW_GAME) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
		char drives[256];
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   867
		const char *s;
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   868
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
		GetLogicalDriveStrings(sizeof(drives), drives);
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   870
		for (s = drives; *s != '\0';) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
			fios = FiosAlloc();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
			fios->type = FIOS_TYPE_DRIVE;
1580
0064c283b59b (svn r2084) Set the name for drive items
tron
parents: 1572
diff changeset
   873
			sprintf(fios->name, "%c:", s[0]);
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   874
			sprintf(fios->title, "%c:", s[0]);
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   875
			while (*s++ != '\0') {}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	*num = _fios_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
	return _fios_items;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
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
   883
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
// Free the list of savegames
1102
316643e34104 (svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents: 1040
diff changeset
   885
void FiosFreeSavegameList(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	free(_fios_items);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
	_fios_items = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	_fios_alloc = _fios_count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
// Browse to
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
char *FiosBrowseTo(const FiosItem *item)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	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
   896
	char *s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   898
	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
   899
		case FIOS_TYPE_DRIVE:
2532
971def34d311 (svn r3061) - CodeChange: revert r3056, r3057 and add a simpler fix to satisfy the needs of the absolute strict (eg. root directory is C:\ not C:)
Darkvater
parents: 2528
diff changeset
   900
			sprintf(path, "%c:\\", item->title[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
   901
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
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
   903
		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
   904
			s = strrchr(path, '\\');
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
   905
			if (s != path + 2) {
2532
971def34d311 (svn r3061) - CodeChange: revert r3056, r3057 and add a simpler fix to satisfy the needs of the absolute strict (eg. root directory is C:\ not C:)
Darkvater
parents: 2528
diff changeset
   906
				s[0] = '\0';
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
   907
			} else {
2532
971def34d311 (svn r3061) - CodeChange: revert r3056, r3057 and add a simpler fix to satisfy the needs of the absolute strict (eg. root directory is C:\ not C:)
Darkvater
parents: 2528
diff changeset
   908
				s[1] = '\0';
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
   909
			}
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
   910
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
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
   912
		case FIOS_TYPE_DIR:
2334
b4e5c353bf38 (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   913
			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
   914
			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
   915
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
2559
08e648022cb0 (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2532
diff changeset
   917
		case FIOS_TYPE_DIRECT:
08e648022cb0 (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2532
diff changeset
   918
			sprintf(path, "%s\\", item->name);
2560
00ad0c27c2f3 (svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents: 2559
diff changeset
   919
			s = strrchr(path, '\\');
00ad0c27c2f3 (svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents: 2559
diff changeset
   920
			if (s[1] == '\0') s[0] = '\0'; // strip trailing slash
2559
08e648022cb0 (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2532
diff changeset
   921
			break;
08e648022cb0 (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2532
diff changeset
   922
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
   923
		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
   924
		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
   925
		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
   926
		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
   927
			static char str_buffr[512];
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   928
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
   929
			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
   930
			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
   931
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
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
   937
/**
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
   938
 * 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
   939
 * 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
   940
 * @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
   941
 * @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
   942
 * @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
   943
 */
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
   944
StringID FiosGetDescText(const char **path, uint32 *tot)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
{
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
   946
	UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS);  // disable 'no-disk' message box
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	char root[4];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	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
   949
	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
   950
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
	*path = _fios_path;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
   953
	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
   954
	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
   955
		*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
   956
		sid = STR_4005_BYTES_FREE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
   957
	} else {
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
   958
		sid = STR_4006_UNABLE_TO_READ_DRIVE;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
   959
	}
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
   960
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
   961
	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
   962
	return sid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
3287
720ed37be8c6 (svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents: 3204
diff changeset
   965
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
{
1508
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1496
diff changeset
   967
	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
   968
	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
   969
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
   970
	extension = (_game_mode == GM_EDITOR ? ".scn" : ".sav");
1508
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1496
diff changeset
   971
3f0d2f3147c2 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1496
diff changeset
   972
	// 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
   973
	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
   974
	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
   975
3287
720ed37be8c6 (svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents: 3204
diff changeset
   976
	snprintf(buf, size, "%s\\%s%s", _fios_path, name, extension);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
2255
ddcaf9e333ff (svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents: 2211
diff changeset
   979
bool FiosDelete(const char *name)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
{
1336
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   981
	char path[512];
c9e6b766bf21 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   982
3287
720ed37be8c6 (svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents: 3204
diff changeset
   983
	FiosMakeSavegameName(path, name, sizeof(path));
2255
ddcaf9e333ff (svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents: 2211
diff changeset
   984
	return DeleteFile(path) != 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
bool FileExists(const char *filename)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
	HANDLE hand = CreateFile(filename, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
	if (hand == INVALID_HANDLE_VALUE) return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	CloseHandle(hand);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
static int CDECL LanguageCompareFunc(const void *a, const void *b)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
{
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
   997
	return strcmp(*(const char* const *)a, *(const char* const *)b);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
int GetLanguageList(char **languages, int max)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
	HANDLE hand;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
	int num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
	char filedir[MAX_PATH];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	WIN32_FIND_DATA fd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	sprintf(filedir, "%s*.lng", _path.lang_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
	hand = FindFirstFile(filedir, &fd);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
	if (hand != INVALID_HANDLE_VALUE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
				languages[num++] = strdup(fd.cFileName);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
				if (num == max) break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
		} while (FindNextFile(hand, &fd));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
		FindClose(hand);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
	qsort(languages, num, sizeof(char*), LanguageCompareFunc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
	return num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
static int ParseCommandLine(char *line, char **argv, int max_argc)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
	int n = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
		// skip whitespace
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
		while (*line == ' ' || *line == '\t')
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
			line++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
		// end?
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1033
		if (*line == '\0')
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
			break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1035
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
		// special handling when quoted
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
		if (*line == '"') {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
			argv[n++] = ++line;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
			while (*line != '"') {
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1040
				if (*line == '\0') return n;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
				line++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
			argv[n++] = line;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
			while (*line != ' ' && *line != '\t') {
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1046
				if (*line == '\0') return n;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
				line++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
		}
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1050
		*line++ = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
	} while (n != max_argc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
	return n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
1102
316643e34104 (svn r1603) -Fix: unused variable in FormatTinyDate
darkvater
parents: 1040
diff changeset
  1056
void CreateConsole(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
	HANDLE hand;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
	CONSOLE_SCREEN_BUFFER_INFO coninfo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
	if (_has_console) return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	_has_console = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
	AllocConsole();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1066
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
	hand = GetStdHandle(STD_OUTPUT_HANDLE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
	GetConsoleScreenBufferInfo(hand, &coninfo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	coninfo.dwSize.Y = 500;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
	SetConsoleScreenBufferSize(hand, coninfo.dwSize);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1071
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
	// redirect unbuffered STDIN, STDOUT, STDERR to the console
2172
41c37f2b7a14 (svn r2686) Revert accidently commited change
tron
parents: 2171
diff changeset
  1073
#if !defined(__CYGWIN__)
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
  1074
	*stdout = *_fdopen( _open_osfhandle((intptr_t)hand, _O_TEXT), "w" );
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
  1075
	*stdin = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_INPUT_HANDLE), _O_TEXT), "r" );
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
  1076
	*stderr = *_fdopen(_open_osfhandle((intptr_t)GetStdHandle(STD_ERROR_HANDLE), _O_TEXT), "w" );
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
	// open_osfhandle is not in cygwin
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
	*stdout = *fdopen(1, "w" );
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1080
	*stdin = *fdopen(0, "r" );
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1081
	*stderr = *fdopen(2, "w" );
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
#endif
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1083
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1084
	setvbuf(stdin, NULL, _IONBF, 0);
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1085
	setvbuf(stdout, NULL, _IONBF, 0);
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1086
	setvbuf(stderr, NULL, _IONBF, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
void ShowInfo(const char *str)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
{
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
  1091
	if (_has_console) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
		puts(str);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3799
diff changeset
  1093
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
		bool old;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1095
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
		ReleaseCapture();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
		_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
  1098
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
		old = MyShowCursor(true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
		if (MessageBoxA(GetActiveWindow(), str, "OpenTTD", MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
			CreateConsole();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
		MyShowCursor(old);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
2428
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
  1107
#ifdef __MINGW32__
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
  1108
	/* _set_error_mode() constants&function (do not exist in mingw headers) */
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
  1109
	#define _OUT_TO_DEFAULT      0
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
  1110
	#define _OUT_TO_STDERR       1
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
  1111
	#define _OUT_TO_MSGBOX       2
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
  1112
	#define _REPORT_ERRMODE      3
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
  1113
	int _set_error_mode(int);
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
  1114
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1116
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1117
	LPTSTR lpCmdLine, int nCmdShow)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
	int argc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
	char *argv[64]; // max 64 command line arguments
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
#if defined(_DEBUG)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
	CreateConsole();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
2428
b2e4fb6665d0 (svn r2954) - Force assertion message to be output to a messagebox instead to the console which MinGW32 had the habit of doing. Using undocumented (in mingw) __set_error_mode() function.
Darkvater
parents: 2338
diff changeset
  1126
	_set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
	// setup random seed to something quite random
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 199
diff changeset
  1129
	_random_seeds[0][0] = GetTickCount();
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 199
diff changeset
  1130
	_random_seeds[0][1] = _random_seeds[0][0] * 0x1234567;
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2062
diff changeset
  1131
	SeedMT(_random_seeds[0][0]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	argc = ParseCommandLine(GetCommandLine(), argv, lengthof(argv));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
#if defined(WIN32_EXCEPTION_TRACKER)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1136
	{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
		Win32InitializeExceptions();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	_try {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
		uint32 _stdcall ExceptionHandler(void *ep);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
		ttd_main(argc, argv);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
#if defined(WIN32_EXCEPTION_TRACKER_DEBUG)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	} _except (ExceptionHandler(_exception_info())) {}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
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
  1154
void DeterminePaths(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
	char *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
	char *cfg;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
	_path.personal_dir = _path.game_data_dir = cfg = malloc(MAX_PATH);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
	GetCurrentDirectory(MAX_PATH - 1, cfg);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1161
2559
08e648022cb0 (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2532
diff changeset
  1162
	cfg[0] = toupper(cfg[0]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
	s = strchr(cfg, 0);
1468
8073826fe82d (svn r1972) Several cleanups and fix some latent bugs
tron
parents: 1466
diff changeset
  1164
	if (s[-1] != '\\') strcpy(s, "\\");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
	_path.save_dir = str_fmt("%ssave", cfg);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
	_path.autosave_dir = str_fmt("%s\\autosave", _path.save_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
	_path.scenario_dir = str_fmt("%sscenario", cfg);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
	_path.gm_dir = str_fmt("%sgm\\", cfg);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
	_path.data_dir = str_fmt("%sdata\\", cfg);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
	_path.lang_dir = str_fmt("%slang\\", cfg);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
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
  1173
	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
  1174
		_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
  1175
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
  1176
	_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
  1177
	_log_file = str_fmt("%sopenttd.log", _path.personal_dir);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
	// make (auto)save and scenario folder
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
	CreateDirectory(_path.save_dir, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
	CreateDirectory(_path.autosave_dir, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
	CreateDirectory(_path.scenario_dir, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
1022
9ea8ee93d6a9 (svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents: 983
diff changeset
  1185
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
  1186
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1187
	va_list ap;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1188
	int ret;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1189
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1190
	va_start(ap, format);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1191
	ret = vsnprintf(str, size, format, ap);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1192
	va_end(ap);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1193
	return ret;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1194
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1195
2764
6225ab46af43 (svn r3309) Cygwin doesn't define _MSC_VER; check it exists before basing decisions on its value.
peter1138
parents: 2639
diff changeset
  1196
#ifdef _MSC_VER
1022
9ea8ee93d6a9 (svn r1523) -Fix: somehow mousewheel was disabled on windows using SDL; reenabled again
darkvater
parents: 983
diff changeset
  1197
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
  1198
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1199
	int ret;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1200
	ret = _vsnprintf(str, size, format, ap);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1201
	if (ret < 0) str[size - 1] = '\0';
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1202
	return ret;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 534
diff changeset
  1203
}
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2458
diff changeset
  1204
#endif
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1205
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1206
/**
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1207
 * 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
  1208
 * 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
  1209
 * 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
  1210
 * @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
  1211
 * @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
  1212
 */
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1213
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
  1214
{
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1215
	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
  1216
		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
  1217
		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
  1218
		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
  1219
		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
  1220
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1221
		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
  1222
		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
  1223
		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
  1224
		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
  1225
3458
d3a6ddfa6784 (svn r4301) - Fix: the maxlength parameter of Textbuf is supposed to be the size of the buffer (so length of string + '\0'), but in the code it was a mix of both. It didn't cause any problems though, only an occasionaly one-less character than allowed. (thanks Tron for noticing)
Darkvater
parents: 3394
diff changeset
  1226
		for (; IsValidAsciiChar(*dataptr) && (tb->length + length) < (tb->maxlength - 1) &&
3799
7f989f09828d (svn r4807) - Fix: win32 compilation was broken by r4802
glx
parents: 3649
diff changeset
  1227
				(tb->maxwidth == 0 || width + tb->width + GetCharacterWidth(FS_NORMAL, (byte)*dataptr) <= tb->maxwidth); dataptr++) {
7f989f09828d (svn r4807) - Fix: win32 compilation was broken by r4802
glx
parents: 3649
diff changeset
  1228
					width += GetCharacterWidth(FS_NORMAL, (byte)*dataptr);
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1229
			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
  1230
		}
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1231
3458
d3a6ddfa6784 (svn r4301) - Fix: the maxlength parameter of Textbuf is supposed to be the size of the buffer (so length of string + '\0'), but in the code it was a mix of both. It didn't cause any problems though, only an occasionaly one-less character than allowed. (thanks Tron for noticing)
Darkvater
parents: 3394
diff changeset
  1232
		if (length == 0) return false;
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1233
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1234
		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
  1235
		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
  1236
		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
  1237
		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
  1238
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1239
		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
  1240
		tb->caretpos += length;
3458
d3a6ddfa6784 (svn r4301) - Fix: the maxlength parameter of Textbuf is supposed to be the size of the buffer (so length of string + '\0'), but in the code it was a mix of both. It didn't cause any problems though, only an occasionaly one-less character than allowed. (thanks Tron for noticing)
Darkvater
parents: 3394
diff changeset
  1241
		tb->buf[tb->length] = '\0'; // terminating zero
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1242
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1243
		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
  1244
		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
  1245
		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
  1246
	}
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
  1247
	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
  1248
}
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
  1249
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2062
diff changeset
  1250
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2062
diff changeset
  1251
void CSleep(int milliseconds)
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2062
diff changeset
  1252
{
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2062
diff changeset
  1253
	Sleep(milliseconds);
2099
22f535ad9eea (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 2091
diff changeset
  1254
}
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1255
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1256
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1257
// Utility function to get the current timestamp in milliseconds
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1258
// Useful for profiling
2139
863a14d0c7a2 (svn r2649) Get rid of 2 warnings.
ludde
parents: 2125
diff changeset
  1259
int64 GetTS(void)
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1260
{
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1261
	static double freq;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1262
	__int64 value;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1263
	if (!freq) {
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1264
		QueryPerformanceFrequency((LARGE_INTEGER*)&value);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1265
		freq = (double)1000000 / value;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1266
	}
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1267
	QueryPerformanceCounter((LARGE_INTEGER*)&value);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2099
diff changeset
  1268
	return (__int64)(value * freq);
2139
863a14d0c7a2 (svn r2649) Get rid of 2 warnings.
ludde
parents: 2125
diff changeset
  1269
}