2017-12-29 07:57:54 +00:00
|
|
|
#include <cstdio>
|
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:
|
2017-11-13 06:18:53 +00:00
|
|
|
DiscIOISO(SystemStringView fpin)
|
2016-10-03 04:37:20 +00:00
|
|
|
: 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;
|
2017-02-05 06:19:34 +00:00
|
|
|
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();}
|
2015-06-30 19:38:51 +00:00
|
|
|
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
|
|
|
|
2015-06-30 19:38:51 +00:00
|
|
|
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const
|
2015-06-26 19:30:03 +00:00
|
|
|
{
|
2017-02-05 06:19:34 +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;
|
2017-02-05 06:19:34 +00:00
|
|
|
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
|
|
|
|
2015-06-30 19:38:51 +00:00
|
|
|
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const
|
2015-06-26 19:30:03 +00:00
|
|
|
{
|
2017-02-05 06:19:34 +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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-13 06:18:53 +00:00
|
|
|
std::unique_ptr<IDiscIO> NewDiscIOISO(SystemStringView 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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|