os2.c
author tron
Wed, 27 Jul 2005 19:22:38 +0000
changeset 2207 be1ef1e1fc58
parent 2195 ed135f2dc5f8
child 2210 b76184e0929c
permissions -rw-r--r--
(svn r2725) Move MyShowCursor() back into win32.c, it fits better there
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2180
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2180
diff changeset
     2
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     3
#include "stdafx.h"
1892
8717d92b32b1 (svn r2398) - CodeChange: forgot to update unix and os2 specific files as well.
Darkvater
parents: 1890
diff changeset
     4
#include "openttd.h"
2167
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
     5
#include "variables.h"
1317
3c90086ff34f (svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents: 1301
diff changeset
     6
#include "string.h"
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     7
#include "table/strings.h"
1888
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
     8
#include "gfx.h"
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
     9
#include "gui.h"
2167
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
    10
#include "functions.h"
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
    11
#include "macros.h"
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    12
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    13
#include <direct.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    14
#include <unistd.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    15
#include <sys/stat.h>
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    16
#include <stdarg.h>
1887
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
    17
#include <stdlib.h>
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
    18
#include <process.h>
1888
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
    19
#include <ctype.h>
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    20
#include <time.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    21
#include <dos.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    22
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    23
#define INCL_DOS
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
    24
#define INCL_WIN
1524
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
    25
#define INCL_WINCLIPBOARD
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    26
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    27
#include <os2.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    28
2167
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
    29
#include <i86.h>
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
    30
2175
06415cf75dc1 (svn r2689) - Split OS/2 music driver into os2_m.c, update project file
orudge
parents: 2167
diff changeset
    31
#include "sound/null_s.h"
06415cf75dc1 (svn r2689) - Split OS/2 music driver into os2_m.c, update project file
orudge
parents: 2167
diff changeset
    32
#include "sound/sdl_s.h"
06415cf75dc1 (svn r2689) - Split OS/2 music driver into os2_m.c, update project file
orudge
parents: 2167
diff changeset
    33
2177
b0f207d47f8e (svn r2691) Separate dedicated video driver and fix bemidi declarations
tron
parents: 2176
diff changeset
    34
#include "video/dedicated_v.h"
2175
06415cf75dc1 (svn r2689) - Split OS/2 music driver into os2_m.c, update project file
orudge
parents: 2167
diff changeset
    35
#include "video/null_v.h"
06415cf75dc1 (svn r2689) - Split OS/2 music driver into os2_m.c, update project file
orudge
parents: 2167
diff changeset
    36
#include "video/sdl_v.h"
06415cf75dc1 (svn r2689) - Split OS/2 music driver into os2_m.c, update project file
orudge
parents: 2167
diff changeset
    37
06415cf75dc1 (svn r2689) - Split OS/2 music driver into os2_m.c, update project file
orudge
parents: 2167
diff changeset
    38
#include "music/null_m.h"
06415cf75dc1 (svn r2689) - Split OS/2 music driver into os2_m.c, update project file
orudge
parents: 2167
diff changeset
    39
#include "music/os2_m.h"
06415cf75dc1 (svn r2689) - Split OS/2 music driver into os2_m.c, update project file
orudge
parents: 2167
diff changeset
    40
1890
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
    41
static inline int strcasecmp(const char* s1, const char* s2)
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
    42
{
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
    43
	return stricmp(s1, s2);
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
    44
}
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
    45
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    46
static char *_fios_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    47
static char *_fios_save_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    48
static char *_fios_scn_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    49
static FiosItem *_fios_items;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    50
static int _fios_count, _fios_alloc;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    51
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    52
static FiosItem *FiosAlloc(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    53
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    54
	if (_fios_count == _fios_alloc) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    55
		_fios_alloc += 256;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    56
		_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem));
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    57
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    58
	return &_fios_items[_fios_count++];
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    59
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    60
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    61
int compare_FiosItems(const void *a, const void *b)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    62
{
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    63
	const FiosItem *da = (const FiosItem *)a;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    64
	const FiosItem *db = (const FiosItem *)b;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    65
	int r;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    66
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    67
	if (_savegame_sort_order < 2) // sort by date
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    68
		r = da->mtime < db->mtime ? -1 : 1;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    69
	else
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
    70
		r = strcasecmp(da->title, db->title);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    71
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    72
	if (_savegame_sort_order & 1) r = -r;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    73
	return r;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    74
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    75
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    76
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    77
static DIR *my_opendir(char *path, char *file)
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    78
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    79
	char paths[MAX_PATH];
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    80
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
    81
	append_path(paths, path, file);
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    82
	return opendir(paths);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    83
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    84
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    85
static void append_path(char *out, const char *path, const char *file)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    86
{
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    87
	if (path[2] == '\\' && path[3] == '\0')
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    88
		sprintf(out, "%s%s", path, file);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    89
	else
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    90
		sprintf(out, "%s\\%s", path, file);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    91
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    92
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    93
// Get a list of savegames
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    94
FiosItem *FiosGetSavegameList(int *num, int mode)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    95
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    96
	FiosItem *fios;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    97
	DIR *dir;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    98
	struct dirent *dirent;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    99
	struct stat sb;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   100
	int sort_start;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   101
	char filename[MAX_PATH];
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   102
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   103
	if (_fios_save_path == NULL) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   104
		_fios_save_path = malloc(MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   105
		strcpy(_fios_save_path, _path.save_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   106
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   107
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   108
	_fios_path = _fios_scn_path;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   109
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   110
	// Parent directory, only if not of the type C:\.
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   111
	if (_fios_path[3] != '\0') {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   112
		fios = FiosAlloc();
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   113
		fios->type = FIOS_TYPE_PARENT;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   114
		fios->mtime = 0;
1572
cf4613ca991e (svn r2076) Set the name for the parent directory to ".."
tron
parents: 1524
diff changeset
   115
		strcpy(fios->name, "..");
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   116
		strcpy(fios->title, ".. (Parent directory)");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   117
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   118
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   119
	// Show subdirectories first
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   120
	dir = my_opendir(_fios_path, "*.*");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   121
	if (dir != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   122
		while ((dirent = readdir(dir)) != NULL) {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   123
			append_path(filename, _fios_path, dirent->d_name);
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   124
			if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) &&
1817
5a284107f72b (svn r2321) - Fix: [ 1202286 ] On OS/2 you get a double backslash in your filename after browsing to the root dir of a drive and "." and ".." are incorrectly displayed. (orudge)
matthijs
parents: 1599
diff changeset
   125
					strcmp(dirent->d_name, ".") != 0 &&
5a284107f72b (svn r2321) - Fix: [ 1202286 ] On OS/2 you get a double backslash in your filename after browsing to the root dir of a drive and "." and ".." are incorrectly displayed. (orudge)
matthijs
parents: 1599
diff changeset
   126
					strcmp(dirent->d_name, "..") != 0) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   127
				fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   128
				fios->type = FIOS_TYPE_DIR;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   129
				fios->mtime = 0;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   130
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   131
				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", dirent->d_name);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   132
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   133
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   134
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   135
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   136
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   137
	{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   138
		/* XXX ugly global variables ... */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   139
		byte order = _savegame_sort_order;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   140
		_savegame_sort_order = 2; // sort ascending by name
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   141
		qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   142
		_savegame_sort_order = order;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   143
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   144
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   145
	// this is where to start sorting
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   146
	sort_start = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   147
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   148
	/* Show savegame files
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   149
	 * .SAV OpenTTD saved game
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   150
	 * .SS1 Transport Tycoon Deluxe preset game
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   151
	 * .SV1 Transport Tycoon Deluxe (Patch) saved game
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   152
	 * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   153
	 */
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   154
	dir = my_opendir(_fios_path, "*.*");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   155
	if (dir != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   156
		while ((dirent = readdir(dir)) != NULL) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   157
			char *t;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   158
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   159
			append_path(filename, _fios_path, dirent->d_name);
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   160
			if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   161
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   162
			t = strrchr(dirent->d_name, '.');
1890
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
   163
			if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   164
				fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   165
				fios->type = FIOS_TYPE_FILE;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   166
				fios->mtime = sb.st_mtime;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   167
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   168
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   169
				*t = '\0'; // strip extension
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   170
				ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   171
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   172
				if (t != NULL && (
1890
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
   173
							strcasecmp(t, ".ss1") == 0 ||
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
   174
							strcasecmp(t, ".sv1") == 0 ||
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
   175
							strcasecmp(t, ".sv2") == 0
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   176
						)) { // TTDLX(Patch)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   177
					fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   178
					fios->type = FIOS_TYPE_OLDFILE;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   179
					fios->mtime = sb.st_mtime;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   180
					ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   181
					GetOldSaveGameName(fios->title, filename);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   182
				}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   183
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   184
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   185
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   186
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   187
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   188
	qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   189
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   190
	// Drives
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   191
	{
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   192
		uint save;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   193
		uint disk;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   194
		uint total;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   195
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   196
		/* save original drive */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   197
		_dos_getdrive(&save);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   198
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   199
		/* get available drive letters */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   200
		for (disk = 1; disk < 27; ++disk)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   201
		{
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   202
			uint disk2;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   203
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   204
			_dos_setdrive(disk, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   205
			_dos_getdrive(&disk2);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   206
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   207
			if (disk == disk2)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   208
			{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   209
				fios = FiosAlloc();
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   210
				fios->type = FIOS_TYPE_DRIVE;
1580
5ffe373bd7fc (svn r2084) Set the name for drive items
tron
parents: 1572
diff changeset
   211
				sprintf(fios->name, "%c:", 'A' + disk - 1);
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   212
				sprintf(fios->title, "%c:", 'A' + disk - 1);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   213
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   214
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   215
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   216
		_dos_setdrive(save, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   217
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   218
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   219
	*num = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   220
	return _fios_items;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   221
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   222
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   223
// Get a list of scenarios
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   224
FiosItem *FiosGetScenarioList(int *num, int mode)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   225
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   226
	FiosItem *fios;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   227
	DIR *dir;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   228
	struct dirent *dirent;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   229
	struct stat sb;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   230
	int sort_start;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   231
	char filename[MAX_PATH];
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   232
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   233
	if (_fios_scn_path == NULL) {
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   234
		_fios_scn_path = malloc(MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   235
		strcpy(_fios_scn_path, _path.scenario_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   236
	}
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   237
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   238
	_fios_path = _fios_scn_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   239
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   240
	// Parent directory, only if not of the type C:\.
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   241
	if (_fios_path[3] != '\0' && mode != SLD_NEW_GAME) {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   242
		fios = FiosAlloc();
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   243
		fios->type = FIOS_TYPE_PARENT;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   244
		fios->mtime = 0;
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   245
		strcpy(fios->title, ".. (Parent directory)");
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   246
	}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   247
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   248
	// Show subdirectories first
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   249
	dir = my_opendir(_fios_path, "*.*");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   250
	if (dir != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   251
		while ((dirent = readdir(dir)) != NULL) {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   252
			append_path(filename, _fios_path, dirent->d_name);
1506
ab7226c26e8f (svn r2010) - Fix: [ 1162209 ] Fix OS/2 build (orudge)
darkvater
parents: 1495
diff changeset
   253
			if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) &&
1817
5a284107f72b (svn r2321) - Fix: [ 1202286 ] On OS/2 you get a double backslash in your filename after browsing to the root dir of a drive and "." and ".." are incorrectly displayed. (orudge)
matthijs
parents: 1599
diff changeset
   254
					strcmp(dirent->d_name, ".") != 0 &&
5a284107f72b (svn r2321) - Fix: [ 1202286 ] On OS/2 you get a double backslash in your filename after browsing to the root dir of a drive and "." and ".." are incorrectly displayed. (orudge)
matthijs
parents: 1599
diff changeset
   255
					strcmp(dirent->d_name, "..") != 0) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   256
				fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   257
				fios->type = FIOS_TYPE_DIR;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   258
				fios->mtime = 0;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   259
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   260
				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", dirent->d_name);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   261
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   262
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   263
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   264
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   265
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   266
	// this is where to start sorting
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   267
	sort_start = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   268
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   269
	/* Show scenario files
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   270
	 * .SCN OpenTTD style scenario file
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   271
	 * .SV0 Transport Tycoon Deluxe (Patch) scenario
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   272
	 * .SS0 Transport Tycoon Deluxe preset scenario
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   273
	 */
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   274
	dir = my_opendir(_fios_path, "*.*");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   275
	if (dir != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   276
		while ((dirent = readdir(dir)) != NULL) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   277
			char *t;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   278
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   279
			append_path(filename, _fios_path, dirent->d_name);
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   280
			if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   281
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   282
			t = strrchr(dirent->d_name, '.');
1890
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
   283
			if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   284
				fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   285
				fios->type = FIOS_TYPE_SCENARIO;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   286
				fios->mtime = sb.st_mtime;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   287
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   288
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   289
				*t = '\0'; // strip extension
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   290
				ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   291
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   292
					mode == SLD_NEW_GAME) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   293
				if (t != NULL && (
1890
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
   294
							strcasecmp(t, ".sv0") == 0 ||
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
   295
							strcasecmp(t, ".ss0") == 0
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   296
						)) { // TTDLX(Patch)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   297
					fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   298
					fios->type = FIOS_TYPE_OLD_SCENARIO;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   299
					fios->mtime = sb.st_mtime;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   300
					GetOldScenarioGameName(fios->title, filename);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   301
					ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   302
				}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   303
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   304
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   305
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   306
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   307
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   308
	qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   309
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   310
	// Drives
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   311
	if (mode != SLD_NEW_GAME)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   312
	{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   313
		unsigned save, disk, disk2, total;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   314
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   315
		/* save original drive */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   316
		_dos_getdrive(&save);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   317
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   318
		/* get available drive letters */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   319
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   320
		for (disk = 1; disk < 27; ++disk)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   321
		{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   322
			_dos_setdrive(disk, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   323
			_dos_getdrive(&disk2);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   324
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   325
			if (disk == disk2)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   326
			{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   327
				fios = FiosAlloc();
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   328
				fios->type = FIOS_TYPE_DRIVE;
1580
5ffe373bd7fc (svn r2084) Set the name for drive items
tron
parents: 1572
diff changeset
   329
				sprintf(fios->name, "%c:", 'A' + disk - 1);
5ffe373bd7fc (svn r2084) Set the name for drive items
tron
parents: 1572
diff changeset
   330
				sprintf(fios->title, "%c:", 'A' + disk - 1);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   331
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   332
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   333
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   334
		_dos_setdrive(save, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   335
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   336
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   337
	*num = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   338
	return _fios_items;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   339
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   340
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   341
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   342
// Free the list of savegames
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   343
void FiosFreeSavegameList(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   344
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   345
	free(_fios_items);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   346
	_fios_items = NULL;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   347
	_fios_alloc = _fios_count = 0;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   348
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   349
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   350
// Browse to
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   351
char *FiosBrowseTo(const FiosItem *item)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   352
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   353
	char *path = _fios_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   354
	char *s;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   355
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   356
	switch (item->type) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   357
		case FIOS_TYPE_DRIVE:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   358
			sprintf(path, "%c:\\", item->title[0]);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   359
			break;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   360
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   361
		case FIOS_TYPE_PARENT:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   362
			s = strrchr(path, '\\');
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   363
			if (s != NULL) *s = '\0';
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   364
			break;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   365
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   366
		case FIOS_TYPE_DIR:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   367
			s = strchr(item->name, '\\');
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   368
			if (s != NULL) *s = '\0';
1817
5a284107f72b (svn r2321) - Fix: [ 1202286 ] On OS/2 you get a double backslash in your filename after browsing to the root dir of a drive and "." and ".." are incorrectly displayed. (orudge)
matthijs
parents: 1599
diff changeset
   369
			if (path[3]!= '\0' ) strcat(path, "\\");
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   370
			strcat(path, item->name);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   371
			break;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   372
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   373
		case FIOS_TYPE_FILE:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   374
		case FIOS_TYPE_OLDFILE:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   375
		case FIOS_TYPE_SCENARIO:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   376
		case FIOS_TYPE_OLD_SCENARIO: {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   377
			static char str_buffr[512];
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   378
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   379
			sprintf(str_buffr, "%s\\%s", path, item->name);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   380
			return str_buffr;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   381
		}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   382
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   383
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   384
	return NULL;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   385
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   386
1596
483007886b59 (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: 1580
diff changeset
   387
/**
483007886b59 (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: 1580
diff changeset
   388
 * Get descriptive texts. Returns the path and free space
483007886b59 (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: 1580
diff changeset
   389
 * left on the device
483007886b59 (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: 1580
diff changeset
   390
 * @param path string describing the path
483007886b59 (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: 1580
diff changeset
   391
 * @param tfs total free space in megabytes, optional (can be NULL)
483007886b59 (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: 1580
diff changeset
   392
 * @return StringID describing the path (free space or failure)
483007886b59 (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: 1580
diff changeset
   393
 */
483007886b59 (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: 1580
diff changeset
   394
StringID FiosGetDescText(const char **path, uint32 *tot)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   395
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   396
	struct diskfree_t free;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   397
	char drive;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   398
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   399
	*path = _fios_path;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   400
	drive = *path[0] - 'A' + 1;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   401
1596
483007886b59 (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: 1580
diff changeset
   402
	if (tot != NULL && _getdiskfree(drive, &free) == 0) {
483007886b59 (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: 1580
diff changeset
   403
		*tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector;
483007886b59 (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: 1580
diff changeset
   404
		return STR_4005_BYTES_FREE;
483007886b59 (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: 1580
diff changeset
   405
	}
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   406
1596
483007886b59 (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: 1580
diff changeset
   407
	return STR_4006_UNABLE_TO_READ_DRIVE;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   408
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   409
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   410
void FiosMakeSavegameName(char *buf, const char *name)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   411
{
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   412
	const char* extension;
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   413
	const char* period;
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   414
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   415
	if (_game_mode == GM_EDITOR)
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   416
		extension = ".scn";
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   417
	else
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   418
		extension = ".sav";
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   419
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   420
	// Don't append the extension, if it is already there
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   421
	period = strrchr(name, '.');
1890
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
   422
	if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   423
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   424
	sprintf(buf, "%s\\%s%s", _fios_path, name, extension);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   425
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   426
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   427
void FiosDelete(const char *name)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   428
{
1336
69391734ce23 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   429
	char path[512];
69391734ce23 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   430
1495
a9e4e2b78877 (svn r1999) r1990 broke savegame deletion, fix that [1161729]
tron
parents: 1486
diff changeset
   431
	snprintf(path, lengthof(path), "%s\\%s", _fios_path, name);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   432
	unlink(path);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   433
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   434
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   435
const DriverDesc _video_driver_descs[] = {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   436
	{	"null",			"Null Video Driver",		&_null_video_driver,		0},
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   437
#if defined(WITH_SDL)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   438
	{	"sdl",			"SDL Video Driver",			&_sdl_video_driver,			1},
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   439
#endif
2195
ed135f2dc5f8 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
   440
#ifdef ENABLE_NETWORK
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   441
	{	"dedicated",	"Dedicated Video Driver",	&_dedicated_video_driver,	0},
2195
ed135f2dc5f8 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
   442
#endif
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   443
	{	NULL,			NULL,						NULL,						0}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   444
};
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   445
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   446
const DriverDesc _sound_driver_descs[] = {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   447
	{	"null",	"Null Sound Driver",	&_null_sound_driver,		0},
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   448
#if defined(WITH_SDL)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   449
	{	"sdl",	"SDL Sound Driver",		&_sdl_sound_driver,			1},
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   450
#endif
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   451
	{	NULL,	NULL,					NULL,						0}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   452
};
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   453
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   454
const DriverDesc _music_driver_descs[] = {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   455
	{	"os2",		"OS/2 Music Driver",		&_os2_music_driver,			0},
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   456
	{   "null",     "Null Music Driver",	    &_null_music_driver,	    1},
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   457
	{	NULL,		NULL,						NULL,						0}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   458
};
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   459
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   460
/* GetOSVersion returns the minimal required version of OS to be able to use that driver.
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   461
	 Not needed for OS/2. */
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   462
byte GetOSVersion(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   463
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   464
	return 2;  // any arbitrary number bigger then 0
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   465
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   466
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   467
bool FileExists(const char *filename)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   468
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   469
	return access(filename, 0) == 0;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   470
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   471
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   472
static int LanguageCompareFunc(const void *a, const void *b)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   473
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   474
	return strcmp(*(const char* const *)a, *(const char* const *)b);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   475
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   476
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   477
int GetLanguageList(char **languages, int max)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   478
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   479
	DIR *dir;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   480
	struct dirent *dirent;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   481
	int num = 0;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   482
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   483
	dir = opendir(_path.lang_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   484
	if (dir != NULL) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   485
		while ((dirent = readdir(dir))) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   486
			char *t = strrchr(dirent->d_name, '.');
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   487
			if (t && !strcmp(t, ".lng")) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   488
				languages[num++] = strdup(dirent->d_name);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   489
				if (num == max) break;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   490
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   491
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   492
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   493
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   494
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   495
	qsort(languages, num, sizeof(char*), LanguageCompareFunc);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   496
	return num;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   497
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   498
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   499
static void ChangeWorkingDirectory(char *exe)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   500
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   501
	char *s = strrchr(exe, '\\');
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   502
	if (s != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   503
		*s = '\0';
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   504
		chdir(exe);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   505
		*s = '\\';
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   506
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   507
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   508
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   509
void ShowInfo(const char *str)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   510
{
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   511
	HAB hab;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   512
	HMQ hmq;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   513
	ULONG rc;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   514
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   515
	// init PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   516
	hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   517
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   518
	// display the box
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   519
	rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, str, "OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_INFORMATION);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   520
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   521
	// terminate PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   522
	WinDestroyMsgQueue(hmq);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   523
	WinTerminate(hab);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   524
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   525
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   526
void ShowOSErrorBox(const char *buf)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   527
{
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   528
	HAB hab;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   529
	HMQ hmq;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   530
	ULONG rc;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   531
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   532
	// init PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   533
	hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   534
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   535
	// display the box
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   536
	rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, buf, "OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_ERROR);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   537
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   538
	// terminate PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   539
	WinDestroyMsgQueue(hmq);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   540
	WinTerminate(hab);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   541
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   542
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   543
int CDECL main(int argc, char* argv[])
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   544
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   545
	// change the working directory to enable doubleclicking in UIs
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   546
	ChangeWorkingDirectory(argv[0]);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   547
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   548
	_random_seeds[0][1] = _random_seeds[0][0] = time(NULL);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   549
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   550
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   551
	return ttd_main(argc, argv);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   552
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   553
1390
e7cdf3ce0fb6 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
   554
void DeterminePaths(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   555
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   556
	char *s;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   557
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   558
	_path.game_data_dir = malloc(MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   559
	ttd_strlcpy(_path.game_data_dir, GAME_DATA_DIR, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   560
	#if defined SECOND_DATA_DIR
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   561
	_path.second_data_dir = malloc(MAX_PATH);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   562
	ttd_strlcpy(_path.second_data_dir, SECOND_DATA_DIR, MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   563
	#endif
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   564
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   565
#if defined(USE_HOMEDIR)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   566
	{
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   567
		const char *homedir = getenv("HOME");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   568
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   569
		if (homedir == NULL) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   570
			const struct passwd *pw = getpwuid(getuid());
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   571
			if (pw != NULL) homedir = pw->pw_dir;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   572
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   573
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   574
		_path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   575
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   576
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   577
#else /* not defined(USE_HOMEDIR) */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   578
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   579
	_path.personal_dir = malloc(MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   580
	ttd_strlcpy(_path.personal_dir, PERSONAL_DIR, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   581
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   582
	// check if absolute or relative path
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   583
	s = strchr(_path.personal_dir, '\\');
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   584
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   585
	// add absolute path
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   586
	if (s == NULL || _path.personal_dir != s) {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   587
		getcwd(_path.personal_dir, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   588
		s = strchr(_path.personal_dir, 0);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   589
		*s++ = '\\';
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   590
		ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   591
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   592
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   593
#endif /* defined(USE_HOMEDIR) */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   594
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   595
	s = strchr(_path.personal_dir, 0);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   596
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   597
	// append a / ?
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   598
	if (s[-1] != '\\') strcpy(s, "\\");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   599
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   600
	_path.save_dir = str_fmt("%ssave", _path.personal_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   601
	_path.autosave_dir = str_fmt("%s\\autosave", _path.save_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   602
	_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   603
	_path.gm_dir = str_fmt("%sgm\\", _path.game_data_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   604
	_path.data_dir = str_fmt("%sdata\\", _path.game_data_dir);
1482
80e315adc3bd (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1390
diff changeset
   605
80e315adc3bd (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1390
diff changeset
   606
	if (_config_file == NULL)
80e315adc3bd (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1390
diff changeset
   607
		_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   608
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   609
	_highscore_file = str_fmt("%shs.dat", _path.personal_dir);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   610
	_log_file = str_fmt("%sopenttd.log", _path.personal_dir);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   611
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   612
#if defined CUSTOM_LANG_DIR
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   613
	// sets the search path for lng files to the custom one
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   614
	_path.lang_dir = malloc( MAX_PATH );
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   615
	ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   616
#else
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   617
	_path.lang_dir = str_fmt("%slang\\", _path.game_data_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   618
#endif
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   619
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   620
	// create necessary folders
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   621
	mkdir(_path.personal_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   622
	mkdir(_path.save_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   623
	mkdir(_path.autosave_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   624
	mkdir(_path.scenario_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   625
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   626
1888
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   627
/**
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   628
 * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   629
 * and append this up to the maximum length (either absolute or screenlength). If maxlength
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   630
 * is zero, we don't care about the screenlength but only about the physical length of the string
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   631
 * @param tb @Textbuf type to be changed
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   632
 * @return Return true on successfull change of Textbuf, or false otherwise
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   633
 */
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   634
bool InsertTextBufferClipboard(Textbuf *tb)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   635
{
1893
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   636
	HAB hab = 0;
1524
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   637
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   638
	if (WinOpenClipbrd(hab))
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   639
	{
1893
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   640
		const char* text = (const char*)WinQueryClipbrdData(hab, CF_TEXT);
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   641
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   642
		if (text != NULL)
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   643
		{
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   644
			uint length = 0;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   645
			uint width = 0;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   646
			const char* i;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   647
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   648
			for (i = text; IsValidAsciiChar(*i); i++)
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   649
			{
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   650
				uint w;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   651
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   652
				if (tb->length + length >= tb->maxlength - 1) break;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   653
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   654
				w = GetCharacterWidth((byte)*i);
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   655
				if (tb->maxwidth != 0 && width + tb->width + w > tb->maxwidth) break;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   656
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   657
				width += w;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   658
				length++;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   659
			}
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   660
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   661
			memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos + 1);
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   662
			memcpy(tb->buf + tb->caretpos, text, length);
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   663
			tb->width += width;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   664
			tb->caretxoffs += width;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   665
			tb->length += length;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   666
			tb->caretpos += length;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   667
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   668
			WinCloseClipbrd(hab);
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   669
			return true;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   670
		}
1888
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   671
1524
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   672
		WinCloseClipbrd(hab);
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   673
	}
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   674
1893
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   675
	return false;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   676
}
1887
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   677
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   678
static TID thread1 = 0;
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   679
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   680
// The thread function must be declared and compiled using _Optlink linkage, apparently
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   681
// It seems to work, though :)
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   682
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   683
bool CreateOTTDThread(void *func, void *param)
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   684
{
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   685
	thread1 = _beginthread(func, NULL, 32768, param);
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   686
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   687
	if (thread1 == -1)
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   688
		return(false);
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   689
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   690
	return(true);
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   691
}
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   692
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   693
void CloseOTTDThread(void)
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   694
{
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   695
	_endthread();
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   696
	return;
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   697
}
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   698
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   699
void JoinOTTDThread(void)
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   700
{
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   701
	if (thread1 == 0)
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   702
		return;
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   703
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   704
	DosWaitThread(&thread1, DCWW_WAIT);
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   705
}
2167
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   706
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   707
void CSleep(int milliseconds)
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   708
{
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   709
	delay(milliseconds);
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   710
}
5686131337a4 (svn r2681) - Fix OS/2 port, please do not modify openttd.wpj/tgt by hand unless you know what you're doing!
orudge
parents: 2099
diff changeset
   711