author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1509 | 795ba683e4f0 |
child 1572 | cf4613ca991e |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
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:
1093
diff
changeset
|
4 |
#include "string.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
437
diff
changeset
|
5 |
#include "table/strings.h" |
0 | 6 |
#include "hal.h" |
7 |
||
8 |
#include <dirent.h> |
|
9 |
#include <unistd.h> |
|
10 |
#include <sys/stat.h> |
|
11 |
#include <time.h> |
|
12 |
#include <pwd.h> |
|
1509
795ba683e4f0
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
13 |
#include <signal.h> |
0 | 14 |
|
15 |
#if defined(__linux__) |
|
16 |
#include <sys/statvfs.h> |
|
17 |
#endif |
|
18 |
||
19 |
||
20 |
#if defined(WITH_SDL) |
|
21 |
#include <SDL.h> |
|
22 |
#endif |
|
23 |
||
24 |
#ifdef __MORPHOS__ |
|
25 |
#include <exec/types.h> |
|
26 |
ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;) |
|
27 |
#endif /* __MORPHOS__ */ |
|
28 |
||
770
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
29 |
#ifdef __AMIGA__ |
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
30 |
#warning add stack symbol to avoid that user needs to set stack manually (tokai) |
915 | 31 |
// ULONG __stack = |
770
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
32 |
#endif |
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
33 |
|
0 | 34 |
static char *_fios_path; |
35 |
static char *_fios_save_path; |
|
36 |
static char *_fios_scn_path; |
|
37 |
static FiosItem *_fios_items; |
|
38 |
static int _fios_count, _fios_alloc; |
|
39 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1050
diff
changeset
|
40 |
static FiosItem *FiosAlloc(void) |
0 | 41 |
{ |
42 |
if (_fios_count == _fios_alloc) { |
|
43 |
_fios_alloc += 256; |
|
44 |
_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem)); |
|
45 |
} |
|
46 |
return &_fios_items[_fios_count++]; |
|
47 |
} |
|
48 |
||
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
|
49 |
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
|
50 |
{ |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
51 |
const FiosItem *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
|
52 |
const FiosItem *db = (const FiosItem *)b; |
0 | 53 |
int r; |
54 |
||
55 |
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
|
56 |
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
|
57 |
else |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
58 |
r = strcasecmp( |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
59 |
da->title[0] != '\0' ? da->title : da->name, |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
60 |
db->title[0] != '\0' ? db->title : db->name |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
61 |
); |
0 | 62 |
|
63 |
if (_savegame_sort_order & 1) r = -r; |
|
64 |
return r; |
|
65 |
} |
|
66 |
||
67 |
||
68 |
// Get a list of savegames |
|
69 |
FiosItem *FiosGetSavegameList(int *num, int mode) |
|
70 |
{ |
|
71 |
FiosItem *fios; |
|
72 |
DIR *dir; |
|
73 |
struct dirent *dirent; |
|
74 |
struct stat sb; |
|
75 |
int sort_start; |
|
76 |
char filename[MAX_PATH]; |
|
77 |
||
78 |
if (_fios_save_path == NULL) { |
|
79 |
_fios_save_path = malloc(MAX_PATH); |
|
80 |
strcpy(_fios_save_path, _path.save_dir); |
|
81 |
} |
|
82 |
||
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
83 |
if (_game_mode == GM_EDITOR) |
0 | 84 |
_fios_path = _fios_scn_path; |
85 |
else |
|
86 |
_fios_path = _fios_save_path; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
87 |
|
0 | 88 |
// Parent directory, only if not in root already. |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
89 |
if (_fios_path[1] != '\0') { |
0 | 90 |
fios = FiosAlloc(); |
91 |
fios->type = FIOS_TYPE_PARENT; |
|
92 |
fios->mtime = 0; |
|
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
93 |
strcpy(fios->title, ".. (Parent directory)"); |
0 | 94 |
} |
95 |
||
96 |
// Show subdirectories first |
|
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
|
97 |
dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/"); |
0 | 98 |
if (dir != NULL) { |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
99 |
while ((dirent = readdir(dir)) != NULL) { |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
100 |
snprintf(filename, lengthof(filename), "%s/%s", |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
101 |
_fios_path, dirent->d_name); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
102 |
if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) && |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
103 |
dirent->d_name[0] != '.') { |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
104 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
105 |
fios->type = FIOS_TYPE_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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
"%s/ (Directory)", dirent->d_name); |
0 | 110 |
} |
111 |
} |
|
112 |
closedir(dir); |
|
113 |
} |
|
114 |
||
307
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
115 |
{ |
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
116 |
/* XXX ugly global variables ... */ |
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
117 |
byte order = _savegame_sort_order; |
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
118 |
_savegame_sort_order = 2; // sort ascending by name |
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
119 |
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems); |
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
120 |
_savegame_sort_order = order; |
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
121 |
} |
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
122 |
|
0 | 123 |
// this is where to start sorting |
124 |
sort_start = _fios_count; |
|
125 |
||
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
|
126 |
/* 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
|
127 |
* .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
|
128 |
* .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
|
129 |
* .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
|
130 |
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game |
0 | 131 |
*/ |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
132 |
dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/"); |
0 | 133 |
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
|
134 |
while ((dirent = readdir(dir)) != NULL) { |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
135 |
char *t; |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
136 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
137 |
snprintf(filename, lengthof(filename), "%s/%s", |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
138 |
_fios_path, dirent->d_name); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
139 |
if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
140 |
|
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
141 |
t = strrchr(dirent->d_name, '.'); |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
142 |
if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
143 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
144 |
fios->type = FIOS_TYPE_FILE; |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
145 |
fios->mtime = sb.st_mtime; |
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
|
146 |
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
|
147 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
148 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
149 |
if (t != 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
|
150 |
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
|
151 |
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
|
152 |
strcasecmp(t, ".sv2") == 0 |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
153 |
)) { // TTDLX(Patch) |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
154 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
155 |
fios->type = FIOS_TYPE_OLDFILE; |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
156 |
fios->mtime = sb.st_mtime; |
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
|
157 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
158 |
GetOldSaveGameName(fios->title, filename); |
0 | 159 |
} |
160 |
} |
|
161 |
} |
|
162 |
closedir(dir); |
|
163 |
} |
|
164 |
||
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
|
165 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 166 |
*num = _fios_count; |
167 |
return _fios_items; |
|
168 |
} |
|
169 |
||
170 |
// Get a list of scenarios |
|
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
171 |
// FIXME: Gross code duplication with FiosGetSavegameList() |
0 | 172 |
FiosItem *FiosGetScenarioList(int *num, int mode) |
173 |
{ |
|
174 |
FiosItem *fios; |
|
175 |
DIR *dir; |
|
176 |
struct dirent *dirent; |
|
177 |
struct stat sb; |
|
178 |
int sort_start; |
|
179 |
char filename[MAX_PATH]; |
|
180 |
||
181 |
if (_fios_scn_path == NULL) { |
|
182 |
_fios_scn_path = malloc(MAX_PATH); |
|
183 |
strcpy(_fios_scn_path, _path.scenario_dir); |
|
184 |
} |
|
185 |
_fios_path = _fios_scn_path; |
|
186 |
||
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
|
187 |
// Parent directory, only if not of the type C:\. |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix 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 |
if (_fios_path[1] != '\0' && 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
|
189 |
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
|
190 |
fios->type = 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
|
191 |
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
|
192 |
strcpy(fios->title, ".. (Parent directory)"); |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix 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 |
} |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
194 |
|
0 | 195 |
// Show subdirectories first |
196 |
dir = opendir(_fios_path[0] ? _fios_path : "/"); |
|
197 |
if (dir != NULL) { |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
198 |
while ((dirent = readdir(dir)) != NULL) { |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
199 |
snprintf(filename, lengthof(filename), "%s/%s", |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
200 |
_fios_path, dirent->d_name); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
201 |
if (!stat(filename, &sb) && S_ISDIR(sb.st_mode) && |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
202 |
dirent->d_name[0] != '.') { |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
203 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
204 |
fios->type = FIOS_TYPE_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
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
"%s/ (Directory)", dirent->d_name); |
0 | 209 |
} |
210 |
} |
|
211 |
closedir(dir); |
|
212 |
} |
|
213 |
||
214 |
// this is where to start sorting |
|
215 |
sort_start = _fios_count; |
|
216 |
||
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
|
217 |
/* 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
|
218 |
* .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
|
219 |
* .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
|
220 |
* .SS0 Transport Tycoon Deluxe preset scenario |
0 | 221 |
*/ |
222 |
dir = opendir(_fios_path[0] ? _fios_path : "/"); |
|
223 |
if (dir != NULL) { |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
224 |
while ((dirent = readdir(dir)) != NULL) { |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
225 |
char *t; |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
226 |
|
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
|
227 |
snprintf(filename, lengthof(filename), "%s/%s", |
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix 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_path, dirent->d_name); |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
229 |
if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue; |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
230 |
|
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
231 |
t = strrchr(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
|
232 |
if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
233 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
234 |
fios->type = FIOS_TYPE_SCENARIO; |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
235 |
fios->mtime = sb.st_mtime; |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
236 |
fios->title[0] = '\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
|
237 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
238 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
239 |
mode == SLD_NEW_GAME) { |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
240 |
if (t != 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 |
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
|
242 |
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
|
243 |
)) { // TTDLX(Patch) |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
244 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
245 |
fios->type = FIOS_TYPE_OLD_SCENARIO; |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
246 |
fios->mtime = sb.st_mtime; |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
247 |
GetOldScenarioGameName(fios->title, filename); |
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
|
248 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
0 | 249 |
} |
250 |
} |
|
251 |
} |
|
252 |
closedir(dir); |
|
253 |
} |
|
254 |
||
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
|
255 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 256 |
*num = _fios_count; |
257 |
return _fios_items; |
|
258 |
} |
|
259 |
||
260 |
||
261 |
// Free the list of savegames |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1050
diff
changeset
|
262 |
void FiosFreeSavegameList(void) |
0 | 263 |
{ |
264 |
free(_fios_items); |
|
265 |
_fios_items = NULL; |
|
266 |
_fios_alloc = _fios_count = 0; |
|
267 |
} |
|
268 |
||
269 |
// Browse to |
|
270 |
char *FiosBrowseTo(const FiosItem *item) |
|
271 |
{ |
|
272 |
char *path = _fios_path; |
|
273 |
char *s; |
|
274 |
||
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
275 |
switch (item->type) { |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
276 |
case FIOS_TYPE_PARENT: |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
277 |
s = strrchr(path, '/'); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
278 |
if (s != NULL) *s = '\0'; |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
279 |
break; |
0 | 280 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
281 |
case FIOS_TYPE_DIR: |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
282 |
s = strchr(item->name, '/'); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
283 |
if (s != NULL) *s = '\0'; |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
284 |
strcat(path, "/"); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
285 |
strcat(path, item->name); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
286 |
break; |
0 | 287 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
288 |
case FIOS_TYPE_FILE: |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
289 |
case FIOS_TYPE_OLDFILE: |
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
|
290 |
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
|
291 |
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
|
292 |
static char str_buffr[512]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
293 |
|
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
|
294 |
sprintf(str_buffr, "%s/%s", path, item->name); |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
295 |
return str_buffr; |
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
296 |
} |
0 | 297 |
} |
298 |
||
299 |
return NULL; |
|
300 |
} |
|
301 |
||
302 |
// Get descriptive texts. |
|
303 |
// Returns a path as well as a |
|
304 |
// string describing the path. |
|
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
|
305 |
StringID FiosGetDescText(const char **path) |
0 | 306 |
{ |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
307 |
*path = _fios_path[0] != '\0' ? _fios_path : "/"; |
0 | 308 |
|
309 |
#if defined(__linux__) |
|
310 |
{ |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
311 |
struct statvfs s; |
0 | 312 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
313 |
if (statvfs(*path, &s) == 0) { |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
314 |
uint64 tot = (uint64)s.f_bsize * s.f_bavail; |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
315 |
SetDParam(0, (uint32)(tot >> 20)); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
316 |
return STR_4005_BYTES_FREE; |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
317 |
} else |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
318 |
return STR_4006_UNABLE_TO_READ_DRIVE; |
0 | 319 |
} |
320 |
#else |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
529
diff
changeset
|
321 |
SetDParam(0, 0); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
322 |
return STR_4005_BYTES_FREE; |
0 | 323 |
#endif |
324 |
} |
|
325 |
||
326 |
void FiosMakeSavegameName(char *buf, const char *name) |
|
327 |
{ |
|
1508
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
328 |
const char* extension; |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
329 |
const char* period; |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
330 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
331 |
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:
1495
diff
changeset
|
332 |
extension = ".scn"; |
0 | 333 |
else |
1508
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
334 |
extension = ".sav"; |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
335 |
|
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
336 |
// 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:
1495
diff
changeset
|
337 |
period = strrchr(name, '.'); |
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
338 |
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:
1495
diff
changeset
|
339 |
|
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
340 |
sprintf(buf, "%s/%s%s", _fios_path, name, extension); |
0 | 341 |
} |
342 |
||
343 |
void FiosDelete(const char *name) |
|
344 |
{ |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
345 |
char path[512]; |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
346 |
|
1495
a9e4e2b78877
(svn r1999) r1990 broke savegame deletion, fix that [1161729]
tron
parents:
1486
diff
changeset
|
347 |
snprintf(path, lengthof(path), "%s/%s", _fios_path, name); |
0 | 348 |
unlink(path); |
349 |
} |
|
350 |
||
351 |
const DriverDesc _video_driver_descs[] = { |
|
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
352 |
{"null", "Null Video Driver", &_null_video_driver, 0}, |
0 | 353 |
#if defined(WITH_SDL) |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
354 |
{ "sdl", "SDL Video Driver", &_sdl_video_driver, 1}, |
0 | 355 |
#endif |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
356 |
{ "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
|
357 |
{ NULL, NULL, NULL, 0} |
0 | 358 |
}; |
359 |
||
360 |
const DriverDesc _sound_driver_descs[] = { |
|
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
361 |
{"null", "Null Sound Driver", &_null_sound_driver, 0}, |
0 | 362 |
#if defined(WITH_SDL) |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
363 |
{ "sdl", "SDL Sound Driver", &_sdl_sound_driver, 1}, |
0 | 364 |
#endif |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
365 |
{ NULL, NULL, NULL, 0} |
0 | 366 |
}; |
367 |
||
368 |
#if defined(__APPLE__) |
|
369 |
#define EXTMIDI_PRI 2 |
|
370 |
#else |
|
371 |
#define EXTMIDI_PRI 0 |
|
372 |
#endif |
|
373 |
||
374 |
const DriverDesc _music_driver_descs[] = { |
|
375 |
#ifndef __BEOS__ |
|
569
1e1755ba1572
(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
|
376 |
#if !defined(__MORPHOS__) && !defined(__AMIGA__) |
1e1755ba1572
(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
|
377 |
// MorphOS and AmigaOS have no music support |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
378 |
{"extmidi", "External MIDI Driver", &_extmidi_music_driver, EXTMIDI_PRI}, |
0 | 379 |
#endif |
380 |
#endif |
|
381 |
#ifdef __BEOS__ |
|
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
382 |
{ "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
|
383 |
#endif |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
384 |
{ "null", "Null Music Driver", &_null_music_driver, 1}, |
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
385 |
{ NULL, NULL, NULL, 0} |
0 | 386 |
}; |
387 |
||
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
|
388 |
/* 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
|
389 |
Not needed for *nix. */ |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1050
diff
changeset
|
390 |
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
|
391 |
{ |
826 | 392 |
return 2; // any arbitrary number bigger than 0 |
268
842dedb3bf05
(svn r274) Mac: restored extmusic to be default, which were accidently turned off by a windows music fix
bjarni
parents:
238
diff
changeset
|
393 |
// 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
|
394 |
} |
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
|
395 |
|
0 | 396 |
bool FileExists(const char *filename) |
397 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
398 |
return access(filename, 0) == 0; |
0 | 399 |
} |
400 |
||
401 |
static int LanguageCompareFunc(const void *a, const void *b) |
|
402 |
{ |
|
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
|
403 |
return strcmp(*(const char* const *)a, *(const char* const *)b); |
0 | 404 |
} |
405 |
||
406 |
int GetLanguageList(char **languages, int max) |
|
407 |
{ |
|
408 |
DIR *dir; |
|
409 |
struct dirent *dirent; |
|
410 |
int num = 0; |
|
411 |
||
412 |
dir = opendir(_path.lang_dir); |
|
413 |
if (dir != NULL) { |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
414 |
while ((dirent = readdir(dir)) != NULL) { |
0 | 415 |
char *t = strrchr(dirent->d_name, '.'); |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
416 |
|
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
417 |
if (t != NULL && strcmp(t, ".lng") == 0) { |
0 | 418 |
languages[num++] = strdup(dirent->d_name); |
419 |
if (num == max) break; |
|
420 |
} |
|
421 |
} |
|
422 |
closedir(dir); |
|
423 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
424 |
|
0 | 425 |
qsort(languages, num, sizeof(char*), LanguageCompareFunc); |
426 |
return num; |
|
427 |
} |
|
428 |
||
1050
958032fed209
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
429 |
#if defined(__BEOS__) || defined(__linux__) |
410 | 430 |
static void ChangeWorkingDirectory(char *exe) |
0 | 431 |
{ |
432 |
char *s = strrchr(exe, '/'); |
|
433 |
if (s != NULL) { |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
434 |
*s = '\0'; |
0 | 435 |
chdir(exe); |
436 |
*s = '/'; |
|
437 |
} |
|
438 |
} |
|
1050
958032fed209
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
439 |
#endif |
0 | 440 |
|
441 |
void ShowInfo(const char *str) |
|
442 |
{ |
|
443 |
puts(str); |
|
444 |
} |
|
445 |
||
446 |
void ShowOSErrorBox(const char *buf) |
|
447 |
{ |
|
529
39d3b5a074c4
(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
|
448 |
#if defined(__APPLE__) |
39d3b5a074c4
(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
|
449 |
// this creates an error in the console and then opens the console. |
39d3b5a074c4
(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
|
450 |
// Colourcodes are not used in the console, so they are skipped here |
39d3b5a074c4
(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
|
451 |
fprintf(stderr, "Error: %s", buf); |
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
452 |
system("/Applications/Utilities/Console.app/Contents/MacOS/Console &"); |
529
39d3b5a074c4
(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
|
453 |
#else |
39d3b5a074c4
(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
|
454 |
// all systems, but OSX |
0 | 455 |
fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf); |
456 |
#endif |
|
457 |
} |
|
458 |
||
459 |
int CDECL main(int argc, char* argv[]) |
|
460 |
{ |
|
461 |
// change the working directory to enable doubleclicking in UIs |
|
1050
958032fed209
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
462 |
#if defined(__BEOS__) || defined(__linux__) |
0 | 463 |
ChangeWorkingDirectory(argv[0]); |
464 |
#endif |
|
465 |
||
206 | 466 |
_random_seeds[0][1] = _random_seeds[0][0] = time(NULL); |
0 | 467 |
|
1509
795ba683e4f0
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
468 |
signal(SIGPIPE, SIG_IGN); |
0 | 469 |
|
470 |
return ttd_main(argc, argv); |
|
471 |
} |
|
472 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1050
diff
changeset
|
473 |
void DeterminePaths(void) |
0 | 474 |
{ |
475 |
char *s; |
|
476 |
||
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
477 |
_path.game_data_dir = malloc(MAX_PATH); |
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
478 |
ttd_strlcpy(_path.game_data_dir, GAME_DATA_DIR, MAX_PATH); |
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
479 |
#if defined SECOND_DATA_DIR |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
480 |
_path.second_data_dir = malloc(MAX_PATH); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
481 |
ttd_strlcpy(_path.second_data_dir, SECOND_DATA_DIR, MAX_PATH); |
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
482 |
#endif |
0 | 483 |
|
484 |
#if defined(USE_HOMEDIR) |
|
485 |
{ |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
486 |
const char *homedir = getenv("HOME"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
487 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
488 |
if (homedir == NULL) { |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
489 |
const struct passwd *pw = getpwuid(getuid()); |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
490 |
if (pw != NULL) homedir = pw->pw_dir; |
0 | 491 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
492 |
|
0 | 493 |
_path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
494 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
495 |
|
0 | 496 |
#else /* not defined(USE_HOMEDIR) */ |
497 |
||
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
498 |
_path.personal_dir = malloc(MAX_PATH); |
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
499 |
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
|
500 |
|
0 | 501 |
// check if absolute or relative path |
502 |
s = strchr(_path.personal_dir, '/'); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
503 |
|
0 | 504 |
// add absolute path |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
505 |
if (s == NULL || _path.personal_dir != s) { |
0 | 506 |
getcwd(_path.personal_dir, MAX_PATH); |
507 |
s = strchr(_path.personal_dir, 0); |
|
508 |
*s++ = '/'; |
|
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
509 |
ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
0 | 510 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
511 |
|
0 | 512 |
#endif /* defined(USE_HOMEDIR) */ |
513 |
||
514 |
s = strchr(_path.personal_dir, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
515 |
|
0 | 516 |
// append a / ? |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
517 |
if (s[-1] != '/') strcpy(s, "/"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
518 |
|
0 | 519 |
_path.save_dir = str_fmt("%ssave", _path.personal_dir); |
520 |
_path.autosave_dir = str_fmt("%s/autosave", _path.save_dir); |
|
521 |
_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir); |
|
522 |
_path.gm_dir = str_fmt("%sgm/", _path.game_data_dir); |
|
523 |
_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:
1470
diff
changeset
|
524 |
|
80e315adc3bd
(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
|
525 |
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:
1470
diff
changeset
|
526 |
_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir); |
80e315adc3bd
(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
|
527 |
|
983
4765bf636f6b
(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
|
528 |
_highscore_file = str_fmt("%shs.dat", _path.personal_dir); |
704
e843dd369938
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
569
diff
changeset
|
529 |
_log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
915 | 530 |
|
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
531 |
#if defined CUSTOM_LANG_DIR |
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
532 |
// sets the search path for lng files to the custom one |
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
533 |
_path.lang_dir = malloc( MAX_PATH ); |
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
534 |
ttd_strlcpy( _path.lang_dir, CUSTOM_LANG_DIR, MAX_PATH); |
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
535 |
#else |
0 | 536 |
_path.lang_dir = str_fmt("%slang/", _path.game_data_dir); |
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
537 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
538 |
|
238
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
539 |
// create necessary folders |
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
540 |
mkdir(_path.personal_dir, 0755); |
0 | 541 |
mkdir(_path.save_dir, 0755); |
542 |
mkdir(_path.autosave_dir, 0755); |
|
543 |
mkdir(_path.scenario_dir, 0755); |
|
544 |
} |
|
545 |
||
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
546 |
bool InsertTextBufferClipboard(Textbuf *tb) |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
547 |
{ |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
548 |
return false; |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
549 |
} |