mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 22:09:19 -07:00
edbbf493f8
Rather than rely on the developer to do the right thing, just make the default behavior safely deallocate resources. If shared semantics are ever needed in the future, the constructor that takes a unique_ptr for shared_ptr can be used.
41 lines
755 B
C++
41 lines
755 B
C++
// Copyright 2008 Dolphin Emulator Project
|
|
// Licensed under GPLv2+
|
|
// Refer to the license.txt file included.
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include "DiscIO/FileBlob.h"
|
|
|
|
namespace DiscIO
|
|
{
|
|
|
|
PlainFileReader::PlainFileReader(std::FILE* file)
|
|
: m_file(file)
|
|
{
|
|
m_size = m_file.GetSize();
|
|
}
|
|
|
|
std::unique_ptr<PlainFileReader> PlainFileReader::Create(const std::string& filename)
|
|
{
|
|
File::IOFile f(filename, "rb");
|
|
if (f)
|
|
return std::unique_ptr<PlainFileReader>(new PlainFileReader(f.ReleaseHandle()));
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
|
{
|
|
if (m_file.Seek(offset, SEEK_SET) && m_file.ReadBytes(out_ptr, nbytes))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
m_file.Clear();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
} // namespace
|