From 192c2a3c5c51be81215563f5f09adb4587e055a0 Mon Sep 17 00:00:00 2001 From: "George V." Date: Sat, 11 Apr 2026 20:49:57 +0300 Subject: [PATCH] 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. --- Minecraft.Client/FolderFile.cpp | 28 ++++++++++++++++++++-------- Minecraft.Client/FolderFile.h | 3 ++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Minecraft.Client/FolderFile.cpp b/Minecraft.Client/FolderFile.cpp index 88a89887..35873207 100644 --- a/Minecraft.Client/FolderFile.cpp +++ b/Minecraft.Client/FolderFile.cpp @@ -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)); diff --git a/Minecraft.Client/FolderFile.h b/Minecraft.Client/FolderFile.h index 7c4cdecb..16d54b56 100644 --- a/Minecraft.Client/FolderFile.h +++ b/Minecraft.Client/FolderFile.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -15,6 +15,7 @@ private: unordered_map m_filePaths; // filename -> full path void _buildFileIndex(); + void _buildFileIndexRecursive(const wstring& currentPath, const wstring& relativePath); public: FolderFile(wstring folderPath);