Skip to content

Commit

Permalink
windows: normalize command line paths
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelash committed Sep 19, 2024
1 parent d7f8924 commit a7597d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion gral_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <Windows.h>
#include <windowsx.h>
#include <strsafe.h>
#include <pathcch.h>
#include <d2d1.h>
#include <wincodec.h>
#include <dwrite.h>
Expand Down Expand Up @@ -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<wchar_t> 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 {
Expand Down

0 comments on commit a7597d1

Please sign in to comment.