reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit bc6a47a87654aaa416101353d0a5f7ed184c7249
parent ea6b3df77c0369d7119c64c63b6ca6946d08e3d7
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 14 Aug 2016 21:52:26 -0700

win32: fix resource path encoding issue in some setups [p=1718542]

eg. Polish edition of Windows with user and system display language set to English

Diffstat:
Msrc/encoding.cpp | 8++++----
Msrc/encoding.hpp | 4+++-
Msrc/reapack.cpp | 6++----
3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/encoding.cpp b/src/encoding.cpp @@ -18,15 +18,14 @@ #include "encoding.hpp" #ifdef _WIN32 -#include <windows.h> -auto_string make_autostring(const std::string &input) +auto_string make_autostring(const std::string &input, UINT codepage) { - const int size = MultiByteToWideChar(CP_UTF8, 0, + const int size = MultiByteToWideChar(codepage, 0, &input[0], -1, nullptr, 0) - 1; auto_string output(size, 0); - MultiByteToWideChar(CP_UTF8, 0, &input[0], -1, &output[0], size); + MultiByteToWideChar(codepage, 0, &input[0], -1, &output[0], size); return output; } @@ -42,4 +41,5 @@ std::string from_autostring(const auto_string &input) return output; } + #endif diff --git a/src/encoding.hpp b/src/encoding.hpp @@ -27,13 +27,15 @@ #ifdef _WIN32 +#include <windows.h> + typedef wchar_t auto_char; typedef std::wstring auto_string; #define AUTO_STR(text) L##text #define to_autostring std::to_wstring #define auto_snprintf(buf, size, ...) _snwprintf(buf, size - 1, __VA_ARGS__) -auto_string make_autostring(const std::string &); +auto_string make_autostring(const std::string &, UINT codepage = CP_UTF8); #define make_autocstring(cstr) make_autostring(cstr).c_str() // temporary string! std::string from_autostring(const auto_string &); diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -63,10 +63,8 @@ static void CleanupTempFiles() std::string ReaPack::resourcePath() { #ifdef _WIN32 - auto_char path[MAX_PATH] = {}; - _mbstowcs_l(path, GetResourcePath(), auto_size(path) - 1, - _create_locale(LC_ALL, "")); - return from_autostring(path); + // convert from current system encoding to unicode... + return from_autostring(make_autostring(GetResourcePath(), CP_ACP)); #else return GetResourcePath(); #endif