2017-07-04 14:35:17 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-07-04 14:35:17 +00:00
|
|
|
|
|
|
|
#include "DiscIO/VolumeFileBlobReader.h"
|
|
|
|
|
2019-05-29 06:16:12 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string_view>
|
|
|
|
|
2017-07-04 14:35:17 +00:00
|
|
|
#include "DiscIO/Filesystem.h"
|
|
|
|
#include "DiscIO/Volume.h"
|
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
std::unique_ptr<VolumeFileBlobReader> VolumeFileBlobReader::Create(const Volume& volume,
|
2017-08-02 16:16:56 +00:00
|
|
|
const Partition& partition,
|
2019-05-29 06:16:12 +00:00
|
|
|
std::string_view file_path)
|
2017-07-04 14:35:17 +00:00
|
|
|
{
|
2017-08-02 16:16:56 +00:00
|
|
|
const FileSystem* file_system = volume.GetFileSystem(partition);
|
|
|
|
if (!file_system)
|
2017-07-04 14:35:17 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2017-08-02 16:16:56 +00:00
|
|
|
std::unique_ptr<FileInfo> file_info = file_system->FindFileInfo(file_path);
|
2017-07-04 14:35:17 +00:00
|
|
|
if (!file_info || file_info->IsDirectory())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return std::unique_ptr<VolumeFileBlobReader>{
|
2017-08-02 16:16:56 +00:00
|
|
|
new VolumeFileBlobReader(volume, partition, std::move(file_info))};
|
2017-07-04 14:35:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 16:16:56 +00:00
|
|
|
VolumeFileBlobReader::VolumeFileBlobReader(const Volume& volume, const Partition& partition,
|
2017-07-04 14:35:17 +00:00
|
|
|
std::unique_ptr<FileInfo> file_info)
|
2017-08-02 16:16:56 +00:00
|
|
|
: m_volume(volume), m_partition(partition), m_file_info(std::move(file_info))
|
2017-07-04 14:35:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-07 12:31:26 +00:00
|
|
|
std::unique_ptr<BlobReader> VolumeFileBlobReader::CopyReader() const
|
|
|
|
{
|
|
|
|
ASSERT_MSG(DISCIO, false, "Unimplemented");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-04 14:35:17 +00:00
|
|
|
u64 VolumeFileBlobReader::GetDataSize() const
|
|
|
|
{
|
|
|
|
return m_file_info->GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 VolumeFileBlobReader::GetRawSize() const
|
|
|
|
{
|
|
|
|
return GetDataSize();
|
|
|
|
}
|
|
|
|
|
2020-06-07 12:11:00 +00:00
|
|
|
u64 VolumeFileBlobReader::GetBlockSize() const
|
|
|
|
{
|
|
|
|
return m_volume.GetBlobReader().GetBlockSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VolumeFileBlobReader::HasFastRandomAccessInBlock() const
|
|
|
|
{
|
|
|
|
return m_volume.GetBlobReader().HasFastRandomAccessInBlock();
|
|
|
|
}
|
|
|
|
|
2020-06-21 18:41:50 +00:00
|
|
|
std::string VolumeFileBlobReader::GetCompressionMethod() const
|
|
|
|
{
|
|
|
|
return m_volume.GetBlobReader().GetCompressionMethod();
|
|
|
|
}
|
|
|
|
|
2022-02-24 10:51:52 +00:00
|
|
|
std::optional<int> VolumeFileBlobReader::GetCompressionLevel() const
|
|
|
|
{
|
|
|
|
return m_volume.GetBlobReader().GetCompressionLevel();
|
|
|
|
}
|
|
|
|
|
2017-07-04 14:35:17 +00:00
|
|
|
bool VolumeFileBlobReader::Read(u64 offset, u64 length, u8* out_ptr)
|
|
|
|
{
|
|
|
|
if (offset + length > m_file_info->GetSize())
|
|
|
|
return false;
|
|
|
|
|
2017-08-02 16:16:56 +00:00
|
|
|
return m_volume.Read(m_file_info->GetOffset() + offset, length, out_ptr, m_partition);
|
2017-07-04 14:35:17 +00:00
|
|
|
}
|
2019-05-05 23:48:12 +00:00
|
|
|
} // namespace DiscIO
|