summaryrefslogtreecommitdiff
path: root/fileio.c
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2005-01-28 08:56:43 +0000
committerdominik <dominik@openttd.org>2005-01-28 08:56:43 +0000
commitc8d084a85e4eb2b20055cffc1bcbddf16b5e337f (patch)
tree5d9b756fe3bff49b8276debff76e632b693e8430 /fileio.c
parent3e0dcfd47fede1060313de42ee75c9f882ae3400 (diff)
downloadopenttd-c8d084a85e4eb2b20055cffc1bcbddf16b5e337f.tar.xz
(svn r1702) - Fix: [ 1110407 ] Game does not crash any more when a newgrf file doesn't exist
Diffstat (limited to 'fileio.c')
-rw-r--r--fileio.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/fileio.c b/fileio.c
index c9fee6ba4..4b6fee1ce 100644
--- a/fileio.c
+++ b/fileio.c
@@ -100,6 +100,42 @@ void FioCloseAll(void)
FioCloseFile(i);
}
+bool FiosCheckFileExists(const char *filename)
+{
+ FILE *f;
+ char buf[MAX_PATH];
+
+ sprintf(buf, "%s%s", _path.data_dir, filename);
+
+ f = fopen(buf, "rb");
+#if !defined(WIN32)
+ if (f == NULL) {
+ char *s;
+ // Make lower case and try again
+ for(s=buf + strlen(_path.data_dir) - 1; *s != 0; s++)
+ *s = tolower(*s);
+ f = fopen(buf, "rb");
+
+#if defined SECOND_DATA_DIR
+ // tries in the 2nd data directory
+ if (f == NULL) {
+ sprintf(buf, "%s%s", _path.second_data_dir, filename);
+ for(s=buf + strlen(_path.second_data_dir) - 1; *s != 0; s++)
+ *s = tolower(*s);
+ f = fopen(buf, "rb");
+ }
+#endif
+ }
+#endif
+
+ if (f == NULL)
+ return false;
+ else {
+ fclose(f);
+ return true;
+ }
+}
+
void FioOpenFile(int slot, const char *filename)
{
FILE *f;