summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2014-03-12 08:47:10 -0700
committerreduz <reduzio@gmail.com>2014-03-12 08:47:10 -0700
commit30aaca25d65207b5adcccce1558c5af0702a92dd (patch)
treeb4c51d2622406c154ebf99954f3d03c0760366a3 /platform
parent777c045bfc165e9dfe20749b02a8ad630218e317 (diff)
parentf7cef6d61723d4c395d4f8e2bd357e42f69d109c (diff)
Merge pull request #187 from marynate/PR-fix-windows-utf8
Fixed bug: Godot wont start in windows when inside non-ascii directory
Diffstat (limited to 'platform')
-rw-r--r--platform/windows/godot_win.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp
index 2999a9beae..fa573b9421 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 <stdio.h>
+#include <locale.h>
PCHAR*
CommandLineToArgvA(
@@ -114,15 +115,42 @@ PCHAR*
return argv;
}
+char* mb_to_utf8(const char* mbs) {
+
+ 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);
+ 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<argc; ++i) {
+ argv_utf8[i] = mb_to_utf8(argv[i]);
+ }
+
+ Main::setup(argv_utf8[0], argc - 1, &argv_utf8[1]);
if (Main::start())
os.run();
Main::cleanup();
+
+ for (int i=0; i<argc; ++i) {
+ delete[] argv_utf8[i];
+ }
+ delete[] argv_utf8;
+
return os.get_exit_code();
};