author | bjarni |
Sat, 18 Mar 2006 15:55:24 +0000 | |
changeset 3260 | ed19f95eb4f7 |
parent 2952 | 58522ed8f0f1 |
child 3262 | 5a556d29194e |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1892
8717d92b32b1
(svn r2398) - CodeChange: forgot to update unix and os2 specific files as well.
Darkvater
parents:
1885
diff
changeset
|
4 |
#include "openttd.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
5 |
#include "functions.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
|
6 |
#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
|
7 |
#include "string.h" |
507
04b5403aaf6b
(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
f6284cf5fab0
(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
795ba683e4f0
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
16 |
#include <signal.h> |
0 | 17 |
|
2323
eadae7d611e7
(svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents:
2285
diff
changeset
|
18 |
#ifdef USE_HOMEDIR |
eadae7d611e7
(svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents:
2285
diff
changeset
|
19 |
#include <pwd.h> |
eadae7d611e7
(svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents:
2285
diff
changeset
|
20 |
#endif |
eadae7d611e7
(svn r2849) Fix r2806: pwd.h is necessary, but only if USE_HOMEDIR is defined
tron
parents:
2285
diff
changeset
|
21 |
|
1850
15826a18b5ac
(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
ef6253448620
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
23 |
#define HAS_STATVFS |
ef6253448620
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
24 |
#endif |
ef6253448620
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
25 |
|
ef6253448620
(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
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
40 |
#ifdef __AMIGA__ |
c2eacca29601
(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
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
43 |
#endif |
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
44 |
|
2188
640a0a5f77ea
(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
7a5d829eca29
(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) |
7a5d829eca29
(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() |
7a5d829eca29
(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> |
7a5d829eca29
(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
640a0a5f77ea
(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 |
640a0a5f77ea
(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 |
|
3260
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
52 |
#include <iconv.h> |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
53 |
#include <locale.h> |
0 | 54 |
static char *_fios_path; |
55 |
static char *_fios_save_path; |
|
56 |
static char *_fios_scn_path; |
|
57 |
static FiosItem *_fios_items; |
|
58 |
static int _fios_count, _fios_alloc; |
|
59 |
||
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
|
60 |
static FiosItem *FiosAlloc(void) |
0 | 61 |
{ |
62 |
if (_fios_count == _fios_alloc) { |
|
63 |
_fios_alloc += 256; |
|
64 |
_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem)); |
|
65 |
} |
|
66 |
return &_fios_items[_fios_count++]; |
|
67 |
} |
|
68 |
||
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
|
69 |
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
|
70 |
{ |
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
|
71 |
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
|
72 |
const FiosItem *db = (const FiosItem *)b; |
0 | 73 |
int r; |
74 |
||
2526
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
75 |
if (_savegame_sort_order & SORT_BY_NAME) { |
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
76 |
r = strcasecmp(da->title, db->title); |
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
77 |
} else { |
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
78 |
r = da->mtime < db->mtime ? -1 : 1; |
2526
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
79 |
} |
0 | 80 |
|
2526
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
81 |
if (_savegame_sort_order & SORT_DESCENDING) r = -r; |
0 | 82 |
return r; |
83 |
} |
|
84 |
||
85 |
||
86 |
// Get a list of savegames |
|
87 |
FiosItem *FiosGetSavegameList(int *num, int mode) |
|
88 |
{ |
|
89 |
FiosItem *fios; |
|
90 |
DIR *dir; |
|
91 |
struct dirent *dirent; |
|
92 |
struct stat sb; |
|
93 |
int sort_start; |
|
94 |
char filename[MAX_PATH]; |
|
95 |
||
96 |
if (_fios_save_path == NULL) { |
|
97 |
_fios_save_path = malloc(MAX_PATH); |
|
98 |
strcpy(_fios_save_path, _path.save_dir); |
|
99 |
} |
|
100 |
||
2099
02c5a49863e9
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
101 |
_fios_path = _fios_save_path; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
102 |
|
0 | 103 |
// 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
|
104 |
if (_fios_path[1] != '\0') { |
0 | 105 |
fios = FiosAlloc(); |
106 |
fios->type = FIOS_TYPE_PARENT; |
|
107 |
fios->mtime = 0; |
|
1572
cf4613ca991e
(svn r2076) Set the name for the parent directory to ".."
tron
parents:
1509
diff
changeset
|
108 |
strcpy(fios->name, ".."); |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
109 |
strcpy(fios->title, ".. (Parent directory)"); |
0 | 110 |
} |
111 |
||
112 |
// Show subdirectories first |
|
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
113 |
dir = opendir(_fios_path); |
0 | 114 |
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
|
115 |
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
|
116 |
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
|
117 |
_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
|
118 |
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
|
119 |
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
|
120 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
"%s/ (Directory)", dirent->d_name); |
2940
2b86050d1a94
(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
|
126 |
str_validate(fios->title); |
0 | 127 |
} |
128 |
} |
|
129 |
closedir(dir); |
|
130 |
} |
|
131 |
||
307
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
132 |
{ |
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
133 |
/* 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
|
134 |
byte order = _savegame_sort_order; |
2526
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
135 |
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING; |
307
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
136 |
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
|
137 |
_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
|
138 |
} |
69da52d9b50f
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
139 |
|
0 | 140 |
// this is where to start sorting |
141 |
sort_start = _fios_count; |
|
142 |
||
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
|
143 |
/* 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
|
144 |
* .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
|
145 |
* .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
|
146 |
* .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
|
147 |
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game |
0 | 148 |
*/ |
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
149 |
dir = opendir(_fios_path); |
0 | 150 |
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
|
151 |
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
|
152 |
char *t; |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
153 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
154 |
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
|
155 |
_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
|
156 |
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
|
157 |
|
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
158 |
t = strrchr(dirent->d_name, '.'); |
2338 | 159 |
if (t == NULL) continue; |
160 |
||
161 |
if (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
|
162 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
163 |
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
|
164 |
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
|
165 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
2099
02c5a49863e9
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
166 |
|
02c5a49863e9
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
167 |
*t = '\0'; // strip extension |
02c5a49863e9
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
168 |
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); |
2940
2b86050d1a94
(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
|
169 |
str_validate(fios->title); |
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
170 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { |
2338 | 171 |
if (strcasecmp(t, ".ss1") == 0 || |
172 |
strcasecmp(t, ".sv1") == 0 || |
|
173 |
strcasecmp(t, ".sv2") == 0) { // TTDLX(Patch) |
|
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
174 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
GetOldSaveGameName(fios->title, filename); |
0 | 179 |
} |
180 |
} |
|
181 |
} |
|
182 |
closedir(dir); |
|
183 |
} |
|
184 |
||
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
|
185 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 186 |
*num = _fios_count; |
187 |
return _fios_items; |
|
188 |
} |
|
189 |
||
190 |
// 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
|
191 |
// FIXME: Gross code duplication with FiosGetSavegameList() |
0 | 192 |
FiosItem *FiosGetScenarioList(int *num, int mode) |
193 |
{ |
|
194 |
FiosItem *fios; |
|
195 |
DIR *dir; |
|
196 |
struct dirent *dirent; |
|
197 |
struct stat sb; |
|
198 |
int sort_start; |
|
199 |
char filename[MAX_PATH]; |
|
200 |
||
201 |
if (_fios_scn_path == NULL) { |
|
202 |
_fios_scn_path = malloc(MAX_PATH); |
|
203 |
strcpy(_fios_scn_path, _path.scenario_dir); |
|
204 |
} |
|
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
205 |
|
0 | 206 |
_fios_path = _fios_scn_path; |
207 |
||
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
|
208 |
// 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
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
} |
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
|
215 |
|
0 | 216 |
// Show subdirectories first |
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
217 |
dir = opendir(_fios_path); |
0 | 218 |
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
|
219 |
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
|
220 |
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
|
221 |
_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
|
222 |
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
|
223 |
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
|
224 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
225 |
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
|
226 |
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
|
227 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
2099
02c5a49863e9
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
228 |
snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name); |
2940
2b86050d1a94
(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
|
229 |
str_validate(fios->title); |
0 | 230 |
} |
231 |
} |
|
232 |
closedir(dir); |
|
233 |
} |
|
234 |
||
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
235 |
{ |
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
236 |
/* XXX ugly global variables ... */ |
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
237 |
byte order = _savegame_sort_order; |
2526
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2380
diff
changeset
|
238 |
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING; |
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
239 |
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems); |
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
240 |
_savegame_sort_order = order; |
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
241 |
} |
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
242 |
|
0 | 243 |
// this is where to start sorting |
244 |
sort_start = _fios_count; |
|
245 |
||
1486
647d3a2be4fe
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
246 |
/* 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
|
247 |
* .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
|
248 |
* .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
|
249 |
* .SS0 Transport Tycoon Deluxe preset scenario |
0 | 250 |
*/ |
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
251 |
dir = opendir(_fios_path); |
0 | 252 |
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
|
253 |
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
|
254 |
char *t; |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
255 |
|
2099
02c5a49863e9
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
256 |
snprintf(filename, lengthof(filename), "%s/%s", _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
|
257 |
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
|
258 |
|
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
259 |
t = strrchr(dirent->d_name, '.'); |
2338 | 260 |
if (t == NULL) continue; |
261 |
||
262 |
if (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
|
263 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
2099
02c5a49863e9
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
267 |
|
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
268 |
*t = '\0'; // strip extension |
2099
02c5a49863e9
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
269 |
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); |
2940
2b86050d1a94
(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
|
270 |
str_validate(fios->title); |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
271 |
} 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
|
272 |
mode == SLD_NEW_GAME) { |
2338 | 273 |
if (strcasecmp(t, ".sv0") == 0 || |
274 |
strcasecmp(t, ".ss0") == 0) { // TTDLX(Patch) |
|
1449
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
275 |
fios = FiosAlloc(); |
df3ccdd9ee66
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
276 |
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
|
277 |
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
|
278 |
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
|
279 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
0 | 280 |
} |
281 |
} |
|
282 |
} |
|
283 |
closedir(dir); |
|
284 |
} |
|
285 |
||
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
|
286 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 287 |
*num = _fios_count; |
288 |
return _fios_items; |
|
289 |
} |
|
290 |
||
291 |
||
292 |
// 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
|
293 |
void FiosFreeSavegameList(void) |
0 | 294 |
{ |
295 |
free(_fios_items); |
|
296 |
_fios_items = NULL; |
|
297 |
_fios_alloc = _fios_count = 0; |
|
298 |
} |
|
299 |
||
300 |
// Browse to |
|
301 |
char *FiosBrowseTo(const FiosItem *item) |
|
302 |
{ |
|
303 |
char *path = _fios_path; |
|
304 |
char *s; |
|
305 |
||
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
306 |
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
|
307 |
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
|
308 |
s = strrchr(path, '/'); |
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
309 |
if (s != path) |
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
310 |
s[0] = '\0'; |
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
311 |
else |
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
312 |
s[1] = '\0'; |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
313 |
break; |
0 | 314 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
315 |
case FIOS_TYPE_DIR: |
2334
8986c80be5be
(svn r2860) Fix some issues in the savegame/scenario list code:
tron
parents:
2323
diff
changeset
|
316 |
if (path[1] != '\0') strcat(path, "/"); |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
317 |
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
|
318 |
break; |
0 | 319 |
|
2559
fe757666278c
(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
|
320 |
case FIOS_TYPE_DIRECT: |
2560
14bc4eaa3551
(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 |
sprintf(path, "%s/", item->name); |
14bc4eaa3551
(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
|
322 |
s = strrchr(path, '/'); |
14bc4eaa3551
(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
|
323 |
if (s[1] == '\0') s[0] = '\0'; // strip trailing slash |
2559
fe757666278c
(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
|
324 |
break; |
fe757666278c
(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
|
325 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
static char str_buffr[512]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
331 |
|
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
|
332 |
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
|
333 |
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
|
334 |
} |
0 | 335 |
} |
336 |
||
337 |
return NULL; |
|
338 |
} |
|
339 |
||
1596
483007886b59
(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 |
/** |
483007886b59
(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 |
* Get descriptive texts. Returns the path and free space |
483007886b59
(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 |
* left on the device |
483007886b59
(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 |
* @param path string describing the path |
483007886b59
(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 |
* @param tfs total free space in megabytes, optional (can be NULL) |
483007886b59
(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 |
* @return StringID describing the path (free space or failure) |
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1572
diff
changeset
|
346 |
*/ |
483007886b59
(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 |
StringID FiosGetDescText(const char **path, uint32 *tot) |
0 | 348 |
{ |
1596
483007886b59
(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
|
349 |
uint32 free = 0; |
2338 | 350 |
*path = _fios_path; |
0 | 351 |
|
1597
ef6253448620
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
352 |
#ifdef HAS_STATVFS |
0 | 353 |
{ |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
354 |
struct statvfs s; |
0 | 355 |
|
1597
ef6253448620
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
356 |
if (statvfs(*path, &s) == 0) { |
ef6253448620
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
357 |
free = (uint64)s.f_frsize * s.f_bavail >> 20; |
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
358 |
} else |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
359 |
return STR_4006_UNABLE_TO_READ_DRIVE; |
0 | 360 |
} |
1596
483007886b59
(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
|
361 |
#endif |
483007886b59
(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
|
362 |
if (tot != NULL) *tot = free; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
363 |
return STR_4005_BYTES_FREE; |
0 | 364 |
} |
365 |
||
366 |
void FiosMakeSavegameName(char *buf, const char *name) |
|
367 |
{ |
|
1508
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
368 |
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
|
369 |
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
|
370 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
371 |
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
|
372 |
extension = ".scn"; |
0 | 373 |
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
|
374 |
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
|
375 |
|
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
376 |
// 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
|
377 |
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
|
378 |
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
|
379 |
|
faae7585cae7
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
380 |
sprintf(buf, "%s/%s%s", _fios_path, name, extension); |
0 | 381 |
} |
382 |
||
2255
fd5d5adee9d9
(svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents:
2223
diff
changeset
|
383 |
bool FiosDelete(const char *name) |
0 | 384 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
385 |
char path[512]; |
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
386 |
|
1495
a9e4e2b78877
(svn r1999) r1990 broke savegame deletion, fix that [1161729]
tron
parents:
1486
diff
changeset
|
387 |
snprintf(path, lengthof(path), "%s/%s", _fios_path, name); |
2255
fd5d5adee9d9
(svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents:
2223
diff
changeset
|
388 |
return unlink(path) == 0; |
0 | 389 |
} |
390 |
||
391 |
bool FileExists(const char *filename) |
|
392 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
393 |
return access(filename, 0) == 0; |
0 | 394 |
} |
395 |
||
396 |
static int LanguageCompareFunc(const void *a, const void *b) |
|
397 |
{ |
|
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
|
398 |
return strcmp(*(const char* const *)a, *(const char* const *)b); |
0 | 399 |
} |
400 |
||
401 |
int GetLanguageList(char **languages, int max) |
|
402 |
{ |
|
403 |
DIR *dir; |
|
404 |
struct dirent *dirent; |
|
405 |
int num = 0; |
|
406 |
||
407 |
dir = opendir(_path.lang_dir); |
|
408 |
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
|
409 |
while ((dirent = readdir(dir)) != NULL) { |
0 | 410 |
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
|
411 |
|
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
412 |
if (t != NULL && strcmp(t, ".lng") == 0) { |
0 | 413 |
languages[num++] = strdup(dirent->d_name); |
414 |
if (num == max) break; |
|
415 |
} |
|
416 |
} |
|
417 |
closedir(dir); |
|
418 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
419 |
|
0 | 420 |
qsort(languages, num, sizeof(char*), LanguageCompareFunc); |
421 |
return num; |
|
422 |
} |
|
423 |
||
1050
958032fed209
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
424 |
#if defined(__BEOS__) || defined(__linux__) |
410 | 425 |
static void ChangeWorkingDirectory(char *exe) |
0 | 426 |
{ |
427 |
char *s = strrchr(exe, '/'); |
|
428 |
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
|
429 |
*s = '\0'; |
0 | 430 |
chdir(exe); |
431 |
*s = '/'; |
|
432 |
} |
|
433 |
} |
|
1050
958032fed209
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
434 |
#endif |
0 | 435 |
|
436 |
void ShowInfo(const char *str) |
|
437 |
{ |
|
438 |
puts(str); |
|
439 |
} |
|
440 |
||
441 |
void ShowOSErrorBox(const char *buf) |
|
442 |
{ |
|
2731
888a994e9fe9
(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
|
443 |
#if defined(__APPLE__) |
2188
640a0a5f77ea
(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 |
// this creates an NSAlertPanel with the contents of 'buf' |
640a0a5f77ea
(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
|
445 |
// this is the native and nicest way to do this on OSX |
640a0a5f77ea
(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
|
446 |
ShowMacDialog( buf, "See readme for more info\nMost likely you are missing files from the original TTD", "Quit" ); |
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
|
447 |
#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
|
448 |
// all systems, but OSX |
0 | 449 |
fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf); |
450 |
#endif |
|
451 |
} |
|
452 |
||
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
453 |
#ifdef WITH_COCOA |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
454 |
void cocoaSetWorkingDirectory(void); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
455 |
void cocoaSetupAutoreleasePool(void); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
456 |
void cocoaReleaseAutoreleasePool(void); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
457 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
458 |
|
0 | 459 |
int CDECL main(int argc, char* argv[]) |
460 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
461 |
int ret; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
462 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
463 |
#ifdef WITH_COCOA |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
464 |
cocoaSetupAutoreleasePool(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
465 |
/* This is passed if we are launched by double-clicking */ |
2952 | 466 |
if (argc >= 2 && strncmp (argv[1], "-psn", 4) == 0) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
467 |
argv[1] = NULL; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
468 |
argc = 1; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
469 |
cocoaSetWorkingDirectory(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
470 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
471 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
472 |
|
0 | 473 |
// 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
|
474 |
#if defined(__BEOS__) || defined(__linux__) |
0 | 475 |
ChangeWorkingDirectory(argv[0]); |
476 |
#endif |
|
477 |
||
206 | 478 |
_random_seeds[0][1] = _random_seeds[0][0] = time(NULL); |
2073 | 479 |
SeedMT(_random_seeds[0][1]); |
0 | 480 |
|
1509
795ba683e4f0
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
481 |
signal(SIGPIPE, SIG_IGN); |
0 | 482 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
483 |
ret = ttd_main(argc, argv); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
484 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
485 |
#ifdef WITH_COCOA |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
486 |
cocoaReleaseAutoreleasePool(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
487 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
488 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
2731
diff
changeset
|
489 |
return ret; |
0 | 490 |
} |
491 |
||
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
|
492 |
void DeterminePaths(void) |
0 | 493 |
{ |
494 |
char *s; |
|
495 |
||
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
496 |
_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
|
497 |
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
|
498 |
#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
|
499 |
_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
|
500 |
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
|
501 |
#endif |
0 | 502 |
|
503 |
#if defined(USE_HOMEDIR) |
|
504 |
{ |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
505 |
const char *homedir = getenv("HOME"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
506 |
|
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
507 |
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
|
508 |
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
|
509 |
if (pw != NULL) homedir = pw->pw_dir; |
0 | 510 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
511 |
|
0 | 512 |
_path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
513 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
514 |
|
0 | 515 |
#else /* not defined(USE_HOMEDIR) */ |
516 |
||
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
517 |
_path.personal_dir = malloc(MAX_PATH); |
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
518 |
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
|
519 |
|
0 | 520 |
// check if absolute or relative path |
521 |
s = strchr(_path.personal_dir, '/'); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
522 |
|
0 | 523 |
// 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
|
524 |
if (s == NULL || _path.personal_dir != s) { |
0 | 525 |
getcwd(_path.personal_dir, MAX_PATH); |
526 |
s = strchr(_path.personal_dir, 0); |
|
527 |
*s++ = '/'; |
|
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
528 |
ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
0 | 529 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
530 |
|
0 | 531 |
#endif /* defined(USE_HOMEDIR) */ |
532 |
||
533 |
s = strchr(_path.personal_dir, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
534 |
|
0 | 535 |
// 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
|
536 |
if (s[-1] != '/') strcpy(s, "/"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
537 |
|
0 | 538 |
_path.save_dir = str_fmt("%ssave", _path.personal_dir); |
539 |
_path.autosave_dir = str_fmt("%s/autosave", _path.save_dir); |
|
540 |
_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir); |
|
541 |
_path.gm_dir = str_fmt("%sgm/", _path.game_data_dir); |
|
542 |
_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
|
543 |
|
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
|
544 |
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
|
545 |
_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
|
546 |
|
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
|
547 |
_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
|
548 |
_log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
915 | 549 |
|
561
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
550 |
#if defined CUSTOM_LANG_DIR |
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
551 |
// 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
|
552 |
_path.lang_dir = malloc( MAX_PATH ); |
9a0c469a251c
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
553 |
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
|
554 |
#else |
0 | 555 |
_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
|
556 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
557 |
|
238
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
558 |
// create necessary folders |
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
559 |
mkdir(_path.personal_dir, 0755); |
0 | 560 |
mkdir(_path.save_dir, 0755); |
561 |
mkdir(_path.autosave_dir, 0755); |
|
562 |
mkdir(_path.scenario_dir, 0755); |
|
563 |
} |
|
564 |
||
1470
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
565 |
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
|
566 |
{ |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
567 |
return false; |
a8fd3e037531
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
568 |
} |
1885
aef601001f5e
(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
|
569 |
|
2073 | 570 |
|
571 |
// multi os compatible sleep function |
|
572 |
||
573 |
#ifdef __AMIGA__ |
|
574 |
// usleep() implementation |
|
575 |
# include <devices/timer.h> |
|
576 |
# include <dos/dos.h> |
|
577 |
||
578 |
extern struct Device *TimerBase = NULL; |
|
579 |
extern struct MsgPort *TimerPort = NULL; |
|
580 |
extern struct timerequest *TimerRequest = NULL; |
|
581 |
#endif // __AMIGA__ |
|
582 |
||
583 |
void CSleep(int milliseconds) |
|
584 |
{ |
|
585 |
#if !defined(__BEOS__) && !defined(__AMIGA__) |
|
586 |
usleep(milliseconds * 1000); |
|
587 |
#endif |
|
588 |
#ifdef __BEOS__ |
|
589 |
snooze(milliseconds * 1000); |
|
590 |
#endif |
|
591 |
#if defined(__AMIGA__) |
|
592 |
{ |
|
593 |
ULONG signals; |
|
594 |
ULONG TimerSigBit = 1 << TimerPort->mp_SigBit; |
|
595 |
||
596 |
// send IORequest |
|
597 |
TimerRequest->tr_node.io_Command = TR_ADDREQUEST; |
|
598 |
TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000; |
|
599 |
TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000; |
|
600 |
SendIO((struct IORequest *)TimerRequest); |
|
601 |
||
602 |
if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) { |
|
603 |
AbortIO((struct IORequest *)TimerRequest); |
|
604 |
} |
|
605 |
WaitIO((struct IORequest *)TimerRequest); |
|
606 |
} |
|
607 |
#endif // __AMIGA__ |
|
608 |
} |
|
3260
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
609 |
|
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
610 |
bool guessUTF8(void) |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
611 |
{ |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
612 |
#if defined(__linux__) |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
613 |
const char *lang = getenv("LANG"); |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
614 |
if(lang != NULL && strstr(lang, "UTF-8") != NULL) |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
615 |
return true; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
616 |
else |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
617 |
return false; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
618 |
#elif defined(__APPLE__) |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
619 |
return true; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
620 |
#else |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
621 |
return false; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
622 |
#endif |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
623 |
|
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
624 |
} |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
625 |
|
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
626 |
/* FYI: This is not thread-safe. |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
627 |
Assumptions: |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
628 |
- the 'from' charset is ISO-8859-15 |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
629 |
- the 'to' charset is either the same, or UTF-8 |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
630 |
*/ |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
631 |
const char *convert_to_fs_charset(const char *filename) |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
632 |
{ |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
633 |
static char statout[1024], statin[1024]; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
634 |
static iconv_t convd; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
635 |
static bool alreadyInited; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
636 |
char *outbuf = statout; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
637 |
const char *inbuf = statin; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
638 |
size_t inlen = strlen(filename), outlen = 1023; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
639 |
size_t retval = 0; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
640 |
if(inbuf == NULL) |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
641 |
inbuf = statin; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
642 |
|
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
643 |
if(guessUTF8() == false) |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
644 |
return filename; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
645 |
setlocale(LC_ALL, "C-UTF-8"); |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
646 |
strcpy(statout, filename); |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
647 |
strcpy(statin, filename); |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
648 |
inbuf = strrchr(statin, '/'); |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
649 |
outbuf = strrchr(statout, '/'); |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
650 |
if(alreadyInited == false) |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
651 |
{ |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
652 |
convd = iconv_open("UTF-8", "ISO-8859-15"); |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
653 |
if(convd == (iconv_t)(-1)) |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
654 |
return filename; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
655 |
alreadyInited = true; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
656 |
} |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
657 |
retval = iconv(convd, NULL, NULL, NULL, NULL); |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
658 |
inlen = iconv(convd, &inbuf, &inlen, &outbuf, &outlen); |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
659 |
// FIX: invalid characters will abort conversion, but they shouldn't occur? |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
660 |
return statout; |
ed19f95eb4f7
(svn r3966) -Fix: [OSX and some linux] [ 1157244 ] Can't save game if name contains german umlauts
bjarni
parents:
2952
diff
changeset
|
661 |
} |