mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-05 00:40:00 +00:00
Filesystem: Modernize variable names
This commit is contained in:
parent
e3a2cd827a
commit
0b7d2e7c68
@ -185,19 +185,19 @@ bool FileInfoGCWii::IsValid(u64 fst_size, const FileInfoGCWii& parent_directory)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystemGCWii::FileSystemGCWii(const Volume* _rVolume, const Partition& partition)
|
FileSystemGCWii::FileSystemGCWii(const Volume* volume, const Partition& partition)
|
||||||
: FileSystem(_rVolume, partition), m_Valid(false), m_offset_shift(0), m_root(nullptr, 0, 0, 0)
|
: FileSystem(volume, partition), m_valid(false), m_offset_shift(0), m_root(nullptr, 0, 0, 0)
|
||||||
{
|
{
|
||||||
// Check if this is a GameCube or Wii disc
|
// Check if this is a GameCube or Wii disc
|
||||||
if (m_rVolume->ReadSwapped<u32>(0x18, m_partition) == u32(0x5D1C9EA3))
|
if (m_volume->ReadSwapped<u32>(0x18, m_partition) == u32(0x5D1C9EA3))
|
||||||
m_offset_shift = 2; // Wii file system
|
m_offset_shift = 2; // Wii file system
|
||||||
else if (m_rVolume->ReadSwapped<u32>(0x1c, m_partition) == u32(0xC2339F3D))
|
else if (m_volume->ReadSwapped<u32>(0x1c, m_partition) == u32(0xC2339F3D))
|
||||||
m_offset_shift = 0; // GameCube file system
|
m_offset_shift = 0; // GameCube file system
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const std::optional<u32> fst_offset_unshifted = m_rVolume->ReadSwapped<u32>(0x424, m_partition);
|
const std::optional<u32> fst_offset_unshifted = m_volume->ReadSwapped<u32>(0x424, m_partition);
|
||||||
const std::optional<u32> fst_size_unshifted = m_rVolume->ReadSwapped<u32>(0x428, m_partition);
|
const std::optional<u32> fst_size_unshifted = m_volume->ReadSwapped<u32>(0x428, m_partition);
|
||||||
if (!fst_offset_unshifted || !fst_size_unshifted)
|
if (!fst_offset_unshifted || !fst_size_unshifted)
|
||||||
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;
|
||||||
@ -222,7 +222,7 @@ FileSystemGCWii::FileSystemGCWii(const Volume* _rVolume, const Partition& partit
|
|||||||
|
|
||||||
// Read the whole FST
|
// Read the whole FST
|
||||||
m_file_system_table.resize(fst_size);
|
m_file_system_table.resize(fst_size);
|
||||||
if (!m_rVolume->Read(fst_offset, fst_size, m_file_system_table.data(), m_partition))
|
if (!m_volume->Read(fst_offset, fst_size, m_file_system_table.data(), m_partition))
|
||||||
{
|
{
|
||||||
ERROR_LOG(DISCIO, "Couldn't read file system table");
|
ERROR_LOG(DISCIO, "Couldn't read file system table");
|
||||||
return;
|
return;
|
||||||
@ -249,7 +249,7 @@ FileSystemGCWii::FileSystemGCWii(const Volume* _rVolume, const Partition& partit
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Valid = m_root.IsValid(fst_size, m_root);
|
m_valid = m_root.IsValid(fst_size, m_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystemGCWii::~FileSystemGCWii()
|
FileSystemGCWii::~FileSystemGCWii()
|
||||||
@ -334,66 +334,66 @@ std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(u64 disc_offset) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 FileSystemGCWii::ReadFile(const FileInfo* file_info, u8* _pBuffer, u64 _MaxBufferSize,
|
u64 FileSystemGCWii::ReadFile(const FileInfo* file_info, u8* buffer, u64 max_buffer_size,
|
||||||
u64 _OffsetInFile) const
|
u64 offset_in_file) const
|
||||||
{
|
{
|
||||||
if (!file_info || file_info->IsDirectory())
|
if (!file_info || file_info->IsDirectory())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (_OffsetInFile >= file_info->GetSize())
|
if (offset_in_file >= file_info->GetSize())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
u64 read_length = std::min(_MaxBufferSize, file_info->GetSize() - _OffsetInFile);
|
u64 read_length = std::min(max_buffer_size, file_info->GetSize() - offset_in_file);
|
||||||
|
|
||||||
DEBUG_LOG(DISCIO, "Reading %" PRIx64 " bytes at %" PRIx64 " from file %s. Offset: %" PRIx64
|
DEBUG_LOG(DISCIO, "Reading %" PRIx64 " bytes at %" PRIx64 " from file %s. Offset: %" PRIx64
|
||||||
" Size: %" PRIx32,
|
" Size: %" PRIx32,
|
||||||
read_length, _OffsetInFile, file_info->GetPath().c_str(), file_info->GetOffset(),
|
read_length, offset_in_file, file_info->GetPath().c_str(), file_info->GetOffset(),
|
||||||
file_info->GetSize());
|
file_info->GetSize());
|
||||||
|
|
||||||
m_rVolume->Read(file_info->GetOffset() + _OffsetInFile, read_length, _pBuffer, m_partition);
|
m_volume->Read(file_info->GetOffset() + offset_in_file, read_length, buffer, m_partition);
|
||||||
return read_length;
|
return read_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileSystemGCWii::ExportFile(const FileInfo* file_info,
|
bool FileSystemGCWii::ExportFile(const FileInfo* file_info,
|
||||||
const std::string& _rExportFilename) const
|
const std::string& export_filename) const
|
||||||
{
|
{
|
||||||
if (!file_info || file_info->IsDirectory())
|
if (!file_info || file_info->IsDirectory())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
u64 remainingSize = file_info->GetSize();
|
u64 remaining_size = file_info->GetSize();
|
||||||
u64 fileOffset = file_info->GetOffset();
|
u64 file_offset = file_info->GetOffset();
|
||||||
|
|
||||||
File::IOFile f(_rExportFilename, "wb");
|
File::IOFile f(export_filename, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
while (remainingSize)
|
while (remaining_size)
|
||||||
{
|
{
|
||||||
// Limit read size to 128 MB
|
// Limit read size to 128 MB
|
||||||
size_t readSize = (size_t)std::min(remainingSize, (u64)0x08000000);
|
size_t read_size = (size_t)std::min(remaining_size, (u64)0x08000000);
|
||||||
|
|
||||||
std::vector<u8> buffer(readSize);
|
std::vector<u8> buffer(read_size);
|
||||||
|
|
||||||
result = m_rVolume->Read(fileOffset, readSize, &buffer[0], m_partition);
|
result = m_volume->Read(file_offset, read_size, &buffer[0], m_partition);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
f.WriteBytes(&buffer[0], readSize);
|
f.WriteBytes(&buffer[0], read_size);
|
||||||
|
|
||||||
remainingSize -= readSize;
|
remaining_size -= read_size;
|
||||||
fileOffset += readSize;
|
file_offset += read_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const
|
bool FileSystemGCWii::ExportApploader(const std::string& export_folder) const
|
||||||
{
|
{
|
||||||
std::optional<u32> apploader_size = m_rVolume->ReadSwapped<u32>(0x2440 + 0x14, m_partition);
|
std::optional<u32> apploader_size = m_volume->ReadSwapped<u32>(0x2440 + 0x14, m_partition);
|
||||||
const std::optional<u32> trailer_size = m_rVolume->ReadSwapped<u32>(0x2440 + 0x18, m_partition);
|
const std::optional<u32> trailer_size = m_volume->ReadSwapped<u32>(0x2440 + 0x18, m_partition);
|
||||||
constexpr u32 header_size = 0x20;
|
constexpr u32 header_size = 0x20;
|
||||||
if (!apploader_size || !trailer_size)
|
if (!apploader_size || !trailer_size)
|
||||||
return false;
|
return false;
|
||||||
@ -401,14 +401,14 @@ bool FileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const
|
|||||||
DEBUG_LOG(DISCIO, "Apploader size -> %x", *apploader_size);
|
DEBUG_LOG(DISCIO, "Apploader size -> %x", *apploader_size);
|
||||||
|
|
||||||
std::vector<u8> buffer(*apploader_size);
|
std::vector<u8> buffer(*apploader_size);
|
||||||
if (m_rVolume->Read(0x2440, *apploader_size, buffer.data(), m_partition))
|
if (m_volume->Read(0x2440, *apploader_size, buffer.data(), m_partition))
|
||||||
{
|
{
|
||||||
std::string exportName(_rExportFolder + "/apploader.img");
|
std::string export_name(export_folder + "/apploader.img");
|
||||||
|
|
||||||
File::IOFile AppFile(exportName, "wb");
|
File::IOFile apploader_file(export_name, "wb");
|
||||||
if (AppFile)
|
if (apploader_file)
|
||||||
{
|
{
|
||||||
AppFile.WriteBytes(buffer.data(), *apploader_size);
|
apploader_file.WriteBytes(buffer.data(), *apploader_size);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -418,7 +418,7 @@ bool FileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const
|
|||||||
|
|
||||||
std::optional<u64> FileSystemGCWii::GetBootDOLOffset() const
|
std::optional<u64> FileSystemGCWii::GetBootDOLOffset() const
|
||||||
{
|
{
|
||||||
std::optional<u32> offset = m_rVolume->ReadSwapped<u32>(0x420, m_partition);
|
std::optional<u32> offset = m_volume->ReadSwapped<u32>(0x420, m_partition);
|
||||||
return offset ? static_cast<u64>(*offset) << m_offset_shift : std::optional<u64>();
|
return offset ? static_cast<u64>(*offset) << m_offset_shift : std::optional<u64>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,9 +430,9 @@ std::optional<u32> FileSystemGCWii::GetBootDOLSize(u64 dol_offset) const
|
|||||||
for (u8 i = 0; i < 7; i++)
|
for (u8 i = 0; i < 7; i++)
|
||||||
{
|
{
|
||||||
const std::optional<u32> offset =
|
const std::optional<u32> offset =
|
||||||
m_rVolume->ReadSwapped<u32>(dol_offset + 0x00 + i * 4, m_partition);
|
m_volume->ReadSwapped<u32>(dol_offset + 0x00 + i * 4, m_partition);
|
||||||
const std::optional<u32> size =
|
const std::optional<u32> size =
|
||||||
m_rVolume->ReadSwapped<u32>(dol_offset + 0x90 + i * 4, m_partition);
|
m_volume->ReadSwapped<u32>(dol_offset + 0x90 + i * 4, m_partition);
|
||||||
if (!offset || !size)
|
if (!offset || !size)
|
||||||
return {};
|
return {};
|
||||||
dol_size = std::max(*offset + *size, dol_size);
|
dol_size = std::max(*offset + *size, dol_size);
|
||||||
@ -442,9 +442,9 @@ std::optional<u32> FileSystemGCWii::GetBootDOLSize(u64 dol_offset) const
|
|||||||
for (u8 i = 0; i < 11; i++)
|
for (u8 i = 0; i < 11; i++)
|
||||||
{
|
{
|
||||||
const std::optional<u32> offset =
|
const std::optional<u32> offset =
|
||||||
m_rVolume->ReadSwapped<u32>(dol_offset + 0x1c + i * 4, m_partition);
|
m_volume->ReadSwapped<u32>(dol_offset + 0x1c + i * 4, m_partition);
|
||||||
const std::optional<u32> size =
|
const std::optional<u32> size =
|
||||||
m_rVolume->ReadSwapped<u32>(dol_offset + 0xac + i * 4, m_partition);
|
m_volume->ReadSwapped<u32>(dol_offset + 0xac + i * 4, m_partition);
|
||||||
if (!offset || !size)
|
if (!offset || !size)
|
||||||
return {};
|
return {};
|
||||||
dol_size = std::max(*offset + *size, dol_size);
|
dol_size = std::max(*offset + *size, dol_size);
|
||||||
@ -453,7 +453,7 @@ std::optional<u32> FileSystemGCWii::GetBootDOLSize(u64 dol_offset) const
|
|||||||
return dol_size;
|
return dol_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const
|
bool FileSystemGCWii::ExportDOL(const std::string& export_folder) const
|
||||||
{
|
{
|
||||||
std::optional<u64> dol_offset = GetBootDOLOffset();
|
std::optional<u64> dol_offset = GetBootDOLOffset();
|
||||||
if (!dol_offset)
|
if (!dol_offset)
|
||||||
@ -463,14 +463,14 @@ bool FileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::vector<u8> buffer(*dol_size);
|
std::vector<u8> buffer(*dol_size);
|
||||||
if (m_rVolume->Read(*dol_offset, *dol_size, &buffer[0], m_partition))
|
if (m_volume->Read(*dol_offset, *dol_size, buffer.data(), m_partition))
|
||||||
{
|
{
|
||||||
std::string exportName(_rExportFolder + "/boot.dol");
|
std::string export_name(export_folder + "/boot.dol");
|
||||||
|
|
||||||
File::IOFile DolFile(exportName, "wb");
|
File::IOFile dol_file(export_name, "wb");
|
||||||
if (DolFile)
|
if (dol_file)
|
||||||
{
|
{
|
||||||
DolFile.WriteBytes(&buffer[0], *dol_size);
|
dol_file.WriteBytes(&buffer[0], *dol_size);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,24 +85,24 @@ private:
|
|||||||
class FileSystemGCWii : public FileSystem
|
class FileSystemGCWii : public FileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileSystemGCWii(const Volume* _rVolume, const Partition& partition);
|
FileSystemGCWii(const Volume* volume, const Partition& partition);
|
||||||
~FileSystemGCWii() override;
|
~FileSystemGCWii() override;
|
||||||
|
|
||||||
bool IsValid() const override { return m_Valid; }
|
bool IsValid() const override { return m_valid; }
|
||||||
const FileInfo& GetRoot() const override;
|
const FileInfo& GetRoot() const override;
|
||||||
std::unique_ptr<FileInfo> FindFileInfo(const std::string& path) const override;
|
std::unique_ptr<FileInfo> FindFileInfo(const std::string& path) const override;
|
||||||
std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const override;
|
std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const override;
|
||||||
|
|
||||||
u64 ReadFile(const FileInfo* file_info, u8* _pBuffer, u64 _MaxBufferSize,
|
u64 ReadFile(const FileInfo* file_info, u8* buffer, u64 max_buffer_size,
|
||||||
u64 _OffsetInFile) const override;
|
u64 offset_in_file) const override;
|
||||||
bool ExportFile(const FileInfo* file_info, const std::string& _rExportFilename) const override;
|
bool ExportFile(const FileInfo* file_info, const std::string& export_filename) const override;
|
||||||
bool ExportApploader(const std::string& _rExportFolder) const override;
|
bool ExportApploader(const std::string& export_folder) const override;
|
||||||
bool ExportDOL(const std::string& _rExportFolder) const override;
|
bool ExportDOL(const std::string& export_folder) const override;
|
||||||
std::optional<u64> GetBootDOLOffset() const override;
|
std::optional<u64> GetBootDOLOffset() const override;
|
||||||
std::optional<u32> GetBootDOLSize(u64 dol_offset) const override;
|
std::optional<u32> GetBootDOLSize(u64 dol_offset) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_Valid;
|
bool m_valid;
|
||||||
u32 m_offset_shift;
|
u32 m_offset_shift;
|
||||||
std::vector<u8> m_file_system_table;
|
std::vector<u8> m_file_system_table;
|
||||||
FileInfoGCWii m_root;
|
FileInfoGCWii m_root;
|
||||||
|
@ -13,8 +13,8 @@ FileInfo::~FileInfo()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystem::FileSystem(const Volume* _rVolume, const Partition& partition)
|
FileSystem::FileSystem(const Volume* volume, const Partition& partition)
|
||||||
: m_rVolume(_rVolume), m_partition(partition)
|
: m_volume(volume), m_partition(partition)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ protected:
|
|||||||
class FileSystem
|
class FileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileSystem(const Volume* _rVolume, const Partition& partition);
|
FileSystem(const Volume* volume, const Partition& partition);
|
||||||
virtual ~FileSystem();
|
virtual ~FileSystem();
|
||||||
|
|
||||||
// If IsValid is false, GetRoot must not be called. CreateFileSystem
|
// If IsValid is false, GetRoot must not be called. CreateFileSystem
|
||||||
@ -120,17 +120,17 @@ public:
|
|||||||
// Returns nullptr if not found
|
// Returns nullptr if not found
|
||||||
virtual std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const = 0;
|
virtual std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const = 0;
|
||||||
|
|
||||||
virtual u64 ReadFile(const FileInfo* file_info, u8* _pBuffer, u64 _MaxBufferSize,
|
virtual u64 ReadFile(const FileInfo* file_info, u8* buffer, u64 max_buffer_size,
|
||||||
u64 _OffsetInFile = 0) const = 0;
|
u64 offset_in_file = 0) const = 0;
|
||||||
virtual bool ExportFile(const FileInfo* file_info, const std::string& _rExportFilename) const = 0;
|
virtual bool ExportFile(const FileInfo* file_info, const std::string& export_filename) const = 0;
|
||||||
virtual bool ExportApploader(const std::string& _rExportFolder) const = 0;
|
virtual bool ExportApploader(const std::string& export_folder) const = 0;
|
||||||
virtual bool ExportDOL(const std::string& _rExportFolder) const = 0;
|
virtual bool ExportDOL(const std::string& export_folder) const = 0;
|
||||||
virtual std::optional<u64> GetBootDOLOffset() const = 0;
|
virtual std::optional<u64> GetBootDOLOffset() const = 0;
|
||||||
virtual std::optional<u32> GetBootDOLSize(u64 dol_offset) const = 0;
|
virtual std::optional<u32> GetBootDOLSize(u64 dol_offset) const = 0;
|
||||||
|
|
||||||
virtual const Partition GetPartition() const { return m_partition; }
|
virtual const Partition GetPartition() const { return m_partition; }
|
||||||
protected:
|
protected:
|
||||||
const Volume* const m_rVolume;
|
const Volume* const m_volume;
|
||||||
const Partition m_partition;
|
const Partition m_partition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user