From 35d830924d21a384164dcbdae6945afd584654b7 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Tue, 23 Sep 2008 23:27:38 +0000 Subject: Moved ScanDirectoryTree() to FileUtil: this is a generic directory scanning function which might be useful in other places as well. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@650 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/FileUtil.cpp | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'Source/Core/Common/Src/FileUtil.cpp') diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index ab8894ee75..742ec097ee 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -23,6 +23,7 @@ #include // for SHGetFolderPath #include #include // for GetSaveFileName +#include #else #include @@ -169,4 +170,70 @@ u64 GetSize(const char *filename) return pos; } +#ifdef _WIN32 +static bool ReadFoundFile(const WIN32_FIND_DATA& ffd, FSTEntry& entry) +{ + // ignore files starting with a . + if(strncmp(ffd.cFileName, ".", 1) == 0) + return false; + + entry.virtualName = ffd.cFileName; + + if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + entry.isDirectory = true; + } + else + { + entry.isDirectory = false; + entry.size = ffd.nFileSizeLow; + } + + return true; +} + +u32 ScanDirectoryTree(const std::string& _Directory, FSTEntry& parentEntry) +{ + // Find the first file in the directory. + WIN32_FIND_DATA ffd; + std::string searchName = _Directory + "\\*"; + HANDLE hFind = FindFirstFile(searchName.c_str(), &ffd); + + u32 foundEntries = 0; + + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + FSTEntry entry; + + if(ReadFoundFile(ffd, entry)) + { + entry.physicalName = _Directory + "\\" + entry.virtualName; + if(entry.isDirectory) + { + u32 childEntries = ScanDirectoryTree(entry.physicalName, entry); + entry.size = childEntries; + foundEntries += childEntries; + } + + ++foundEntries; + + parentEntry.children.push_back(entry); + } + } while (FindNextFile(hFind, &ffd) != 0); + } + + FindClose(hFind); + + return foundEntries; +} +#else +u32 ScanDirectoryTree(const std::string& _Directory, FSTEntry& parentEntry) +{ + // TODO - Insert linux stuff here + return 0; +} +#endif + } // namespace -- cgit v1.2.3