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