Windows refactors

This commit is contained in:
Jack Andersen 2015-08-30 17:37:22 -10:00
parent 83b96b1bc2
commit 23a536a2b1
4 changed files with 26 additions and 6 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(NODLib) project(NODLib)
if(NOT WIN32) if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif() endif()

@ -1 +1 @@
Subproject commit 154b84413050cdb03f281c42861b9af6eaef7d14 Subproject commit 828db515ba316903c367b9dc7acf9d0bec0969e7

View File

@ -139,7 +139,7 @@ public:
p->wbfs_sec_sz = 1<<p->wbfs_sec_sz_s; p->wbfs_sec_sz = 1<<p->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 = 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->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; p->freeblks_lba = (p->wbfs_sec_sz - p->n_wbfs_sec/8)>>p->hd_sec_sz_s;

View File

@ -1,3 +1,7 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
#include "NOD/NOD.hpp" #include "NOD/NOD.hpp"
namespace NOD namespace NOD
@ -5,29 +9,45 @@ namespace NOD
std::string WideToUTF8(const std::wstring& src) 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; std::string retval;
retval.reserve(src.length()); retval.reserve(src.length());
std::mbstate_t state = {};
for (wchar_t ch : src) for (wchar_t ch : src)
{ {
char mb[4]; char mb[MB_LEN_MAX];
int c = std::wctomb(mb, ch); int c = std::wcrtomb(mb, ch, &state);
retval.append(mb, c); retval.append(mb, c);
} }
return retval; return retval;
#endif
} }
std::wstring UTF8ToWide(const std::string& src) 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; std::wstring retval;
retval.reserve(src.length()); retval.reserve(src.length());
const char* buf = src.c_str(); const char* buf = src.c_str();
std::mbstate_t state = {};
while (*buf) while (*buf)
{ {
wchar_t wc; wchar_t wc;
buf += std::mbtowc(&wc, buf, MB_CUR_MAX); buf += std::mbrtowc(&wc, buf, MB_LEN_MAX, &state);
retval += wc; retval += wc;
} }
return retval; return retval;
#endif
} }
} }