mirror of https://github.com/bjornbytes/lovr.git
Windows: Always use WinMain for UTF8 command line arguments;
This fixes problems with paths containing special characters on windows.
This commit is contained in:
parent
dd0891d087
commit
746735259c
|
@ -555,8 +555,8 @@ if(WIN32)
|
|||
target_sources(lovr PRIVATE src/core/os_win32.c)
|
||||
target_sources(lovr PRIVATE src/resources/lovr.rc)
|
||||
set_target_properties(lovr PROPERTIES COMPILE_FLAGS "/wd4244 /MP")
|
||||
set_target_properties(lovr PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
|
||||
set_target_properties(lovr PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
|
||||
set_target_properties(lovr PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:console /ENTRY:WinMainCRTStartup")
|
||||
set_target_properties(lovr PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:windows /ENTRY:WinMainCRTStartup")
|
||||
target_compile_definitions(lovr PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
target_compile_definitions(lovr PRIVATE _CRT_NONSTDC_NO_WARNINGS)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "os.h"
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <KnownFolders.h>
|
||||
#include <ShlObj.h>
|
||||
#include <stdio.h>
|
||||
|
@ -9,6 +10,45 @@
|
|||
|
||||
static uint64_t frequency;
|
||||
|
||||
int main(int argc, char** argv);
|
||||
|
||||
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev, LPSTR args, int show) {
|
||||
int argc;
|
||||
char** argv;
|
||||
|
||||
LPWSTR* wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||
if (!wargv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
argv = calloc(argc + 1, sizeof(char*));
|
||||
if (!argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < argc; i++) {
|
||||
int size = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
|
||||
|
||||
argv[i] = malloc(size);
|
||||
if (!argv[i]) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], size, NULL, NULL)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
int status = main(argc, argv);
|
||||
|
||||
for (int i = 0; i < argc; i++) {
|
||||
free(argv[i]);
|
||||
}
|
||||
free(argv);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool os_init() {
|
||||
LARGE_INTEGER f;
|
||||
QueryPerformanceFrequency(&f);
|
||||
|
|
Loading…
Reference in New Issue