WIN32: Ensure the translated dialog strings are using the correct encoding

This commit is contained in:
Cameron Cawley 2019-04-02 20:23:13 +01:00 committed by Filippos Karapetis
parent ca054ba0b9
commit e4b78f4f62
3 changed files with 28 additions and 10 deletions

View file

@ -138,11 +138,11 @@ Common::DialogManager::DialogResult Win32DialogManager::showFileBrowser(const ch
hr = dialog->SetOptions(dwOptions);
}
LPWSTR str = Win32::ansiToUnicode(title);
LPWSTR str = Win32::ansiToUnicode(title, Win32::getCurrentCharset());
hr = dialog->SetTitle(str);
delete[] str;
str = Win32::ansiToUnicode(_("Choose"));
str = Win32::ansiToUnicode(_("Choose"), Win32::getCurrentCharset());
hr = dialog->SetOkButtonLabel(str);
delete[] str;

View file

@ -29,6 +29,7 @@
#include <shlobj.h>
#include "common/scummsys.h"
#include "common/translation.h"
#include "backends/platform/sdl/win32/win32_wrapper.h"
// VerSetConditionMask, VerifyVersionInfo and SHGetFolderPath didn't appear until Windows 2000,
@ -80,28 +81,43 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion) {
return VerifyVersionInfoFunc(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask);
}
wchar_t *ansiToUnicode(const char *s) {
DWORD size = MultiByteToWideChar(0, 0, s, -1, NULL, 0);
wchar_t *ansiToUnicode(const char *s, uint codePage) {
DWORD size = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);
if (size > 0) {
LPWSTR result = new WCHAR[size];
if (MultiByteToWideChar(0, 0, s, -1, result, size) != 0)
if (MultiByteToWideChar(codePage, 0, s, -1, result, size) != 0)
return result;
}
return NULL;
}
char *unicodeToAnsi(const wchar_t *s) {
DWORD size = WideCharToMultiByte(0, 0, s, -1, NULL, 0, 0, 0);
char *unicodeToAnsi(const wchar_t *s, uint codePage) {
DWORD size = WideCharToMultiByte(codePage, 0, s, -1, NULL, 0, 0, 0);
if (size > 0) {
char *result = new char[size];
if (WideCharToMultiByte(0, 0, s, -1, result, size, 0, 0) != 0)
if (WideCharToMultiByte(codePage, 0, s, -1, result, size, 0, 0) != 0)
return result;
}
return NULL;
}
uint getCurrentCharset() {
#ifdef USE_TRANSLATION
Common::String charset = TransMan.getCurrentCharset();
if (charset == "iso-8859-2")
return 28592;
if (charset == "iso-8859-5")
return 28595;
if (charset == "iso-8859-7")
return 28597;
if (charset == "iso-8859-8")
return 28598;
#endif
return 28591;
}
}

View file

@ -45,7 +45,7 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion);
*
* @note Return value must be freed by the caller.
*/
wchar_t *ansiToUnicode(const char *s);
wchar_t *ansiToUnicode(const char *s, uint codePage = CP_ACP);
/**
* Converts a Windows wide-character string into a C string.
* Used to interact with Win32 Unicode APIs with no ANSI fallback.
@ -55,7 +55,9 @@ wchar_t *ansiToUnicode(const char *s);
*
* @note Return value must be freed by the caller.
*/
char *unicodeToAnsi(const wchar_t *s);
char *unicodeToAnsi(const wchar_t *s, uint codePage = CP_ACP);
uint getCurrentCharset();
}