Add "MinGW" precompile

Signed-off-by: yami-hack <yami-hack@foxmail.com>
This commit is contained in:
yami-hack 2016-06-11 16:17:33 +08:00
parent e74d322724
commit 4cd902da5e
3 changed files with 18 additions and 9 deletions

View File

@ -9,6 +9,7 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#ifdef _WIN32 #ifdef _WIN32
#include <share.h>
#include <windows.h> #include <windows.h>
#include <shlobj.h> // for SHGetFolderPath #include <shlobj.h> // for SHGetFolderPath
#include <shellapi.h> #include <shellapi.h>
@ -927,7 +928,11 @@ bool IOFile::Open(const std::string& filename, const char openmode[])
{ {
Close(); Close();
#ifdef _WIN32 #ifdef _WIN32
#if defined(__MINGW64__)
m_file = _wfsopen(Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str(),SH_DENYNO);
#else
_wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str()); _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str());
#endif
#else #else
m_file = fopen(filename.c_str(), openmode); m_file = fopen(filename.c_str(), openmode);
#endif #endif
@ -980,10 +985,16 @@ bool IOFile::Flush()
bool IOFile::Resize(u64 size) bool IOFile::Resize(u64 size)
{ {
if (!IsOpen() || 0 != if (!IsOpen() || 0 !=
#ifdef _WIN32 #ifdef _WIN32
#if defined(__MINGW64__)
//TDM-GCC64 does not supports _chsize_s ?in <io_s.h>
_chsize(_fileno(m_file), size)
#else
// ector: _chsize sucks, not 64-bit safe // ector: _chsize sucks, not 64-bit safe
// F|RES: changed to _chsize_s. i think it is 64-bit safe // F|RES: changed to _chsize_s. i think it is 64-bit safe
_chsize_s(_fileno(m_file), size) _chsize_s(_fileno(m_file), size)
#endif
#else #else
// TODO: handle 64bit and growing // TODO: handle 64bit and growing
ftruncate(fileno(m_file), size) ftruncate(fileno(m_file), size)

View File

@ -13,7 +13,7 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/string_util.h" #include "common/string_util.h"
#ifdef _MSC_VER #if defined(_MSC_VER) || __MINGW64__
#include <Windows.h> #include <Windows.h>
#include <codecvt> #include <codecvt>
#include "common/common_funcs.h" #include "common/common_funcs.h"
@ -52,7 +52,7 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
{ {
int writtenCount; int writtenCount;
#ifdef _MSC_VER #if defined(_MSC_VER) || !defined(__MINGW64__)
// You would think *printf are simple, right? Iterate on each character, // You would think *printf are simple, right? Iterate on each character,
// if it's a format specifier handle it properly, etc. // if it's a format specifier handle it properly, etc.
// //
@ -292,11 +292,11 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st
return result; return result;
} }
#ifdef _MSC_VER #if defined(_MSC_VER) || !__MINGW32__ || __MINGW64__
std::string UTF16ToUTF8(const std::u16string& input) std::string UTF16ToUTF8(const std::u16string& input)
{ {
#if _MSC_VER >= 1900 #if _MSC_VER >= 1900 && defined(__MINGW64__)
// Workaround for missing char16_t/char32_t instantiations in MSVC2015 // Workaround for missing char16_t/char32_t instantiations in MSVC2015
std::wstring_convert<std::codecvt_utf8_utf16<__int16>, __int16> convert; std::wstring_convert<std::codecvt_utf8_utf16<__int16>, __int16> convert;
std::basic_string<__int16> tmp_buffer(input.cbegin(), input.cend()); std::basic_string<__int16> tmp_buffer(input.cbegin(), input.cend());
@ -309,7 +309,7 @@ std::string UTF16ToUTF8(const std::u16string& input)
std::u16string UTF8ToUTF16(const std::string& input) std::u16string UTF8ToUTF16(const std::string& input)
{ {
#if _MSC_VER >= 1900 #if _MSC_VER >= 1900 && defined(__MINGW64__)
// Workaround for missing char16_t/char32_t instantiations in MSVC2015 // Workaround for missing char16_t/char32_t instantiations in MSVC2015
std::wstring_convert<std::codecvt_utf8_utf16<__int16>, __int16> convert; std::wstring_convert<std::codecvt_utf8_utf16<__int16>, __int16> convert;
auto tmp_buffer = convert.from_bytes(input); auto tmp_buffer = convert.from_bytes(input);
@ -323,13 +323,11 @@ std::u16string UTF8ToUTF16(const std::string& input)
static std::wstring CPToUTF16(u32 code_page, const std::string& input) static std::wstring CPToUTF16(u32 code_page, const std::string& input)
{ {
auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0);
std::wstring output(size,'\0');
std::wstring output;
output.resize(size); output.resize(size);
if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()))) if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size())))
output.clear(); output.clear();
return output; return output;
} }

View File

@ -14,7 +14,7 @@
#include <map> #include <map>
#include <numeric> #include <numeric>
#ifdef _MSC_VER #if defined(_MSC_VER) || (__MINGW64__)
#include <WinSock2.h> #include <WinSock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <common/x64/abi.h> #include <common/x64/abi.h>