DiscIO/DirectoryBlob: Add ability to have a start-of-file offset for a file ContentSource.

This commit is contained in:
Admiral H. Curtiss 2021-09-22 01:37:45 +02:00
parent 885e6690c5
commit a14436fe3f
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
2 changed files with 21 additions and 7 deletions

View File

@ -97,11 +97,15 @@ bool DiscContent::Read(u64* offset, u64* length, u8** buffer) const
{
const u64 bytes_to_read = std::min(m_size - offset_in_content, *length);
if (std::holds_alternative<std::string>(m_content_source))
if (std::holds_alternative<ContentFile>(m_content_source))
{
File::IOFile file(std::get<std::string>(m_content_source), "rb");
if (!file.Seek(offset_in_content, SEEK_SET) || !file.ReadBytes(*buffer, bytes_to_read))
const auto& content = std::get<ContentFile>(m_content_source);
File::IOFile file(content.m_filename, "rb");
if (!file.Seek(content.m_offset + offset_in_content, SEEK_SET) ||
!file.ReadBytes(*buffer, bytes_to_read))
{
return false;
}
}
else if (std::holds_alternative<const u8*>(m_content_source))
{
@ -136,14 +140,14 @@ void DiscContentContainer::Add(u64 offset, u64 size, ContentSource source)
u64 DiscContentContainer::CheckSizeAndAdd(u64 offset, const std::string& path)
{
const u64 size = File::GetSize(path);
Add(offset, size, path);
Add(offset, size, ContentFile{path, 0});
return size;
}
u64 DiscContentContainer::CheckSizeAndAdd(u64 offset, u64 max_size, const std::string& path)
{
const u64 size = std::min(File::GetSize(path), max_size);
Add(offset, size, path);
Add(offset, size, ContentFile{path, 0});
return size;
}
@ -791,7 +795,7 @@ void DirectoryBlobPartition::WriteDirectory(const File::FSTEntry& parent_entry,
WriteEntryName(name_offset, entry.virtualName, name_table_offset);
// write entry to virtual disc
m_contents.Add(*data_offset, entry.size, entry.physicalName);
m_contents.Add(*data_offset, entry.size, ContentFile{entry.physicalName, 0});
// 32 KiB aligned - many games are fine with less alignment, but not all
*data_offset = Common::AlignUp(*data_offset + entry.size, 0x8000ull);

View File

@ -33,8 +33,18 @@ class DirectoryBlobReader;
// Returns true if the path is inside a DirectoryBlob and doesn't represent the DirectoryBlob itself
bool ShouldHideFromGameList(const std::string& volume_path);
// Content chunk that is loaded from a file in the host file system.
struct ContentFile
{
// Path where the file can be found.
std::string m_filename;
// Offset from the start of the file where the first byte of this content chunk is.
u64 m_offset;
};
using ContentSource =
std::variant<std::string, // File
std::variant<ContentFile, // File
const u8*, // Memory
DirectoryBlobReader* // Partition (which one it is is determined by m_offset)
>;