author | celestar |
Wed, 22 Mar 2006 11:26:08 +0000 | |
branch | 0.4.5 |
changeset 9948 | 877dccfeb22e |
parent 2940 | ce57a148333e |
child 9956 | 341e963c63c4 |
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 |
|
12 |
#include <dirent.h> |
|
13 |
#include <unistd.h> |
|
14 |
#include <sys/stat.h> |
|
15 |
#include <time.h> |
|
1509
2c232b7d2114
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
16 |
#include <signal.h> |
0 | 17 |
|
2323
13182c22f164
(svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents:
2285
diff
changeset
|
18 |
#ifdef USE_HOMEDIR |
13182c22f164
(svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents:
2285
diff
changeset
|
19 |
#include <pwd.h> |
13182c22f164
(svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents:
2285
diff
changeset
|
20 |
#endif |
13182c22f164
(svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents:
2285
diff
changeset
|
21 |
|
1850
7fa9e3ecb486
(svn r2356) Make check if statvfs() is availible a bit more sensible
tron
parents:
1687
diff
changeset
|
22 |
#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
|
23 |
#define HAS_STATVFS |
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
24 |
#endif |
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
25 |
|
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
26 |
#ifdef HAS_STATVFS |
0 | 27 |
#include <sys/statvfs.h> |
28 |
#endif |
|
29 |
||
30 |
||
31 |
#ifdef __MORPHOS__ |
|
32 |
#include <exec/types.h> |
|
33 |
ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;) |
|
2356 | 34 |
|
35 |
// The system supplied definition of SIG_IGN does not match |
|
36 |
#undef SIG_IGN |
|
37 |
#define SIG_IGN (void (*)(int))1 |
|
0 | 38 |
#endif /* __MORPHOS__ */ |
39 |
||
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
40 |
#ifdef __AMIGA__ |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
41 |
#warning add stack symbol to avoid that user needs to set stack manually (tokai) |
915 | 42 |
// ULONG __stack = |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
43 |
#endif |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
44 |
|
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
|
45 |
#if defined(__APPLE__) |
2217
c3a8a3bbc81f
(svn r2735) -Fix: [OSX] fixed issue introduced in 2733 where dedicated servers on OSX included sdl.h even when WITH_SDL was not defined (oops)
bjarni
parents:
2215
diff
changeset
|
46 |
#if defined(WITH_SDL) |
c3a8a3bbc81f
(svn r2735) -Fix: [OSX] fixed issue introduced in 2733 where dedicated servers on OSX included sdl.h even when WITH_SDL was not defined (oops)
bjarni
parents:
2215
diff
changeset
|
47 |
//the mac implementation needs this file included in the same file as main() |
c3a8a3bbc81f
(svn r2735) -Fix: [OSX] fixed issue introduced in 2733 where dedicated servers on OSX included sdl.h even when WITH_SDL was not defined (oops)
bjarni
parents:
2215
diff
changeset
|
48 |
#include <SDL.h> |
c3a8a3bbc81f
(svn r2735) -Fix: [OSX] fixed issue introduced in 2733 where dedicated servers on OSX included sdl.h even when WITH_SDL was not defined (oops)
bjarni
parents:
2215
diff
changeset
|
49 |
#endif |
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
|
50 |
#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
|
51 |
|
0 | 52 |
static char *_fios_path; |
53 |
static char *_fios_save_path; |
|
54 |
static char *_fios_scn_path; |
|
55 |
static FiosItem *_fios_items; |
|
56 |
static int _fios_count, _fios_alloc; |
|
57 |
||
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
|
58 |
static FiosItem *FiosAlloc(void) |
0 | 59 |
{ |
60 |
if (_fios_count == _fios_alloc) { |
|
61 |
_fios_alloc += 256; |
|
62 |
_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem)); |
|
63 |
} |
|
64 |
return &_fios_items[_fios_count++]; |
|
65 |
} |
|
66 |
||
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
|
67 |
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
|
68 |
{ |
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
|
69 |
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
|
70 |
const FiosItem *db = (const FiosItem *)b; |
0 | 71 |
int r; |
72 |
||
2526
cae4842086a9
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
73 |
if (_savegame_sort_order & SORT_BY_NAME) { |
cae4842086a9
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
74 |
r = strcasecmp(da->title, db->title); |
cae4842086a9
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
75 |
} else { |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
76 |
r = da->mtime < db->mtime ? -1 : 1; |
2526
cae4842086a9
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
77 |
} |
0 | 78 |
|
2526
cae4842086a9
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
79 |
if (_savegame_sort_order & SORT_DESCENDING) r = -r; |
0 | 80 |
return r; |
81 |
} |
|
82 |
||
83 |
||
84 |
// Get a list of savegames |
|
85 |
FiosItem *FiosGetSavegameList(int *num, int mode) |
|
86 |
{ |
|
87 |
FiosItem *fios; |
|
88 |
DIR *dir; |
|
89 |
struct dirent *dirent; |
|
90 |
struct stat sb; |
|
91 |
int sort_start; |
|
92 |
char filename[MAX_PATH]; |
|
93 |
||
94 |
if (_fios_save_path == NULL) { |
|
95 |
_fios_save_path = malloc(MAX_PATH); |
|
96 |
strcpy(_fios_save_path, _path.save_dir); |
|
97 |
} |
|
98 |
||
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
99 |
_fios_path = _fios_save_path; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
100 |
|
0 | 101 |
// 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
|
102 |
if (_fios_path[1] != '\0') { |
0 | 103 |
fios = FiosAlloc(); |
104 |
fios->type = FIOS_TYPE_PARENT; |
|
105 |
fios->mtime = 0; |
|
1572
6d0111113f0b
(svn r2076) Set the name for the parent directory to ".."
tron
parents:
1509
diff
changeset
|
106 |
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
|
107 |
strcpy(fios->title, ".. (Parent directory)"); |
0 | 108 |
} |
109 |
||
110 |
// Show subdirectories first |
|
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
111 |
dir = opendir(_fios_path); |
0 | 112 |
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
|
113 |
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
|
114 |
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
|
115 |
_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
|
116 |
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
|
117 |
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
|
118 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
"%s/ (Directory)", dirent->d_name); |
2940
ce57a148333e
(svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents:
2736
diff
changeset
|
124 |
str_validate(fios->title); |
0 | 125 |
} |
126 |
} |
|
127 |
closedir(dir); |
|
128 |
} |
|
129 |
||
307
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
130 |
{ |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
131 |
/* 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
|
132 |
byte order = _savegame_sort_order; |
2526
cae4842086a9
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
133 |
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING; |
307
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
134 |
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
|
135 |
_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
|
136 |
} |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
137 |
|
0 | 138 |
// this is where to start sorting |
139 |
sort_start = _fios_count; |
|
140 |
||
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
|
141 |
/* 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
|
142 |
* .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
|
143 |
* .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
|
144 |
* .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
|
145 |
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game |
0 | 146 |
*/ |
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
147 |
dir = opendir(_fios_path); |
0 | 148 |
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
|
149 |
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
|
150 |
char *t; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
151 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
152 |
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
|
153 |
_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
|
154 |
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
|
155 |
|
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
156 |
t = strrchr(dirent->d_name, '.'); |
2338 | 157 |
if (t == NULL) continue; |
158 |
||
159 |
if (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
|
160 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
|
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
165 |
*t = '\0'; // strip extension |
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
166 |
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); |
2940
ce57a148333e
(svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents:
2736
diff
changeset
|
167 |
str_validate(fios->title); |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
168 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { |
2338 | 169 |
if (strcasecmp(t, ".ss1") == 0 || |
170 |
strcasecmp(t, ".sv1") == 0 || |
|
171 |
strcasecmp(t, ".sv2") == 0) { // TTDLX(Patch) |
|
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
172 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
GetOldSaveGameName(fios->title, filename); |
0 | 177 |
} |
178 |
} |
|
179 |
} |
|
180 |
closedir(dir); |
|
181 |
} |
|
182 |
||
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
|
183 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 184 |
*num = _fios_count; |
185 |
return _fios_items; |
|
186 |
} |
|
187 |
||
188 |
// 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
|
189 |
// FIXME: Gross code duplication with FiosGetSavegameList() |
0 | 190 |
FiosItem *FiosGetScenarioList(int *num, int mode) |
191 |
{ |
|
192 |
FiosItem *fios; |
|
193 |
DIR *dir; |
|
194 |
struct dirent *dirent; |
|
195 |
struct stat sb; |
|
196 |
int sort_start; |
|
197 |
char filename[MAX_PATH]; |
|
198 |
||
199 |
if (_fios_scn_path == NULL) { |
|
200 |
_fios_scn_path = malloc(MAX_PATH); |
|
201 |
strcpy(_fios_scn_path, _path.scenario_dir); |
|
202 |
} |
|
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
203 |
|
0 | 204 |
_fios_path = _fios_scn_path; |
205 |
||
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
|
206 |
// 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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
} |
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 |
|
0 | 214 |
// Show subdirectories first |
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
215 |
dir = opendir(_fios_path); |
0 | 216 |
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
|
217 |
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
|
218 |
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
|
219 |
_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
|
220 |
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
|
221 |
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
|
222 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name); |
2940
ce57a148333e
(svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents:
2736
diff
changeset
|
227 |
str_validate(fios->title); |
0 | 228 |
} |
229 |
} |
|
230 |
closedir(dir); |
|
231 |
} |
|
232 |
||
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
233 |
{ |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
234 |
/* XXX ugly global variables ... */ |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
235 |
byte order = _savegame_sort_order; |
2526
cae4842086a9
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
236 |
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING; |
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
237 |
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems); |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
238 |
_savegame_sort_order = order; |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
239 |
} |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
240 |
|
0 | 241 |
// this is where to start sorting |
242 |
sort_start = _fios_count; |
|
243 |
||
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
|
244 |
/* 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
|
245 |
* .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
|
246 |
* .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
|
247 |
* .SS0 Transport Tycoon Deluxe preset scenario |
0 | 248 |
*/ |
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
249 |
dir = opendir(_fios_path); |
0 | 250 |
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
|
251 |
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
|
252 |
char *t; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
253 |
|
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
|
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
257 |
t = strrchr(dirent->d_name, '.'); |
2338 | 258 |
if (t == NULL) continue; |
259 |
||
260 |
if (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
|
261 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
|
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
266 |
*t = '\0'; // strip extension |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
267 |
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); |
2940
ce57a148333e
(svn r3496) - Validate filename titles before they get displayed. This avoids crashes with UTF-8 encoded or bad filenames by replacing undisplayable characters with a '?'
peter1138
parents:
2736
diff
changeset
|
268 |
str_validate(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
|
269 |
} 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
|
270 |
mode == SLD_NEW_GAME) { |
2338 | 271 |
if (strcasecmp(t, ".sv0") == 0 || |
272 |
strcasecmp(t, ".ss0") == 0) { // TTDLX(Patch) |
|
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
273 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
0 | 278 |
} |
279 |
} |
|
280 |
} |
|
281 |
closedir(dir); |
|
282 |
} |
|
283 |
||
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
|
284 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 285 |
*num = _fios_count; |
286 |
return _fios_items; |
|
287 |
} |
|
288 |
||
289 |
||
290 |
// 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
|
291 |
void FiosFreeSavegameList(void) |
0 | 292 |
{ |
293 |
free(_fios_items); |
|
294 |
_fios_items = NULL; |
|
295 |
_fios_alloc = _fios_count = 0; |
|
296 |
} |
|
297 |
||
298 |
// Browse to |
|
299 |
char *FiosBrowseTo(const FiosItem *item) |
|
300 |
{ |
|
301 |
char *path = _fios_path; |
|
302 |
char *s; |
|
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 |
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
|
305 |
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
|
306 |
s = strrchr(path, '/'); |
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
307 |
if (s != path) |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
308 |
s[0] = '\0'; |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
309 |
else |
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
310 |
s[1] = '\0'; |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
311 |
break; |
0 | 312 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
313 |
case FIOS_TYPE_DIR: |
2334
b4e5c353bf38
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
314 |
if (path[1] != '\0') strcat(path, "/"); |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
315 |
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
|
316 |
break; |
0 | 317 |
|
2559
08e648022cb0
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2526
diff
changeset
|
318 |
case FIOS_TYPE_DIRECT: |
2560
00ad0c27c2f3
(svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents:
2559
diff
changeset
|
319 |
sprintf(path, "%s/", item->name); |
00ad0c27c2f3
(svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents:
2559
diff
changeset
|
320 |
s = strrchr(path, '/'); |
00ad0c27c2f3
(svn r3097) - Fix (regression): unix has a trailing slash after the paths, windows does not, no idea why os2 has. Way to go consistency :s. So anyways, just strip trailing slash
Darkvater
parents:
2559
diff
changeset
|
321 |
if (s[1] == '\0') s[0] = '\0'; // strip trailing slash |
2559
08e648022cb0
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2526
diff
changeset
|
322 |
break; |
08e648022cb0
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2526
diff
changeset
|
323 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
324 |
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
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
static char str_buffr[512]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
329 |
|
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
|
330 |
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
|
331 |
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
|
332 |
} |
0 | 333 |
} |
334 |
||
335 |
return NULL; |
|
336 |
} |
|
337 |
||
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
|
338 |
/** |
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
|
339 |
* 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
|
340 |
* 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
|
341 |
* @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
|
342 |
* @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
|
343 |
* @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
|
344 |
*/ |
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
|
345 |
StringID FiosGetDescText(const char **path, uint32 *tot) |
0 | 346 |
{ |
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
|
347 |
uint32 free = 0; |
2338 | 348 |
*path = _fios_path; |
0 | 349 |
|
1597
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
350 |
#ifdef HAS_STATVFS |
0 | 351 |
{ |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
352 |
struct statvfs s; |
0 | 353 |
|
1597
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
354 |
if (statvfs(*path, &s) == 0) { |
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
355 |
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
|
356 |
} else |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
357 |
return STR_4006_UNABLE_TO_READ_DRIVE; |
0 | 358 |
} |
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
|
359 |
#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
|
360 |
if (tot != NULL) *tot = free; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
361 |
return STR_4005_BYTES_FREE; |
0 | 362 |
} |
363 |
||
9948 | 364 |
void FiosMakeSavegameName(char *buf, const char *name, size_t size) |
0 | 365 |
{ |
1508
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
366 |
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
|
367 |
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
|
368 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
369 |
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
|
370 |
extension = ".scn"; |
0 | 371 |
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
|
372 |
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
|
373 |
|
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
374 |
// 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
|
375 |
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
|
376 |
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
|
377 |
|
9948 | 378 |
snprintf(buf, size, "%s/%s%s", _fios_path, name, extension); |
0 | 379 |
} |
380 |
||
2255
ddcaf9e333ff
(svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents:
2223
diff
changeset
|
381 |
bool FiosDelete(const char *name) |
0 | 382 |
{ |
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
383 |
char path[512]; |
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
384 |
|
9948 | 385 |
FiosMakeSavegameName(path, name, sizeof(path)); |
2255
ddcaf9e333ff
(svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents:
2223
diff
changeset
|
386 |
return unlink(path) == 0; |
0 | 387 |
} |
388 |
||
389 |
bool FileExists(const char *filename) |
|
390 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
391 |
return access(filename, 0) == 0; |
0 | 392 |
} |
393 |
||
394 |
static int LanguageCompareFunc(const void *a, const void *b) |
|
395 |
{ |
|
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
|
396 |
return strcmp(*(const char* const *)a, *(const char* const *)b); |
0 | 397 |
} |
398 |
||
399 |
int GetLanguageList(char **languages, int max) |
|
400 |
{ |
|
401 |
DIR *dir; |
|
402 |
struct dirent *dirent; |
|
403 |
int num = 0; |
|
404 |
||
405 |
dir = opendir(_path.lang_dir); |
|
406 |
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
|
407 |
while ((dirent = readdir(dir)) != NULL) { |
0 | 408 |
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
|
409 |
|
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
410 |
if (t != NULL && strcmp(t, ".lng") == 0) { |
0 | 411 |
languages[num++] = strdup(dirent->d_name); |
412 |
if (num == max) break; |
|
413 |
} |
|
414 |
} |
|
415 |
closedir(dir); |
|
416 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
417 |
|
0 | 418 |
qsort(languages, num, sizeof(char*), LanguageCompareFunc); |
419 |
return num; |
|
420 |
} |
|
421 |
||
1050
e76fa5c5d835
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
422 |
#if defined(__BEOS__) || defined(__linux__) |
410 | 423 |
static void ChangeWorkingDirectory(char *exe) |
0 | 424 |
{ |
425 |
char *s = strrchr(exe, '/'); |
|
426 |
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
|
427 |
*s = '\0'; |
0 | 428 |
chdir(exe); |
429 |
*s = '/'; |
|
430 |
} |
|
431 |
} |
|
1050
e76fa5c5d835
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
432 |
#endif |
0 | 433 |
|
434 |
void ShowInfo(const char *str) |
|
435 |
{ |
|
436 |
puts(str); |
|
437 |
} |
|
438 |
||
439 |
void ShowOSErrorBox(const char *buf) |
|
440 |
{ |
|
2731
97a409a62741
(svn r3276) reverted the last two commits. OSX 10.2 kept finding new stuff to prevent it from running OpenTTD, so now it's not supported anymore
bjarni
parents:
2730
diff
changeset
|
441 |
#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
|
442 |
// 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
|
443 |
// 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
|
444 |
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
|
445 |
#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
|
446 |
// all systems, but OSX |
0 | 447 |
fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf); |
448 |
#endif |
|
449 |
} |
|
450 |
||
2736
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
451 |
#ifdef WITH_COCOA |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
452 |
void cocoaSetWorkingDirectory(void); |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
453 |
void cocoaSetupAutoreleasePool(void); |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
454 |
void cocoaReleaseAutoreleasePool(void); |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
455 |
#endif |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
456 |
|
0 | 457 |
int CDECL main(int argc, char* argv[]) |
458 |
{ |
|
2736
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
459 |
int ret; |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
460 |
|
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
461 |
#ifdef WITH_COCOA |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
462 |
cocoaSetupAutoreleasePool(); |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
463 |
/* This is passed if we are launched by double-clicking */ |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
464 |
if(argc >= 2 && strncmp (argv[1], "-psn", 4) == 0) { |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
465 |
argv[1] = NULL; |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
466 |
argc = 1; |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
467 |
cocoaSetWorkingDirectory(); |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
468 |
} |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
469 |
#endif |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
470 |
|
0 | 471 |
// 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
|
472 |
#if defined(__BEOS__) || defined(__linux__) |
0 | 473 |
ChangeWorkingDirectory(argv[0]); |
474 |
#endif |
|
475 |
||
206 | 476 |
_random_seeds[0][1] = _random_seeds[0][0] = time(NULL); |
2073 | 477 |
SeedMT(_random_seeds[0][1]); |
0 | 478 |
|
1509
2c232b7d2114
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
479 |
signal(SIGPIPE, SIG_IGN); |
0 | 480 |
|
2736
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
481 |
ret = ttd_main(argc, argv); |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
482 |
|
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
483 |
#ifdef WITH_COCOA |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
484 |
cocoaReleaseAutoreleasePool(); |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
485 |
#endif |
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
486 |
|
1ea068235989
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
487 |
return ret; |
0 | 488 |
} |
489 |
||
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
|
490 |
void DeterminePaths(void) |
0 | 491 |
{ |
492 |
char *s; |
|
493 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
494 |
_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
|
495 |
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
|
496 |
#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
|
497 |
_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
|
498 |
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
|
499 |
#endif |
0 | 500 |
|
501 |
#if defined(USE_HOMEDIR) |
|
502 |
{ |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
503 |
const char *homedir = getenv("HOME"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
504 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
505 |
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
|
506 |
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
|
507 |
if (pw != NULL) homedir = pw->pw_dir; |
0 | 508 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
509 |
|
0 | 510 |
_path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
511 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
512 |
|
0 | 513 |
#else /* not defined(USE_HOMEDIR) */ |
514 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
515 |
_path.personal_dir = malloc(MAX_PATH); |
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
516 |
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
|
517 |
|
0 | 518 |
// check if absolute or relative path |
519 |
s = strchr(_path.personal_dir, '/'); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
520 |
|
0 | 521 |
// 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
|
522 |
if (s == NULL || _path.personal_dir != s) { |
0 | 523 |
getcwd(_path.personal_dir, MAX_PATH); |
524 |
s = strchr(_path.personal_dir, 0); |
|
525 |
*s++ = '/'; |
|
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
526 |
ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
0 | 527 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
528 |
|
0 | 529 |
#endif /* defined(USE_HOMEDIR) */ |
530 |
||
531 |
s = strchr(_path.personal_dir, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
532 |
|
0 | 533 |
// 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
|
534 |
if (s[-1] != '/') strcpy(s, "/"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
535 |
|
0 | 536 |
_path.save_dir = str_fmt("%ssave", _path.personal_dir); |
537 |
_path.autosave_dir = str_fmt("%s/autosave", _path.save_dir); |
|
538 |
_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir); |
|
539 |
_path.gm_dir = str_fmt("%sgm/", _path.game_data_dir); |
|
540 |
_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
|
541 |
|
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
|
542 |
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
|
543 |
_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
|
544 |
|
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
|
545 |
_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
|
546 |
_log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
915 | 547 |
|
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
548 |
#if defined CUSTOM_LANG_DIR |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
549 |
// 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
|
550 |
_path.lang_dir = malloc( MAX_PATH ); |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
551 |
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
|
552 |
#else |
0 | 553 |
_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
|
554 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
555 |
|
238
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
556 |
// create necessary folders |
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
557 |
mkdir(_path.personal_dir, 0755); |
0 | 558 |
mkdir(_path.save_dir, 0755); |
559 |
mkdir(_path.autosave_dir, 0755); |
|
560 |
mkdir(_path.scenario_dir, 0755); |
|
561 |
} |
|
562 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
563 |
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
|
564 |
{ |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
565 |
return false; |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
566 |
} |
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
|
567 |
|
2073 | 568 |
|
569 |
// multi os compatible sleep function |
|
570 |
||
571 |
#ifdef __AMIGA__ |
|
572 |
// usleep() implementation |
|
573 |
# include <devices/timer.h> |
|
574 |
# include <dos/dos.h> |
|
575 |
||
576 |
extern struct Device *TimerBase = NULL; |
|
577 |
extern struct MsgPort *TimerPort = NULL; |
|
578 |
extern struct timerequest *TimerRequest = NULL; |
|
579 |
#endif // __AMIGA__ |
|
580 |
||
581 |
void CSleep(int milliseconds) |
|
582 |
{ |
|
583 |
#if !defined(__BEOS__) && !defined(__AMIGA__) |
|
584 |
usleep(milliseconds * 1000); |
|
585 |
#endif |
|
586 |
#ifdef __BEOS__ |
|
587 |
snooze(milliseconds * 1000); |
|
588 |
#endif |
|
589 |
#if defined(__AMIGA__) |
|
590 |
{ |
|
591 |
ULONG signals; |
|
592 |
ULONG TimerSigBit = 1 << TimerPort->mp_SigBit; |
|
593 |
||
594 |
// send IORequest |
|
595 |
TimerRequest->tr_node.io_Command = TR_ADDREQUEST; |
|
596 |
TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000; |
|
597 |
TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000; |
|
598 |
SendIO((struct IORequest *)TimerRequest); |
|
599 |
||
600 |
if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) { |
|
601 |
AbortIO((struct IORequest *)TimerRequest); |
|
602 |
} |
|
603 |
WaitIO((struct IORequest *)TimerRequest); |
|
604 |
} |
|
605 |
#endif // __AMIGA__ |
|
606 |
} |