Merge pull request #2361 from JosJuice/filesystem-read32

Remove CFileSystemGCWii::Read32
This commit is contained in:
Ryan Houdek 2015-05-25 23:40:28 -04:00
commit 5911dd528a
2 changed files with 19 additions and 27 deletions

View File

@ -126,9 +126,9 @@ bool CFileSystemGCWii::ExportFile(const std::string& _rFullPath, const std::stri
bool CFileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const
{
u32 AppSize = Read32(0x2440 + 0x14);// apploader size
AppSize += Read32(0x2440 + 0x18); // + trailer size
AppSize += 0x20; // + header size
u32 AppSize = m_rVolume->Read32(0x2440 + 0x14, m_Wii); // apploader size
AppSize += m_rVolume->Read32(0x2440 + 0x18, m_Wii); // + trailer size
AppSize += 0x20; // + header size
DEBUG_LOG(DISCIO,"AppSize -> %x", AppSize);
std::vector<u8> buffer(AppSize);
@ -149,14 +149,14 @@ bool CFileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const
u32 CFileSystemGCWii::GetBootDOLSize() const
{
u32 DolOffset = Read32(0x420) << GetOffsetShift();
u32 DolOffset = m_rVolume->Read32(0x420, m_Wii) << GetOffsetShift();
u32 DolSize = 0, offset = 0, size = 0;
// Iterate through the 7 code segments
for (u8 i = 0; i < 7; i++)
{
offset = Read32(DolOffset + 0x00 + i * 4);
size = Read32(DolOffset + 0x90 + i * 4);
offset = m_rVolume->Read32(DolOffset + 0x00 + i * 4, m_Wii);
size = m_rVolume->Read32(DolOffset + 0x90 + i * 4, m_Wii);
if (offset + size > DolSize)
DolSize = offset + size;
}
@ -164,8 +164,8 @@ u32 CFileSystemGCWii::GetBootDOLSize() const
// Iterate through the 11 data segments
for (u8 i = 0; i < 11; i++)
{
offset = Read32(DolOffset + 0x1c + i * 4);
size = Read32(DolOffset + 0xac + i * 4);
offset = m_rVolume->Read32(DolOffset + 0x1c + i * 4, m_Wii);
size = m_rVolume->Read32(DolOffset + 0xac + i * 4, m_Wii);
if (offset + size > DolSize)
DolSize = offset + size;
}
@ -174,13 +174,13 @@ u32 CFileSystemGCWii::GetBootDOLSize() const
bool CFileSystemGCWii::GetBootDOL(u8* &buffer, u32 DolSize) const
{
u32 DolOffset = Read32(0x420) << GetOffsetShift();
u32 DolOffset = m_rVolume->Read32(0x420, m_Wii) << GetOffsetShift();
return m_rVolume->Read(DolOffset, DolSize, buffer, m_Wii);
}
bool CFileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const
{
u32 DolOffset = Read32(0x420) << GetOffsetShift();
u32 DolOffset = m_rVolume->Read32(0x420, m_Wii) << GetOffsetShift();
u32 DolSize = GetBootDOLSize();
std::vector<u8> buffer(DolSize);
@ -199,13 +199,6 @@ bool CFileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const
return false;
}
u32 CFileSystemGCWii::Read32(u64 _Offset) const
{
u32 Temp = 0;
m_rVolume->Read(_Offset, 4, (u8*)&Temp, m_Wii);
return Common::swap32(Temp);
}
std::string CFileSystemGCWii::GetStringFromOffset(u64 _Offset) const
{
std::string data(255, 0x00);
@ -247,12 +240,12 @@ const SFileInfo* CFileSystemGCWii::FindFileInfo(const std::string& _rFullPath)
bool CFileSystemGCWii::DetectFileSystem()
{
if (Read32(0x18) == 0x5D1C9EA3)
if (m_rVolume->Read32(0x18, false) == 0x5D1C9EA3)
{
m_Wii = true;
return true;
}
else if (Read32(0x1c) == 0xC2339F3D)
else if (m_rVolume->Read32(0x1c, false) == 0xC2339F3D)
{
m_Wii = false;
return true;
@ -267,7 +260,7 @@ void CFileSystemGCWii::InitFileSystem()
u32 const shift = GetOffsetShift();
// read the whole FST
u64 FSTOffset = static_cast<u64>(Read32(0x424)) << shift;
u64 FSTOffset = static_cast<u64>(m_rVolume->Read32(0x424, m_Wii)) << shift;
// u32 FSTSize = Read32(0x428);
// u32 FSTMaxSize = Read32(0x42C);
@ -275,9 +268,9 @@ void CFileSystemGCWii::InitFileSystem()
// read all fileinfos
SFileInfo Root
{
Read32(FSTOffset + 0x0),
m_rVolume->Read32(FSTOffset + 0x0, m_Wii),
static_cast<u64>(FSTOffset + 0x4) << shift,
Read32(FSTOffset + 0x8)
m_rVolume->Read32(FSTOffset + 0x8, m_Wii)
};
if (!Root.IsDirectory())
@ -291,9 +284,9 @@ void CFileSystemGCWii::InitFileSystem()
for (u32 i = 0; i < Root.m_FileSize; i++)
{
u64 const read_offset = FSTOffset + (i * 0xC);
u64 const name_offset = Read32(read_offset + 0x0);
u64 const offset = static_cast<u64>(Read32(read_offset + 0x4)) << shift;
u64 const size = Read32(read_offset + 0x8);
u64 const name_offset = m_rVolume->Read32(read_offset + 0x0, m_Wii);
u64 const offset = static_cast<u64>(m_rVolume->Read32(read_offset + 0x4, m_Wii)) << shift;
u64 const size = m_rVolume->Read32(read_offset + 0x8, m_Wii);
m_FileInfoVector.emplace_back(name_offset, offset, size);
NameTableOffset += 0xC;
}

View File

@ -36,9 +36,8 @@ private:
bool m_Initialized;
bool m_Valid;
bool m_Wii;
std::vector<SFileInfo> m_FileInfoVector;
std::vector <SFileInfo> m_FileInfoVector;
u32 Read32(u64 _Offset) const;
std::string GetStringFromOffset(u64 _Offset) const;
const SFileInfo* FindFileInfo(const std::string& _rFullPath);
bool DetectFileSystem();