diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-12-10 07:22:22 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-12-10 07:22:22 +0100 |
commit | aa61bbe9e414648399aff2802df5b587dee1a084 (patch) | |
tree | ff7809bea445bb76c9fd27a3245e1b2cb7c72596 /mmc_updater/src/DirIterator.cpp | |
parent | 3f5c46a1c4b27e82976e0067e4ec2d6abfffd9ba (diff) | |
parent | 712b87c643bbd7bc4ed2cfd459d0b9fdb69e5f0d (diff) | |
download | PrismLauncher-aa61bbe9e414648399aff2802df5b587dee1a084.tar.gz PrismLauncher-aa61bbe9e414648399aff2802df5b587dee1a084.tar.bz2 PrismLauncher-aa61bbe9e414648399aff2802df5b587dee1a084.zip |
Merge branch 'develop' of github.com:MultiMC/MultiMC5 into develop
Conflicts:
CMakeLists.txt
gui/MainWindow.cpp
Diffstat (limited to 'mmc_updater/src/DirIterator.cpp')
-rw-r--r-- | mmc_updater/src/DirIterator.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/mmc_updater/src/DirIterator.cpp b/mmc_updater/src/DirIterator.cpp new file mode 100644 index 00000000..a4604f05 --- /dev/null +++ b/mmc_updater/src/DirIterator.cpp @@ -0,0 +1,85 @@ +#include "DirIterator.h" + +#include "Log.h" +#include "StringUtils.h" + +#ifdef PLATFORM_UNIX + #include <dirent.h> +#endif + +#include <string.h> + +DirIterator::DirIterator(const char* path) +{ + m_path = path; + +#ifdef PLATFORM_UNIX + m_dir = opendir(path); + m_entry = 0; +#else + // to list the contents of a directory, the first + // argument to FindFirstFile needs to be a wildcard + // of the form: C:\path\to\dir\* + std::string searchPath = m_path; + if (!endsWith(searchPath,"/")) + { + searchPath.append("/"); + } + searchPath.append("*"); + m_findHandle = FindFirstFile(searchPath.c_str(),&m_findData); + m_firstEntry = true; +#endif +} + +DirIterator::~DirIterator() +{ +#ifdef PLATFORM_UNIX + closedir(m_dir); +#else + FindClose(m_findHandle); +#endif +} + +bool DirIterator::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 DirIterator::fileName() const +{ +#ifdef PLATFORM_UNIX + return m_entry->d_name; +#else + return m_findData.cFileName; +#endif +} + +std::string DirIterator::filePath() const +{ + return m_path + '/' + fileName(); +} + +bool DirIterator::isDir() const +{ +#ifdef PLATFORM_UNIX + return m_entry->d_type == DT_DIR; +#else + return (m_findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; +#endif +} + |