AuroraRuntime/Source/IO/FS/FSRecursion.cpp
Reece Wilson d63571e4b5 [+] AuCompression::CompressionInterceptor
[+] AuCrypto::CBC::CBCContext
[+] AuFS::ReadDirRecursive
[+] AuFS::DirDeleter
[+] AuCrypto::PBKDF2
[+] AuCrypto::AES::CBCEncrypt
[+] AuCrypto::AES::CBCDecrypt
[+] AuCrypto::TDES::CBCEncrypt
[+] AuCrypto::TDES::CBCDecrypt
[+] Optimize read write locks
[*] Added `ContextFlags = CONTEXT_ALL` to Win32 PlatformWalkCallStack
2022-11-06 13:23:22 +00:00

98 lines
2.1 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FSRecursion.cpp
Date: 2022-11-06
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "FS.hpp"
namespace Aurora::IO::FS
{
struct RecursiveDirIterator : IReadDir
{
AuSPtr<IReadDir> pDir;
AuList<AuString> nextLevel;
AuString curPath;
AuString curSubDir;
bool OpenDir(const AuString &str)
{
curPath = str;
pDir = ReadDir(str);
return bool(pDir);
}
bool OpenNext(const AuString &str)
{
curPath = str;
pDir = ReadDir(str);
return bool(pDir);
}
void DoNext()
{
this->pDir.reset();
if (!nextLevel.size())
{
return;
}
auto a = nextLevel[0];
nextLevel.erase(nextLevel.begin());
pDir = ReadDir(curPath + "/" + a);
curSubDir = a;
}
virtual StatEx *Next() override
{
if (!this->pDir)
{
return {};
}
auto pNext = this->pDir->Next();
while (!pNext)
{
DoNext();
if (!this->pDir)
{
return {};
}
pNext = this->pDir->Next();
}
if (curSubDir.size())
{
pNext->fileName.insert(pNext->fileName.begin(), curSubDir.begin(), curSubDir.end());
}
if (pNext->bExistsDirectory)
{
nextLevel.push_back(pNext->fileName + "/");
}
return pNext;
}
};
AUKN_SYM AuSPtr<IReadDir> ReadDirRecursive(const AuString &string)
{
auto pObj = AuMakeShared<RecursiveDirIterator>();
if (!pObj)
{
SysPushErrorMem();
return {};
}
if (!pObj->OpenDir(string))
{
return {};
}
return pObj;
}
}