From 791056d9669e5a02e19398e647b2ac16404799ef Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 26 Jun 2015 09:30:03 -1000 Subject: [PATCH] initial class layout --- NODLib.pro | 24 ++++++++++++++++ include/DiscBase.hpp | 64 +++++++++++++++++++++++++++++++++++++++++ include/DiscGCN.hpp | 18 ++++++++++++ include/DiscWii.hpp | 17 +++++++++++ include/IDiscIO.hpp | 32 +++++++++++++++++++++ include/IFileIO.hpp | 36 +++++++++++++++++++++++ include/NODLib.hpp | 17 +++++++++++ lib/DiscBase.cpp | 0 lib/DiscGCN.cpp | 0 lib/DiscIOFILE.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++ lib/DiscIOWBFS.cpp | 0 lib/DiscWii.cpp | 7 +++++ main.cpp | 10 +++++++ 13 files changed, 293 insertions(+) create mode 100644 NODLib.pro create mode 100644 include/DiscBase.hpp create mode 100644 include/DiscGCN.hpp create mode 100644 include/DiscWii.hpp create mode 100644 include/IDiscIO.hpp create mode 100644 include/IFileIO.hpp create mode 100644 include/NODLib.hpp create mode 100644 lib/DiscBase.cpp create mode 100644 lib/DiscGCN.cpp create mode 100644 lib/DiscIOFILE.cpp create mode 100644 lib/DiscIOWBFS.cpp create mode 100644 lib/DiscWii.cpp create mode 100644 main.cpp diff --git a/NODLib.pro b/NODLib.pro new file mode 100644 index 0000000..30e77d4 --- /dev/null +++ b/NODLib.pro @@ -0,0 +1,24 @@ +TEMPLATE = lib +CONFIG += staticlib c++11 +CONFIG -= app_bundle +CONFIG -= qt +QT = + +INCLUDEPATH += include + +HEADERS += \ + include/NODLib.hpp \ + include/IDiscIO.hpp \ + include/IFileIO.hpp \ + include/DiscBase.hpp \ + include/DiscGCN.hpp \ + include/DiscWii.hpp + +SOURCES += \ + lib/DiscIOFILE.cpp \ + lib/DiscIOWBFS.cpp \ + lib/FileIOFILE.cpp \ + lib/FileIOMEM.cpp \ + lib/DiscBase.cpp \ + lib/DiscGCN.cpp \ + lib/DiscWii.cpp diff --git a/include/DiscBase.hpp b/include/DiscBase.hpp new file mode 100644 index 0000000..633c1b3 --- /dev/null +++ b/include/DiscBase.hpp @@ -0,0 +1,64 @@ +#ifndef __NOD_DISC_BASE__ +#define __NOD_DISC_BASE__ + +#include +#include +#include +#include "IDiscIO.hpp" +#include "IFileIO.hpp" + +namespace NOD +{ + +class DiscBase +{ + IDiscIO& m_discIO; +protected: + struct Partition + { + enum Kind + { + PART_DATA, + PART_UPDATE + }; + struct File + { + std::unique_ptr m_hddFile; + std::string m_discPath; + size_t m_discOffset; + size_t m_discLength; + File(const std::string& discPath) + : m_discPath(discPath) {} + }; + std::list files; + Kind m_kind; + Partition(Kind kind) + : m_kind(kind) {} + }; + std::list partitions; + Partition& addPartition(Partition::Kind kind); +public: + DiscBase(IDiscIO& dio); + virtual bool sync()=0; + + class IPartReadStream + { + public: + virtual size_t read(void* buf, size_t length)=0; + }; + virtual std::unique_ptr beginDataReadStream()=0; + virtual std::unique_ptr beginUpdateReadStream()=0; + + class IPartWriteStream + { + public: + virtual size_t write(void* buf, size_t length)=0; + }; + virtual std::unique_ptr beginDataWriteStream()=0; + virtual std::unique_ptr beginUpdateWriteStream()=0; + +}; + +} + +#endif // __NOD_DISC_BASE__ diff --git a/include/DiscGCN.hpp b/include/DiscGCN.hpp new file mode 100644 index 0000000..a8e9932 --- /dev/null +++ b/include/DiscGCN.hpp @@ -0,0 +1,18 @@ +#ifndef __NOD_DISC_GCN__ +#define __NOD_DISC_GCN__ + +#include "DiscBase.hpp" + +namespace NOD +{ + +class DiscGCN : public DiscBase +{ +public: + DiscGCN(IDiscIO& discio); +}; + +} + + +#endif // __NOD_DISC_GCN__ diff --git a/include/DiscWii.hpp b/include/DiscWii.hpp new file mode 100644 index 0000000..806fded --- /dev/null +++ b/include/DiscWii.hpp @@ -0,0 +1,17 @@ +#ifndef __NOD_DISC_WII__ +#define __NOD_DISC_WII__ + +#include "DiscBase.hpp" + +namespace NOD +{ + +class DiscWii : public DiscBase +{ +public: + DiscWii(IDiscIO& discio); +}; + +} + +#endif // __NOD_DISC_WII__ diff --git a/include/IDiscIO.hpp b/include/IDiscIO.hpp new file mode 100644 index 0000000..5ad04d4 --- /dev/null +++ b/include/IDiscIO.hpp @@ -0,0 +1,32 @@ +#ifndef __NOD_IDISC_IO__ +#define __NOD_IDISC_IO__ + +#include +#include + +namespace NOD +{ + +class IDiscIO +{ +public: + virtual ~IDiscIO() {} + + class IReadStream + { + public: + virtual size_t read(void* buf, size_t length)=0; + }; + virtual std::unique_ptr beginReadStream(size_t offset); + + class IWriteStream + { + public: + virtual size_t write(void* buf, size_t length)=0; + }; + virtual std::unique_ptr beginWriteStream(size_t offset); +}; + +} + +#endif // __NOD_IDISC_IO__ diff --git a/include/IFileIO.hpp b/include/IFileIO.hpp new file mode 100644 index 0000000..cdef712 --- /dev/null +++ b/include/IFileIO.hpp @@ -0,0 +1,36 @@ +#ifndef __NOD_IFILE_IO__ +#define __NOD_IFILE_IO__ + +#include +#include +#include "IDiscIO.hpp" + +namespace NOD +{ + +class IFileIO +{ +public: + virtual ~IFileIO() {} + virtual size_t size()=0; + + class IWriteStream + { + public: + virtual ~IWriteStream() {} + virtual size_t copyFromDisc(IDiscIO::IReadStream& discio, size_t length)=0; + }; + virtual std::unique_ptr beginWriteStream(); + + class IReadStream + { + public: + virtual ~IReadStream() {} + virtual size_t copyToDisc(IDiscIO::IWriteStream& discio, size_t length)=0; + }; + virtual std::unique_ptr beginReadStream(); +}; + +} + +#endif // __NOD_IFILE_IO__ diff --git a/include/NODLib.hpp b/include/NODLib.hpp new file mode 100644 index 0000000..8ce4b32 --- /dev/null +++ b/include/NODLib.hpp @@ -0,0 +1,17 @@ +#ifndef __NOD_LIB__ +#define __NOD_LIB__ + +#include +#include "DiscGCN.hpp" +#include "DiscWii.hpp" +#include "IDiscIO.hpp" + +namespace NOD +{ + +std::unique_ptr NewDiscIOFILE(const char* path); +std::unique_ptr NewDiscIOWBFS(const char* path); + +} + +#endif // __NOD_LIB__ diff --git a/lib/DiscBase.cpp b/lib/DiscBase.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/DiscGCN.cpp b/lib/DiscGCN.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/DiscIOFILE.cpp b/lib/DiscIOFILE.cpp new file mode 100644 index 0000000..d58848e --- /dev/null +++ b/lib/DiscIOFILE.cpp @@ -0,0 +1,68 @@ +#include +#include +#include "IDiscIO.hpp" + +namespace NOD +{ + +class DiscIOFILE : public IDiscIO +{ + std::string filepath; +public: + DiscIOFILE(const std::string& fpin) + : filepath(fpin) {} + + class FILEReadStream : public IReadStream + { + friend class DiscIOFILE; + FILE* fp; + FILEReadStream(FILE* fpin) + : fp(fpin) {} + ~FILEReadStream() {fclose(fp);} + public: + size_t read(void* buf, size_t length) + {return fread(buf, 1, length, fp);} + }; + std::unique_ptr beginReadStream(size_t offset) + { + FILE* fp = fopen(filepath.c_str(), "rb"); + if (!fp) + { + throw std::runtime_error("Unable to open '" + filepath + "' for reading"); + return std::unique_ptr(); + } + fseek(fp, offset, SEEK_SET); + return std::unique_ptr(new FILEReadStream(fp)); + } + + class FILEWriteStream : public IWriteStream + { + friend class DiscIOFILE; + FILE* fp; + FILEWriteStream(FILE* fpin) + : fp(fpin) {} + ~FILEWriteStream() {fclose(fp);} + public: + size_t write(void* buf, size_t length) + {return fwrite(buf, 1, length, fp);} + }; + std::unique_ptr beginWriteStream(size_t offset) + { + FILE* fp = fopen(filepath.c_str(), "wb"); + if (!fp) + { + throw std::runtime_error("Unable to open '" + filepath + "' for writing"); + return std::unique_ptr(); + } + fseek(fp, offset, SEEK_SET); + return std::unique_ptr(new FILEWriteStream(fp)); + } +}; + +std::unique_ptr NewDiscIOFILE(const char* path) +{ + return std::unique_ptr(new DiscIOFILE(path)); +} + +} + diff --git a/lib/DiscIOWBFS.cpp b/lib/DiscIOWBFS.cpp new file mode 100644 index 0000000..e69de29 diff --git a/lib/DiscWii.cpp b/lib/DiscWii.cpp new file mode 100644 index 0000000..911c2bf --- /dev/null +++ b/lib/DiscWii.cpp @@ -0,0 +1,7 @@ +#include "DiscWii.hpp" + +namespace NOD +{ + + +} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..5f5419b --- /dev/null +++ b/main.cpp @@ -0,0 +1,10 @@ +#include + +using namespace std; + +int main() +{ + cout << "Hello World!" << endl; + return 0; +} +