2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 05:09:55 +02:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 06:30:24 +01:00
|
|
|
|
2015-12-07 05:15:51 +01:00
|
|
|
#include <memory>
|
2014-03-12 20:33:41 +01:00
|
|
|
#include <string>
|
2016-12-21 12:50:15 +01:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "DiscIO/FileBlob.h"
|
2008-12-08 06:30:24 +01:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2016-12-21 12:50:15 +01:00
|
|
|
PlainFileReader::PlainFileReader(File::IOFile file) : m_file(std::move(file))
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
2011-03-11 11:21:46 +01:00
|
|
|
m_size = m_file.GetSize();
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2016-12-21 12:50:15 +01:00
|
|
|
std::unique_ptr<PlainFileReader> PlainFileReader::Create(File::IOFile file)
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
2016-12-21 12:50:15 +01:00
|
|
|
if (file)
|
|
|
|
return std::unique_ptr<PlainFileReader>(new PlainFileReader(std::move(file)));
|
2015-12-07 05:15:51 +01:00
|
|
|
|
|
|
|
return nullptr;
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
|
|
|
{
|
2014-12-14 13:16:21 +01:00
|
|
|
if (m_file.Seek(offset, SEEK_SET) && m_file.ReadBytes(out_ptr, nbytes))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_file.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2019-05-06 01:48:12 +02:00
|
|
|
} // namespace DiscIO
|