Merge pull request #4558 from JosJuice/volumedirectory-fst-sort

VolumeDirectory: Sort the FST
This commit is contained in:
Mat M 2016-12-25 17:38:58 -05:00 committed by GitHub
commit 9c8e27e3bb
2 changed files with 32 additions and 28 deletions

View File

@ -363,10 +363,7 @@ void CVolumeDirectory::BuildFST()
// write root entry // write root entry
WriteEntryData(fstOffset, DIRECTORY_ENTRY, 0, 0, rootEntry.size); WriteEntryData(fstOffset, DIRECTORY_ENTRY, 0, 0, rootEntry.size);
for (auto& entry : rootEntry.children) WriteDirectory(rootEntry, fstOffset, nameOffset, curDataAddress, rootOffset);
{
WriteEntry(entry, fstOffset, nameOffset, curDataAddress, rootOffset);
}
// overflow check // overflow check
_dbg_assert_(DVDINTERFACE, nameOffset == name_table_size); _dbg_assert_(DVDINTERFACE, nameOffset == name_table_size);
@ -443,9 +440,18 @@ void CVolumeDirectory::WriteEntryName(u32& nameOffset, const std::string& name)
nameOffset += (u32)(name.length() + 1); nameOffset += (u32)(name.length() + 1);
} }
void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u32& nameOffset, void CVolumeDirectory::WriteDirectory(const File::FSTEntry& parent_entry, u32& fstOffset,
u64& dataOffset, u32 parentEntryNum) u32& nameOffset, u64& dataOffset, u32 parentEntryNum)
{ {
std::vector<File::FSTEntry> sorted_entries = parent_entry.children;
std::sort(sorted_entries.begin(), sorted_entries.end(),
[](const File::FSTEntry& one, const File::FSTEntry& two) {
return one.virtualName < two.virtualName;
});
for (const File::FSTEntry& entry : sorted_entries)
{
if (entry.isDirectory) if (entry.isDirectory)
{ {
u32 myOffset = fstOffset; u32 myOffset = fstOffset;
@ -454,10 +460,7 @@ void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u
myEntryNum + entry.size + 1); myEntryNum + entry.size + 1);
WriteEntryName(nameOffset, entry.virtualName); WriteEntryName(nameOffset, entry.virtualName);
for (const auto& child : entry.children) WriteDirectory(entry, fstOffset, nameOffset, dataOffset, myEntryNum);
{
WriteEntry(child, fstOffset, nameOffset, dataOffset, myEntryNum);
}
} }
else else
{ {
@ -472,6 +475,7 @@ void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u
// 4 byte aligned // 4 byte aligned
dataOffset = Common::AlignUp(dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull); dataOffset = Common::AlignUp(dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull);
} }
}
} }
static u32 ComputeNameSize(const File::FSTEntry& parentEntry) static u32 ComputeNameSize(const File::FSTEntry& parentEntry)

View File

@ -85,8 +85,8 @@ private:
// FST creation // FST creation
void WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u64 length); void WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u64 length);
void WriteEntryName(u32& nameOffset, const std::string& name); void WriteEntryName(u32& nameOffset, const std::string& name);
void WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u32& nameOffset, u64& dataOffset, void WriteDirectory(const File::FSTEntry& parent_entry, u32& fstOffset, u32& nameOffset,
u32 parentEntryNum); u64& dataOffset, u32 parentEntryNum);
std::string m_rootDirectory; std::string m_rootDirectory;