From 29bb2fd84de224884fd5ec826d936c4f47d6fc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20S=2E=20Ga=C3=9Fmann?= Date: Tue, 30 Jan 2024 18:38:25 +0100 Subject: [PATCH] fix: Set active CP to UTF-8 on Windows 10 and 11 This notably allows passing unicode filenames as commandline arguments to the demo utility `bin/base64` without them being mangled in case the unicode filename cannot be represented in the currently active system code page. Note that this only works/takes effect on Windows 10 Version 1903 and later. See-Also: https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page --- .github/workflows/test.yml | 7 ++++++ CMakeLists.txt | 4 ++++ bin/base64.manifest | 23 +++++++++++++++++++ bin/base64.rc | 2 ++ test/ci/.gitattributes | 2 ++ test/ci/checksums.txt | 1 + ...7\230\265\342\200\215\360\237\222\253.bin" | 2 ++ 7 files changed, 41 insertions(+) create mode 100644 bin/base64.manifest create mode 100644 bin/base64.rc create mode 100644 test/ci/.gitattributes create mode 100644 test/ci/checksums.txt create mode 100644 "test/ci/\360\237\230\265\342\200\215\360\237\222\253.bin" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e1e59247..28d8b66a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -212,6 +212,13 @@ jobs: - name: CTest shell: msys2 {0} run: ctest --no-tests=error --test-dir out -VV --build-config Release + - name: Test demo utility with unicode filenames and file contents on Windows + shell: msys2 {0} + run: | + out/bin/base64 test/ci/😵‍💫.bin > test/ci/😵‍💫.bin.b64 + out/bin/base64 -d test/ci/😵‍💫.bin.b64 > test/ci/😵‍💫.bin + cd test/ci + sha256sum -c checksums.txt msys2-makefile-test: name: msys2-makefile-${{ matrix.msystem }} diff --git a/CMakeLists.txt b/CMakeLists.txt index ff9f6f21..4d154e4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,6 +249,10 @@ if (BASE64_BUILD_CLI) set_target_properties(base64-bin PROPERTIES OUTPUT_NAME base64 ) + + if (WIN32) + target_sources(base64-bin PRIVATE bin/base64.rc) + endif () endif() ######################################################################## diff --git a/bin/base64.manifest b/bin/base64.manifest new file mode 100644 index 00000000..2bd35617 --- /dev/null +++ b/bin/base64.manifest @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + UTF-8 + + + diff --git a/bin/base64.rc b/bin/base64.rc new file mode 100644 index 00000000..017cf652 --- /dev/null +++ b/bin/base64.rc @@ -0,0 +1,2 @@ +#include "winuser.h" +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "base64.manifest" diff --git a/test/ci/.gitattributes b/test/ci/.gitattributes new file mode 100644 index 00000000..0ca047d8 --- /dev/null +++ b/test/ci/.gitattributes @@ -0,0 +1,2 @@ +😵‍💫.bin binary -text +checksums.txt text eol=lf diff --git a/test/ci/checksums.txt b/test/ci/checksums.txt new file mode 100644 index 00000000..03ba10a2 --- /dev/null +++ b/test/ci/checksums.txt @@ -0,0 +1 @@ +4cd842ba8dce30216f77d2d5bf8a648e2dba6d95be5b12884f81e55bfab7b3cc *😵‍💫.bin diff --git "a/test/ci/\360\237\230\265\342\200\215\360\237\222\253.bin" "b/test/ci/\360\237\230\265\342\200\215\360\237\222\253.bin" new file mode 100644 index 00000000..96b4e221 --- /dev/null +++ "b/test/ci/\360\237\230\265\342\200\215\360\237\222\253.bin" @@ -0,0 +1,2 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. +😵‍💫