diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2017-07-04 16:35:17 +0200 |
|---|---|---|
| committer | Léo Lam <leo@innovatetechnologi.es> | 2017-08-10 23:47:18 +0800 |
| commit | eb1ba4b0e960339fd22a1346c38925cdab7ca290 (patch) | |
| tree | c4a4c227d54e2d049da7cfc6e116156fe5f82bf6 /Source/Core/DiscIO/VolumeFileBlobReader.cpp | |
| parent | ca0438e26db13ed8f7579cff11ccd7db618abfc3 (diff) | |
DiscIO: Add a blob reader for Volume files
Diffstat (limited to 'Source/Core/DiscIO/VolumeFileBlobReader.cpp')
| -rw-r--r-- | Source/Core/DiscIO/VolumeFileBlobReader.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Source/Core/DiscIO/VolumeFileBlobReader.cpp b/Source/Core/DiscIO/VolumeFileBlobReader.cpp new file mode 100644 index 0000000000..5b243acc29 --- /dev/null +++ b/Source/Core/DiscIO/VolumeFileBlobReader.cpp @@ -0,0 +1,51 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DiscIO/VolumeFileBlobReader.h" + +#include "DiscIO/Filesystem.h" +#include "DiscIO/Volume.h" + +namespace DiscIO +{ +std::unique_ptr<VolumeFileBlobReader> VolumeFileBlobReader::Create(const Volume& volume, + const FileSystem& file_system, + const std::string& file_path) +{ + if (!file_system.IsValid()) + return nullptr; + + std::unique_ptr<FileInfo> file_info = file_system.FindFileInfo(file_path); + if (!file_info || file_info->IsDirectory()) + return nullptr; + + return std::unique_ptr<VolumeFileBlobReader>{ + new VolumeFileBlobReader(volume, file_system, std::move(file_info))}; +} + +VolumeFileBlobReader::VolumeFileBlobReader(const Volume& volume, const FileSystem& file_system, + std::unique_ptr<FileInfo> file_info) + : m_volume(volume), m_file_system(file_system), m_file_info(std::move(file_info)) +{ +} + +u64 VolumeFileBlobReader::GetDataSize() const +{ + return m_file_info->GetSize(); +} + +u64 VolumeFileBlobReader::GetRawSize() const +{ + return GetDataSize(); +} + +bool VolumeFileBlobReader::Read(u64 offset, u64 length, u8* out_ptr) +{ + if (offset + length > m_file_info->GetSize()) + return false; + + return m_volume.Read(m_file_info->GetOffset() + offset, length, out_ptr, + m_file_system.GetPartition()); +} +} // namespace |
