From 9ba57ee3a6f72308ff01263dfe143cf23c1cf321 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sat, 19 Apr 2008 23:13:26 +0000 Subject: Fixes to compile with Visual C++. Moved direct.cc and direct.h to directn.* to avoid conflict with VC++ direct.h header. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@4390 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/files.cc | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'crawl-ref/source/files.cc') diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index 7b7211adce..7d04269590 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -52,20 +52,13 @@ #include #include -#if _MSC_VER -// # include conflicts with crawl's header. Yes this sucks -# include -#else -#include -#endif - #include "externs.h" #include "chardump.h" #include "cloud.h" #include "clua.h" #include "debug.h" -#include "direct.h" +#include "directn.h" #include "dungeon.h" #include "effects.h" #include "ghost.h" @@ -100,6 +93,14 @@ #include "view.h" #include "xom.h" +#if _MSC_VER +#include +#define WIN32_LEAN_AND_MEAN +#include +#else +#include +#endif + #ifndef HAVE_STAT #if defined(UNIX) || defined(__MINGW32__) || defined(DOS) #define HAVE_STAT @@ -225,12 +226,30 @@ player_save_info read_character_info(const std::string &savefile) return fromfile; } +static bool _is_good_filename(const std::string &s) +{ + return (s != "." && s != ".."); +} + // Returns the names of all files in the given directory. Note that the // filenames returned are relative to the directory. std::vector get_dir_files(const std::string &dirname) { std::vector files; +#ifdef _MSC_VER + WIN32_FIND_DATA lData; + HANDLE hFind = FindFirstFile(dirname.c_str(), &lData); + if (hFind != INVALID_HANDLE_VALUE) + { + if (_is_good_filename(lData.cFileName)) + files.push_back(lData.cFileName); + while (FindNextFile(hFind, &lData)) + files.push_back(lData.cFileName); + FindClose(hFind); + } +#else // non-MS VC++ compilers + DIR *dir = opendir(dirname.c_str()); if (!dir) return (files); @@ -244,6 +263,7 @@ std::vector get_dir_files(const std::string &dirname) files.push_back(name); } closedir(dir); +#endif return (files); } @@ -323,12 +343,18 @@ static bool file_exists(const std::string &name) // Low-tech existence check. static bool dir_exists(const std::string &dir) { +#ifdef _MSC_VER + DWORD lAttr = GetFileAttributes(dir.c_str()); + return (lAttr != INVALID_FILE_ATTRIBUTES + && (lAttr & FILE_ATTRIBUTE_DIRECTORY)); +#else DIR *d = opendir(dir.c_str()); const bool exists = !!d; if (d) closedir(d); return (exists); +#endif } static int create_directory(const char *dir) -- cgit v1.2.3-54-g00ecf