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
WriteEntryData(fstOffset, DIRECTORY_ENTRY, 0, 0, rootEntry.size);
for (auto& entry : rootEntry.children)
{
WriteEntry(entry, fstOffset, nameOffset, curDataAddress, rootOffset);
}
WriteDirectory(rootEntry, fstOffset, nameOffset, curDataAddress, rootOffset);
// overflow check
_dbg_assert_(DVDINTERFACE, nameOffset == name_table_size);
@ -443,34 +440,41 @@ void CVolumeDirectory::WriteEntryName(u32& nameOffset, const std::string& name)
nameOffset += (u32)(name.length() + 1);
}
void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u32& nameOffset,
u64& dataOffset, u32 parentEntryNum)
void CVolumeDirectory::WriteDirectory(const File::FSTEntry& parent_entry, u32& fstOffset,
u32& nameOffset, u64& dataOffset, u32 parentEntryNum)
{
if (entry.isDirectory)
{
u32 myOffset = fstOffset;
u32 myEntryNum = myOffset / ENTRY_SIZE;
WriteEntryData(fstOffset, DIRECTORY_ENTRY, nameOffset, parentEntryNum,
myEntryNum + entry.size + 1);
WriteEntryName(nameOffset, entry.virtualName);
std::vector<File::FSTEntry> sorted_entries = parent_entry.children;
for (const auto& child : 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)
{
WriteEntry(child, fstOffset, nameOffset, dataOffset, myEntryNum);
u32 myOffset = fstOffset;
u32 myEntryNum = myOffset / ENTRY_SIZE;
WriteEntryData(fstOffset, DIRECTORY_ENTRY, nameOffset, parentEntryNum,
myEntryNum + entry.size + 1);
WriteEntryName(nameOffset, entry.virtualName);
WriteDirectory(entry, fstOffset, nameOffset, dataOffset, myEntryNum);
}
}
else
{
// put entry in FST
WriteEntryData(fstOffset, FILE_ENTRY, nameOffset, dataOffset, entry.size);
WriteEntryName(nameOffset, entry.virtualName);
else
{
// put entry in FST
WriteEntryData(fstOffset, FILE_ENTRY, nameOffset, dataOffset, entry.size);
WriteEntryName(nameOffset, entry.virtualName);
// write entry to virtual disk
_dbg_assert_(DVDINTERFACE, m_virtualDisk.find(dataOffset) == m_virtualDisk.end());
m_virtualDisk.emplace(dataOffset, entry.physicalName);
// write entry to virtual disk
_dbg_assert_(DVDINTERFACE, m_virtualDisk.find(dataOffset) == m_virtualDisk.end());
m_virtualDisk.emplace(dataOffset, entry.physicalName);
// 4 byte aligned
dataOffset = Common::AlignUp(dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull);
// 4 byte aligned
dataOffset = Common::AlignUp(dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull);
}
}
}

View File

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