wchar_t support for windows

This commit is contained in:
Jack Andersen 2015-07-02 10:37:07 -10:00
parent 5c736af2b0
commit b461f63ae4
10 changed files with 57 additions and 25 deletions

View File

@ -1,3 +1,6 @@
win32-g++ {
CROSS_COMPILE = x86_64-w64-mingw32-
}
TEMPLATE = subdirs TEMPLATE = subdirs
CONFIG -= app_bundle CONFIG -= app_bundle
CONFIG -= qt CONFIG -= qt

View File

@ -1,3 +1,6 @@
win32-g++ {
QMAKE_LFLAGS += -municode
}
TEMPLATE = app TEMPLATE = app
CONFIG += console c++11 CONFIG += console c++11
CONFIG -= app_bundle CONFIG -= app_bundle

View File

@ -9,7 +9,15 @@ static void printHelp()
" nodlib make <dir-in> [<image-out>]\n"); " 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[]) int main(int argc, char* argv[])
#endif
{ {
if (argc < 3) if (argc < 3)
{ {
@ -17,8 +25,8 @@ int main(int argc, char* argv[])
return -1; return -1;
} }
const char* inDir = nullptr; const NOD::SystemChar* inDir = nullptr;
const char* outDir = "."; const NOD::SystemChar* outDir = _S(".");
bool force = false; bool force = false;
for (int a=2 ; a<argc ; ++a) for (int a=2 ; a<argc ; ++a)
{ {
@ -30,7 +38,7 @@ int main(int argc, char* argv[])
outDir = argv[a]; outDir = argv[a];
} }
if (!strcasecmp(argv[1], "extract")) if (!strcasecmp(argv[1], _S("extract")))
{ {
std::unique_ptr<NOD::DiscBase> disc = NOD::OpenDiscFromImage(inDir); std::unique_ptr<NOD::DiscBase> disc = NOD::OpenDiscFromImage(inDir);
if (!disc) if (!disc)
@ -42,7 +50,7 @@ int main(int argc, char* argv[])
dataPart->extractToDirectory(outDir, force); dataPart->extractToDirectory(outDir, force);
} }
else if (!strcasecmp(argv[1], "make")) else if (!strcasecmp(argv[1], _S("make")))
{ {
} }
else else

View File

@ -7,11 +7,21 @@
namespace NOD namespace NOD
{ {
/* System char type */ /* filesystem char type */
#if _WIN32 && UNICODE #if _WIN32 && UNICODE
#include <wctype.h> #include <wctype.h>
#include <direct.h>
#include <sys/stat.h>
#define NOD_UCS2 1 #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 <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 #endif
/* String Converters */ /* String Converters */

View File

@ -1,4 +1,3 @@
#include <sys/stat.h>
#include "NOD/DiscBase.hpp" #include "NOD/DiscBase.hpp"
#include "NOD/IFileIO.hpp" #include "NOD/IFileIO.hpp"
@ -55,15 +54,18 @@ void DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
SystemString path = basePath + _S("/") + nameView.sys_str(); SystemString path = basePath + _S("/") + nameView.sys_str();
if (m_kind == NODE_DIRECTORY) if (m_kind == NODE_DIRECTORY)
{ {
if (mkdir(path.c_str(), 0755) && errno != EEXIST) if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
throw std::runtime_error("unable to mkdir '" + path + "'"); {
SystemUTF8View pathView(path);
throw std::runtime_error("unable to mkdir '" + pathView.utf8_str() + "'");
}
for (Node& subnode : *this) for (Node& subnode : *this)
subnode.extractToDirectory(path, force); subnode.extractToDirectory(path, force);
} }
else if (m_kind == NODE_FILE) else if (m_kind == NODE_FILE)
{ {
struct stat theStat; Sstat theStat;
if (force || stat(path.c_str(), &theStat)) if (force || Stat(path.c_str(), &theStat))
{ {
m_hddFile = NewFileIO(path); m_hddFile = NewFileIO(path);
std::unique_ptr<IPartReadStream> rs = beginReadStream(); 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) void DiscBase::IPartition::extractToDirectory(const SystemString& path, bool force)
{ {
struct stat theStat; Sstat theStat;
if (mkdir(path.c_str(), 0755) && errno != EEXIST) if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
throw std::runtime_error("unable to mkdir '" + path + "'"); {
SystemUTF8View pathView(path);
throw std::runtime_error("unable to mkdir '" + pathView.utf8_str() + "'");
}
/* Extract Apploader */ /* Extract Apploader */
std::string apploaderPath = path + "/apploader.bin"; SystemString apploaderPath = path + _S("/apploader.bin");
if (force || stat(apploaderPath.c_str(), &theStat)) if (force || Stat(apploaderPath.c_str(), &theStat))
{ {
std::unique_ptr<uint8_t[]> buf(new uint8_t[m_apploaderSz]); std::unique_ptr<uint8_t[]> buf(new uint8_t[m_apploaderSz]);
std::unique_ptr<IPartReadStream> rs = beginReadStream(0x2440); std::unique_ptr<IPartReadStream> rs = beginReadStream(0x2440);
rs->read(buf.get(), m_apploaderSz); 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); ws->write(buf.get(), m_apploaderSz);
} }

View File

@ -29,7 +29,7 @@ public:
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const
{ {
#if NOD_UCS2 #if NOD_UCS2
FILE* fp = wfopen(filepath.c_str(), L"rb"); FILE* fp = _wfopen(filepath.c_str(), L"rb");
#else #else
FILE* fp = fopen(filepath.c_str(), "rb"); FILE* fp = fopen(filepath.c_str(), "rb");
#endif #endif
@ -60,7 +60,7 @@ public:
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const
{ {
#if NOD_UCS2 #if NOD_UCS2
FILE* fp = wfopen(filepath.c_str(), L"wb"); FILE* fp = _wfopen(filepath.c_str(), L"wb");
#else #else
FILE* fp = fopen(filepath.c_str(), "wb"); FILE* fp = fopen(filepath.c_str(), "wb");
#endif #endif

View File

@ -29,7 +29,7 @@ public:
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const
{ {
#if NOD_UCS2 #if NOD_UCS2
FILE* fp = wfopen(filepath.c_str(), L"rb"); FILE* fp = _wfopen(filepath.c_str(), L"rb");
#else #else
FILE* fp = fopen(filepath.c_str(), "rb"); FILE* fp = fopen(filepath.c_str(), "rb");
#endif #endif
@ -60,7 +60,7 @@ public:
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const
{ {
#if NOD_UCS2 #if NOD_UCS2
FILE* fp = wfopen(filepath.c_str(), L"wb"); FILE* fp = _wfopen(filepath.c_str(), L"wb");
#else #else
FILE* fp = fopen(filepath.c_str(), "wb"); FILE* fp = fopen(filepath.c_str(), "wb");
#endif #endif

View File

@ -1,4 +1,3 @@
#include <sys/stat.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdexcept> #include <stdexcept>
@ -22,7 +21,7 @@ public:
uint64_t size() uint64_t size()
{ {
#if NOD_UCS2 #if NOD_UCS2
FILE* fp = wfopen(m_path.c_str(), L"rb"); FILE* fp = _wfopen(m_path.c_str(), L"rb");
#else #else
FILE* fp = fopen(m_path.c_str(), "rb"); FILE* fp = fopen(m_path.c_str(), "rb");
#endif #endif
@ -41,7 +40,7 @@ public:
WriteStream(const SystemString& path) WriteStream(const SystemString& path)
{ {
#if NOD_UCS2 #if NOD_UCS2
fp = wfopen(path.c_str(), L"wb"); fp = _wfopen(path.c_str(), L"wb");
#else #else
fp = fopen(path.c_str(), "wb"); fp = fopen(path.c_str(), "wb");
#endif #endif
@ -84,7 +83,7 @@ public:
ReadStream(const SystemString& path) ReadStream(const SystemString& path)
{ {
#if NOD_UCS2 #if NOD_UCS2
fp = wfopen(path.c_str(), L"rb"); fp = _wfopen(path.c_str(), L"rb");
#else #else
fp = fopen(path.c_str(), "rb"); fp = fopen(path.c_str(), "rb");
#endif #endif

View File

@ -10,7 +10,11 @@ std::unique_ptr<IDiscIO> NewDiscIOWBFS(const SystemChar* path);
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii) std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
{ {
/* Temporary file handle to determine image type */ /* Temporary file handle to determine image type */
#if NOD_UCS2
FILE* fp = _wfopen(path, L"rb");
#else
FILE* fp = fopen(path, "rb"); FILE* fp = fopen(path, "rb");
#endif
if (!fp) if (!fp)
{ {
#if NOD_UCS2 #if NOD_UCS2

View File

@ -1,6 +1,6 @@
#include "NOD/NOD.hpp"
#include <locale> #include <locale>
#include <codecvt> #include <codecvt>
#include "NOD/NOD.hpp"
namespace NOD namespace NOD
{ {