This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch upstream/latest
in repository colobot.

commit 83599238d16cecfd159a593bed5107beb70d4c38
Author: krzys-h <krzy...@interia.pl>
Date:   Sun Mar 22 13:10:38 2015 +0100

    Added workaround for argv encoding on Windows
    
    First part of fixing #414
---
 src/app/main.cpp         | 34 ++++++++++++++++++++++++++++++++--
 src/app/system_windows.h |  6 +++---
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/app/main.cpp b/src/app/main.cpp
index 03bd507..0d1e289 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -29,6 +29,12 @@
 #include "common/logger.h"
 #include "common/misc.h"
 #include "common/restext.h"
+#include "common/resources/resourcemanager.h"
+
+#if PLATFORM_WINDOWS
+    #include <windows.h>
+    #include "app/system_windows.h"
+#endif
 
 
 /* Doxygen main page */
@@ -71,8 +77,6 @@ The current layout is the following:
  - src/script - link with the CBot library
 */
 
-#include "common/resources/resourcemanager.h"
-
 //! Entry point to the program
 extern "C"
 {
@@ -80,6 +84,26 @@ extern "C"
 int SDL_MAIN_FUNC(int argc, char *argv[])
 {
     CLogger logger; // single istance of logger
+
+    // Workaround for character encoding in argv on Windows
+    #if PLATFORM_WINDOWS
+    int wargc;
+    wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
+    if(wargv == nullptr)
+    {
+        logger.Error("CommandLineToArgvW failed\n");
+        return 1;
+    }
+    argv = new char*[wargc];
+    for(int i = 0; i < wargc; i++) {
+        std::wstring warg = wargv[i];
+        std::string arg = CSystemUtilsWindows::UTF8_Encode(warg);
+        argv[i] = new char[arg.length()+1];
+        strcpy(argv[i], arg.c_str());
+    }
+    LocalFree(wargv);
+    #endif
+
     CResourceManager manager(argv[0]);
 
     // Initialize static string arrays
@@ -128,6 +152,12 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
     }
 
     logger.Info("Exiting with code %d\n", code);
+
+    #if PLATFORM_WINDOWS
+    // See the workaround above
+    delete[] argv;
+    #endif
+
     return code;
 }
 
diff --git a/src/app/system_windows.h b/src/app/system_windows.h
index 9175a44..572eb99 100644
--- a/src/app/system_windows.h
+++ b/src/app/system_windows.h
@@ -48,9 +48,9 @@ public:
 
     virtual std::string GetSaveDir() override;
 
-private:
-    std::string UTF8_Encode(const std::wstring &wstr);
-    std::wstring UTF8_Decode(const std::string &str);
+public:
+    static std::string UTF8_Encode(const std::wstring &wstr);
+    static std::wstring UTF8_Decode(const std::string &str);
 
 protected:
     long long m_counterFrequency;

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-games/colobot.git

_______________________________________________
Pkg-games-commits mailing list
Pkg-games-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

Reply via email to