os2.c
author tron
Sun, 21 May 2006 13:51:36 +0000
changeset 3884 793081f80381
parent 3800 75a58f751bfe
child 4077 d4d440dd8925
permissions -rw-r--r--
(svn r4940) Remove the dubious feature of remembering the last built depot. It serves no real purpose except causing confusion
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"
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2195
diff changeset
     5
#include "hal.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
     6
#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
     7
#include "string.h"
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     8
#include "table/strings.h"
1888
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
     9
#include "gfx.h"
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
    10
#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
    11
#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
    12
#include "macros.h"
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    13
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    14
#include <direct.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    15
#include <unistd.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    16
#include <sys/stat.h>
1887
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
    17
#include <stdlib.h>
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    18
#include <time.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    19
#include <dos.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    20
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
    21
#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
    22
#define INCL_WINCLIPBOARD
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    23
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    24
#include <os2.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    25
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
    26
#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
    27
1890
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
    28
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
    29
{
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
    30
	return stricmp(s1, s2);
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
    31
}
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
    32
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    33
static char *_fios_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    34
static char *_fios_save_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    35
static char *_fios_scn_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    36
static FiosItem *_fios_items;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    37
static int _fios_count, _fios_alloc;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    38
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
    39
static FiosItem *FiosAlloc(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    40
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    41
	if (_fios_count == _fios_alloc) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    42
		_fios_alloc += 256;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    43
		_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
    44
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    45
	return &_fios_items[_fios_count++];
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    46
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    47
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
    48
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
    49
{
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
    50
	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
    51
	const FiosItem *db = (const FiosItem *)b;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    52
	int r;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    53
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2338
diff changeset
    54
	if (_savegame_sort_order & SORT_BY_NAME) {
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2338
diff changeset
    55
		r = strcasecmp(da->title, db->title);
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2338
diff changeset
    56
	} else {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    57
		r = da->mtime < db->mtime ? -1 : 1;
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2338
diff changeset
    58
	}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    59
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2338
diff changeset
    60
	if (_savegame_sort_order & SORT_DESCENDING) r = -r;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    61
	return r;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    62
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    63
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    64
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
    65
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
    66
{
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
    67
	if (path[2] == '\\' && path[3] == '\0')
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    68
		sprintf(out, "%s%s", path, file);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    69
	else
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    70
		sprintf(out, "%s\\%s", path, file);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    71
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    72
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    73
// Get a list of savegames
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    74
FiosItem *FiosGetSavegameList(int *num, int mode)
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
	FiosItem *fios;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    77
	DIR *dir;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    78
	struct dirent *dirent;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    79
	struct stat sb;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    80
	int sort_start;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    81
	char filename[MAX_PATH];
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    82
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    83
	if (_fios_save_path == NULL) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    84
		_fios_save_path = malloc(MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    85
		strcpy(_fios_save_path, _path.save_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    86
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    87
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
    88
	_fios_path = _fios_save_path;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    89
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    90
	// 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
    91
	if (_fios_path[3] != '\0') {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    92
		fios = FiosAlloc();
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    93
		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
    94
		fios->mtime = 0;
1572
cf4613ca991e (svn r2076) Set the name for the parent directory to ".."
tron
parents: 1524
diff changeset
    95
		strcpy(fios->name, "..");
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    96
		strcpy(fios->title, ".. (Parent directory)");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    97
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    98
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    99
	// Show subdirectories first
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   100
	dir = opendir(_fios_path);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   101
	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
   102
		while ((dirent = readdir(dir)) != NULL) {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   103
			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
   104
			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
   105
					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
   106
					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
   107
				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
   108
				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
   109
				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
   110
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3287
diff changeset
   111
				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", FS2OTTD(dirent->d_name));
2940
2b86050d1a94 (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2560
diff changeset
   112
				str_validate(fios->title);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   113
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   114
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   115
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   116
	}
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
		/* XXX ugly global variables ... */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   120
		byte order = _savegame_sort_order;
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2338
diff changeset
   121
		_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   122
		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
   123
		_savegame_sort_order = order;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   124
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   125
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   126
	// this is where to start sorting
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   127
	sort_start = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   128
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
   129
	/* 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
   130
	 * .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
   131
	 * .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
   132
	 * .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
   133
	 * .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
   134
	 */
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   135
	dir = opendir(_fios_path);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   136
	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
   137
		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
   138
			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
   139
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   140
			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
   141
			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
   142
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
   143
			t = strrchr(dirent->d_name, '.');
2338
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   144
			if (t == NULL) continue;
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   145
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   146
			if (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
   147
				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
   148
				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
   149
				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
   150
				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
   151
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   152
				*t = '\0'; // strip extension
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3287
diff changeset
   153
				ttd_strlcpy(fios->title, FS2OTTD(dirent->d_name), lengthof(fios->title));
2940
2b86050d1a94 (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2560
diff changeset
   154
				str_validate(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
   155
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
2338
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   156
				if (strcasecmp(t, ".ss1") == 0 ||
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   157
						strcasecmp(t, ".sv1") == 0 ||
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   158
						strcasecmp(t, ".sv2") == 0) { // TTDLX(Patch)
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
   159
					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
   160
					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
   161
					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
   162
					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
   163
					GetOldSaveGameName(fios->title, filename);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   164
				}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   165
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   166
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   167
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   168
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   169
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   170
	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
   171
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   172
	// Drives
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   173
	{
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
   174
		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
   175
		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
   176
		uint total;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   177
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   178
		/* save original drive */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   179
		_dos_getdrive(&save);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   180
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   181
		/* get available drive letters */
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   182
		for (disk = 1; disk < 27; ++disk) {
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
   183
			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
   184
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   185
			_dos_setdrive(disk, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   186
			_dos_getdrive(&disk2);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   187
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   188
			if (disk == disk2) {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   189
				fios = FiosAlloc();
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   190
				fios->type = FIOS_TYPE_DRIVE;
1580
5ffe373bd7fc (svn r2084) Set the name for drive items
tron
parents: 1572
diff changeset
   191
				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
   192
				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
   193
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   194
		}
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
		_dos_setdrive(save, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   197
	}
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
	*num = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   200
	return _fios_items;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   201
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   202
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   203
// Get a list of scenarios
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   204
FiosItem *FiosGetScenarioList(int *num, int mode)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   205
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   206
	FiosItem *fios;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   207
	DIR *dir;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   208
	struct dirent *dirent;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   209
	struct stat sb;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   210
	int sort_start;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   211
	char filename[MAX_PATH];
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   212
2099
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   213
	if (_fios_scn_path == NULL) {
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   214
		_fios_scn_path = malloc(MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   215
		strcpy(_fios_scn_path, _path.scenario_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   216
	}
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   217
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   218
	_fios_path = _fios_scn_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   219
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   220
	// 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
   221
	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
   222
		fios = FiosAlloc();
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   223
		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
   224
		fios->mtime = 0;
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   225
		strcpy(fios->title, ".. (Parent directory)");
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   226
	}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   227
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   228
	// Show subdirectories first
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   229
	dir = opendir(_fios_path);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   230
	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
   231
		while ((dirent = readdir(dir)) != NULL) {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   232
			append_path(filename, _fios_path, dirent->d_name);
1506
ab7226c26e8f (svn r2010) - Fix: [ 1162209 ] Fix OS/2 build (orudge)
darkvater
parents: 1495
diff changeset
   233
			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
   234
					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
   235
					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
   236
				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
   237
				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
   238
				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
   239
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3287
diff changeset
   240
				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", FS2OTTD(dirent->d_name));
2940
2b86050d1a94 (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2560
diff changeset
   241
				str_validate(fios->title);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   242
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   243
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   244
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   245
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   246
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   247
	{
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   248
		/* XXX ugly global variables ... */
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   249
		byte order = _savegame_sort_order;
2526
29eef390cabb (svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents: 2338
diff changeset
   250
		_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   251
		qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   252
		_savegame_sort_order = order;
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   253
	}
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   254
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   255
	// this is where to start sorting
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   256
	sort_start = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   257
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
   258
	/* 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
   259
	 * .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
   260
	 * .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
   261
	 * .SS0 Transport Tycoon Deluxe preset scenario
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   262
	 */
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   263
	dir = opendir(_fios_path);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   264
	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
   265
		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
   266
			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
   267
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   268
			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
   269
			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
   270
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
			t = strrchr(dirent->d_name, '.');
2338
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   272
			if (t == NULL) continue;
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   273
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   274
			if (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
   275
				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
   276
				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
   277
				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
   278
				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
   279
02c5a49863e9 (svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents: 1893
diff changeset
   280
				*t = '\0'; // strip extension
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3287
diff changeset
   281
				ttd_strlcpy(fios->title, FS2OTTD(dirent->d_name), lengthof(fios->title));
2940
2b86050d1a94 (svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents: 2560
diff changeset
   282
				str_validate(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
   283
			} 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
   284
					mode == SLD_NEW_GAME) {
2338
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   285
				if (strcasecmp(t, ".sv0") == 0 ||
8fadf1e5c5ea (svn r2864) Code simplification and diff reduction
tron
parents: 2334
diff changeset
   286
						strcasecmp(t, ".ss0") == 0) { // TTDLX(Patch)
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
   287
					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
   288
					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
   289
					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
   290
					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
   291
					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
   292
				}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   293
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   294
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   295
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   296
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   297
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   298
	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
   299
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   300
	// Drives
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   301
	if (mode != SLD_NEW_GAME) {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   302
		unsigned save, disk, disk2, total;
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
		/* save original drive */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   305
		_dos_getdrive(&save);
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
		/* get available drive letters */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   308
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   309
		for (disk = 1; disk < 27; ++disk) {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   310
			_dos_setdrive(disk, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   311
			_dos_getdrive(&disk2);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   312
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   313
			if (disk == disk2) {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   314
				fios = FiosAlloc();
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   315
				fios->type = FIOS_TYPE_DRIVE;
1580
5ffe373bd7fc (svn r2084) Set the name for drive items
tron
parents: 1572
diff changeset
   316
				sprintf(fios->name, "%c:", 'A' + disk - 1);
5ffe373bd7fc (svn r2084) Set the name for drive items
tron
parents: 1572
diff changeset
   317
				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
   318
			}
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
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   321
		_dos_setdrive(save, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   322
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   323
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   324
	*num = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   325
	return _fios_items;
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
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   328
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   329
// 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
   330
void FiosFreeSavegameList(void)
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
	free(_fios_items);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   333
	_fios_items = NULL;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   334
	_fios_alloc = _fios_count = 0;
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
// Browse to
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   338
char *FiosBrowseTo(const FiosItem *item)
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
	char *path = _fios_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   341
	char *s;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   342
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
	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
   344
		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
   345
			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
   346
			break;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   347
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
   348
		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
   349
			s = strrchr(path, '\\');
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   350
			if (s != path + 2)
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   351
				s[0] = '\0';
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   352
			else
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   353
				s[1] = '\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
   354
			break;
801
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
		case FIOS_TYPE_DIR:
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   357
			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
   358
			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
   359
			break;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   360
2559
fe757666278c (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2548
diff changeset
   361
		case FIOS_TYPE_DIRECT:
fe757666278c (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2548
diff changeset
   362
			sprintf(path, "%s\\", item->name);
2560
14bc4eaa3551 (svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents: 2559
diff changeset
   363
			s = strrchr(path, '\\');
14bc4eaa3551 (svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents: 2559
diff changeset
   364
			if (s[1] == '\0') s[0] = '\0'; // strip trailing slash
2559
fe757666278c (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2548
diff changeset
   365
			break;
fe757666278c (svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents: 2548
diff changeset
   366
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
   367
		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
   368
		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
   369
		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
   370
		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
   371
			static char str_buffr[512];
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
			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
   374
			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
   375
		}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   376
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   377
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   378
	return NULL;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   379
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   380
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
   381
/**
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
   382
 * 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
   383
 * 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
   384
 * @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
   385
 * @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
   386
 * @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
   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
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
   389
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   390
	struct diskfree_t free;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   391
	char drive;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   392
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   393
	*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
   394
	drive = *path[0] - 'A' + 1;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   395
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
   396
	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
   397
		*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
   398
		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
   399
	}
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   400
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
   401
	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
   402
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   403
3287
609b5f5fdccb (svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents: 2940
diff changeset
   404
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   405
{
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   406
	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
   407
	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
   408
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
   409
	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
   410
		extension = ".scn";
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   411
	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
   412
		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
   413
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   414
	// 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
   415
	period = strrchr(name, '.');
1890
634da7d89c2b (svn r2396) - Fix: Put strcasecmp back into os2.c, sorry Tron!
orudge
parents: 1888
diff changeset
   416
	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
   417
3287
609b5f5fdccb (svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents: 2940
diff changeset
   418
	snprintf(buf, size, "%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
   419
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   420
2255
fd5d5adee9d9 (svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents: 2210
diff changeset
   421
bool FiosDelete(const char *name)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   422
{
1336
69391734ce23 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   423
	char path[512];
69391734ce23 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   424
3287
609b5f5fdccb (svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents: 2940
diff changeset
   425
	FiosMakeSavegameName(path, name, sizeof(path));
2255
fd5d5adee9d9 (svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents: 2210
diff changeset
   426
	return unlink(path) == 0;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   427
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   428
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   429
bool FileExists(const char *filename)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   430
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   431
	return access(filename, 0) == 0;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   432
}
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
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
   435
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   436
	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
   437
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   438
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   439
int GetLanguageList(char **languages, int max)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   440
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   441
	DIR *dir;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   442
	struct dirent *dirent;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   443
	int num = 0;
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
	dir = opendir(_path.lang_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   446
	if (dir != NULL) {
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   447
		while ((dirent = readdir(dir)) != NULL) {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   448
			char *t = strrchr(dirent->d_name, '.');
2334
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   449
8986c80be5be (svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents: 2285
diff changeset
   450
			if (t != NULL && strcmp(t, ".lng") == 0) {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   451
				languages[num++] = strdup(dirent->d_name);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   452
				if (num == max) break;
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
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   455
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   456
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   457
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   458
	qsort(languages, num, sizeof(char*), LanguageCompareFunc);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   459
	return num;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   460
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   461
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   462
static void ChangeWorkingDirectory(char *exe)
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
	char *s = strrchr(exe, '\\');
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   465
	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
   466
		*s = '\0';
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   467
		chdir(exe);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   468
		*s = '\\';
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   469
	}
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
void ShowInfo(const char *str)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   473
{
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   474
	HAB hab;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   475
	HMQ hmq;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   476
	ULONG rc;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   477
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   478
	// init PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   479
	hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   480
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   481
	// display the box
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   482
	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
   483
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   484
	// terminate PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   485
	WinDestroyMsgQueue(hmq);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   486
	WinTerminate(hab);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   487
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   488
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   489
void ShowOSErrorBox(const char *buf)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   490
{
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   491
	HAB hab;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   492
	HMQ hmq;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   493
	ULONG rc;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   494
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   495
	// init PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   496
	hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   497
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   498
	// display the box
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   499
	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
   500
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   501
	// terminate PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   502
	WinDestroyMsgQueue(hmq);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   503
	WinTerminate(hab);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   504
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   505
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   506
int CDECL main(int argc, char* argv[])
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
	// 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
   509
	ChangeWorkingDirectory(argv[0]);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   510
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   511
	_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
   512
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   513
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   514
	return ttd_main(argc, argv);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   515
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   516
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
   517
void DeterminePaths(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   518
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   519
	char *s;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   520
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
   521
	_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
   522
	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
   523
	#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
   524
	_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
   525
	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
   526
	#endif
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   527
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   528
#if defined(USE_HOMEDIR)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   529
	{
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
   530
		const char *homedir = getenv("HOME");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   531
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
   532
		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
   533
			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
   534
			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
   535
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   536
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   537
		_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
   538
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   539
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   540
#else /* not defined(USE_HOMEDIR) */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   541
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
   542
	_path.personal_dir = malloc(MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   543
	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
   544
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   545
	// check if absolute or relative path
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   546
	s = strchr(_path.personal_dir, '\\');
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
	// 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
   549
	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
   550
		getcwd(_path.personal_dir, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   551
		s = strchr(_path.personal_dir, 0);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   552
		*s++ = '\\';
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   553
		ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   554
	}
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
#endif /* defined(USE_HOMEDIR) */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   557
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   558
	s = strchr(_path.personal_dir, 0);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   559
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   560
	// 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
   561
	if (s[-1] != '\\') strcpy(s, "\\");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   562
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   563
	_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
   564
	_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
   565
	_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
   566
	_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
   567
	_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
   568
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
   569
	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
   570
		_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   571
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
   572
	_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
   573
	_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
   574
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   575
#if defined CUSTOM_LANG_DIR
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   576
	// 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
   577
	_path.lang_dir = malloc( MAX_PATH );
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   578
	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
   579
#else
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   580
	_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
   581
#endif
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   582
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   583
	// create necessary folders
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   584
	mkdir(_path.personal_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   585
	mkdir(_path.save_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   586
	mkdir(_path.autosave_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   587
	mkdir(_path.scenario_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   588
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   589
1888
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   590
/**
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   591
 * 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
   592
 * 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
   593
 * 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
   594
 * @param tb @Textbuf type to be changed
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   595
 * @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
   596
 */
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
   597
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
   598
{
1893
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   599
	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
   600
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
   601
	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
   602
	{
1893
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   603
		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
   604
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   605
		if (text != NULL)
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   606
		{
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   607
			uint length = 0;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   608
			uint width = 0;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   609
			const char* i;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   610
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   611
			for (i = text; IsValidAsciiChar(*i); i++)
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   612
			{
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   613
				uint w;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   614
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   615
				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
   616
3800
75a58f751bfe (svn r4808) - Fix GetCharacterWidth() change in os2.c missed in r4802.
peter1138
parents: 3329
diff changeset
   617
				w = GetCharacterWidth(FS_NORMAL, (byte)*i);
1893
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   618
				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
   619
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   620
				width += w;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   621
				length++;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   622
			}
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   623
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   624
			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
   625
			memcpy(tb->buf + tb->caretpos, text, length);
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   626
			tb->width += width;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   627
			tb->caretxoffs += width;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   628
			tb->length += length;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   629
			tb->caretpos += length;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   630
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   631
			WinCloseClipbrd(hab);
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   632
			return true;
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   633
		}
1888
dac7806032f8 (svn r2394) - Completed clipboard functions for OS/2 port
orudge
parents: 1887
diff changeset
   634
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
   635
		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
   636
	}
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
1893
99e4c49938af (svn r2399) - Fix: Update OS/2 project file with filename changes
orudge
parents: 1892
diff changeset
   638
	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
   639
}
1887
6107f7704454 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1817
diff changeset
   640
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
   641
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
   642
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
   643
{
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
   644
	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
   645
}