mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Wrapped fopen/close/read/write functions inside a simple "IOFile" class. Reading, writing, and error checking became simpler in most cases. It should be near impossible to forget to close a file now that the destructor takes care of it. (I hope this fixes Issue 3635) I have tested the functionality of most things, but it is possible I broke something. :p
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7328 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -15,40 +15,30 @@
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "Blob.h"
|
||||
#include "FileBlob.h"
|
||||
#include "FileUtil.h"
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
PlainFileReader::PlainFileReader(FILE* file__)
|
||||
PlainFileReader::PlainFileReader(std::FILE* file)
|
||||
: m_file(file)
|
||||
{
|
||||
file_ = file__;
|
||||
size = File::GetSize(file__);
|
||||
m_size = m_file.GetSize();
|
||||
}
|
||||
|
||||
PlainFileReader* PlainFileReader::Create(const char* filename)
|
||||
{
|
||||
FILE* f = fopen(filename, "rb");
|
||||
File::IOFile f(filename, "rb");
|
||||
if (f)
|
||||
return new PlainFileReader(f);
|
||||
return new PlainFileReader(f.ReleaseHandle());
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PlainFileReader::~PlainFileReader()
|
||||
{
|
||||
fclose(file_);
|
||||
}
|
||||
|
||||
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||
{
|
||||
int seekStatus = fseeko(file_, offset, SEEK_SET);
|
||||
if (seekStatus != 0)
|
||||
return false;
|
||||
size_t bytesRead = fread(out_ptr, 1, nbytes, file_);
|
||||
return bytesRead == nbytes;
|
||||
m_file.Seek(offset, SEEK_SET);
|
||||
return m_file.ReadBytes(out_ptr, nbytes);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user