VolumeFileBlobReader.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2017 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "DiscIO/VolumeFileBlobReader.h"
  4. #include <memory>
  5. #include <string_view>
  6. #include "DiscIO/Filesystem.h"
  7. #include "DiscIO/Volume.h"
  8. namespace DiscIO
  9. {
  10. std::unique_ptr<VolumeFileBlobReader> VolumeFileBlobReader::Create(const Volume& volume,
  11. const Partition& partition,
  12. std::string_view file_path)
  13. {
  14. const FileSystem* file_system = volume.GetFileSystem(partition);
  15. if (!file_system)
  16. return nullptr;
  17. std::unique_ptr<FileInfo> file_info = file_system->FindFileInfo(file_path);
  18. if (!file_info || file_info->IsDirectory())
  19. return nullptr;
  20. return std::unique_ptr<VolumeFileBlobReader>{
  21. new VolumeFileBlobReader(volume, partition, std::move(file_info))};
  22. }
  23. VolumeFileBlobReader::VolumeFileBlobReader(const Volume& volume, const Partition& partition,
  24. std::unique_ptr<FileInfo> file_info)
  25. : m_volume(volume), m_partition(partition), m_file_info(std::move(file_info))
  26. {
  27. }
  28. std::unique_ptr<BlobReader> VolumeFileBlobReader::CopyReader() const
  29. {
  30. ASSERT_MSG(DISCIO, false, "Unimplemented");
  31. return nullptr;
  32. }
  33. u64 VolumeFileBlobReader::GetDataSize() const
  34. {
  35. return m_file_info->GetSize();
  36. }
  37. u64 VolumeFileBlobReader::GetRawSize() const
  38. {
  39. return GetDataSize();
  40. }
  41. u64 VolumeFileBlobReader::GetBlockSize() const
  42. {
  43. return m_volume.GetBlobReader().GetBlockSize();
  44. }
  45. bool VolumeFileBlobReader::HasFastRandomAccessInBlock() const
  46. {
  47. return m_volume.GetBlobReader().HasFastRandomAccessInBlock();
  48. }
  49. std::string VolumeFileBlobReader::GetCompressionMethod() const
  50. {
  51. return m_volume.GetBlobReader().GetCompressionMethod();
  52. }
  53. std::optional<int> VolumeFileBlobReader::GetCompressionLevel() const
  54. {
  55. return m_volume.GetBlobReader().GetCompressionLevel();
  56. }
  57. bool VolumeFileBlobReader::Read(u64 offset, u64 length, u8* out_ptr)
  58. {
  59. if (offset + length > m_file_info->GetSize())
  60. return false;
  61. return m_volume.Read(m_file_info->GetOffset() + offset, length, out_ptr, m_partition);
  62. }
  63. } // namespace DiscIO