author | bjarni |
Sun, 24 Jul 2005 20:47:42 +0000 | |
changeset 2188 | 9acde6fcc645 |
parent 2186 | 461a2aff3486 |
child 2195 | 8960c86bf103 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1892
45894b95a925
(svn r2398) - CodeChange: forgot to update unix and os2 specific files as well.
Darkvater
parents:
1885
diff
changeset
|
4 |
#include "openttd.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
5 |
#include "functions.h" |
1390
53a5713cf3f9
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1346
diff
changeset
|
6 |
#include "window.h" |
1317
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1093
diff
changeset
|
7 |
#include "string.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
437
diff
changeset
|
8 |
#include "table/strings.h" |
0 | 9 |
#include "hal.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2099
diff
changeset
|
10 |
#include "variables.h" |
0 | 11 |
|
2177
73d67828ea5e
(svn r2691) Separate dedicated video driver and fix bemidi declarations
tron
parents:
2174
diff
changeset
|
12 |
#include "music/bemidi.h" |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
13 |
#include "music/extmidi.h" |
2174
41d7c884dc52
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
2171
diff
changeset
|
14 |
#include "music/null_m.h" |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
15 |
|
2174
41d7c884dc52
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
2171
diff
changeset
|
16 |
#include "sound/null_s.h" |
41d7c884dc52
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
2171
diff
changeset
|
17 |
#include "sound/sdl_s.h" |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
18 |
|
2177
73d67828ea5e
(svn r2691) Separate dedicated video driver and fix bemidi declarations
tron
parents:
2174
diff
changeset
|
19 |
#include "video/dedicated_v.h" |
2174
41d7c884dc52
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
2171
diff
changeset
|
20 |
#include "video/null_v.h" |
41d7c884dc52
(svn r2688) MSVC and Watcom can't handle identical file names in different directories, oh my...
tron
parents:
2171
diff
changeset
|
21 |
#include "video/sdl_v.h" |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
22 |
|
0 | 23 |
#include <dirent.h> |
24 |
#include <unistd.h> |
|
25 |
#include <sys/stat.h> |
|
26 |
#include <time.h> |
|
27 |
#include <pwd.h> |
|
1509
2c232b7d2114
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
28 |
#include <signal.h> |
1911
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
29 |
#if !defined(__MORPHOS__) && !defined(__AMIGA__) |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
30 |
#include <pthread.h> |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
31 |
#endif |
0 | 32 |
|
1850
7fa9e3ecb486
(svn r2356) Make check if statvfs() is availible a bit more sensible
tron
parents:
1687
diff
changeset
|
33 |
#if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__) |
1597
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
34 |
#define HAS_STATVFS |
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
35 |
#endif |
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
36 |
|
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
37 |
#ifdef HAS_STATVFS |
0 | 38 |
#include <sys/statvfs.h> |
39 |
#endif |
|
40 |
||
41 |
||
42 |
#if defined(WITH_SDL) |
|
43 |
#include <SDL.h> |
|
44 |
#endif |
|
45 |
||
46 |
#ifdef __MORPHOS__ |
|
47 |
#include <exec/types.h> |
|
48 |
ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;) |
|
49 |
#endif /* __MORPHOS__ */ |
|
50 |
||
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
51 |
#ifdef __AMIGA__ |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
52 |
#warning add stack symbol to avoid that user needs to set stack manually (tokai) |
915 | 53 |
// ULONG __stack = |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
54 |
#endif |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
55 |
|
2188
9acde6fcc645
(svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
2186
diff
changeset
|
56 |
#if defined(__APPLE__) |
9acde6fcc645
(svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
2186
diff
changeset
|
57 |
#include "os/macosx/macos.h" |
9acde6fcc645
(svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
2186
diff
changeset
|
58 |
#endif |
9acde6fcc645
(svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
2186
diff
changeset
|
59 |
|
0 | 60 |
static char *_fios_path; |
61 |
static char *_fios_save_path; |
|
62 |
static char *_fios_scn_path; |
|
63 |
static FiosItem *_fios_items; |
|
64 |
static int _fios_count, _fios_alloc; |
|
65 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1050
diff
changeset
|
66 |
static FiosItem *FiosAlloc(void) |
0 | 67 |
{ |
68 |
if (_fios_count == _fios_alloc) { |
|
69 |
_fios_alloc += 256; |
|
70 |
_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem)); |
|
71 |
} |
|
72 |
return &_fios_items[_fios_count++]; |
|
73 |
} |
|
74 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
75 |
int compare_FiosItems(const void *a, const void *b) |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
76 |
{ |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
77 |
const FiosItem *da = (const FiosItem *)a; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
78 |
const FiosItem *db = (const FiosItem *)b; |
0 | 79 |
int r; |
80 |
||
81 |
if (_savegame_sort_order < 2) // sort by date |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
82 |
r = da->mtime < db->mtime ? -1 : 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
83 |
else |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
84 |
r = strcasecmp(da->title, db->title); |
0 | 85 |
|
86 |
if (_savegame_sort_order & 1) r = -r; |
|
87 |
return r; |
|
88 |
} |
|
89 |
||
90 |
||
91 |
// Get a list of savegames |
|
92 |
FiosItem *FiosGetSavegameList(int *num, int mode) |
|
93 |
{ |
|
94 |
FiosItem *fios; |
|
95 |
DIR *dir; |
|
96 |
struct dirent *dirent; |
|
97 |
struct stat sb; |
|
98 |
int sort_start; |
|
99 |
char filename[MAX_PATH]; |
|
100 |
||
101 |
if (_fios_save_path == NULL) { |
|
102 |
_fios_save_path = malloc(MAX_PATH); |
|
103 |
strcpy(_fios_save_path, _path.save_dir); |
|
104 |
} |
|
105 |
||
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
106 |
_fios_path = _fios_save_path; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
107 |
|
0 | 108 |
// Parent directory, only if not in root already. |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
109 |
if (_fios_path[1] != '\0') { |
0 | 110 |
fios = FiosAlloc(); |
111 |
fios->type = FIOS_TYPE_PARENT; |
|
112 |
fios->mtime = 0; |
|
1572
6d0111113f0b
(svn r2076) Set the name for the parent directory to ".."
tron
parents:
1509
diff
changeset
|
113 |
strcpy(fios->name, ".."); |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
114 |
strcpy(fios->title, ".. (Parent directory)"); |
0 | 115 |
} |
116 |
||
117 |
// Show subdirectories first |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
118 |
dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/"); |
0 | 119 |
if (dir != NULL) { |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
120 |
while ((dirent = readdir(dir)) != NULL) { |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
121 |
snprintf(filename, lengthof(filename), "%s/%s", |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
122 |
_fios_path, dirent->d_name); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
123 |
if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) && |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
124 |
dirent->d_name[0] != '.') { |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
125 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
126 |
fios->type = FIOS_TYPE_DIR; |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
127 |
fios->mtime = 0; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
128 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
129 |
snprintf(fios->title, lengthof(fios->title), |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
130 |
"%s/ (Directory)", dirent->d_name); |
0 | 131 |
} |
132 |
} |
|
133 |
closedir(dir); |
|
134 |
} |
|
135 |
||
307
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
136 |
{ |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
137 |
/* XXX ugly global variables ... */ |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
138 |
byte order = _savegame_sort_order; |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
139 |
_savegame_sort_order = 2; // sort ascending by name |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
140 |
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems); |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
141 |
_savegame_sort_order = order; |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
142 |
} |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
143 |
|
0 | 144 |
// this is where to start sorting |
145 |
sort_start = _fios_count; |
|
146 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
147 |
/* Show savegame files |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
148 |
* .SAV OpenTTD saved game |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
149 |
* .SS1 Transport Tycoon Deluxe preset game |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
150 |
* .SV1 Transport Tycoon Deluxe (Patch) saved game |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
151 |
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game |
0 | 152 |
*/ |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
153 |
dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/"); |
0 | 154 |
if (dir != NULL) { |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
155 |
while ((dirent = readdir(dir)) != NULL) { |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
156 |
char *t; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
157 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
158 |
snprintf(filename, lengthof(filename), "%s/%s", |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
159 |
_fios_path, dirent->d_name); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
160 |
if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
161 |
|
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
162 |
t = strrchr(dirent->d_name, '.'); |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
163 |
if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
164 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
165 |
fios->type = FIOS_TYPE_FILE; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
166 |
fios->mtime = sb.st_mtime; |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
167 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
168 |
|
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
169 |
*t = '\0'; // strip extension |
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
170 |
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
171 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
172 |
if (t != NULL && ( |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
173 |
strcasecmp(t, ".ss1") == 0 || |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
174 |
strcasecmp(t, ".sv1") == 0 || |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
175 |
strcasecmp(t, ".sv2") == 0 |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
176 |
)) { // TTDLX(Patch) |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
177 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
178 |
fios->type = FIOS_TYPE_OLDFILE; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
179 |
fios->mtime = sb.st_mtime; |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
180 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
181 |
GetOldSaveGameName(fios->title, filename); |
0 | 182 |
} |
183 |
} |
|
184 |
} |
|
185 |
closedir(dir); |
|
186 |
} |
|
187 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
188 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 189 |
*num = _fios_count; |
190 |
return _fios_items; |
|
191 |
} |
|
192 |
||
193 |
// Get a list of scenarios |
|
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
194 |
// FIXME: Gross code duplication with FiosGetSavegameList() |
0 | 195 |
FiosItem *FiosGetScenarioList(int *num, int mode) |
196 |
{ |
|
197 |
FiosItem *fios; |
|
198 |
DIR *dir; |
|
199 |
struct dirent *dirent; |
|
200 |
struct stat sb; |
|
201 |
int sort_start; |
|
202 |
char filename[MAX_PATH]; |
|
203 |
||
204 |
if (_fios_scn_path == NULL) { |
|
205 |
_fios_scn_path = malloc(MAX_PATH); |
|
206 |
strcpy(_fios_scn_path, _path.scenario_dir); |
|
207 |
} |
|
208 |
_fios_path = _fios_scn_path; |
|
209 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
210 |
// Parent directory, only if not of the type C:\. |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
211 |
if (_fios_path[1] != '\0' && mode != SLD_NEW_GAME) { |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
212 |
fios = FiosAlloc(); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
213 |
fios->type = FIOS_TYPE_PARENT; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
214 |
fios->mtime = 0; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
215 |
strcpy(fios->title, ".. (Parent directory)"); |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
216 |
} |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
217 |
|
0 | 218 |
// Show subdirectories first |
219 |
dir = opendir(_fios_path[0] ? _fios_path : "/"); |
|
220 |
if (dir != NULL) { |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
221 |
while ((dirent = readdir(dir)) != NULL) { |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
222 |
snprintf(filename, lengthof(filename), "%s/%s", |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
223 |
_fios_path, dirent->d_name); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
224 |
if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) && |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
225 |
dirent->d_name[0] != '.') { |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
226 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
227 |
fios->type = FIOS_TYPE_DIR; |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
228 |
fios->mtime = 0; |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
229 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
230 |
snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name); |
0 | 231 |
} |
232 |
} |
|
233 |
closedir(dir); |
|
234 |
} |
|
235 |
||
236 |
// this is where to start sorting |
|
237 |
sort_start = _fios_count; |
|
238 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
239 |
/* Show scenario files |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
240 |
* .SCN OpenTTD style scenario file |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
241 |
* .SV0 Transport Tycoon Deluxe (Patch) scenario |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
242 |
* .SS0 Transport Tycoon Deluxe preset scenario |
0 | 243 |
*/ |
244 |
dir = opendir(_fios_path[0] ? _fios_path : "/"); |
|
245 |
if (dir != NULL) { |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
246 |
while ((dirent = readdir(dir)) != NULL) { |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
247 |
char *t; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
248 |
|
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
249 |
snprintf(filename, lengthof(filename), "%s/%s", _fios_path, dirent->d_name); |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
250 |
if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
251 |
|
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
252 |
t = strrchr(dirent->d_name, '.'); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
253 |
if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
254 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
255 |
fios->type = FIOS_TYPE_SCENARIO; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
256 |
fios->mtime = sb.st_mtime; |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
257 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
258 |
|
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
259 |
*t = '\0'; // strip extension |
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
260 |
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
261 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
262 |
mode == SLD_NEW_GAME) { |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
263 |
if (t != NULL && ( |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
264 |
strcasecmp(t, ".sv0") == 0 || |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
265 |
strcasecmp(t, ".ss0") == 0 |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
266 |
)) { // TTDLX(Patch) |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
267 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
268 |
fios->type = FIOS_TYPE_OLD_SCENARIO; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
269 |
fios->mtime = sb.st_mtime; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
270 |
GetOldScenarioGameName(fios->title, filename); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
271 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
0 | 272 |
} |
273 |
} |
|
274 |
} |
|
275 |
closedir(dir); |
|
276 |
} |
|
277 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
278 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 279 |
*num = _fios_count; |
280 |
return _fios_items; |
|
281 |
} |
|
282 |
||
283 |
||
284 |
// Free the list of savegames |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1050
diff
changeset
|
285 |
void FiosFreeSavegameList(void) |
0 | 286 |
{ |
287 |
free(_fios_items); |
|
288 |
_fios_items = NULL; |
|
289 |
_fios_alloc = _fios_count = 0; |
|
290 |
} |
|
291 |
||
292 |
// Browse to |
|
293 |
char *FiosBrowseTo(const FiosItem *item) |
|
294 |
{ |
|
295 |
char *path = _fios_path; |
|
296 |
char *s; |
|
297 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
298 |
switch (item->type) { |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
299 |
case FIOS_TYPE_PARENT: |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
300 |
s = strrchr(path, '/'); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
301 |
if (s != NULL) *s = '\0'; |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
302 |
break; |
0 | 303 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
304 |
case FIOS_TYPE_DIR: |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
305 |
s = strchr(item->name, '/'); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
306 |
if (s != NULL) *s = '\0'; |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
307 |
strcat(path, "/"); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
308 |
strcat(path, item->name); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
309 |
break; |
0 | 310 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
311 |
case FIOS_TYPE_FILE: |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
312 |
case FIOS_TYPE_OLDFILE: |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
313 |
case FIOS_TYPE_SCENARIO: |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
314 |
case FIOS_TYPE_OLD_SCENARIO: { |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
315 |
static char str_buffr[512]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
316 |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
317 |
sprintf(str_buffr, "%s/%s", path, item->name); |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
318 |
return str_buffr; |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
319 |
} |
0 | 320 |
} |
321 |
||
322 |
return NULL; |
|
323 |
} |
|
324 |
||
1596
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
325 |
/** |
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
326 |
* Get descriptive texts. Returns the path and free space |
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
327 |
* left on the device |
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
328 |
* @param path string describing the path |
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
329 |
* @param tfs total free space in megabytes, optional (can be NULL) |
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
330 |
* @return StringID describing the path (free space or failure) |
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
331 |
*/ |
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
332 |
StringID FiosGetDescText(const char **path, uint32 *tot) |
0 | 333 |
{ |
1596
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
334 |
uint32 free = 0; |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
335 |
*path = _fios_path[0] != '\0' ? _fios_path : "/"; |
0 | 336 |
|
1597
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
337 |
#ifdef HAS_STATVFS |
0 | 338 |
{ |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
339 |
struct statvfs s; |
0 | 340 |
|
1597
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
341 |
if (statvfs(*path, &s) == 0) { |
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
342 |
free = (uint64)s.f_frsize * s.f_bavail >> 20; |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
343 |
} else |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
344 |
return STR_4006_UNABLE_TO_READ_DRIVE; |
0 | 345 |
} |
1596
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
346 |
#endif |
c1c439a2d5b2
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
347 |
if (tot != NULL) *tot = free; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
348 |
return STR_4005_BYTES_FREE; |
0 | 349 |
} |
350 |
||
351 |
void FiosMakeSavegameName(char *buf, const char *name) |
|
352 |
{ |
|
1508
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
353 |
const char* extension; |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
354 |
const char* period; |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
355 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
356 |
if (_game_mode == GM_EDITOR) |
1508
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
357 |
extension = ".scn"; |
0 | 358 |
else |
1508
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
359 |
extension = ".sav"; |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
360 |
|
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
361 |
// Don't append the extension, if it is already there |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
362 |
period = strrchr(name, '.'); |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
363 |
if (period != NULL && strcasecmp(period, extension) == 0) extension = ""; |
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
364 |
|
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
365 |
sprintf(buf, "%s/%s%s", _fios_path, name, extension); |
0 | 366 |
} |
367 |
||
368 |
void FiosDelete(const char *name) |
|
369 |
{ |
|
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
370 |
char path[512]; |
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
371 |
|
1495
c8a61d136f26
(svn r1999) r1990 broke savegame deletion, fix that [1161729]
tron
parents:
1486
diff
changeset
|
372 |
snprintf(path, lengthof(path), "%s/%s", _fios_path, name); |
0 | 373 |
unlink(path); |
374 |
} |
|
375 |
||
376 |
const DriverDesc _video_driver_descs[] = { |
|
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
377 |
{"null", "Null Video Driver", &_null_video_driver, 0}, |
0 | 378 |
#if defined(WITH_SDL) |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
379 |
{ "sdl", "SDL Video Driver", &_sdl_video_driver, 1}, |
0 | 380 |
#endif |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
381 |
{ "dedicated", "Dedicated Video Driver", &_dedicated_video_driver, 0}, |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
382 |
{ NULL, NULL, NULL, 0} |
0 | 383 |
}; |
384 |
||
385 |
const DriverDesc _sound_driver_descs[] = { |
|
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
386 |
{"null", "Null Sound Driver", &_null_sound_driver, 0}, |
0 | 387 |
#if defined(WITH_SDL) |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
388 |
{ "sdl", "SDL Sound Driver", &_sdl_sound_driver, 1}, |
0 | 389 |
#endif |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
390 |
{ NULL, NULL, NULL, 0} |
0 | 391 |
}; |
392 |
||
393 |
#if defined(__APPLE__) |
|
394 |
#define EXTMIDI_PRI 2 |
|
395 |
#else |
|
396 |
#define EXTMIDI_PRI 0 |
|
397 |
#endif |
|
398 |
||
399 |
const DriverDesc _music_driver_descs[] = { |
|
400 |
#ifndef __BEOS__ |
|
569
2e86ae517874
(svn r980) Fixed issues where MorphOS would get problems if AmigaOS would get a port, since MorphOS also have the flag __AMIGA__ defined (Tokai)
bjarni
parents:
561
diff
changeset
|
401 |
#if !defined(__MORPHOS__) && !defined(__AMIGA__) |
2e86ae517874
(svn r980) Fixed issues where MorphOS would get problems if AmigaOS would get a port, since MorphOS also have the flag __AMIGA__ defined (Tokai)
bjarni
parents:
561
diff
changeset
|
402 |
// MorphOS and AmigaOS have no music support |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
403 |
{"extmidi", "External MIDI Driver", &_extmidi_music_driver, EXTMIDI_PRI}, |
0 | 404 |
#endif |
405 |
#endif |
|
406 |
#ifdef __BEOS__ |
|
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
407 |
{ "bemidi", "BeOS MIDI Driver", &_bemidi_music_driver, 1}, |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
408 |
#endif |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
409 |
{ "null", "Null Music Driver", &_null_music_driver, 1}, |
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
410 |
{ NULL, NULL, NULL, 0} |
0 | 411 |
}; |
412 |
||
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
413 |
/* GetOSVersion returns the minimal required version of OS to be able to use that driver. |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
414 |
Not needed for *nix. */ |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1050
diff
changeset
|
415 |
byte GetOSVersion(void) |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
416 |
{ |
826 | 417 |
return 2; // any arbitrary number bigger than 0 |
268
00fabd0160bc
(svn r274) Mac: restored extmusic to be default, which were accidently turned off by a windows music fix
bjarni
parents:
238
diff
changeset
|
418 |
// numbers lower than 2 breaks default music selection on mac |
223
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
419 |
} |
0e5cc5a65df6
(svn r224) -Fix: Music now finally works on WinXP. DirectMusic is now default for an OS >= WinNT4 (WinNT4, Win2k, WinXP), and MIDI driver for lower OS's (Win95, Win98, WinME, etc).
darkvater
parents:
222
diff
changeset
|
420 |
|
0 | 421 |
bool FileExists(const char *filename) |
422 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
423 |
return access(filename, 0) == 0; |
0 | 424 |
} |
425 |
||
426 |
static int LanguageCompareFunc(const void *a, const void *b) |
|
427 |
{ |
|
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
206
diff
changeset
|
428 |
return strcmp(*(const char* const *)a, *(const char* const *)b); |
0 | 429 |
} |
430 |
||
431 |
int GetLanguageList(char **languages, int max) |
|
432 |
{ |
|
433 |
DIR *dir; |
|
434 |
struct dirent *dirent; |
|
435 |
int num = 0; |
|
436 |
||
437 |
dir = opendir(_path.lang_dir); |
|
438 |
if (dir != NULL) { |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
439 |
while ((dirent = readdir(dir)) != NULL) { |
0 | 440 |
char *t = strrchr(dirent->d_name, '.'); |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
441 |
|
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
442 |
if (t != NULL && strcmp(t, ".lng") == 0) { |
0 | 443 |
languages[num++] = strdup(dirent->d_name); |
444 |
if (num == max) break; |
|
445 |
} |
|
446 |
} |
|
447 |
closedir(dir); |
|
448 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
449 |
|
0 | 450 |
qsort(languages, num, sizeof(char*), LanguageCompareFunc); |
451 |
return num; |
|
452 |
} |
|
453 |
||
1050
e76fa5c5d835
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
454 |
#if defined(__BEOS__) || defined(__linux__) |
410 | 455 |
static void ChangeWorkingDirectory(char *exe) |
0 | 456 |
{ |
457 |
char *s = strrchr(exe, '/'); |
|
458 |
if (s != NULL) { |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
459 |
*s = '\0'; |
0 | 460 |
chdir(exe); |
461 |
*s = '/'; |
|
462 |
} |
|
463 |
} |
|
1050
e76fa5c5d835
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
464 |
#endif |
0 | 465 |
|
466 |
void ShowInfo(const char *str) |
|
467 |
{ |
|
468 |
puts(str); |
|
469 |
} |
|
470 |
||
471 |
void ShowOSErrorBox(const char *buf) |
|
472 |
{ |
|
529
3b23d5073d32
(svn r869) Mac: finally made asserts open the console, so people should be able to see what went wrong even if they opened the game in the GUI
bjarni
parents:
507
diff
changeset
|
473 |
#if defined(__APPLE__) |
2188
9acde6fcc645
(svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
2186
diff
changeset
|
474 |
// this creates an NSAlertPanel with the contents of 'buf' |
9acde6fcc645
(svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
2186
diff
changeset
|
475 |
// this is the native and nicest way to do this on OSX |
9acde6fcc645
(svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
bjarni
parents:
2186
diff
changeset
|
476 |
ShowMacDialog( buf, "See readme for more info\nMost likely you are missing files from the original TTD", "Quit" ); |
529
3b23d5073d32
(svn r869) Mac: finally made asserts open the console, so people should be able to see what went wrong even if they opened the game in the GUI
bjarni
parents:
507
diff
changeset
|
477 |
#else |
3b23d5073d32
(svn r869) Mac: finally made asserts open the console, so people should be able to see what went wrong even if they opened the game in the GUI
bjarni
parents:
507
diff
changeset
|
478 |
// all systems, but OSX |
0 | 479 |
fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf); |
480 |
#endif |
|
481 |
} |
|
482 |
||
483 |
int CDECL main(int argc, char* argv[]) |
|
484 |
{ |
|
485 |
// change the working directory to enable doubleclicking in UIs |
|
1050
e76fa5c5d835
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
486 |
#if defined(__BEOS__) || defined(__linux__) |
0 | 487 |
ChangeWorkingDirectory(argv[0]); |
488 |
#endif |
|
489 |
||
206 | 490 |
_random_seeds[0][1] = _random_seeds[0][0] = time(NULL); |
2073 | 491 |
SeedMT(_random_seeds[0][1]); |
0 | 492 |
|
1509
2c232b7d2114
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
493 |
signal(SIGPIPE, SIG_IGN); |
0 | 494 |
|
495 |
return ttd_main(argc, argv); |
|
496 |
} |
|
497 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1050
diff
changeset
|
498 |
void DeterminePaths(void) |
0 | 499 |
{ |
500 |
char *s; |
|
501 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
502 |
_path.game_data_dir = malloc(MAX_PATH); |
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
503 |
ttd_strlcpy(_path.game_data_dir, GAME_DATA_DIR, MAX_PATH); |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
504 |
#if defined SECOND_DATA_DIR |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
505 |
_path.second_data_dir = malloc(MAX_PATH); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
506 |
ttd_strlcpy(_path.second_data_dir, SECOND_DATA_DIR, MAX_PATH); |
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
507 |
#endif |
0 | 508 |
|
509 |
#if defined(USE_HOMEDIR) |
|
510 |
{ |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
511 |
const char *homedir = getenv("HOME"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
512 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
513 |
if (homedir == NULL) { |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
514 |
const struct passwd *pw = getpwuid(getuid()); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
515 |
if (pw != NULL) homedir = pw->pw_dir; |
0 | 516 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
517 |
|
0 | 518 |
_path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
519 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
520 |
|
0 | 521 |
#else /* not defined(USE_HOMEDIR) */ |
522 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
523 |
_path.personal_dir = malloc(MAX_PATH); |
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
524 |
ttd_strlcpy(_path.personal_dir, PERSONAL_DIR, MAX_PATH); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
525 |
|
0 | 526 |
// check if absolute or relative path |
527 |
s = strchr(_path.personal_dir, '/'); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
528 |
|
0 | 529 |
// add absolute path |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
530 |
if (s == NULL || _path.personal_dir != s) { |
0 | 531 |
getcwd(_path.personal_dir, MAX_PATH); |
532 |
s = strchr(_path.personal_dir, 0); |
|
533 |
*s++ = '/'; |
|
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
534 |
ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
0 | 535 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
536 |
|
0 | 537 |
#endif /* defined(USE_HOMEDIR) */ |
538 |
||
539 |
s = strchr(_path.personal_dir, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
540 |
|
0 | 541 |
// append a / ? |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
542 |
if (s[-1] != '/') strcpy(s, "/"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
543 |
|
0 | 544 |
_path.save_dir = str_fmt("%ssave", _path.personal_dir); |
545 |
_path.autosave_dir = str_fmt("%s/autosave", _path.save_dir); |
|
546 |
_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir); |
|
547 |
_path.gm_dir = str_fmt("%sgm/", _path.game_data_dir); |
|
548 |
_path.data_dir = str_fmt("%sdata/", _path.game_data_dir); |
|
1482
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1470
diff
changeset
|
549 |
|
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1470
diff
changeset
|
550 |
if (_config_file == NULL) |
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1470
diff
changeset
|
551 |
_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir); |
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1470
diff
changeset
|
552 |
|
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
915
diff
changeset
|
553 |
_highscore_file = str_fmt("%shs.dat", _path.personal_dir); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
569
diff
changeset
|
554 |
_log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
915 | 555 |
|
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
556 |
#if defined CUSTOM_LANG_DIR |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
557 |
// sets the search path for lng files to the custom one |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
558 |
_path.lang_dir = malloc( MAX_PATH ); |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
559 |
ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH); |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
560 |
#else |
0 | 561 |
_path.lang_dir = str_fmt("%slang/", _path.game_data_dir); |
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
562 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
563 |
|
238
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
564 |
// create necessary folders |
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
565 |
mkdir(_path.personal_dir, 0755); |
0 | 566 |
mkdir(_path.save_dir, 0755); |
567 |
mkdir(_path.autosave_dir, 0755); |
|
568 |
mkdir(_path.scenario_dir, 0755); |
|
569 |
} |
|
570 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
571 |
bool InsertTextBufferClipboard(Textbuf *tb) |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
572 |
{ |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
573 |
return false; |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
574 |
} |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
575 |
|
1911
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
576 |
/** Dummy stubs as MorphOS/ AmigaOS does not really |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
577 |
* know about a thread concept nor has a working libpthread */ |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
578 |
#if defined(__MORPHOS__) || defined(__AMIGA__) |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
579 |
typedef int pthread_t; |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
580 |
#define pthread_create(thread, attr, function, arg) (true) |
1912 | 581 |
#define pthread_join(thread, retval) |
1911
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
582 |
#endif |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
583 |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
584 |
static pthread_t thread1 = 0; |
1911
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
585 |
|
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
586 |
bool CreateOTTDThread(void *func, void *param) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
587 |
{ |
1899
98317b840d7b
(svn r2405) Simplify a few '? true : false' and '? false : true', especially the latter is confusing
tron
parents:
1892
diff
changeset
|
588 |
return pthread_create(&thread1, NULL, func, param) == 0; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
589 |
} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
590 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
591 |
void CloseOTTDThread(void) {return;} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
592 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
593 |
void JoinOTTDThread(void) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
594 |
{ |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
595 |
if (thread1 == 0) return; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
596 |
|
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
597 |
pthread_join(thread1, NULL); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
598 |
} |
2073 | 599 |
|
600 |
||
601 |
||
602 |
#ifdef ENABLE_NETWORK |
|
603 |
||
604 |
// multi os compatible sleep function |
|
605 |
||
606 |
#ifdef __AMIGA__ |
|
607 |
// usleep() implementation |
|
608 |
# include <devices/timer.h> |
|
609 |
# include <dos/dos.h> |
|
610 |
||
611 |
extern struct Device *TimerBase = NULL; |
|
612 |
extern struct MsgPort *TimerPort = NULL; |
|
613 |
extern struct timerequest *TimerRequest = NULL; |
|
614 |
#endif // __AMIGA__ |
|
615 |
||
616 |
void CSleep(int milliseconds) |
|
617 |
{ |
|
618 |
#if !defined(__BEOS__) && !defined(__AMIGA__) |
|
619 |
usleep(milliseconds * 1000); |
|
620 |
#endif |
|
621 |
#ifdef __BEOS__ |
|
622 |
snooze(milliseconds * 1000); |
|
623 |
#endif |
|
624 |
#if defined(__AMIGA__) |
|
625 |
{ |
|
626 |
ULONG signals; |
|
627 |
ULONG TimerSigBit = 1 << TimerPort->mp_SigBit; |
|
628 |
||
629 |
// send IORequest |
|
630 |
TimerRequest->tr_node.io_Command = TR_ADDREQUEST; |
|
631 |
TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000; |
|
632 |
TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000; |
|
633 |
SendIO((struct IORequest *)TimerRequest); |
|
634 |
||
635 |
if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) { |
|
636 |
AbortIO((struct IORequest *)TimerRequest); |
|
637 |
} |
|
638 |
WaitIO((struct IORequest *)TimerRequest); |
|
639 |
} |
|
640 |
#endif // __AMIGA__ |
|
641 |
} |
|
642 |
||
643 |
#endif /* ENABLE_NETWORK */ |
|
644 |