Filesystem: Store pointer to beginning of FST in file infos

Needed for the next commit.
This commit is contained in:
JosJuice 2015-08-02 17:39:03 +02:00
parent 1262f08ac1
commit ee2b88ebb6
2 changed files with 15 additions and 10 deletions

View File

@ -22,8 +22,10 @@
namespace DiscIO namespace DiscIO
{ {
FileInfoGCWii::FileInfoGCWii(u8 offset_shift, const u8* fst_entry, const u8* name_table_start) constexpr u32 FST_ENTRY_SIZE = 4 * 3; // An FST entry consists of three 32-bit integers
: m_offset_shift(offset_shift), m_fst_entry(fst_entry), m_name_table_start(name_table_start)
FileInfoGCWii::FileInfoGCWii(const u8* fst, u8 offset_shift, u32 index, u32 total_file_infos)
: m_fst(fst), m_offset_shift(offset_shift), m_index(index), m_total_file_infos(total_file_infos)
{ {
} }
@ -33,7 +35,8 @@ FileInfoGCWii::~FileInfoGCWii()
u32 FileInfoGCWii::Get(EntryProperty entry_property) const u32 FileInfoGCWii::Get(EntryProperty entry_property) const
{ {
return Common::swap32(m_fst_entry + sizeof(u32) * static_cast<int>(entry_property)); return Common::swap32(m_fst + FST_ENTRY_SIZE * m_index +
sizeof(u32) * static_cast<int>(entry_property));
} }
u32 FileInfoGCWii::GetSize() const u32 FileInfoGCWii::GetSize() const
@ -55,7 +58,8 @@ std::string FileInfoGCWii::GetName() const
{ {
// TODO: Should we really always use SHIFT-JIS? // TODO: Should we really always use SHIFT-JIS?
// Some names in Pikmin (NTSC-U) don't make sense without it, but is it correct? // Some names in Pikmin (NTSC-U) don't make sense without it, but is it correct?
const u8* name = m_name_table_start + (Get(EntryProperty::NAME_OFFSET) & 0xFFFFFF); u32 name_offset = Get(EntryProperty::NAME_OFFSET) & 0xFFFFFF;
const u8* name = m_fst + FST_ENTRY_SIZE * m_total_file_infos + name_offset;
return SHIFTJISToUTF8(reinterpret_cast<const char*>(name)); return SHIFTJISToUTF8(reinterpret_cast<const char*>(name));
} }
@ -76,7 +80,7 @@ FileSystemGCWii::FileSystemGCWii(const Volume* _rVolume, const Partition& partit
return; return;
const u64 fst_offset = static_cast<u64>(*fst_offset_unshifted) << m_offset_shift; const u64 fst_offset = static_cast<u64>(*fst_offset_unshifted) << m_offset_shift;
const u64 fst_size = static_cast<u64>(*fst_size_unshifted) << m_offset_shift; const u64 fst_size = static_cast<u64>(*fst_size_unshifted) << m_offset_shift;
if (fst_size < 0xC) if (fst_size < FST_ENTRY_SIZE)
return; return;
// 128 MiB is more than the total amount of RAM in a Wii. // 128 MiB is more than the total amount of RAM in a Wii.
@ -99,12 +103,12 @@ FileSystemGCWii::FileSystemGCWii(const Volume* _rVolume, const Partition& partit
// Create all file info objects // Create all file info objects
u32 number_of_file_infos = Common::swap32(*((u32*)m_file_system_table.data() + 2)); u32 number_of_file_infos = Common::swap32(*((u32*)m_file_system_table.data() + 2));
const u8* fst_start = m_file_system_table.data(); const u8* fst_start = m_file_system_table.data();
const u8* name_table_start = fst_start + (number_of_file_infos * 0xC); const u8* name_table_start = fst_start + (FST_ENTRY_SIZE * number_of_file_infos);
const u8* name_table_end = fst_start + fst_size; const u8* name_table_end = fst_start + fst_size;
if (name_table_end < name_table_start) if (name_table_end < name_table_start)
return; return;
for (u32 i = 0; i < number_of_file_infos; i++) for (u32 i = 0; i < number_of_file_infos; i++)
m_FileInfoVector.emplace_back(m_offset_shift, fst_start + (i * 0xC), name_table_start); m_FileInfoVector.emplace_back(fst_start, m_offset_shift, i, number_of_file_infos);
// If we haven't returned yet, everything succeeded // If we haven't returned yet, everything succeeded
m_Valid = true; m_Valid = true;

View File

@ -21,7 +21,7 @@ class FileInfoGCWii : public FileInfo
{ {
public: public:
// Does not take ownership of pointers // Does not take ownership of pointers
FileInfoGCWii(u8 offset_shift, const u8* fst_entry, const u8* name_table_start); FileInfoGCWii(const u8* fst, u8 offset_shift, u32 index, u32 total_file_infos);
~FileInfoGCWii() override; ~FileInfoGCWii() override;
@ -40,9 +40,10 @@ private:
u32 Get(EntryProperty entry_property) const; u32 Get(EntryProperty entry_property) const;
const u8* const m_fst;
const u8 m_offset_shift; const u8 m_offset_shift;
const u8* const m_fst_entry; const u32 m_index;
const u8* const m_name_table_start; const u32 m_total_file_infos;
}; };
class FileSystemGCWii : public FileSystem class FileSystemGCWii : public FileSystem