Browse Source

LOVE arguments now work with Unicode in Windows.

rude 16 years ago
parent
commit
0dc6d985ee
3 changed files with 65 additions and 7 deletions
  1. 2 2
      platform/msvc2008/love.vcproj
  2. 4 0
      src/common/config.h
  3. 59 5
      src/love.cpp

+ 2 - 2
platform/msvc2008/love.vcproj

@@ -20,7 +20,7 @@
 			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
 			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
 			IntermediateDirectory="$(ConfigurationName)"
 			IntermediateDirectory="$(ConfigurationName)"
 			ConfigurationType="1"
 			ConfigurationType="1"
-			CharacterSet="2"
+			CharacterSet="1"
 			>
 			>
 			<Tool
 			<Tool
 				Name="VCPreBuildEventTool"
 				Name="VCPreBuildEventTool"
@@ -61,7 +61,7 @@
 			/>
 			/>
 			<Tool
 			<Tool
 				Name="VCLinkerTool"
 				Name="VCLinkerTool"
-				AdditionalDependencies="lua.lib d/SDLmain.lib d/SDL.lib opengl32.lib glu32.lib DevIL.lib freetype.lib physfs.lib ws2_32.lib openal32.lib libmodplug.lib libmpg123.lib libogg.lib libvorbis.lib libvorbisfile.lib libFLAC_static_d.lib libFLAC++_static_d.lib"
+				AdditionalDependencies="lua.lib SDLmain.lib SDL.lib opengl32.lib glu32.lib DevIL.lib freetype.lib physfs.lib ws2_32.lib openal32.lib libmodplug.lib libmpg123.lib libogg.lib libvorbis.lib libvorbisfile.lib libFLAC_static_d.lib libFLAC++_static_d.lib"
 				AdditionalLibraryDirectories="lib;Debug"
 				AdditionalLibraryDirectories="lib;Debug"
 				GenerateDebugInformation="true"
 				GenerateDebugInformation="true"
 				SubSystem="1"
 				SubSystem="1"

+ 4 - 0
src/common/config.h

@@ -62,4 +62,8 @@
 #	define LOVE_EXPORT
 #	define LOVE_EXPORT
 #endif
 #endif
 
 
+#if defined(LOVE_WINDOWS)
+#	define	LOVE_LEGENDARY_UTF8_ARGV_HACK
+#endif
+
 #endif // LOVE_CONFIG_H
 #endif // LOVE_CONFIG_H

+ 59 - 5
src/love.cpp

@@ -24,6 +24,10 @@
 #include <common/runtime.h>
 #include <common/runtime.h>
 #include <common/MemoryData.h>
 #include <common/MemoryData.h>
 
 
+#ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK
+#include <windows.h>
+#endif // #ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK
+
 #ifdef LOVE_BUILD_EXE
 #ifdef LOVE_BUILD_EXE
 
 
 // SDL
 // SDL
@@ -120,10 +124,56 @@ extern "C" LOVE_EXPORT int luaopen_love(lua_State * L)
 	return 0;
 	return 0;
 }
 }
 
 
+#ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK
+
+void get_utf8_arguments(int & argc, char **& argv)
+{
+	LPWSTR cmd = GetCommandLineW();
+
+	if(!cmd)
+		return;
+
+	LPWSTR * argv_w = CommandLineToArgvW(cmd, &argc);
+
+	argv = new char*[argc];
+
+	for(int i = 0; i<argc; ++i)
+	{
+		// Size of wide char buffer (plus one for trailing '\0').
+		size_t wide_len = wcslen(argv_w[i])+1;
+
+		// Get size in UTF-8.
+		int utf8_size = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], wide_len, argv[i], 0, 0, 0);
+
+		argv[i] = new char[utf8_size];
+
+		// Convert to UTF-8.
+		int ok = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], wide_len, argv[i], utf8_size, 0, 0);
+
+		int len = strlen(argv[i]);
+
+		if(!ok)
+			printf("Warning: could not convert to UTF8.\n");
+	}
+
+	LocalFree(argv_w);
+}
+
+#endif // LOVE_LEGENDARY_UTF8_ARGV_HACK
+
 #ifdef LOVE_BUILD_EXE
 #ifdef LOVE_BUILD_EXE
 
 
 int main(int argc, char ** argv)
 int main(int argc, char ** argv)
 {
 {
+
+#ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK
+	int hack_argc = 0;
+	char ** hack_argv = 0;
+	get_utf8_arguments(hack_argc, hack_argv);
+	argc = hack_argc;
+	argv = hack_argv;
+#endif // LOVE_LEGENDARY_UTF8_ARGV_HACK
+
 	// Oh, you just want the version? Okay!
 	// Oh, you just want the version? Okay!
 	if(argc > 1 && strcmp(argv[1],"--version") == 0) {
 	if(argc > 1 && strcmp(argv[1],"--version") == 0) {
 		printf("This is LOVE %s (%s), the unquestionably awesome 2D game engine.\n", love::VERSION_STR, love::VERSION_CODENAME);
 		printf("This is LOVE %s (%s), the unquestionably awesome 2D game engine.\n", love::VERSION_STR, love::VERSION_CODENAME);
@@ -166,11 +216,15 @@ int main(int argc, char ** argv)
 
 
 	lua_close(L);
 	lua_close(L);
 
 
-#if defined(LOVE_DEBUG) && defined(LOVE_WINDOWS)
-	printf("(press key)\n");
-	getchar();
-#endif
-	printf("Done. This was: %s (%s)\n", love::VERSION_STR, love::VERSION_CODENAME);
+#ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK
+	if(hack_argv)
+	{
+		for(int i = 0; i<hack_argc; ++i)
+			delete [] hack_argv[i];
+		delete [] hack_argv;
+	}
+#endif // LOVE_LEGENDARY_UTF8_ARGV_HACK
+
 	return 0;
 	return 0;
 }
 }