2017-07-04 14:35:17 +00:00
|
|
|
// 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,
|
2017-08-02 16:16:56 +00:00
|
|
|
const Partition& partition,
|
2017-07-04 14:35:17 +00:00
|
|
|
const std::string& file_path)
|
|
|
|
{
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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
|