From 5a3aee5118feafd0f477fd05974a7cbeab2b05f2 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Tue, 23 Sep 2008 22:13:53 +0000 Subject: [PATCH] Split functionality from AddDirectoryEntries into ScanDirectoryTree (generic directory scanning; OS depedent) and ComputeNameSize (specific for CVolumeDirectory; OS independent). git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@646 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/DiscIO/Src/VolumeDirectory.cpp | 29 +++++++++++++++++++--- Source/Core/DiscIO/Src/VolumeDirectory.h | 20 +++++++-------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Source/Core/DiscIO/Src/VolumeDirectory.cpp b/Source/Core/DiscIO/Src/VolumeDirectory.cpp index 33ae382d14..bc92dd96c8 100644 --- a/Source/Core/DiscIO/Src/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/Src/VolumeDirectory.cpp @@ -455,7 +455,7 @@ static bool ReadFoundFile(const WIN32_FIND_DATA& ffd, CVolumeDirectory::FSTEntry return true; } -u32 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, FSTEntry& parentEntry) +static u32 ScanDirectoryTree(const std::string& _Directory, FSTEntry& parentEntry) { // Find the first file in the directory. WIN32_FIND_DATA ffd; @@ -483,7 +483,6 @@ u32 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, FSTEntr ++foundEntries; parentEntry.children.push_back(entry); - m_totalNameSize += entry.virtualName.length() + 1; } } while (FindNextFile(hFind, &ffd) != 0); } @@ -493,11 +492,35 @@ u32 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, FSTEntr return foundEntries; } #else -u32 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, FSTEntry& parentEntry) +static u32 ScanDirectoryTree(const std::string& _Directory, FSTEntry& parentEntry) { // TODO - Insert linux stuff here return 0; } #endif +static u32 ComputeNameSize(const FSTEntry& parentEntry) +{ + u32 nameSize = 0; + const std::vector& children = parentEntry.children; + for (std::vector::const_iterator it = children.begin(); + it != children.end(); ++it) + { + const FSTEntry& entry = *it; + if (entry.isDirectory) + { + nameSize += ComputeNameSize(entry); + } + nameSize += entry.virtualName.length() + 1; + } + return nameSize; +} + +u32 CVolumeDirectory::AddDirectoryEntries(const std::string& _Directory, FSTEntry& parentEntry) +{ + u32 foundEntries = ScanDirectoryTree(_Directory, parentEntry); + m_totalNameSize += ComputeNameSize(parentEntry); + return foundEntries; +} + } // namespace diff --git a/Source/Core/DiscIO/Src/VolumeDirectory.h b/Source/Core/DiscIO/Src/VolumeDirectory.h index 8f590924ae..f88abbbb69 100644 --- a/Source/Core/DiscIO/Src/VolumeDirectory.h +++ b/Source/Core/DiscIO/Src/VolumeDirectory.h @@ -30,6 +30,15 @@ namespace DiscIO { +struct FSTEntry +{ + bool isDirectory; + u32 size; // file length or number of entries from children + std::string physicalName; // name on disk + std::string virtualName; // name in FST names table + std::vector children; +}; + class CVolumeDirectory : public IVolume { @@ -55,15 +64,6 @@ class CVolumeDirectory void BuildFST(); - struct FSTEntry - { - bool isDirectory; - u32 size; // file length or number of entries from children - std::string physicalName; // name on disk - std::string virtualName; // name in FST names table - std::vector children; - }; - private: static std::string ExtractDirectoryName(const std::string& _rDirectory); @@ -84,7 +84,7 @@ class CVolumeDirectory void WriteEntry(const FSTEntry& entry, u32& fstOffset, u32& nameOffset, u64& dataOffset, u32 parentEntryNum); // returns number of entries found in _Directory - u32 AddDirectoryEntries(const std::string& _Directory, FSTEntry& parentEntry); + u32 AddDirectoryEntries(const std::string& _Directory, FSTEntry& parentEntry); std::string m_rootDirectory;