author | bjarni |
Thu, 28 Jul 2005 09:01:41 +0000 | |
changeset 2217 | c3a8a3bbc81f |
parent 2215 | 062de758687f |
child 2223 | 29d61b962cb0 |
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> |
|
16 |
#include <pwd.h> |
|
1509
2c232b7d2114
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
17 |
#include <signal.h> |
1911
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
18 |
#if !defined(__MORPHOS__) && !defined(__AMIGA__) |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
19 |
#include <pthread.h> |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
20 |
#endif |
0 | 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 ;) |
|
34 |
#endif /* __MORPHOS__ */ |
|
35 |
||
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
36 |
#ifdef __AMIGA__ |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
37 |
#warning add stack symbol to avoid that user needs to set stack manually (tokai) |
915 | 38 |
// ULONG __stack = |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
39 |
#endif |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
704
diff
changeset
|
40 |
|
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
|
41 |
#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
|
42 |
#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
|
43 |
//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
|
44 |
#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
|
45 |
#endif |
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 |
#include "os/macosx/macos.h" |
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
|
47 |
#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
|
48 |
|
0 | 49 |
static char *_fios_path; |
50 |
static char *_fios_save_path; |
|
51 |
static char *_fios_scn_path; |
|
52 |
static FiosItem *_fios_items; |
|
53 |
static int _fios_count, _fios_alloc; |
|
54 |
||
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
|
55 |
static FiosItem *FiosAlloc(void) |
0 | 56 |
{ |
57 |
if (_fios_count == _fios_alloc) { |
|
58 |
_fios_alloc += 256; |
|
59 |
_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem)); |
|
60 |
} |
|
61 |
return &_fios_items[_fios_count++]; |
|
62 |
} |
|
63 |
||
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
|
64 |
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
|
65 |
{ |
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
|
66 |
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
|
67 |
const FiosItem *db = (const FiosItem *)b; |
0 | 68 |
int r; |
69 |
||
70 |
if (_savegame_sort_order < 2) // sort by date |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
71 |
r = da->mtime < db->mtime ? -1 : 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
72 |
else |
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
73 |
r = strcasecmp(da->title, db->title); |
0 | 74 |
|
75 |
if (_savegame_sort_order & 1) r = -r; |
|
76 |
return r; |
|
77 |
} |
|
78 |
||
79 |
||
80 |
// Get a list of savegames |
|
81 |
FiosItem *FiosGetSavegameList(int *num, int mode) |
|
82 |
{ |
|
83 |
FiosItem *fios; |
|
84 |
DIR *dir; |
|
85 |
struct dirent *dirent; |
|
86 |
struct stat sb; |
|
87 |
int sort_start; |
|
88 |
char filename[MAX_PATH]; |
|
89 |
||
90 |
if (_fios_save_path == NULL) { |
|
91 |
_fios_save_path = malloc(MAX_PATH); |
|
92 |
strcpy(_fios_save_path, _path.save_dir); |
|
93 |
} |
|
94 |
||
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
95 |
_fios_path = _fios_save_path; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
96 |
|
0 | 97 |
// 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
|
98 |
if (_fios_path[1] != '\0') { |
0 | 99 |
fios = FiosAlloc(); |
100 |
fios->type = FIOS_TYPE_PARENT; |
|
101 |
fios->mtime = 0; |
|
1572
6d0111113f0b
(svn r2076) Set the name for the parent directory to ".."
tron
parents:
1509
diff
changeset
|
102 |
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
|
103 |
strcpy(fios->title, ".. (Parent directory)"); |
0 | 104 |
} |
105 |
||
106 |
// Show subdirectories first |
|
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
107 |
dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/"); |
0 | 108 |
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
|
109 |
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
|
110 |
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
|
111 |
_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
|
112 |
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
|
113 |
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
|
114 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
"%s/ (Directory)", dirent->d_name); |
0 | 120 |
} |
121 |
} |
|
122 |
closedir(dir); |
|
123 |
} |
|
124 |
||
307
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
125 |
{ |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
126 |
/* 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
|
127 |
byte order = _savegame_sort_order; |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
128 |
_savegame_sort_order = 2; // sort ascending by name |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
129 |
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
|
130 |
_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
|
131 |
} |
d251be6c0d54
(svn r313) -Feature/Fix: directories in *nix are now sorted alphabetically in ascending order (Tron).
darkvater
parents:
268
diff
changeset
|
132 |
|
0 | 133 |
// this is where to start sorting |
134 |
sort_start = _fios_count; |
|
135 |
||
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
|
136 |
/* 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
|
137 |
* .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
|
138 |
* .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
|
139 |
* .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
|
140 |
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game |
0 | 141 |
*/ |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
142 |
dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/"); |
0 | 143 |
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
|
144 |
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
|
145 |
char *t; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
146 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
147 |
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
|
148 |
_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
|
149 |
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
|
150 |
|
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
151 |
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
|
152 |
if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
153 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
|
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
158 |
*t = '\0'; // strip extension |
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
159 |
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
160 |
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) { |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
161 |
if (t != NULL && ( |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
162 |
strcasecmp(t, ".ss1") == 0 || |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
163 |
strcasecmp(t, ".sv1") == 0 || |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
164 |
strcasecmp(t, ".sv2") == 0 |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
165 |
)) { // TTDLX(Patch) |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
166 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
GetOldSaveGameName(fios->title, filename); |
0 | 171 |
} |
172 |
} |
|
173 |
} |
|
174 |
closedir(dir); |
|
175 |
} |
|
176 |
||
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
|
177 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 178 |
*num = _fios_count; |
179 |
return _fios_items; |
|
180 |
} |
|
181 |
||
182 |
// 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
|
183 |
// FIXME: Gross code duplication with FiosGetSavegameList() |
0 | 184 |
FiosItem *FiosGetScenarioList(int *num, int mode) |
185 |
{ |
|
186 |
FiosItem *fios; |
|
187 |
DIR *dir; |
|
188 |
struct dirent *dirent; |
|
189 |
struct stat sb; |
|
190 |
int sort_start; |
|
191 |
char filename[MAX_PATH]; |
|
192 |
||
193 |
if (_fios_scn_path == NULL) { |
|
194 |
_fios_scn_path = malloc(MAX_PATH); |
|
195 |
strcpy(_fios_scn_path, _path.scenario_dir); |
|
196 |
} |
|
197 |
_fios_path = _fios_scn_path; |
|
198 |
||
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
|
199 |
// 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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
} |
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 |
|
0 | 207 |
// Show subdirectories first |
208 |
dir = opendir(_fios_path[0] ? _fios_path : "/"); |
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
_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
|
213 |
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
|
214 |
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
|
215 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
216 |
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
|
217 |
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
|
218 |
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
|
219 |
snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name); |
0 | 220 |
} |
221 |
} |
|
222 |
closedir(dir); |
|
223 |
} |
|
224 |
||
225 |
// this is where to start sorting |
|
226 |
sort_start = _fios_count; |
|
227 |
||
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
228 |
/* 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
|
229 |
* .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
|
230 |
* .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
|
231 |
* .SS0 Transport Tycoon Deluxe preset scenario |
0 | 232 |
*/ |
233 |
dir = opendir(_fios_path[0] ? _fios_path : "/"); |
|
234 |
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
|
235 |
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
|
236 |
char *t; |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
237 |
|
2099
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
238 |
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
|
239 |
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
|
240 |
|
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
241 |
t = strrchr(dirent->d_name, '.'); |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
242 |
if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
243 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
|
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
248 |
*t = '\0'; // strip extension |
22f535ad9eea
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
Darkvater
parents:
2073
diff
changeset
|
249 |
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title)); |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
250 |
} 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
|
251 |
mode == SLD_NEW_GAME) { |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
252 |
if (t != NULL && ( |
1486
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
253 |
strcasecmp(t, ".sv0") == 0 || |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
254 |
strcasecmp(t, ".ss0") == 0 |
6a31e3d7dfe3
(svn r1990) Reduce the diff between the OS specific files with respect to file handling and fix some inconsitencies (I hope I didn't break the OS/2 part, couldn't test it, feedback is welcome)
tron
parents:
1482
diff
changeset
|
255 |
)) { // TTDLX(Patch) |
1449
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
256 |
fios = FiosAlloc(); |
71331c8f3f90
(svn r1953) Codechange: Tidyup, reduced ridiculous indentation levels, some sprintf()s replced by snprintf()s.
pasky
parents:
1390
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name)); |
0 | 261 |
} |
262 |
} |
|
263 |
} |
|
264 |
closedir(dir); |
|
265 |
} |
|
266 |
||
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
|
267 |
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems); |
0 | 268 |
*num = _fios_count; |
269 |
return _fios_items; |
|
270 |
} |
|
271 |
||
272 |
||
273 |
// 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
|
274 |
void FiosFreeSavegameList(void) |
0 | 275 |
{ |
276 |
free(_fios_items); |
|
277 |
_fios_items = NULL; |
|
278 |
_fios_alloc = _fios_count = 0; |
|
279 |
} |
|
280 |
||
281 |
// Browse to |
|
282 |
char *FiosBrowseTo(const FiosItem *item) |
|
283 |
{ |
|
284 |
char *path = _fios_path; |
|
285 |
char *s; |
|
286 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
s = strrchr(path, '/'); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
290 |
if (s != NULL) *s = '\0'; |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
291 |
break; |
0 | 292 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
293 |
case FIOS_TYPE_DIR: |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
294 |
s = strchr(item->name, '/'); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
295 |
if (s != NULL) *s = '\0'; |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
296 |
strcat(path, "/"); |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
297 |
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
|
298 |
break; |
0 | 299 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
static char str_buffr[512]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
305 |
|
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
|
306 |
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
|
307 |
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
|
308 |
} |
0 | 309 |
} |
310 |
||
311 |
return NULL; |
|
312 |
} |
|
313 |
||
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
|
314 |
/** |
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
|
315 |
* 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
|
316 |
* 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
|
317 |
* @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
|
318 |
* @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
|
319 |
* @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
|
320 |
*/ |
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
|
321 |
StringID FiosGetDescText(const char **path, uint32 *tot) |
0 | 322 |
{ |
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
|
323 |
uint32 free = 0; |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
324 |
*path = _fios_path[0] != '\0' ? _fios_path : "/"; |
0 | 325 |
|
1597
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
326 |
#ifdef HAS_STATVFS |
0 | 327 |
{ |
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
328 |
struct statvfs s; |
0 | 329 |
|
1597
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
330 |
if (statvfs(*path, &s) == 0) { |
cc09dbccddac
(svn r2101) statvfs() is availible on POSIX.1 conformant systems.
tron
parents:
1596
diff
changeset
|
331 |
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
|
332 |
} else |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
333 |
return STR_4006_UNABLE_TO_READ_DRIVE; |
0 | 334 |
} |
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
|
335 |
#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
|
336 |
if (tot != NULL) *tot = free; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
337 |
return STR_4005_BYTES_FREE; |
0 | 338 |
} |
339 |
||
340 |
void FiosMakeSavegameName(char *buf, const char *name) |
|
341 |
{ |
|
1508
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
342 |
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
|
343 |
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
|
344 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
345 |
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
|
346 |
extension = ".scn"; |
0 | 347 |
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
|
348 |
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
|
349 |
|
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
350 |
// 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
|
351 |
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
|
352 |
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
|
353 |
|
3f0d2f3147c2
(svn r2012) When making a savegame name, don't append the extension, if it is already there
tron
parents:
1495
diff
changeset
|
354 |
sprintf(buf, "%s/%s%s", _fios_path, name, extension); |
0 | 355 |
} |
356 |
||
357 |
void FiosDelete(const char *name) |
|
358 |
{ |
|
1336
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
359 |
char path[512]; |
c9e6b766bf21
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1317
diff
changeset
|
360 |
|
1495
c8a61d136f26
(svn r1999) r1990 broke savegame deletion, fix that [1161729]
tron
parents:
1486
diff
changeset
|
361 |
snprintf(path, lengthof(path), "%s/%s", _fios_path, name); |
0 | 362 |
unlink(path); |
363 |
} |
|
364 |
||
365 |
bool FileExists(const char *filename) |
|
366 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
367 |
return access(filename, 0) == 0; |
0 | 368 |
} |
369 |
||
370 |
static int LanguageCompareFunc(const void *a, const void *b) |
|
371 |
{ |
|
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
|
372 |
return strcmp(*(const char* const *)a, *(const char* const *)b); |
0 | 373 |
} |
374 |
||
375 |
int GetLanguageList(char **languages, int max) |
|
376 |
{ |
|
377 |
DIR *dir; |
|
378 |
struct dirent *dirent; |
|
379 |
int num = 0; |
|
380 |
||
381 |
dir = opendir(_path.lang_dir); |
|
382 |
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
|
383 |
while ((dirent = readdir(dir)) != NULL) { |
0 | 384 |
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
|
385 |
|
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
386 |
if (t != NULL && strcmp(t, ".lng") == 0) { |
0 | 387 |
languages[num++] = strdup(dirent->d_name); |
388 |
if (num == max) break; |
|
389 |
} |
|
390 |
} |
|
391 |
closedir(dir); |
|
392 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
393 |
|
0 | 394 |
qsort(languages, num, sizeof(char*), LanguageCompareFunc); |
395 |
return num; |
|
396 |
} |
|
397 |
||
1050
e76fa5c5d835
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
398 |
#if defined(__BEOS__) || defined(__linux__) |
410 | 399 |
static void ChangeWorkingDirectory(char *exe) |
0 | 400 |
{ |
401 |
char *s = strrchr(exe, '/'); |
|
402 |
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
|
403 |
*s = '\0'; |
0 | 404 |
chdir(exe); |
405 |
*s = '/'; |
|
406 |
} |
|
407 |
} |
|
1050
e76fa5c5d835
(svn r1551) Silence a warning and simplify a preprocessor check
tron
parents:
1010
diff
changeset
|
408 |
#endif |
0 | 409 |
|
410 |
void ShowInfo(const char *str) |
|
411 |
{ |
|
412 |
puts(str); |
|
413 |
} |
|
414 |
||
415 |
void ShowOSErrorBox(const char *buf) |
|
416 |
{ |
|
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
|
417 |
#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
|
418 |
// 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
|
419 |
// 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
|
420 |
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
|
421 |
#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
|
422 |
// all systems, but OSX |
0 | 423 |
fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf); |
424 |
#endif |
|
425 |
} |
|
426 |
||
427 |
int CDECL main(int argc, char* argv[]) |
|
428 |
{ |
|
429 |
// 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
|
430 |
#if defined(__BEOS__) || defined(__linux__) |
0 | 431 |
ChangeWorkingDirectory(argv[0]); |
432 |
#endif |
|
433 |
||
206 | 434 |
_random_seeds[0][1] = _random_seeds[0][0] = time(NULL); |
2073 | 435 |
SeedMT(_random_seeds[0][1]); |
0 | 436 |
|
1509
2c232b7d2114
(svn r2013) Always ignore SIGPIPE, not only when SDL is used (ShadowJK)
tron
parents:
1508
diff
changeset
|
437 |
signal(SIGPIPE, SIG_IGN); |
0 | 438 |
|
439 |
return ttd_main(argc, argv); |
|
440 |
} |
|
441 |
||
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
|
442 |
void DeterminePaths(void) |
0 | 443 |
{ |
444 |
char *s; |
|
445 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
446 |
_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
|
447 |
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
|
448 |
#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
|
449 |
_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
|
450 |
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
|
451 |
#endif |
0 | 452 |
|
453 |
#if defined(USE_HOMEDIR) |
|
454 |
{ |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
455 |
const char *homedir = getenv("HOME"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
456 |
|
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
457 |
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
|
458 |
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
|
459 |
if (pw != NULL) homedir = pw->pw_dir; |
0 | 460 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
461 |
|
0 | 462 |
_path.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR); |
463 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
464 |
|
0 | 465 |
#else /* not defined(USE_HOMEDIR) */ |
466 |
||
1470
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
467 |
_path.personal_dir = malloc(MAX_PATH); |
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
468 |
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
|
469 |
|
0 | 470 |
// check if absolute or relative path |
471 |
s = strchr(_path.personal_dir, '/'); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
472 |
|
0 | 473 |
// 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
|
474 |
if (s == NULL || _path.personal_dir != s) { |
0 | 475 |
getcwd(_path.personal_dir, MAX_PATH); |
476 |
s = strchr(_path.personal_dir, 0); |
|
477 |
*s++ = '/'; |
|
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
478 |
ttd_strlcpy(s, PERSONAL_DIR, MAX_PATH); |
0 | 479 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
480 |
|
0 | 481 |
#endif /* defined(USE_HOMEDIR) */ |
482 |
||
483 |
s = strchr(_path.personal_dir, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
484 |
|
0 | 485 |
// 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
|
486 |
if (s[-1] != '/') strcpy(s, "/"); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
487 |
|
0 | 488 |
_path.save_dir = str_fmt("%ssave", _path.personal_dir); |
489 |
_path.autosave_dir = str_fmt("%s/autosave", _path.save_dir); |
|
490 |
_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir); |
|
491 |
_path.gm_dir = str_fmt("%sgm/", _path.game_data_dir); |
|
492 |
_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
|
493 |
|
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
|
494 |
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
|
495 |
_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
|
496 |
|
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
|
497 |
_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
|
498 |
_log_file = str_fmt("%sopenttd.log", _path.personal_dir); |
915 | 499 |
|
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
500 |
#if defined CUSTOM_LANG_DIR |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
501 |
// 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
|
502 |
_path.lang_dir = malloc( MAX_PATH ); |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
543
diff
changeset
|
503 |
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
|
504 |
#else |
0 | 505 |
_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
|
506 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
507 |
|
238
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
508 |
// create necessary folders |
a73a3e50c7f9
(svn r239) Fix: [ 1025361 ] PERSONAL_DIR is created at startup now
dominik
parents:
223
diff
changeset
|
509 |
mkdir(_path.personal_dir, 0755); |
0 | 510 |
mkdir(_path.save_dir, 0755); |
511 |
mkdir(_path.autosave_dir, 0755); |
|
512 |
mkdir(_path.scenario_dir, 0755); |
|
513 |
} |
|
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 |
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
|
516 |
{ |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
517 |
return false; |
25c332b43280
(svn r1974) Cleanups, quite similar to those done to win32.c in r1972 (code duplication, anyone?)
tron
parents:
1449
diff
changeset
|
518 |
} |
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
|
519 |
|
1911
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
520 |
/** Dummy stubs as MorphOS/ AmigaOS does not really |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
521 |
* know about a thread concept nor has a working libpthread */ |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
522 |
#if defined(__MORPHOS__) || defined(__AMIGA__) |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
523 |
typedef int pthread_t; |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
524 |
#define pthread_create(thread, attr, function, arg) (true) |
1912 | 525 |
#define pthread_join(thread, retval) |
1911
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
526 |
#endif |
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
527 |
|
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
|
528 |
static pthread_t thread1 = 0; |
1911
ec2b67cf5414
(svn r2417) - Fix: threads on morphos are apparently unexistent, so implement stubs for them (tokai)
Darkvater
parents:
1899
diff
changeset
|
529 |
|
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
|
530 |
bool CreateOTTDThread(void *func, void *param) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
531 |
{ |
1899
98317b840d7b
(svn r2405) Simplify a few '? true : false' and '? false : true', especially the latter is confusing
tron
parents:
1892
diff
changeset
|
532 |
return pthread_create(&thread1, NULL, func, param) == 0; |
1885
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
533 |
} |
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
|
534 |
|
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
|
535 |
void CloseOTTDThread(void) {return;} |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
536 |
|
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
|
537 |
void JoinOTTDThread(void) |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
538 |
{ |
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
|
539 |
if (thread1 == 0) return; |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
540 |
|
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
|
541 |
pthread_join(thread1, NULL); |
4ce583a5275b
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
Darkvater
parents:
1850
diff
changeset
|
542 |
} |
2073 | 543 |
|
544 |
||
545 |
||
546 |
#ifdef ENABLE_NETWORK |
|
547 |
||
548 |
// multi os compatible sleep function |
|
549 |
||
550 |
#ifdef __AMIGA__ |
|
551 |
// usleep() implementation |
|
552 |
# include <devices/timer.h> |
|
553 |
# include <dos/dos.h> |
|
554 |
||
555 |
extern struct Device *TimerBase = NULL; |
|
556 |
extern struct MsgPort *TimerPort = NULL; |
|
557 |
extern struct timerequest *TimerRequest = NULL; |
|
558 |
#endif // __AMIGA__ |
|
559 |
||
560 |
void CSleep(int milliseconds) |
|
561 |
{ |
|
562 |
#if !defined(__BEOS__) && !defined(__AMIGA__) |
|
563 |
usleep(milliseconds * 1000); |
|
564 |
#endif |
|
565 |
#ifdef __BEOS__ |
|
566 |
snooze(milliseconds * 1000); |
|
567 |
#endif |
|
568 |
#if defined(__AMIGA__) |
|
569 |
{ |
|
570 |
ULONG signals; |
|
571 |
ULONG TimerSigBit = 1 << TimerPort->mp_SigBit; |
|
572 |
||
573 |
// send IORequest |
|
574 |
TimerRequest->tr_node.io_Command = TR_ADDREQUEST; |
|
575 |
TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000; |
|
576 |
TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000; |
|
577 |
SendIO((struct IORequest *)TimerRequest); |
|
578 |
||
579 |
if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) { |
|
580 |
AbortIO((struct IORequest *)TimerRequest); |
|
581 |
} |
|
582 |
WaitIO((struct IORequest *)TimerRequest); |
|
583 |
} |
|
584 |
#endif // __AMIGA__ |
|
585 |
} |
|
586 |
||
587 |
#endif /* ENABLE_NETWORK */ |
|
588 |