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