nod/lib/DiscIOISO.cpp

70 lines
1.8 KiB
C++
Raw Normal View History

2015-06-26 19:30:03 +00:00
#include <stdio.h>
2016-03-04 23:04:30 +00:00
#include "nod/Util.hpp"
#include "nod/IDiscIO.hpp"
#include "nod/IFileIO.hpp"
2015-06-26 19:30:03 +00:00
2016-03-04 23:04:30 +00:00
namespace nod
2015-06-26 19:30:03 +00:00
{
2015-06-28 05:43:53 +00:00
class DiscIOISO : public IDiscIO
2015-06-26 19:30:03 +00:00
{
2016-01-26 02:01:55 +00:00
std::unique_ptr<IFileIO> m_fio;
2015-06-26 19:30:03 +00:00
public:
2015-07-02 18:33:55 +00:00
DiscIOISO(const SystemString& fpin)
: m_fio(NewFileIO(fpin)) {}
2015-06-26 19:30:03 +00:00
2015-06-28 05:43:53 +00:00
class ReadStream : public IReadStream
2015-06-26 19:30:03 +00:00
{
2015-06-28 05:43:53 +00:00
friend class DiscIOISO;
2016-01-26 02:01:55 +00:00
std::unique_ptr<IFileIO::IReadStream> fp;
ReadStream(std::unique_ptr<IFileIO::IReadStream>&& fpin, bool& err)
: fp(std::move(fpin)) { if (!fp) err = true; }
2015-06-26 19:30:03 +00:00
public:
2016-01-25 05:55:31 +00:00
uint64_t read(void* buf, uint64_t length)
2016-01-26 02:01:55 +00:00
{return fp->read(buf, length);}
2015-07-07 03:22:19 +00:00
uint64_t position() const
2016-01-26 02:01:55 +00:00
{return fp->position();}
void seek(int64_t offset, int whence)
2016-01-26 02:01:55 +00:00
{fp->seek(offset, whence);}
2015-06-26 19:30:03 +00:00
};
2016-01-25 05:55:31 +00:00
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const
2015-06-26 19:30:03 +00:00
{
bool Err = false;
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_fio->beginReadStream(offset), Err));
if (Err)
return {};
return ret;
2016-01-25 05:55:31 +00:00
}
2015-06-26 19:30:03 +00:00
2015-06-28 05:43:53 +00:00
class WriteStream : public IWriteStream
2015-06-26 19:30:03 +00:00
{
2015-06-28 05:43:53 +00:00
friend class DiscIOISO;
2016-01-26 02:01:55 +00:00
std::unique_ptr<IFileIO::IWriteStream> fp;
WriteStream(std::unique_ptr<IFileIO::IWriteStream>&& fpin, bool& err)
: fp(std::move(fpin)) { if (!fp) err = true; }
2015-06-26 19:30:03 +00:00
public:
2016-01-25 05:55:31 +00:00
uint64_t write(const void* buf, uint64_t length)
{
2016-01-26 02:01:55 +00:00
return fp->write(buf, length);
2016-01-25 05:55:31 +00:00
}
2015-06-26 19:30:03 +00:00
};
2016-01-25 05:55:31 +00:00
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const
2015-06-26 19:30:03 +00:00
{
bool Err = false;
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_fio->beginWriteStream(offset), Err));
if (Err)
return {};
return ret;
2015-06-26 19:30:03 +00:00
}
};
2015-07-02 18:33:55 +00:00
std::unique_ptr<IDiscIO> NewDiscIOISO(const SystemChar* path)
2015-06-26 19:30:03 +00:00
{
2015-06-28 05:43:53 +00:00
return std::unique_ptr<IDiscIO>(new DiscIOISO(path));
2015-06-26 19:30:03 +00:00
}
}