From 19b8f1c10adeefd9413687ab7a7c21b509fe777d Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 13 Jun 2015 12:51:24 +0200 Subject: VolumeWiiCrypted: Replace ChangePartition with a partition parameter By removing mutable state in VolumeWiiCrypted, this change makes partition-related code simpler. It also gets rid of other ugly things, like ISOProperties's "over 9000" loop that creates a list of partitions by trying possible combinations, and DiscScrubber's volume swapping that recreates the entire volume when it needs to change partition. --- Source/Core/DiscIO/FileSystemGCWii.cpp | 46 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'Source/Core/DiscIO/FileSystemGCWii.cpp') diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index b19fd7cf95..ec4f8c2c28 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_Wii(false) { 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 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 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,7 +155,7 @@ bool CFileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const u64 CFileSystemGCWii::GetBootDOLOffset() const { u32 offset = 0; - m_rVolume->ReadSwapped(0x420, &offset, m_Wii); + m_rVolume->ReadSwapped(0x420, &offset, m_partition); return static_cast(offset) << GetOffsetShift(); } @@ -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 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,12 +251,12 @@ 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; 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; return true; @@ -272,15 +272,15 @@ void CFileSystemGCWii::InitFileSystem() // 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(fst_offset_unshifted) << 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(offset) << shift, size}; @@ -308,11 +308,11 @@ 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_rVolume->ReadSwapped(read_offset + 0x8, &size, m_partition); m_FileInfoVector.emplace_back(name_offset, static_cast(offset) << shift, size); NameTableOffset += 0xC; } -- cgit v1.2.3 From 639ce6c484c58c577c978eb9eda08e7800e959b1 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 13 Jun 2015 20:50:03 +0200 Subject: FileSystemGCWii: Replace m_Wii with m_offset_shift I replaced m_OffsetShift with m_Wii in bb93336 to support the decrypt parameter for read functions. Doing that is no longer necessary, so m_offset_shift is now used like before. --- Source/Core/DiscIO/FileSystemGCWii.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'Source/Core/DiscIO/FileSystemGCWii.cpp') diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index ec4f8c2c28..c3b9df3119 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -21,7 +21,7 @@ namespace DiscIO { CFileSystemGCWii::CFileSystemGCWii(const IVolume* _rVolume, const Partition& partition) - : IFileSystem(_rVolume, partition), m_Initialized(false), m_Valid(false), m_Wii(false) + : IFileSystem(_rVolume, partition), m_Initialized(false), m_Valid(false), m_offset_shift(0) { m_Valid = DetectFileSystem(); } @@ -156,7 +156,7 @@ u64 CFileSystemGCWii::GetBootDOLOffset() const { u32 offset = 0; m_rVolume->ReadSwapped(0x420, &offset, m_partition); - return static_cast(offset) << GetOffsetShift(); + return static_cast(offset) << m_offset_shift; } u32 CFileSystemGCWii::GetBootDOLSize(u64 dol_offset) const @@ -253,12 +253,12 @@ bool CFileSystemGCWii::DetectFileSystem() u32 magic_bytes; 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, m_partition) && magic_bytes == 0xC2339F3D) { - m_Wii = false; + m_offset_shift = 0; // GameCube file system return true; } @@ -268,13 +268,12 @@ 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_partition)) return; - u64 FSTOffset = static_cast(fst_offset_unshifted) << shift; + u64 FSTOffset = static_cast(fst_offset_unshifted) << m_offset_shift; // read all fileinfos u32 name_offset, offset, size; @@ -282,7 +281,7 @@ void CFileSystemGCWii::InitFileSystem() !m_rVolume->ReadSwapped(FSTOffset + 0x4, &offset, m_partition) || !m_rVolume->ReadSwapped(FSTOffset + 0x8, &size, m_partition)) return; - SFileInfo root = {name_offset, static_cast(offset) << shift, size}; + SFileInfo root = {name_offset, static_cast(offset) << m_offset_shift, size}; if (!root.IsDirectory()) return; @@ -313,7 +312,7 @@ void CFileSystemGCWii::InitFileSystem() m_rVolume->ReadSwapped(read_offset + 0x4, &offset, m_partition); size = 0; m_rVolume->ReadSwapped(read_offset + 0x8, &size, m_partition); - m_FileInfoVector.emplace_back(name_offset, static_cast(offset) << shift, size); + m_FileInfoVector.emplace_back(name_offset, static_cast(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 -- cgit v1.2.3