mirror of https://github.com/AxioDL/nod.git
wchar_t support for windows
This commit is contained in:
parent
5c736af2b0
commit
b461f63ae4
|
@ -1,3 +1,6 @@
|
|||
win32-g++ {
|
||||
CROSS_COMPILE = x86_64-w64-mingw32-
|
||||
}
|
||||
TEMPLATE = subdirs
|
||||
CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
win32-g++ {
|
||||
QMAKE_LFLAGS += -municode
|
||||
}
|
||||
TEMPLATE = app
|
||||
CONFIG += console c++11
|
||||
CONFIG -= app_bundle
|
||||
|
|
|
@ -9,7 +9,15 @@ static void printHelp()
|
|||
" nodlib make <dir-in> [<image-out>]\n");
|
||||
}
|
||||
|
||||
#if NOD_UCS2
|
||||
#ifdef strcasecmp
|
||||
#undef strcasecmp
|
||||
#endif
|
||||
#define strcasecmp _wcsicmp
|
||||
int wmain(int argc, wchar_t* argv[])
|
||||
#else
|
||||
int main(int argc, char* argv[])
|
||||
#endif
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
|
@ -17,8 +25,8 @@ int main(int argc, char* argv[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
const char* inDir = nullptr;
|
||||
const char* outDir = ".";
|
||||
const NOD::SystemChar* inDir = nullptr;
|
||||
const NOD::SystemChar* outDir = _S(".");
|
||||
bool force = false;
|
||||
for (int a=2 ; a<argc ; ++a)
|
||||
{
|
||||
|
@ -30,7 +38,7 @@ int main(int argc, char* argv[])
|
|||
outDir = argv[a];
|
||||
}
|
||||
|
||||
if (!strcasecmp(argv[1], "extract"))
|
||||
if (!strcasecmp(argv[1], _S("extract")))
|
||||
{
|
||||
std::unique_ptr<NOD::DiscBase> disc = NOD::OpenDiscFromImage(inDir);
|
||||
if (!disc)
|
||||
|
@ -42,7 +50,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
dataPart->extractToDirectory(outDir, force);
|
||||
}
|
||||
else if (!strcasecmp(argv[1], "make"))
|
||||
else if (!strcasecmp(argv[1], _S("make")))
|
||||
{
|
||||
}
|
||||
else
|
||||
|
|
|
@ -7,11 +7,21 @@
|
|||
namespace NOD
|
||||
{
|
||||
|
||||
/* System char type */
|
||||
/* filesystem char type */
|
||||
#if _WIN32 && UNICODE
|
||||
#include <wctype.h>
|
||||
#include <direct.h>
|
||||
#include <sys/stat.h>
|
||||
#define NOD_UCS2 1
|
||||
typedef struct _stat Sstat;
|
||||
static inline int Mkdir(const wchar_t* path, int) {return _wmkdir(path);}
|
||||
static inline int Stat(const wchar_t* path, Sstat* statout) {return _wstat(path, statout);}
|
||||
#else
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
typedef struct stat Sstat;
|
||||
static inline int Mkdir(const char* path, mode_t mode) {return mkdir(path, mode);}
|
||||
static inline int Stat(const char* path, Sstat* statout) {return stat(path, statout);}
|
||||
#endif
|
||||
|
||||
/* String Converters */
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include <sys/stat.h>
|
||||
#include "NOD/DiscBase.hpp"
|
||||
#include "NOD/IFileIO.hpp"
|
||||
|
||||
|
@ -55,15 +54,18 @@ void DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
|
|||
SystemString path = basePath + _S("/") + nameView.sys_str();
|
||||
if (m_kind == NODE_DIRECTORY)
|
||||
{
|
||||
if (mkdir(path.c_str(), 0755) && errno != EEXIST)
|
||||
throw std::runtime_error("unable to mkdir '" + path + "'");
|
||||
if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
|
||||
{
|
||||
SystemUTF8View pathView(path);
|
||||
throw std::runtime_error("unable to mkdir '" + pathView.utf8_str() + "'");
|
||||
}
|
||||
for (Node& subnode : *this)
|
||||
subnode.extractToDirectory(path, force);
|
||||
}
|
||||
else if (m_kind == NODE_FILE)
|
||||
{
|
||||
struct stat theStat;
|
||||
if (force || stat(path.c_str(), &theStat))
|
||||
Sstat theStat;
|
||||
if (force || Stat(path.c_str(), &theStat))
|
||||
{
|
||||
m_hddFile = NewFileIO(path);
|
||||
std::unique_ptr<IPartReadStream> rs = beginReadStream();
|
||||
|
@ -75,18 +77,21 @@ void DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
|
|||
|
||||
void DiscBase::IPartition::extractToDirectory(const SystemString& path, bool force)
|
||||
{
|
||||
struct stat theStat;
|
||||
if (mkdir(path.c_str(), 0755) && errno != EEXIST)
|
||||
throw std::runtime_error("unable to mkdir '" + path + "'");
|
||||
Sstat theStat;
|
||||
if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
|
||||
{
|
||||
SystemUTF8View pathView(path);
|
||||
throw std::runtime_error("unable to mkdir '" + pathView.utf8_str() + "'");
|
||||
}
|
||||
|
||||
/* Extract Apploader */
|
||||
std::string apploaderPath = path + "/apploader.bin";
|
||||
if (force || stat(apploaderPath.c_str(), &theStat))
|
||||
SystemString apploaderPath = path + _S("/apploader.bin");
|
||||
if (force || Stat(apploaderPath.c_str(), &theStat))
|
||||
{
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[m_apploaderSz]);
|
||||
std::unique_ptr<IPartReadStream> rs = beginReadStream(0x2440);
|
||||
rs->read(buf.get(), m_apploaderSz);
|
||||
std::unique_ptr<IFileIO::IWriteStream> ws = NewFileIO(path + "/apploader.bin")->beginWriteStream();
|
||||
std::unique_ptr<IFileIO::IWriteStream> ws = NewFileIO(path + _S("/apploader.bin"))->beginWriteStream();
|
||||
ws->write(buf.get(), m_apploaderSz);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const
|
||||
{
|
||||
#if NOD_UCS2
|
||||
FILE* fp = wfopen(filepath.c_str(), L"rb");
|
||||
FILE* fp = _wfopen(filepath.c_str(), L"rb");
|
||||
#else
|
||||
FILE* fp = fopen(filepath.c_str(), "rb");
|
||||
#endif
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const
|
||||
{
|
||||
#if NOD_UCS2
|
||||
FILE* fp = wfopen(filepath.c_str(), L"wb");
|
||||
FILE* fp = _wfopen(filepath.c_str(), L"wb");
|
||||
#else
|
||||
FILE* fp = fopen(filepath.c_str(), "wb");
|
||||
#endif
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const
|
||||
{
|
||||
#if NOD_UCS2
|
||||
FILE* fp = wfopen(filepath.c_str(), L"rb");
|
||||
FILE* fp = _wfopen(filepath.c_str(), L"rb");
|
||||
#else
|
||||
FILE* fp = fopen(filepath.c_str(), "rb");
|
||||
#endif
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const
|
||||
{
|
||||
#if NOD_UCS2
|
||||
FILE* fp = wfopen(filepath.c_str(), L"wb");
|
||||
FILE* fp = _wfopen(filepath.c_str(), L"wb");
|
||||
#else
|
||||
FILE* fp = fopen(filepath.c_str(), "wb");
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdexcept>
|
||||
|
@ -22,7 +21,7 @@ public:
|
|||
uint64_t size()
|
||||
{
|
||||
#if NOD_UCS2
|
||||
FILE* fp = wfopen(m_path.c_str(), L"rb");
|
||||
FILE* fp = _wfopen(m_path.c_str(), L"rb");
|
||||
#else
|
||||
FILE* fp = fopen(m_path.c_str(), "rb");
|
||||
#endif
|
||||
|
@ -41,7 +40,7 @@ public:
|
|||
WriteStream(const SystemString& path)
|
||||
{
|
||||
#if NOD_UCS2
|
||||
fp = wfopen(path.c_str(), L"wb");
|
||||
fp = _wfopen(path.c_str(), L"wb");
|
||||
#else
|
||||
fp = fopen(path.c_str(), "wb");
|
||||
#endif
|
||||
|
@ -84,7 +83,7 @@ public:
|
|||
ReadStream(const SystemString& path)
|
||||
{
|
||||
#if NOD_UCS2
|
||||
fp = wfopen(path.c_str(), L"rb");
|
||||
fp = _wfopen(path.c_str(), L"rb");
|
||||
#else
|
||||
fp = fopen(path.c_str(), "rb");
|
||||
#endif
|
||||
|
|
|
@ -10,7 +10,11 @@ std::unique_ptr<IDiscIO> NewDiscIOWBFS(const SystemChar* path);
|
|||
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
|
||||
{
|
||||
/* Temporary file handle to determine image type */
|
||||
#if NOD_UCS2
|
||||
FILE* fp = _wfopen(path, L"rb");
|
||||
#else
|
||||
FILE* fp = fopen(path, "rb");
|
||||
#endif
|
||||
if (!fp)
|
||||
{
|
||||
#if NOD_UCS2
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "NOD/NOD.hpp"
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include "NOD/NOD.hpp"
|
||||
|
||||
namespace NOD
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue