diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f9b220..d85b52e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.0) project(NODLib) -if(NOT WIN32) +if(NOT MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() diff --git a/LogVisor b/LogVisor index 154b844..828db51 160000 --- a/LogVisor +++ b/LogVisor @@ -1 +1 @@ -Subproject commit 154b84413050cdb03f281c42861b9af6eaef7d14 +Subproject commit 828db515ba316903c367b9dc7acf9d0bec0969e7 diff --git a/lib/DiscIOWBFS.cpp b/lib/DiscIOWBFS.cpp index 0202dd5..1c29119 100644 --- a/lib/DiscIOWBFS.cpp +++ b/lib/DiscIOWBFS.cpp @@ -139,7 +139,7 @@ public: p->wbfs_sec_sz = 1<wbfs_sec_sz_s; p->n_wbfs_sec = p->n_wii_sec >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s); p->n_wbfs_sec_per_disc = p->n_wii_sec_per_disc >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s); - p->disc_info_sz = ALIGN_LBA(sizeof(WBFSDiscInfo) + p->n_wbfs_sec_per_disc*2); + p->disc_info_sz = ALIGN_LBA(uint16_t(sizeof(WBFSDiscInfo)) + p->n_wbfs_sec_per_disc*2); p->freeblks_lba = (p->wbfs_sec_sz - p->n_wbfs_sec/8)>>p->hd_sec_sz_s; diff --git a/lib/WideStringConvert.cpp b/lib/WideStringConvert.cpp index 1f254bd..9da5139 100644 --- a/lib/WideStringConvert.cpp +++ b/lib/WideStringConvert.cpp @@ -1,3 +1,7 @@ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#include #include "NOD/NOD.hpp" namespace NOD @@ -5,29 +9,45 @@ namespace NOD std::string WideToUTF8(const std::wstring& src) { +#if _WIN32 + int len = WideCharToMultiByte(CP_UTF8, 0, src.c_str(), src.size(), nullptr, 0, nullptr, nullptr); + std::string retval(len, '\0'); + WideCharToMultiByte(CP_UTF8, 0, src.c_str(), src.size(), &retval[0], len, nullptr, nullptr); + return retval; +#else std::string retval; retval.reserve(src.length()); + std::mbstate_t state = {}; for (wchar_t ch : src) { - char mb[4]; - int c = std::wctomb(mb, ch); + char mb[MB_LEN_MAX]; + int c = std::wcrtomb(mb, ch, &state); retval.append(mb, c); } return retval; +#endif } std::wstring UTF8ToWide(const std::string& src) { +#if _WIN32 + int len = MultiByteToWideChar(CP_UTF8, 0, src.c_str(), src.size(), nullptr, 0); + std::wstring retval(len, L'\0'); + MultiByteToWideChar(CP_UTF8, 0, src.c_str(), src.size(), &retval[0], len); + return retval; +#else std::wstring retval; retval.reserve(src.length()); const char* buf = src.c_str(); + std::mbstate_t state = {}; while (*buf) { wchar_t wc; - buf += std::mbtowc(&wc, buf, MB_CUR_MAX); + buf += std::mbrtowc(&wc, buf, MB_LEN_MAX, &state); retval += wc; } return retval; +#endif } }