feat: implement recursive folder traversal for file indexing

The previous implementation only indexed files in the root directory,
ignoring files in subdirectories. This change adds recursive traversal
to index all files within the folder hierarchy while maintaining
relative paths for compatibility.
This commit is contained in:
George V. 2026-04-11 20:49:57 +03:00
parent 566f7ba683
commit 192c2a3c5c
No known key found for this signature in database
GPG key ID: 1DB61094F2DD4982
2 changed files with 22 additions and 9 deletions

View file

@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "../Minecraft.World/StringHelpers.h"
#include "../Minecraft.World/compression.h"
@ -7,7 +7,12 @@
void FolderFile::_buildFileIndex()
{
wstring searchPath = m_folderPath + L"\\*";
_buildFileIndexRecursive(m_folderPath, L"");
}
void FolderFile::_buildFileIndexRecursive(const wstring& currentPath, const wstring& relativePath)
{
wstring searchPath = currentPath + L"\\*";
WIN32_FIND_DATAW findData;
HANDLE hFind = FindFirstFileW(searchPath.c_str(), &findData);
@ -19,13 +24,20 @@ void FolderFile::_buildFileIndex()
do
{
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
if (wcscmp(findData.cFileName, L".") == 0 || wcscmp(findData.cFileName, L"..") == 0)
continue;
wstring filename = findData.cFileName;
wstring fullRelativePath = relativePath.empty() ? filename : relativePath + L"\\" + filename;
wstring fullPath = currentPath + L"\\" + filename;
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
wstring filename = findData.cFileName;
wstring fullPath = m_folderPath + L"\\" + filename;
// Store filename without path for compatibility with existing code
m_filePaths[filename] = fullPath;
_buildFileIndexRecursive(fullPath, fullRelativePath);
}
else
{
m_filePaths[fullRelativePath] = fullPath;
}
} while (FindNextFileW(hFind, &findData));

View file

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <vector>
#include <unordered_map>
@ -15,6 +15,7 @@ private:
unordered_map<wstring, wstring> m_filePaths; // filename -> full path
void _buildFileIndex();
void _buildFileIndexRecursive(const wstring& currentPath, const wstring& relativePath);
public:
FolderFile(wstring folderPath);