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