diff --git a/LogVisor b/LogVisor index 828db51..317e75c 160000 --- a/LogVisor +++ b/LogVisor @@ -1 +1 @@ -Subproject commit 828db515ba316903c367b9dc7acf9d0bec0969e7 +Subproject commit 317e75c22e31746947bd1b3700cd72d53c97c837 diff --git a/include/NOD/Util.hpp b/include/NOD/Util.hpp index 0541943..becf373 100644 --- a/include/NOD/Util.hpp +++ b/include/NOD/Util.hpp @@ -4,6 +4,10 @@ #if _WIN32 && UNICODE #include #include +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif #else #include #endif @@ -31,10 +35,6 @@ 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 */ -std::string WideToUTF8(const std::wstring& src); -std::wstring UTF8ToWide(const std::string& src); - /* String-converting views */ #if NOD_UCS2 typedef wchar_t SystemChar; @@ -48,7 +48,11 @@ class SystemUTF8View std::string m_utf8; public: SystemUTF8View(const SystemString& str) - : m_utf8(WideToUTF8(str)) {} + { + int len = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.size(), nullptr, 0, nullptr, nullptr); + m_utf8.assign('\0', len); + WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.size(), &m_utf8[0], len, nullptr, nullptr); + } inline const std::string& utf8_str() {return m_utf8;} }; class SystemStringView @@ -56,7 +60,11 @@ class SystemStringView std::wstring m_sys; public: SystemStringView(const std::string& str) - : m_sys(UTF8ToWide(str)) {} + { + int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), nullptr, 0); + m_sys.assign(L'\0', len); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), &m_sys[0], len); + } inline const std::wstring& sys_str() {return m_sys;} }; #ifndef _S diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 73d7e8f..696dbd4 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -11,7 +11,6 @@ add_library(NOD FileIOFILE.cpp FileIOMEM.cpp NOD.cpp - WideStringConvert.cpp ${NOD_HEADERS}) if(NOT WIN32) set_source_files_properties(aes.cpp PROPERTIES COMPILE_FLAGS -maes) diff --git a/lib/DiscIOWBFS.cpp b/lib/DiscIOWBFS.cpp index 1c29119..4a6b2c0 100644 --- a/lib/DiscIOWBFS.cpp +++ b/lib/DiscIOWBFS.cpp @@ -1,4 +1,5 @@ #include +#include #include "NOD/Util.hpp" #include "NOD/IDiscIO.hpp" @@ -82,7 +83,7 @@ class DiscIOWBFS : public IDiscIO off*=512ULL; if (fseeko(fp, off, SEEK_SET)) { - LogModule.report(LogVisor::FatalError, "error seeking in disc partition: %lld %d", off, count); + LogModule.report(LogVisor::FatalError, "error seeking in disc partition: %" PRId64 " %d", off, count); return 1; } if (fread(buf, count*512ULL, 1, fp) != 1){ diff --git a/lib/WideStringConvert.cpp b/lib/WideStringConvert.cpp deleted file mode 100644 index 9da5139..0000000 --- a/lib/WideStringConvert.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN 1 -#endif -#include -#include "NOD/NOD.hpp" - -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[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::mbrtowc(&wc, buf, MB_LEN_MAX, &state); - retval += wc; - } - return retval; -#endif -} - -}