2016-03-04 23:04:30 +00:00
|
|
|
#include "nod/IDiscIO.hpp"
|
|
|
|
#include "nod/IFileIO.hpp"
|
2019-08-30 07:52:22 +00:00
|
|
|
#include "nod/Util.hpp"
|
2015-06-26 19:30:03 +00:00
|
|
|
|
2018-12-08 05:21:47 +00:00
|
|
|
namespace nod {
|
2015-06-26 19:30:03 +00:00
|
|
|
|
2018-12-08 05:21:47 +00:00
|
|
|
class DiscIOISO : public IDiscIO {
|
|
|
|
std::unique_ptr<IFileIO> m_fio;
|
2016-01-25 05:55:31 +00:00
|
|
|
|
2018-12-08 05:21:47 +00:00
|
|
|
public:
|
2021-06-22 19:16:56 +00:00
|
|
|
DiscIOISO(std::string_view fpin) : m_fio(NewFileIO(fpin)) {}
|
2018-12-08 05:21:47 +00:00
|
|
|
|
|
|
|
class ReadStream : public IReadStream {
|
|
|
|
friend class DiscIOISO;
|
|
|
|
std::unique_ptr<IFileIO::IReadStream> fp;
|
|
|
|
ReadStream(std::unique_ptr<IFileIO::IReadStream>&& fpin, bool& err) : fp(std::move(fpin)) {
|
|
|
|
if (!fp)
|
|
|
|
err = true;
|
2016-01-25 05:55:31 +00:00
|
|
|
}
|
2015-06-26 19:30:03 +00:00
|
|
|
|
2018-12-08 05:21:47 +00:00
|
|
|
public:
|
2019-08-10 05:41:41 +00:00
|
|
|
uint64_t read(void* buf, uint64_t length) override { return fp->read(buf, length); }
|
|
|
|
uint64_t position() const override { return fp->position(); }
|
|
|
|
void seek(int64_t offset, int whence) override { fp->seek(offset, whence); }
|
2018-12-08 05:21:47 +00:00
|
|
|
};
|
|
|
|
|
2019-08-10 05:41:41 +00:00
|
|
|
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const override {
|
2019-08-30 09:02:35 +00:00
|
|
|
bool err = false;
|
|
|
|
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_fio->beginReadStream(offset), err));
|
|
|
|
|
2019-11-24 03:24:33 +00:00
|
|
|
if (err)
|
|
|
|
return {};
|
2019-08-30 09:02:35 +00:00
|
|
|
|
2018-12-08 05:21:47 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
class WriteStream : public IWriteStream {
|
|
|
|
friend class DiscIOISO;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-12-08 05:21:47 +00:00
|
|
|
public:
|
2019-08-10 05:41:41 +00:00
|
|
|
uint64_t write(const void* buf, uint64_t length) override { return fp->write(buf, length); }
|
2018-12-08 05:21:47 +00:00
|
|
|
};
|
|
|
|
|
2019-08-10 05:41:41 +00:00
|
|
|
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override {
|
2019-08-30 09:02:35 +00:00
|
|
|
bool err = false;
|
|
|
|
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_fio->beginWriteStream(offset), err));
|
|
|
|
|
2019-11-24 03:24:33 +00:00
|
|
|
if (err)
|
|
|
|
return {};
|
2019-08-30 09:02:35 +00:00
|
|
|
|
2018-12-08 05:21:47 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
2015-06-26 19:30:03 +00:00
|
|
|
|
2021-06-22 19:16:56 +00:00
|
|
|
std::unique_ptr<IDiscIO> NewDiscIOISO(std::string_view path) { return std::make_unique<DiscIOISO>(path); }
|
2015-06-26 19:30:03 +00:00
|
|
|
|
2018-12-08 05:21:47 +00:00
|
|
|
} // namespace nod
|