diff --git a/src/Dir.cpp b/src/Dir.cpp index 9cc89a8..1097c7f 100644 --- a/src/Dir.cpp +++ b/src/Dir.cpp @@ -5,26 +5,53 @@ #endif Dir::Dir(const char* path) -: m_dir(0) { m_path = path; + +#ifdef PLATFORM_UNIX m_dir = opendir(path); +#else + m_findHandle = FindFirstFile(path,&m_findData); + m_firstEntry = true; +#endif } Dir::~Dir() { +#ifdef PLATFORM_UNIX closedir(m_dir); +#else + FindClose(m_findHandle); +#endif } bool Dir::next() { +#ifdef PLATFORM_UNIX m_entry = readdir(m_dir); return m_entry != 0; +#else + bool result; + if (m_firstEntry) + { + m_firstEntry = false; + return m_findHandle != INVALID_HANDLE_VALUE; + } + else + { + result = FindNextFile(m_findHandle,&m_findData); + } + return result; +#endif } std::string Dir::fileName() const { +#ifdef PLATFORM_UNIX return m_entry->d_name; +#else + return m_findData.cFileName; +#endif } std::string Dir::filePath() const @@ -34,6 +61,10 @@ std::string Dir::filePath() const bool Dir::isDir() const { +#ifdef PLATFORM_UNIX return m_entry->d_type == DT_DIR; +#else + return (m_findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; +#endif } diff --git a/src/Dir.h b/src/Dir.h index 53162f2..fc0e2af 100644 --- a/src/Dir.h +++ b/src/Dir.h @@ -30,5 +30,11 @@ class Dir DIR* m_dir; dirent* m_entry; #endif + +#ifdef PLATFORM_WINDOWS + HANDLE m_findHandle; + WIN32_FIND_DATA m_findData; + bool m_firstEntry; +#endif };