From a7597d1c6371c4990b8918a007f88712c3b4d6ee Mon Sep 17 00:00:00 2001 From: Elias Aebi Date: Thu, 19 Sep 2024 12:01:09 +0200 Subject: [PATCH] windows: normalize command line paths --- CMakeLists.txt | 2 +- gral_windows.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 526dc7a..6f61080 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(libgral) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") add_library(gral gral_windows.cpp) - target_link_libraries(gral d2d1 dwrite mfplat mfuuid winmm) + target_link_libraries(gral pathcch d2d1 dwrite mfplat mfuuid winmm) target_compile_definitions(gral PUBLIC GRAL_WINDOWS) elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") find_library(COCOA Cocoa) diff --git a/gral_windows.cpp b/gral_windows.cpp index d8fcc77..f31bba9 100644 --- a/gral_windows.cpp +++ b/gral_windows.cpp @@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include #include #include @@ -541,8 +542,14 @@ int gral_application_run(gral_application *application, int argc_, char **argv_) int argc; LPWSTR *argv = CommandLineToArgvW(GetCommandLine(), &argc); if (argc > 1) { + DWORD current_directory_length = GetCurrentDirectory(0, NULL); + Buffer current_directory(current_directory_length); + GetCurrentDirectory(current_directory_length, current_directory); for (int i = 1; i < argc; i++) { - application->iface.open_file(utf16_to_utf8(argv[i]), application->user_data); + PWSTR path; + PathAllocCombine(current_directory, argv[i], PATHCCH_NONE, &path); + application->iface.open_file(utf16_to_utf8(path), application->user_data); + LocalFree(path); } } else {