From 2b0db06858f89f96aa5dffd053c9f130c68e1a94 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Fri, 29 May 2015 20:51:19 +0600 Subject: [PATCH] Add Android compatible wrapper for wcscat and wchar_t* constant strings. --- projects/msvc12/GLideN64.vcxproj | 1 + projects/msvc12/GLideN64.vcxproj.filters | 3 ++ src/Config.cpp | 3 +- src/OpenGL.cpp | 3 +- src/wst.h | 40 ++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/wst.h diff --git a/projects/msvc12/GLideN64.vcxproj b/projects/msvc12/GLideN64.vcxproj index 14ea5ff6..79c0193c 100644 --- a/projects/msvc12/GLideN64.vcxproj +++ b/projects/msvc12/GLideN64.vcxproj @@ -388,6 +388,7 @@ + true true diff --git a/projects/msvc12/GLideN64.vcxproj.filters b/projects/msvc12/GLideN64.vcxproj.filters index 3934bd1a..d5820e40 100644 --- a/projects/msvc12/GLideN64.vcxproj.filters +++ b/projects/msvc12/GLideN64.vcxproj.filters @@ -346,5 +346,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/src/Config.cpp b/src/Config.cpp index 929b0b31..6c7cea6c 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -6,6 +6,7 @@ #include "RSP.h" #include "PluginAPI.h" #include "Config.h" +#include "wst.h" void Config::resetToDefaults() { @@ -53,7 +54,7 @@ void Config::resetToDefaults() textureFilter.txSaveCache = 1; api().GetUserDataPath(textureFilter.txPath); - wcscat(textureFilter.txPath, L"/hires_texture"); + gln_wcscat(textureFilter.txPath, wst("/hires_texture")); #ifdef OS_WINDOWS font.name.assign("arial.ttf"); diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index b0236f99..766f6a9f 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -25,6 +25,7 @@ #include "GLideNHQ/Ext_TxFilter.h" #include "VI.h" #include "Config.h" +#include "wst.h" #include "Log.h" #include "TextDrawer.h" #include "PluginAPI.h" @@ -1352,7 +1353,7 @@ void TextureFilterHandler::init() wchar_t * pTexPackPath = config.textureFilter.txPath; if (::wcslen(config.textureFilter.txPath) == 0) { api().GetUserDataPath(txPath); - wcscat(txPath, L"/hires_texture"); + gln_wcscat(txPath, wst("/hires_texture")); pTexPackPath = txPath; } wchar_t txCachePath[PLUGIN_PATH_SIZE]; diff --git a/src/wst.h b/src/wst.h new file mode 100644 index 00000000..66b92bfe --- /dev/null +++ b/src/wst.h @@ -0,0 +1,40 @@ +#ifndef WST_H +#define WST_H + +#ifdef ANDROID +void gln_wcscat(wchar_t* destination, const wchar_t* source) +{ + const u32 bufSize = 512; + char cbuf[bufSize]; + wcstombs(cbuf, destination, bufSize); + std::string dest(cbuf); + wcstombs(cbuf, source, bufSize); + dest.append(cbuf); + mbstowcs(destination, dest.c_str(), PLUGIN_PATH_SIZE); +} + +class dummyWString +{ +public: + dummyWString(const char * _str) + { + wchar_t buf[512]; + mbstowcs(buf, _str, 512); + _wstr.assign(buf); + } + + const wchar_t * c_str() const { + return _wstr.c_str(); + } + +private: + std::wstring _wstr; +}; + +#define wst(A) dummyWString(A).c_str() +#else // ANDROID +#define gln_wcscat wcscat +#define wst(A) L##A +#endif // ANDROID + +#endif // WST_H