VolumeDirectory: Sort the FST
We can't rely on the OS returning files and directories in a deterministic order, so we should sort them on our own if we want VolumeDirectory to work for movies and netplay.
This commit is contained in:
parent
09c6148aba
commit
a502f069e8
|
@ -363,10 +363,7 @@ void CVolumeDirectory::BuildFST()
|
|||
// write root entry
|
||||
WriteEntryData(fstOffset, DIRECTORY_ENTRY, 0, 0, totalEntries);
|
||||
|
||||
for (auto& entry : rootEntry.children)
|
||||
{
|
||||
WriteEntry(entry, fstOffset, nameOffset, curDataAddress, rootOffset);
|
||||
}
|
||||
WriteDirectory(rootEntry, fstOffset, nameOffset, curDataAddress, rootOffset);
|
||||
|
||||
// overflow check
|
||||
_dbg_assert_(DVDINTERFACE, nameOffset == m_totalNameSize);
|
||||
|
@ -443,9 +440,18 @@ 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
u32 myOffset = fstOffset;
|
||||
|
@ -454,10 +460,7 @@ void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u
|
|||
myEntryNum + entry.size + 1);
|
||||
WriteEntryName(nameOffset, entry.virtualName);
|
||||
|
||||
for (const auto& child : entry.children)
|
||||
{
|
||||
WriteEntry(child, fstOffset, nameOffset, dataOffset, myEntryNum);
|
||||
}
|
||||
WriteDirectory(entry, fstOffset, nameOffset, dataOffset, myEntryNum);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -472,6 +475,7 @@ void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u
|
|||
// 4 byte aligned
|
||||
dataOffset = Common::AlignUp(dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static u32 ComputeNameSize(const File::FSTEntry& parentEntry)
|
||||
|
|
|
@ -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);
|
||||
|
||||
// returns number of entries found in _Directory
|
||||
u64 AddDirectoryEntries(const std::string& _Directory, File::FSTEntry& parentEntry);
|
||||
|
|
Loading…
Reference in New Issue