summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/FileSystemGCWii.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2017-05-16 23:06:32 +0200
committerGitHub <noreply@github.com>2017-05-16 23:06:32 +0200
commitfa06d10f4a09ec5f16c0653f6e3e2cbbc043e925 (patch)
tree56ee1ce35f3a7128467289ff180cd6fd56af2f50 /Source/Core/DiscIO/FileSystemGCWii.cpp
parentf4e8a01d166378bda874fdfd7063b2fcce1ac89e (diff)
parent2bcad57225b9b0a4635d62eeabbbb138d71386bf (diff)
Merge pull request #2353 from JosJuice/wii-partition-cleanup
VolumeWiiCrypted: Replace ChangePartition with a partition parameter
Diffstat (limited to 'Source/Core/DiscIO/FileSystemGCWii.cpp')
-rw-r--r--Source/Core/DiscIO/FileSystemGCWii.cpp64
1 files changed, 29 insertions, 35 deletions
diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp
index b19fd7cf95..c3b9df3119 100644
--- a/Source/Core/DiscIO/FileSystemGCWii.cpp
+++ b/Source/Core/DiscIO/FileSystemGCWii.cpp
@@ -20,8 +20,8 @@
namespace DiscIO
{
-CFileSystemGCWii::CFileSystemGCWii(const IVolume* _rVolume)
- : IFileSystem(_rVolume), m_Initialized(false), m_Valid(false), m_Wii(false)
+CFileSystemGCWii::CFileSystemGCWii(const IVolume* _rVolume, const Partition& partition)
+ : IFileSystem(_rVolume, partition), m_Initialized(false), m_Valid(false), m_offset_shift(0)
{
m_Valid = DetectFileSystem();
}
@@ -80,7 +80,7 @@ u64 CFileSystemGCWii::ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64
read_length, _OffsetInFile, _rFullPath.c_str(), pFileInfo->m_Offset,
pFileInfo->m_FileSize);
- m_rVolume->Read(pFileInfo->m_Offset + _OffsetInFile, read_length, _pBuffer, m_Wii);
+ m_rVolume->Read(pFileInfo->m_Offset + _OffsetInFile, read_length, _pBuffer, m_partition);
return read_length;
}
@@ -111,7 +111,7 @@ bool CFileSystemGCWii::ExportFile(const std::string& _rFullPath,
std::vector<u8> buffer(readSize);
- result = m_rVolume->Read(fileOffset, readSize, &buffer[0], m_Wii);
+ result = m_rVolume->Read(fileOffset, readSize, &buffer[0], m_partition);
if (!result)
break;
@@ -130,14 +130,14 @@ bool CFileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const
u32 apploader_size;
u32 trailer_size;
const u32 header_size = 0x20;
- if (!m_rVolume->ReadSwapped(0x2440 + 0x14, &apploader_size, m_Wii) ||
- !m_rVolume->ReadSwapped(0x2440 + 0x18, &trailer_size, m_Wii))
+ if (!m_rVolume->ReadSwapped(0x2440 + 0x14, &apploader_size, m_partition) ||
+ !m_rVolume->ReadSwapped(0x2440 + 0x18, &trailer_size, m_partition))
return false;
apploader_size += trailer_size + header_size;
DEBUG_LOG(DISCIO, "Apploader size -> %x", apploader_size);
std::vector<u8> buffer(apploader_size);
- if (m_rVolume->Read(0x2440, apploader_size, buffer.data(), m_Wii))
+ if (m_rVolume->Read(0x2440, apploader_size, buffer.data(), m_partition))
{
std::string exportName(_rExportFolder + "/apploader.img");
@@ -155,8 +155,8 @@ bool CFileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const
u64 CFileSystemGCWii::GetBootDOLOffset() const
{
u32 offset = 0;
- m_rVolume->ReadSwapped(0x420, &offset, m_Wii);
- return static_cast<u64>(offset) << GetOffsetShift();
+ m_rVolume->ReadSwapped(0x420, &offset, m_partition);
+ return static_cast<u64>(offset) << m_offset_shift;
}
u32 CFileSystemGCWii::GetBootDOLSize(u64 dol_offset) const
@@ -173,8 +173,8 @@ u32 CFileSystemGCWii::GetBootDOLSize(u64 dol_offset) const
// Iterate through the 7 code segments
for (u8 i = 0; i < 7; i++)
{
- if (!m_rVolume->ReadSwapped(dol_offset + 0x00 + i * 4, &offset, m_Wii) ||
- !m_rVolume->ReadSwapped(dol_offset + 0x90 + i * 4, &size, m_Wii))
+ if (!m_rVolume->ReadSwapped(dol_offset + 0x00 + i * 4, &offset, m_partition) ||
+ !m_rVolume->ReadSwapped(dol_offset + 0x90 + i * 4, &size, m_partition))
return 0;
dol_size = std::max(offset + size, dol_size);
}
@@ -182,8 +182,8 @@ u32 CFileSystemGCWii::GetBootDOLSize(u64 dol_offset) const
// Iterate through the 11 data segments
for (u8 i = 0; i < 11; i++)
{
- if (!m_rVolume->ReadSwapped(dol_offset + 0x1c + i * 4, &offset, m_Wii) ||
- !m_rVolume->ReadSwapped(dol_offset + 0xac + i * 4, &size, m_Wii))
+ if (!m_rVolume->ReadSwapped(dol_offset + 0x1c + i * 4, &offset, m_partition) ||
+ !m_rVolume->ReadSwapped(dol_offset + 0xac + i * 4, &size, m_partition))
return 0;
dol_size = std::max(offset + size, dol_size);
}
@@ -200,7 +200,7 @@ bool CFileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const
return false;
std::vector<u8> buffer(DolSize);
- if (m_rVolume->Read(DolOffset, DolSize, &buffer[0], m_Wii))
+ if (m_rVolume->Read(DolOffset, DolSize, &buffer[0], m_partition))
{
std::string exportName(_rExportFolder + "/boot.dol");
@@ -218,7 +218,7 @@ bool CFileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const
std::string CFileSystemGCWii::GetStringFromOffset(u64 _Offset) const
{
std::string data(255, 0x00);
- m_rVolume->Read(_Offset, data.size(), (u8*)&data[0], m_Wii);
+ m_rVolume->Read(_Offset, data.size(), (u8*)&data[0], m_partition);
data.erase(std::find(data.begin(), data.end(), 0x00), data.end());
// TODO: Should we really always use SHIFT-JIS?
@@ -251,14 +251,14 @@ const SFileInfo* CFileSystemGCWii::FindFileInfo(const std::string& _rFullPath)
bool CFileSystemGCWii::DetectFileSystem()
{
u32 magic_bytes;
- if (m_rVolume->ReadSwapped(0x18, &magic_bytes, false) && magic_bytes == 0x5D1C9EA3)
+ if (m_rVolume->ReadSwapped(0x18, &magic_bytes, m_partition) && magic_bytes == 0x5D1C9EA3)
{
- m_Wii = true;
+ m_offset_shift = 2; // Wii file system
return true;
}
- else if (m_rVolume->ReadSwapped(0x1c, &magic_bytes, false) && magic_bytes == 0xC2339F3D)
+ else if (m_rVolume->ReadSwapped(0x1c, &magic_bytes, m_partition) && magic_bytes == 0xC2339F3D)
{
- m_Wii = false;
+ m_offset_shift = 0; // GameCube file system
return true;
}
@@ -268,21 +268,20 @@ bool CFileSystemGCWii::DetectFileSystem()
void CFileSystemGCWii::InitFileSystem()
{
m_Initialized = true;
- u32 const shift = GetOffsetShift();
// read the whole FST
u32 fst_offset_unshifted;
- if (!m_rVolume->ReadSwapped(0x424, &fst_offset_unshifted, m_Wii))
+ if (!m_rVolume->ReadSwapped(0x424, &fst_offset_unshifted, m_partition))
return;
- u64 FSTOffset = static_cast<u64>(fst_offset_unshifted) << shift;
+ u64 FSTOffset = static_cast<u64>(fst_offset_unshifted) << m_offset_shift;
// read all fileinfos
u32 name_offset, offset, size;
- if (!m_rVolume->ReadSwapped(FSTOffset + 0x0, &name_offset, m_Wii) ||
- !m_rVolume->ReadSwapped(FSTOffset + 0x4, &offset, m_Wii) ||
- !m_rVolume->ReadSwapped(FSTOffset + 0x8, &size, m_Wii))
+ if (!m_rVolume->ReadSwapped(FSTOffset + 0x0, &name_offset, m_partition) ||
+ !m_rVolume->ReadSwapped(FSTOffset + 0x4, &offset, m_partition) ||
+ !m_rVolume->ReadSwapped(FSTOffset + 0x8, &size, m_partition))
return;
- SFileInfo root = {name_offset, static_cast<u64>(offset) << shift, size};
+ SFileInfo root = {name_offset, static_cast<u64>(offset) << m_offset_shift, size};
if (!root.IsDirectory())
return;
@@ -308,12 +307,12 @@ void CFileSystemGCWii::InitFileSystem()
{
const u64 read_offset = FSTOffset + (i * 0xC);
name_offset = 0;
- m_rVolume->ReadSwapped(read_offset + 0x0, &name_offset, m_Wii);
+ m_rVolume->ReadSwapped(read_offset + 0x0, &name_offset, m_partition);
offset = 0;
- m_rVolume->ReadSwapped(read_offset + 0x4, &offset, m_Wii);
+ m_rVolume->ReadSwapped(read_offset + 0x4, &offset, m_partition);
size = 0;
- m_rVolume->ReadSwapped(read_offset + 0x8, &size, m_Wii);
- m_FileInfoVector.emplace_back(name_offset, static_cast<u64>(offset) << shift, size);
+ m_rVolume->ReadSwapped(read_offset + 0x8, &size, m_partition);
+ m_FileInfoVector.emplace_back(name_offset, static_cast<u64>(offset) << m_offset_shift, size);
NameTableOffset += 0xC;
}
@@ -351,9 +350,4 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _
return CurrentIndex;
}
-u32 CFileSystemGCWii::GetOffsetShift() const
-{
- return m_Wii ? 2 : 0;
-}
-
} // namespace