mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2025-01-22 15:31:08 +00:00
Dir iterator implementation for Win32 - Untested
This commit is contained in:
parent
28b9d50f0a
commit
f4c6f1c1d7
2 changed files with 38 additions and 1 deletions
33
src/Dir.cpp
33
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue