mirror of https://github.com/AxioDL/nod.git
initial class layout
This commit is contained in:
commit
791056d966
|
@ -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
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef __NOD_DISC_BASE__
|
||||
#define __NOD_DISC_BASE__
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#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<IFileIO> m_hddFile;
|
||||
std::string m_discPath;
|
||||
size_t m_discOffset;
|
||||
size_t m_discLength;
|
||||
File(const std::string& discPath)
|
||||
: m_discPath(discPath) {}
|
||||
};
|
||||
std::list<File> files;
|
||||
Kind m_kind;
|
||||
Partition(Kind kind)
|
||||
: m_kind(kind) {}
|
||||
};
|
||||
std::list<Partition> 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<IPartReadStream> beginDataReadStream()=0;
|
||||
virtual std::unique_ptr<IPartReadStream> beginUpdateReadStream()=0;
|
||||
|
||||
class IPartWriteStream
|
||||
{
|
||||
public:
|
||||
virtual size_t write(void* buf, size_t length)=0;
|
||||
};
|
||||
virtual std::unique_ptr<IPartWriteStream> beginDataWriteStream()=0;
|
||||
virtual std::unique_ptr<IPartWriteStream> beginUpdateWriteStream()=0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __NOD_DISC_BASE__
|
|
@ -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__
|
|
@ -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__
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef __NOD_IDISC_IO__
|
||||
#define __NOD_IDISC_IO__
|
||||
|
||||
#include <memory>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace NOD
|
||||
{
|
||||
|
||||
class IDiscIO
|
||||
{
|
||||
public:
|
||||
virtual ~IDiscIO() {}
|
||||
|
||||
class IReadStream
|
||||
{
|
||||
public:
|
||||
virtual size_t read(void* buf, size_t length)=0;
|
||||
};
|
||||
virtual std::unique_ptr<IReadStream> beginReadStream(size_t offset);
|
||||
|
||||
class IWriteStream
|
||||
{
|
||||
public:
|
||||
virtual size_t write(void* buf, size_t length)=0;
|
||||
};
|
||||
virtual std::unique_ptr<IWriteStream> beginWriteStream(size_t offset);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __NOD_IDISC_IO__
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef __NOD_IFILE_IO__
|
||||
#define __NOD_IFILE_IO__
|
||||
|
||||
#include <memory>
|
||||
#include <stdlib.h>
|
||||
#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<IWriteStream> beginWriteStream();
|
||||
|
||||
class IReadStream
|
||||
{
|
||||
public:
|
||||
virtual ~IReadStream() {}
|
||||
virtual size_t copyToDisc(IDiscIO::IWriteStream& discio, size_t length)=0;
|
||||
};
|
||||
virtual std::unique_ptr<IReadStream> beginReadStream();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __NOD_IFILE_IO__
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef __NOD_LIB__
|
||||
#define __NOD_LIB__
|
||||
|
||||
#include <memory>
|
||||
#include "DiscGCN.hpp"
|
||||
#include "DiscWii.hpp"
|
||||
#include "IDiscIO.hpp"
|
||||
|
||||
namespace NOD
|
||||
{
|
||||
|
||||
std::unique_ptr<IDiscIO> NewDiscIOFILE(const char* path);
|
||||
std::unique_ptr<IDiscIO> NewDiscIOWBFS(const char* path);
|
||||
|
||||
}
|
||||
|
||||
#endif // __NOD_LIB__
|
|
@ -0,0 +1,68 @@
|
|||
#include <stdio.h>
|
||||
#include <stdexcept>
|
||||
#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<IReadStream> 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<IReadStream>();
|
||||
}
|
||||
fseek(fp, offset, SEEK_SET);
|
||||
return std::unique_ptr<IReadStream>(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<IWriteStream> 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<IWriteStream>();
|
||||
}
|
||||
fseek(fp, offset, SEEK_SET);
|
||||
return std::unique_ptr<IWriteStream>(new FILEWriteStream(fp));
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<IDiscIO> NewDiscIOFILE(const char* path)
|
||||
{
|
||||
return std::unique_ptr<IDiscIO>(new DiscIOFILE(path));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#include "DiscWii.hpp"
|
||||
|
||||
namespace NOD
|
||||
{
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue