Commit 253b3f6f authored by Ivan Dokunov's avatar Ivan Dokunov

Add FolderIterator

parent 9aed8f85
......@@ -44,6 +44,7 @@
<ClCompile Include="..\..\..\source\core\FileInMemory.cpp" />
<ClCompile Include="..\..\..\source\core\FileExtIterator.cpp" />
<ClCompile Include="..\..\..\source\core\FileSystem.cpp" />
<ClCompile Include="..\..\..\source\core\FolderIterator.cpp" />
<ClCompile Include="..\..\..\source\core\ModelPhysbox.cpp" />
<ClCompile Include="..\..\..\source\core\ModelProvider.cpp" />
<ClCompile Include="..\..\..\source\core\PerfMon.cpp" />
......@@ -83,6 +84,7 @@
<ClInclude Include="..\..\..\source\core\File.h" />
<ClInclude Include="..\..\..\source\core\FileExtIterator.h" />
<ClInclude Include="..\..\..\source\core\FileSystem.h" />
<ClInclude Include="..\..\..\source\core\FolderIterator.h" />
<ClInclude Include="..\..\..\source\core\IFile.h" />
<ClInclude Include="..\..\..\source\core\ITask.h" />
<ClInclude Include="..\..\..\source\core\ModelPhysbox.h" />
......
......@@ -85,6 +85,9 @@
<ClCompile Include="..\..\..\source\core\FIleExtPathsIterator.cpp">
<Filter>Source\FileSystem</Filter>
</ClCompile>
<ClCompile Include="..\..\..\source\core\FolderIterator.cpp">
<Filter>Source\FileSystem</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Source">
......@@ -245,5 +248,8 @@
<ClInclude Include="..\..\..\source\core\FileExtPathsIterator.h">
<Filter>Header\FileSystem</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\core\FolderIterator.h">
<Filter>Header\FileSystem</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -2,6 +2,7 @@
#include "FileExtIterator.h"
#include "FileExtsIterator.h"
#include "FileExtPathsIterator.h"
#include "FolderIterator.h"
#include "File.h"
#include <shellapi.h>
#include <ShlObj.h>
......@@ -333,7 +334,7 @@ time_t CFileSystem::getFileModifyTime(const char *szPath)
IFileSystem::IFileIterator *CFileSystem::getFolderList(const char *szPath)
{
return nullptr;
return new CFolderIterator(szPath);
}
IFileSystem::IFileIterator *CFileSystem::getFileList(const char *szPath, const char *szExt)
......
#include "FolderIterator.h"
CFolderIterator::CFolderIterator(const char *szPath)
: m_sPath(szPath)
{
if (szPath[strlen(szPath) != '\\'] || szPath[strlen(szPath) != '/'])
{
m_sPath += "/";
}
}
const char *CFolderIterator::next()
{
WIN32_FIND_DATA FindFileData;
HANDLE hf;
/*В отличии от fileIterator тут мы должны искать все файлы
для корректной проверки, является ли файл - директорией*/
hf = INVALID_OR_NULL(m_handle) ? FindFirstFile((m_sPath + "*.*").c_str(), &FindFileData) : m_handle;
if (hf != INVALID_HANDLE_VALUE)
{
while (FindNextFile(hf, &FindFileData) != 0)
{
m_handle = hf;
m_pathStr = m_sPath + FindFileData.cFileName;
DWORD flag = GetFileAttributes(m_pathStr.c_str());
if (!strcmp(FindFileData.cFileName, "..") || !strcmp(FindFileData.cFileName, "."))
{
continue;
}
//Берет только имена директорий
if (flag != INVALID_FILE_ATTRIBUTES && flag & FILE_ATTRIBUTE_DIRECTORY)
{
//Возвращаем полный путь к директории
return m_pathStr.c_str();
}
}
}
//Если вообще не нашли файлов возвращаем nullptr
return nullptr;
}
void CFolderIterator::reset()
{
FIND_CLOSE(m_handle);
}
CFolderIterator::~CFolderIterator()
{
FIND_CLOSE(m_handle);
}
/***********************************************************
Copyright © Vitaliy Buturlin, Evgeny Danilovich, Ivan Dokunov, 2019
See the license in LICENSE
***********************************************************/
#ifndef __FOLDER_ITERATOR_H
#define __FOLDER_ITERATOR_H
#include "FileSystem.h"
class CFolderIterator final : public IFileSystem::IFileIterator
{
private:
String m_sPath;
String m_pathStr;
HANDLE m_handle = nullptr;
public:
CFolderIterator(const char *szPath);
const char *XMETHODCALLTYPE next() override;
void XMETHODCALLTYPE reset() override;
~CFolderIterator();
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment