os2.c
author truelight
Thu, 24 Mar 2005 14:43:40 +0000
changeset 1540 6eef12dab5bf
parent 1524 d5cb3a8cfddc
child 1572 cf4613ca991e
permissions -rw-r--r--
(svn r2044) -Fix: fix that TriggerVehicle is called from the wrong user
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     1
#include "stdafx.h"
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     2
#include "ttd.h"
1390
e7cdf3ce0fb6 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
     3
#include "window.h"
1317
3c90086ff34f (svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents: 1301
diff changeset
     4
#include "string.h"
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     5
#include "table/strings.h"
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     6
#include "hal.h"
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     7
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     8
#include <direct.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
     9
#include <unistd.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    10
#include <sys/stat.h>
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    11
#include <stdarg.h>
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    12
#include <time.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    13
#include <dos.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    14
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    15
#define INCL_DOS
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    16
#define INCL_OS2MM
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
    17
#define INCL_WIN
1524
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
    18
#define INCL_WINCLIPBOARD
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    19
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    20
#include <os2.h>
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    21
#include <os2me.h>
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    22
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    23
#if defined(WITH_SDL)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    24
#include <SDL.h>
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    25
#endif
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    26
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    27
static inline int strcasecmp(const char* s1, const char* s2)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    28
{
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    29
	return stricmp(s1, s2);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    30
}
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    31
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    32
static char *_fios_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    33
static char *_fios_save_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    34
static char *_fios_scn_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    35
static FiosItem *_fios_items;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    36
static int _fios_count, _fios_alloc;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    37
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    38
static FiosItem *FiosAlloc(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    39
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    40
	if (_fios_count == _fios_alloc) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    41
		_fios_alloc += 256;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    42
		_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem));
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    43
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    44
	return &_fios_items[_fios_count++];
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    45
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    46
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    47
int compare_FiosItems(const void *a, const void *b)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    48
{
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    49
	const FiosItem *da = (const FiosItem *)a;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    50
	const FiosItem *db = (const FiosItem *)b;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    51
	int r;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    52
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    53
	if (_savegame_sort_order < 2) // sort by date
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    54
		r = da->mtime < db->mtime ? -1 : 1;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    55
	else
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    56
		r = strcasecmp(
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    57
			da->title[0] != '\0' ? da->title : da->name,
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    58
			db->title[0] != '\0' ? db->title : db->name
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    59
		);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    60
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    61
	if (_savegame_sort_order & 1) r = -r;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    62
	return r;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    63
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    64
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    65
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    66
static DIR *my_opendir(char *path, char *file)
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    67
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    68
	char paths[MAX_PATH];
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    69
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
    70
	append_path(paths, path, file);
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    71
	return opendir(paths);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    72
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    73
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    74
static void append_path(char *out, const char *path, const char *file)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    75
{
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
    76
	if (path[2] == '\\' && path[3] == '\0')
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    77
		sprintf(out, "%s%s", path, file);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    78
	else
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    79
		sprintf(out, "%s\\%s", path, file);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    80
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    81
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    82
// Get a list of savegames
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    83
FiosItem *FiosGetSavegameList(int *num, int mode)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    84
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    85
	FiosItem *fios;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    86
	DIR *dir;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    87
	struct dirent *dirent;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    88
	struct stat sb;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    89
	int sort_start;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    90
	char filename[MAX_PATH];
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    91
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    92
	if (_fios_save_path == NULL) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    93
		_fios_save_path = malloc(MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    94
		strcpy(_fios_save_path, _path.save_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    95
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    96
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
    97
	if (_game_mode == GM_EDITOR)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    98
		_fios_path = _fios_scn_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
    99
	else
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   100
		_fios_path = _fios_save_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   101
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   102
	// Parent directory, only if not of the type C:\.
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   103
	if (_fios_path[3] != '\0') {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   104
		fios = FiosAlloc();
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   105
		fios->type = FIOS_TYPE_PARENT;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   106
		fios->mtime = 0;
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   107
		strcpy(fios->title, ".. (Parent directory)");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   108
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   109
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   110
	// Show subdirectories first
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   111
	dir = my_opendir(_fios_path, "*.*");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   112
	if (dir != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   113
		while ((dirent = readdir(dir)) != NULL) {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   114
			append_path(filename, _fios_path, dirent->d_name);
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   115
			if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) &&
1506
ab7226c26e8f (svn r2010) - Fix: [ 1162209 ] Fix OS/2 build (orudge)
darkvater
parents: 1495
diff changeset
   116
					strcmp(filename, ".") != 0 &&
ab7226c26e8f (svn r2010) - Fix: [ 1162209 ] Fix OS/2 build (orudge)
darkvater
parents: 1495
diff changeset
   117
					strcmp(filename, "..") != 0) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   118
				fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   119
				fios->type = FIOS_TYPE_DIR;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   120
				fios->mtime = 0;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   121
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   122
				snprintf(fios->title, lengthof(fios->title),
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   123
					"%s\\ (Directory)", dirent->d_name);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   124
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   125
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   126
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   127
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   128
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   129
	{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   130
		/* XXX ugly global variables ... */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   131
		byte order = _savegame_sort_order;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   132
		_savegame_sort_order = 2; // sort ascending by name
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   133
		qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   134
		_savegame_sort_order = order;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   135
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   136
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   137
	// this is where to start sorting
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   138
	sort_start = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   139
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   140
	/* Show savegame files
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   141
	 * .SAV OpenTTD saved game
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   142
	 * .SS1 Transport Tycoon Deluxe preset game
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   143
	 * .SV1 Transport Tycoon Deluxe (Patch) saved game
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   144
	 * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   145
	 */
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   146
	dir = my_opendir(_fios_path, "*.*");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   147
	if (dir != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   148
		while ((dirent = readdir(dir)) != NULL) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   149
			char *t;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   150
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   151
			append_path(filename, _fios_path, dirent->d_name);
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   152
			if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   153
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   154
			t = strrchr(dirent->d_name, '.');
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   155
			if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   156
				fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   157
				fios->type = FIOS_TYPE_FILE;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   158
				fios->mtime = sb.st_mtime;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   159
				fios->title[0] = '\0';
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   160
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   161
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   162
				if (t != NULL && (
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   163
							strcasecmp(t, ".ss1") == 0 ||
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   164
							strcasecmp(t, ".sv1") == 0 ||
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   165
							strcasecmp(t, ".sv2") == 0
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   166
						)) { // TTDLX(Patch)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   167
					fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   168
					fios->type = FIOS_TYPE_OLDFILE;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   169
					fios->mtime = sb.st_mtime;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   170
					ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   171
					GetOldSaveGameName(fios->title, filename);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   172
				}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   173
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   174
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   175
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   176
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   177
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   178
	qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   179
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   180
	// Drives
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   181
	{
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   182
		uint save;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   183
		uint disk;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   184
		uint total;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   185
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   186
		/* save original drive */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   187
		_dos_getdrive(&save);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   188
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   189
		/* get available drive letters */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   190
		for (disk = 1; disk < 27; ++disk)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   191
		{
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   192
			uint disk2;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   193
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   194
			_dos_setdrive(disk, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   195
			_dos_getdrive(&disk2);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   196
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   197
			if (disk == disk2)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   198
			{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   199
				fios = FiosAlloc();
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   200
				fios->type = FIOS_TYPE_DRIVE;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   201
				sprintf(fios->title, "%c:", 'A' + disk - 1);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   202
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   203
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   204
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   205
		_dos_setdrive(save, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   206
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   207
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   208
	*num = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   209
	return _fios_items;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   210
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   211
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   212
// Get a list of scenarios
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   213
FiosItem *FiosGetScenarioList(int *num, int mode)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   214
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   215
	FiosItem *fios;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   216
	DIR *dir;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   217
	struct dirent *dirent;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   218
	struct stat sb;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   219
	int sort_start;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   220
	char filename[MAX_PATH];
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   221
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   222
	if (mode == SLD_NEW_GAME || _fios_scn_path == NULL) {
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   223
		if (_fios_scn_path == NULL)
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   224
			_fios_scn_path = malloc(MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   225
		strcpy(_fios_scn_path, _path.scenario_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   226
	}
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   227
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   228
	_fios_path = _fios_scn_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   229
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   230
	// Parent directory, only if not of the type C:\.
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   231
	if (_fios_path[3] != '\0' && mode != SLD_NEW_GAME) {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   232
		fios = FiosAlloc();
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   233
		fios->type = FIOS_TYPE_PARENT;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   234
		fios->mtime = 0;
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   235
		strcpy(fios->title, ".. (Parent directory)");
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   236
	}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   237
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   238
	// Show subdirectories first
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   239
	dir = my_opendir(_fios_path, "*.*");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   240
	if (dir != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   241
		while ((dirent = readdir(dir)) != NULL) {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   242
			append_path(filename, _fios_path, dirent->d_name);
1506
ab7226c26e8f (svn r2010) - Fix: [ 1162209 ] Fix OS/2 build (orudge)
darkvater
parents: 1495
diff changeset
   243
			if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) &&
ab7226c26e8f (svn r2010) - Fix: [ 1162209 ] Fix OS/2 build (orudge)
darkvater
parents: 1495
diff changeset
   244
					strcmp(filename, ".") != 0 &&
ab7226c26e8f (svn r2010) - Fix: [ 1162209 ] Fix OS/2 build (orudge)
darkvater
parents: 1495
diff changeset
   245
					strcmp(filename, "..") != 0) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   246
				fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   247
				fios->type = FIOS_TYPE_DIR;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   248
				fios->mtime = 0;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   249
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   250
				snprintf(fios->title, lengthof(fios->title),
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   251
					"%s\\ (Directory)", dirent->d_name);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   252
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   253
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   254
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   255
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   256
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   257
	// this is where to start sorting
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   258
	sort_start = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   259
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   260
	/* Show scenario files
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   261
	 * .SCN OpenTTD style scenario file
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   262
	 * .SV0 Transport Tycoon Deluxe (Patch) scenario
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   263
	 * .SS0 Transport Tycoon Deluxe preset scenario
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   264
	 */
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   265
	dir = my_opendir(_fios_path, "*.*");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   266
	if (dir != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   267
		while ((dirent = readdir(dir)) != NULL) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   268
			char *t;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   269
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   270
			append_path(filename, _fios_path, dirent->d_name);
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   271
			if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   272
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   273
			t = strrchr(dirent->d_name, '.');
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   274
			if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   275
				fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   276
				fios->type = FIOS_TYPE_SCENARIO;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   277
				fios->mtime = sb.st_mtime;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   278
				fios->title[0] = '\0';
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   279
				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   280
			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   281
					mode == SLD_NEW_GAME) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   282
				if (t != NULL && (
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   283
							strcasecmp(t, ".sv0") == 0 ||
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   284
							strcasecmp(t, ".ss0") == 0
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   285
						)) { // TTDLX(Patch)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   286
					fios = FiosAlloc();
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   287
					fios->type = FIOS_TYPE_OLD_SCENARIO;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   288
					fios->mtime = sb.st_mtime;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   289
					GetOldScenarioGameName(fios->title, filename);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   290
					ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   291
				}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   292
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   293
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   294
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   295
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   296
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   297
	qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   298
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   299
	// Drives
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   300
	if (mode != SLD_NEW_GAME)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   301
	{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   302
		unsigned save, disk, disk2, total;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   303
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   304
		/* save original drive */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   305
		_dos_getdrive(&save);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   306
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   307
		/* get available drive letters */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   308
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   309
		for (disk = 1; disk < 27; ++disk)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   310
		{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   311
			_dos_setdrive(disk, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   312
			_dos_getdrive(&disk2);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   313
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   314
			if (disk == disk2)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   315
			{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   316
				fios = FiosAlloc();
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   317
				fios->type = FIOS_TYPE_DRIVE;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   318
				fios->title[0] = disk + 'A'-1;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   319
				fios->title[1] = ':';
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   320
				fios->title[2] = 0;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   321
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   322
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   323
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   324
		_dos_setdrive(save, &total);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   325
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   326
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   327
	*num = _fios_count;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   328
	return _fios_items;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   329
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   330
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   331
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   332
// Free the list of savegames
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   333
void FiosFreeSavegameList(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   334
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   335
	free(_fios_items);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   336
	_fios_items = NULL;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   337
	_fios_alloc = _fios_count = 0;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   338
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   339
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   340
// Browse to
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   341
char *FiosBrowseTo(const FiosItem *item)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   342
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   343
	char *path = _fios_path;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   344
	char *s;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   345
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   346
	switch (item->type) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   347
		case FIOS_TYPE_DRIVE:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   348
			sprintf(path, "%c:\\", item->title[0]);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   349
			break;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   350
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   351
		case FIOS_TYPE_PARENT:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   352
			s = strrchr(path, '\\');
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   353
			if (s != NULL) *s = '\0';
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   354
			break;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   355
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   356
		case FIOS_TYPE_DIR:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   357
			s = strchr(item->name, '\\');
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   358
			if (s != NULL) *s = '\0';
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   359
			strcat(path, "\\");
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   360
			strcat(path, item->name);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   361
			break;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   362
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   363
		case FIOS_TYPE_FILE:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   364
		case FIOS_TYPE_OLDFILE:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   365
		case FIOS_TYPE_SCENARIO:
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   366
		case FIOS_TYPE_OLD_SCENARIO: {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   367
			static char str_buffr[512];
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   368
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   369
			sprintf(str_buffr, "%s\\%s", path, item->name);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   370
			return str_buffr;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   371
		}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   372
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   373
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   374
	return NULL;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   375
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   376
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   377
// Get descriptive texts.
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   378
// Returns a path as well as a
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   379
//  string describing the path.
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   380
StringID FiosGetDescText(const char **path)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   381
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   382
	struct diskfree_t free;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   383
	char drive;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   384
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   385
	*path = _fios_path;
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   386
	drive = *path[0] - 'A' + 1;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   387
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   388
	_getdiskfree(drive, &free);
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   389
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   390
	SetDParam(0, free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   391
	return STR_4005_BYTES_FREE;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   392
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   393
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   394
void FiosMakeSavegameName(char *buf, const char *name)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   395
{
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   396
	const char* extension;
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   397
	const char* period;
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   398
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   399
	if (_game_mode == GM_EDITOR)
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   400
		extension = ".scn";
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   401
	else
1508
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   402
		extension = ".sav";
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   403
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   404
	// Don't append the extension, if it is already there
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   405
	period = strrchr(name, '.');
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   406
	if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   407
faae7585cae7 (svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents: 1506
diff changeset
   408
	sprintf(buf, "%s\\%s%s", _fios_path, name, extension);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   409
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   410
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   411
void FiosDelete(const char *name)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   412
{
1336
69391734ce23 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   413
	char path[512];
69391734ce23 (svn r1840) Repel str_buffr and use local buffers where possible
tron
parents: 1317
diff changeset
   414
1495
a9e4e2b78877 (svn r1999) r1990 broke savegame deletion, fix that [1161729]
tron
parents: 1486
diff changeset
   415
	snprintf(path, lengthof(path), "%s\\%s", _fios_path, name);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   416
	unlink(path);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   417
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   418
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   419
const DriverDesc _video_driver_descs[] = {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   420
	{	"null",			"Null Video Driver",		&_null_video_driver,		0},
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   421
#if defined(WITH_SDL)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   422
	{	"sdl",			"SDL Video Driver",			&_sdl_video_driver,			1},
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   423
#endif
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   424
	{	"dedicated",	"Dedicated Video Driver",	&_dedicated_video_driver,	0},
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   425
	{	NULL,			NULL,						NULL,						0}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   426
};
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   427
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   428
const DriverDesc _sound_driver_descs[] = {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   429
	{	"null",	"Null Sound Driver",	&_null_sound_driver,		0},
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   430
#if defined(WITH_SDL)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   431
	{	"sdl",	"SDL Sound Driver",		&_sdl_sound_driver,			1},
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   432
#endif
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   433
	{	NULL,	NULL,					NULL,						0}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   434
};
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   435
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   436
const DriverDesc _music_driver_descs[] = {
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   437
	{	"os2",		"OS/2 Music Driver",		&_os2_music_driver,			0},
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   438
	{   "null",     "Null Music Driver",	    &_null_music_driver,	    1},
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   439
	{	NULL,		NULL,						NULL,						0}
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   440
};
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   441
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   442
/* GetOSVersion returns the minimal required version of OS to be able to use that driver.
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   443
	 Not needed for OS/2. */
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   444
byte GetOSVersion(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   445
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   446
	return 2;  // any arbitrary number bigger then 0
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   447
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   448
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   449
bool FileExists(const char *filename)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   450
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   451
	return access(filename, 0) == 0;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   452
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   453
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   454
static int LanguageCompareFunc(const void *a, const void *b)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   455
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   456
	return strcmp(*(const char* const *)a, *(const char* const *)b);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   457
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   458
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   459
int GetLanguageList(char **languages, int max)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   460
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   461
	DIR *dir;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   462
	struct dirent *dirent;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   463
	int num = 0;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   464
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   465
	dir = opendir(_path.lang_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   466
	if (dir != NULL) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   467
		while ((dirent = readdir(dir))) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   468
			char *t = strrchr(dirent->d_name, '.');
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   469
			if (t && !strcmp(t, ".lng")) {
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   470
				languages[num++] = strdup(dirent->d_name);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   471
				if (num == max) break;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   472
			}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   473
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   474
		closedir(dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   475
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   476
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   477
	qsort(languages, num, sizeof(char*), LanguageCompareFunc);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   478
	return num;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   479
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   480
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   481
static void ChangeWorkingDirectory(char *exe)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   482
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   483
	char *s = strrchr(exe, '\\');
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   484
	if (s != NULL) {
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   485
		*s = '\0';
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   486
		chdir(exe);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   487
		*s = '\\';
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   488
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   489
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   490
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   491
void ShowInfo(const char *str)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   492
{
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   493
	HAB hab;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   494
	HMQ hmq;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   495
	ULONG rc;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   496
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   497
	// init PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   498
	hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   499
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   500
	// display the box
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   501
	rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, str, "OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_INFORMATION);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   502
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   503
	// terminate PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   504
	WinDestroyMsgQueue(hmq);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   505
	WinTerminate(hab);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   506
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   507
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   508
void ShowOSErrorBox(const char *buf)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   509
{
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   510
	HAB hab;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   511
	HMQ hmq;
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   512
	ULONG rc;
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   513
818
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   514
	// init PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   515
	hmq = WinCreateMsgQueue((hab = WinInitialize(0)), 0);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   516
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   517
	// display the box
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   518
	rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, buf, "OpenTTD", 0, MB_OK | MB_MOVEABLE | MB_ERROR);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   519
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   520
	// terminate PM env.
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   521
	WinDestroyMsgQueue(hmq);
546a7894f312 (svn r1289) -Fix: Minor fix for OS/2 message boxes (orudge)
truelight
parents: 810
diff changeset
   522
	WinTerminate(hab);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   523
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   524
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   525
int CDECL main(int argc, char* argv[])
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   526
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   527
	// change the working directory to enable doubleclicking in UIs
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   528
	ChangeWorkingDirectory(argv[0]);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   529
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   530
	_random_seeds[0][1] = _random_seeds[0][0] = time(NULL);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   531
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   532
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   533
	return ttd_main(argc, argv);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   534
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   535
1390
e7cdf3ce0fb6 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1346
diff changeset
   536
void DeterminePaths(void)
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   537
{
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   538
	char *s;
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   539
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   540
	_path.game_data_dir = malloc(MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   541
	ttd_strlcpy(_path.game_data_dir, GAME_DATA_DIR, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   542
	#if defined SECOND_DATA_DIR
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   543
	_path.second_data_dir = malloc(MAX_PATH);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   544
	ttd_strlcpy(_path.second_data_dir, SECOND_DATA_DIR, MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   545
	#endif
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   546
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   547
#if defined(USE_HOMEDIR)
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   548
	{
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   549
		const char *homedir = getenv("HOME");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   550
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   551
		if (homedir == NULL) {
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   552
			const struct passwd *pw = getpwuid(getuid());
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   553
			if (pw != NULL) homedir = pw->pw_dir;
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   554
		}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   555
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   556
		_path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   557
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   558
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   559
#else /* not defined(USE_HOMEDIR) */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   560
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   561
	_path.personal_dir = malloc(MAX_PATH);
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   562
	ttd_strlcpy(_path.personal_dir, PERSONAL_DIR, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   563
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   564
	// check if absolute or relative path
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   565
	s = strchr(_path.personal_dir, '\\');
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   566
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   567
	// add absolute path
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   568
	if (s == NULL || _path.personal_dir != s) {
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   569
		getcwd(_path.personal_dir, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   570
		s = strchr(_path.personal_dir, 0);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   571
		*s++ = '\\';
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   572
		ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   573
	}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   574
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   575
#endif /* defined(USE_HOMEDIR) */
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   576
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   577
	s = strchr(_path.personal_dir, 0);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   578
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   579
	// append a / ?
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   580
	if (s[-1] != '\\') strcpy(s, "\\");
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   581
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   582
	_path.save_dir = str_fmt("%ssave", _path.personal_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   583
	_path.autosave_dir = str_fmt("%s\\autosave", _path.save_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   584
	_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   585
	_path.gm_dir = str_fmt("%sgm\\", _path.game_data_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   586
	_path.data_dir = str_fmt("%sdata\\", _path.game_data_dir);
1482
80e315adc3bd (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1390
diff changeset
   587
80e315adc3bd (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1390
diff changeset
   588
	if (_config_file == NULL)
80e315adc3bd (svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents: 1390
diff changeset
   589
		_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 818
diff changeset
   590
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   591
	_highscore_file = str_fmt("%shs.dat", _path.personal_dir);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   592
	_log_file = str_fmt("%sopenttd.log", _path.personal_dir);
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   593
801
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   594
#if defined CUSTOM_LANG_DIR
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   595
	// sets the search path for lng files to the custom one
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   596
	_path.lang_dir = malloc( MAX_PATH );
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   597
	ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   598
#else
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   599
	_path.lang_dir = str_fmt("%slang\\", _path.game_data_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   600
#endif
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   601
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   602
	// create necessary folders
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   603
	mkdir(_path.personal_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   604
	mkdir(_path.save_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   605
	mkdir(_path.autosave_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   606
	mkdir(_path.scenario_dir);
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   607
}
7b6cb481359c (svn r1271) -Fix: set eol-style to native on missing files
darkvater
parents: 782
diff changeset
   608
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   609
// FUNCTION: OS2_SwitchToConsoleMode
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   610
//
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   611
// Switches OpenTTD to a console app at run-time, instead of a PM app
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   612
// Necessary to see stdout, etc
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   613
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   614
void OS2_SwitchToConsoleMode(void)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   615
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   616
	PPIB pib;
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   617
	PTIB tib;
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   618
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   619
	DosGetInfoBlocks(&tib, &pib);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   620
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   621
	// Change flag from PM to VIO
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   622
	pib->pib_ultype = 3;
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   623
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   624
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   625
/**********************
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   626
 * OS/2 MIDI PLAYER
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   627
 **********************/
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   628
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   629
/* Interesting how similar the MCI API in OS/2 is to the Win32 MCI API,
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   630
 * eh? Anyone would think they both came from the same place originally! ;)
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   631
 */
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   632
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   633
static long CDECL MidiSendCommand(const char *cmd, ...)
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   634
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   635
	va_list va;
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   636
	char buf[512];
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   637
	va_start(va, cmd);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   638
	vsprintf(buf, cmd, va);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   639
	va_end(va);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   640
	return mciSendString(buf, NULL, 0, NULL, 0);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   641
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   642
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   643
static void OS2MidiPlaySong(const char *filename)
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   644
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   645
	MidiSendCommand("close all");
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   646
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   647
	if (MidiSendCommand("open %s type sequencer alias song", filename) != 0)
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   648
		return;
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   649
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   650
	MidiSendCommand("play song from 0");
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   651
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   652
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   653
static void OS2MidiStopSong(void)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   654
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   655
	MidiSendCommand("close all");
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   656
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   657
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   658
static void OS2MidiSetVolume(byte vol)
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   659
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   660
	MidiSendCommand("set song audio volume %d", ((vol/127)*100));
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   661
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   662
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   663
static bool OS2MidiIsSongPlaying(void)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   664
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   665
	char buf[16];
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   666
	mciSendString("status song mode", buf, sizeof(buf), NULL, 0);
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   667
	return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   668
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   669
1301
bf64ba5b6774 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 915
diff changeset
   670
static const char *OS2MidiStart(const char * const *parm)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   671
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   672
	return 0;
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   673
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   674
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   675
static void OS2MidiStop(void)
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   676
{
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   677
	MidiSendCommand("close all");
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   678
}
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   679
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   680
const HalMusicDriver _os2_music_driver = {
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   681
	OS2MidiStart,
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   682
	OS2MidiStop,
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   683
	OS2MidiPlaySong,
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   684
	OS2MidiStopSong,
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   685
	OS2MidiIsSongPlaying,
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   686
	OS2MidiSetVolume,
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   687
};
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 801
diff changeset
   688
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   689
bool InsertTextBufferClipboard(Textbuf *tb)
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   690
{
1524
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   691
#if 0
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   692
	HAB hab = 0; // anchor-block handle
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   693
	PSZ pszClipText, pszLocalText;
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   694
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   695
	if (WinOpenClipbrd(hab))
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   696
	{
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   697
		if (pszClipText = (PSZ) WinQueryClipbrdData(hab, CF_TEXT))
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   698
		{
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   699
			while (*pszLocalText++ = *pszClipText++);
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   700
		}
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   701
		WinCloseClipbrd(hab);
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   702
	}
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   703
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   704
	// text is now in pszLocalText, do something with it!
d5cb3a8cfddc (svn r2028) Added detection of SVN version (rev.c generation) for OS/2, updated readme, initial clipboard support (orudge)
celestar
parents: 1508
diff changeset
   705
#endif
1506
ab7226c26e8f (svn r2010) - Fix: [ 1162209 ] Fix OS/2 build (orudge)
darkvater
parents: 1495
diff changeset
   706
	// TODO
1486
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   707
	return false;
647d3a2be4fe (svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents: 1482
diff changeset
   708
}