From 6e3ef9fa1a6705e91467678ce615c630ee4d343d Mon Sep 17 00:00:00 2001 From: alberth Date: Fri, 27 May 2011 21:42:51 +0000 Subject: (svn r22501) -Codechange: Move FileExists to a better place. --- src/fileio.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/fileio.cpp') diff --git a/src/fileio.cpp b/src/fileio.cpp index 78e946d23..5ddce0570 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -264,6 +264,24 @@ bool FioCheckFileExists(const char *filename, Subdirectory subdir) return true; } +/** + * Test whether the fiven filename exists. + * @param filename the file to test. + * @return true if and only if the file exists. + */ +bool FileExists(const char *filename) +{ +#if defined(WINCE) + /* There is always one platform that doesn't support basic commands... */ + HANDLE hand = CreateFile(OTTD2FS(filename), 0, 0, NULL, OPEN_EXISTING, 0, NULL); + if (hand == INVALID_HANDLE_VALUE) return 1; + CloseHandle(hand); + return 0; +#else + return access(OTTD2FS(filename), 0) == 0; +#endif +} + /** * Close a file in a safe way. */ -- cgit v1.2.3-54-g00ecf