Commit b26ce44f authored by Ivan Dokunov's avatar Ivan Dokunov

Add FolderPathsIterator

parent 5a34acb5
......@@ -45,6 +45,7 @@
<ClCompile Include="..\..\..\source\core\FileExtIterator.cpp" />
<ClCompile Include="..\..\..\source\core\FileSystem.cpp" />
<ClCompile Include="..\..\..\source\core\FolderIterator.cpp" />
<ClCompile Include="..\..\..\source\core\FolderPathsIterator.cpp" />
<ClCompile Include="..\..\..\source\core\ModelPhysbox.cpp" />
<ClCompile Include="..\..\..\source\core\ModelProvider.cpp" />
<ClCompile Include="..\..\..\source\core\PerfMon.cpp" />
......@@ -85,6 +86,7 @@
<ClInclude Include="..\..\..\source\core\FileExtIterator.h" />
<ClInclude Include="..\..\..\source\core\FileSystem.h" />
<ClInclude Include="..\..\..\source\core\FolderIterator.h" />
<ClInclude Include="..\..\..\source\core\FolderPathsIterator.h" />
<ClInclude Include="..\..\..\source\core\IFile.h" />
<ClInclude Include="..\..\..\source\core\ITask.h" />
<ClInclude Include="..\..\..\source\core\ModelPhysbox.h" />
......
......@@ -88,6 +88,9 @@
<ClCompile Include="..\..\..\source\core\FolderIterator.cpp">
<Filter>Source\FileSystem</Filter>
</ClCompile>
<ClCompile Include="..\..\..\source\core\FolderPathsIterator.cpp">
<Filter>Source\FileSystem</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Source">
......@@ -251,5 +254,8 @@
<ClInclude Include="..\..\..\source\core\FolderIterator.h">
<Filter>Header\FileSystem</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\core\FolderPathsIterator.h">
<Filter>Header\FileSystem</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
#include "FolderPathsIterator.h"
CFolderPathsIterator::CFolderPathsIterator(Array<String> *paths)
: m_paths(paths)
{
}
const char *CFolderPathsIterator::next()
{
WIN32_FIND_DATA FindFileData;
HANDLE hf;
int size = m_paths->size();
while (index < size)
{
hf = INVALID_OR_NULL(m_handle) ? FindFirstFile(((*m_paths)[index] + "*.*").c_str(), &FindFileData) : m_handle;
if (hf != INVALID_HANDLE_VALUE)
{
while (FindNextFile(hf, &FindFileData) != 0)
{
m_handle = hf;
m_pathStr = (*m_paths)[index] + 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();
}
}
FIND_CLOSE(m_handle);
++index;
}
}
//Если вообще не нашли файлов возвращаем nullptr
return nullptr;
}
void CFolderPathsIterator::reset()
{
index = 0;
FIND_CLOSE(m_handle);
}
CFolderPathsIterator::~CFolderPathsIterator()
{
FIND_CLOSE(m_handle);
mem_delete_a(m_paths);
}
/***********************************************************
Copyright © Vitaliy Buturlin, Evgeny Danilovich, Ivan Dokunov, 2019
See the license in LICENSE
***********************************************************/
#ifndef __FOLDER_PATHS_ITERATOR_H
#define __FOLDER_PATHS_ITERATOR_H
#include "FileSystem.h"
class CFolderPathsIterator final : public IFileSystem::IFileIterator
{
private:
Array<String>* m_paths;
String m_pathStr;
int index = 0;
HANDLE m_handle = nullptr;
public:
CFolderPathsIterator(Array<String> *paths);
const char *XMETHODCALLTYPE next() override;
void XMETHODCALLTYPE reset() override;
~CFolderPathsIterator();
};
#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