From 0552b76475bcc09fcbe33a0ebeedcc84158c7ea0 Mon Sep 17 00:00:00 2001 From: marynate Date: Fri, 21 Feb 2014 19:00:23 +0800 Subject: [PATCH 1/2] Convert windows main entry arguments to UTF8; Set locale to system default for locale-awared console output; memery clearnup --- platform/windows/godot_win.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp index 2999a9beaea..ddfadf98cac 100644 --- a/platform/windows/godot_win.cpp +++ b/platform/windows/godot_win.cpp @@ -29,6 +29,7 @@ #include "os_windows.h" #include "main/main.h" #include +#include PCHAR* CommandLineToArgvA( @@ -114,15 +115,45 @@ PCHAR* return argv; } +char* mb_to_utf8(const char* mbs) { + int wlen = MultiByteToWideChar(CP_ACP,0,mbs,-1,NULL,0); + if (wlen < 0) + wlen = 0; + wchar_t *wbuf = new wchar_t[wlen + 1]; + MultiByteToWideChar(CP_ACP,0,mbs,-1,wbuf,wlen); + wbuf[wlen]=0; + + int ulen = WideCharToMultiByte(CP_UTF8,0,wbuf,-1,NULL,0,NULL,NULL); + if (ulen < 0) + ulen = 0; + char * ubuf = new char[ulen + 1]; + WideCharToMultiByte(CP_UTF8,0,wbuf,-1,ubuf,ulen,NULL,NULL); + ubuf[ulen] = 0; + return ubuf; +} + int main(int argc, char** argv) { OS_Windows os(NULL); - Main::setup(argv[0], argc - 1, &argv[1]); + setlocale(LC_CTYPE, ""); + + char ** argv_utf8 = new char*[argc]; + for(int i=0; i Date: Fri, 21 Feb 2014 19:48:04 +0800 Subject: [PATCH 2/2] remove unnecessary error check when converting ascii to unicode --- platform/windows/godot_win.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp index ddfadf98cac..fa573b9421f 100644 --- a/platform/windows/godot_win.cpp +++ b/platform/windows/godot_win.cpp @@ -116,16 +116,13 @@ PCHAR* } char* mb_to_utf8(const char* mbs) { - int wlen = MultiByteToWideChar(CP_ACP,0,mbs,-1,NULL,0); - if (wlen < 0) - wlen = 0; + + int wlen = MultiByteToWideChar(CP_ACP,0,mbs,-1,NULL,0); // returns 0 if failed wchar_t *wbuf = new wchar_t[wlen + 1]; MultiByteToWideChar(CP_ACP,0,mbs,-1,wbuf,wlen); wbuf[wlen]=0; int ulen = WideCharToMultiByte(CP_UTF8,0,wbuf,-1,NULL,0,NULL,NULL); - if (ulen < 0) - ulen = 0; char * ubuf = new char[ulen + 1]; WideCharToMultiByte(CP_UTF8,0,wbuf,-1,ubuf,ulen,NULL,NULL); ubuf[ulen] = 0;