changeset 6299:b87d403d1f4d utf8-path

stop trying to support non-ASCII paths when building with MinGW + fix
author Alain Mazy <am@orthanc.team>
date Thu, 04 Sep 2025 18:19:25 +0200
parents 96619f473bee
children bb8c961c37a6
files NEWS OrthancFramework/Sources/Compression/ZipReader.cpp OrthancFramework/Sources/SystemToolbox.cpp OrthancFramework/UnitTestsSources/FileStorageTests.cpp OrthancFramework/UnitTestsSources/ZipTests.cpp OrthancServer/CMakeLists.txt OrthancServer/Resources/Samples/Tools/RecoverCompressedFile.cpp OrthancServer/Sources/main.cpp OrthancServer/UnitTestsSources/UnitTestsMain.cpp
diffstat 9 files changed, 19 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Sep 04 15:24:37 2025 +0200
+++ b/NEWS	Thu Sep 04 18:19:25 2025 +0200
@@ -10,7 +10,7 @@
   However, on Windows, some features might still not support non ASCII-only paths:
   - Reading a DCMTK dictionary ("ExternalDictionaries" configuration)
   - Using a "TemporaryDirectory" to save zip file or to export DICOMDIR
-  - "SslCertificate"
+  - The "SslCertificate" and other related configurations
 
 
 Version 1.12.9 (2025-08-11)
--- a/OrthancFramework/Sources/Compression/ZipReader.cpp	Thu Sep 04 15:24:37 2025 +0200
+++ b/OrthancFramework/Sources/Compression/ZipReader.cpp	Thu Sep 04 18:19:25 2025 +0200
@@ -419,7 +419,7 @@
     {
       std::unique_ptr<ZipReader> reader(new ZipReader);
 
-      reader->pimpl_->unzip_ = unzOpen64(path.c_str());
+      reader->pimpl_->unzip_ = unzOpen64(SystemToolbox::PathToUtf8(path).c_str());
       if (reader->pimpl_->unzip_ == NULL)
       {
         throw OrthancException(ErrorCode_BadFileFormat, "Cannot open ZIP archive from file: " + SystemToolbox::PathToUtf8(path));
--- a/OrthancFramework/Sources/SystemToolbox.cpp	Thu Sep 04 15:24:37 2025 +0200
+++ b/OrthancFramework/Sources/SystemToolbox.cpp	Thu Sep 04 18:19:25 2025 +0200
@@ -725,8 +725,8 @@
 
     boost::filesystem::path SystemToolbox::PathFromUtf8(const std::string &utf8)
   {
-#ifdef _WIN32
-    return boost::filesystem::path(Utf8ToWString(utf8));
+#if defined(_WIN32) && !defined(__MINGW32__)  // non-ASCII paths are not supported when building with MinGW
+return boost::filesystem::path(Utf8ToWString(utf8));
 #else
     return boost::filesystem::path(utf8); // POSIX: std::string is UTF-8
 #endif
@@ -734,7 +734,7 @@
 
   std::string SystemToolbox::PathToUtf8(const boost::filesystem::path &p)
   {
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__MINGW32__)  // non-ASCII paths are not supported when building with MinGW
     return WStringToUtf8(p.wstring());
 #else
     return p.string(); // POSIX: already UTF-8
--- a/OrthancFramework/UnitTestsSources/FileStorageTests.cpp	Thu Sep 04 15:24:37 2025 +0200
+++ b/OrthancFramework/UnitTestsSources/FileStorageTests.cpp	Thu Sep 04 18:19:25 2025 +0200
@@ -141,7 +141,7 @@
   s.Clear();
 }
 
-
+#if !defined(__MINGW32__)  // non-ASCII paths are not supported when built with mingw
 TEST(FilesystemStorage, FileAlreadyExistsUtf8)
 {
   FilesystemStorage s("\xd0\x95UnitTestsStorageFileAlreadyExists");
@@ -155,7 +155,7 @@
   ASSERT_THROW(s.Create("12345678-1234-1234-1234-1234567890ab", &data[0], data.size(), FileContentType_Unknown), OrthancException);
   s.Clear();
 }
-
+#endif
 
 TEST(FilesystemStorage, EndToEnd)
 {
--- a/OrthancFramework/UnitTestsSources/ZipTests.cpp	Thu Sep 04 15:24:37 2025 +0200
+++ b/OrthancFramework/UnitTestsSources/ZipTests.cpp	Thu Sep 04 18:19:25 2025 +0200
@@ -194,7 +194,7 @@
     Orthanc::ZipWriter w;
     ASSERT_EQ(0u, w.GetArchiveSize());
 
-    w.SetOutputPath(f.GetPath().c_str());
+    w.SetOutputPath(f.GetPath());
     w.Open();
     w.OpenFile("world/hello");
     w.Write("Hello world");
@@ -207,7 +207,7 @@
   std::unique_ptr<ZipReader> reader(ZipReader::CreateFromFile(f.GetPath()));
 
   ASSERT_EQ(1u, reader->GetFilesCount());
-  
+
   std::string filename, content;
   ASSERT_TRUE(reader->ReadNextFile(filename, content));
   ASSERT_EQ("world/hello", filename);
--- a/OrthancServer/CMakeLists.txt	Thu Sep 04 15:24:37 2025 +0200
+++ b/OrthancServer/CMakeLists.txt	Thu Sep 04 18:19:25 2025 +0200
@@ -471,15 +471,6 @@
 
 target_link_libraries(Orthanc ServerLibrary CoreLibrary ${DCMTK_LIBRARIES})
 
-# since we use wmain on Windows, we need to tell MinGW to link with wmain
-if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
-  set_property(
-    TARGET Orthanc
-    PROPERTY LINK_FLAGS "-municode"
-    )
-endif()
-
-
 if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
   # The link flag below hides all the global functions so that a Linux
   # Standard Base (LSB) build of Orthanc can load plugins that are not
@@ -940,14 +931,6 @@
 
   target_link_libraries(OrthancRecoverCompressedFile CoreLibrary)
 
-  # since we use wmain on Windows, we need to tell MinGW to link with wmain
-  if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
-    set_property(
-      TARGET OrthancRecoverCompressedFile
-      PROPERTY LINK_FLAGS "-municode"
-    )
-  endif()
-
   install(
     TARGETS OrthancRecoverCompressedFile
     RUNTIME DESTINATION bin
--- a/OrthancServer/Resources/Samples/Tools/RecoverCompressedFile.cpp	Thu Sep 04 15:24:37 2025 +0200
+++ b/OrthancServer/Resources/Samples/Tools/RecoverCompressedFile.cpp	Thu Sep 04 18:19:25 2025 +0200
@@ -32,7 +32,7 @@
 #endif
 
 
-#if defined(_WIN32)
+#if defined(_WIN32) && !defined(__MINGW32__)
 // arguments are passed as UTF-16 on Windows
 int wmain(int argc, wchar_t *argv[])
 {
--- a/OrthancServer/Sources/main.cpp	Thu Sep 04 15:24:37 2025 +0200
+++ b/OrthancServer/Sources/main.cpp	Thu Sep 04 18:19:25 2025 +0200
@@ -1866,7 +1866,7 @@
 }
 
 
-#if defined(_WIN32)
+#if defined(_WIN32) && !defined(__MINGW32__)
 // arguments are passed as UTF-16 on Windows
 int wmain(int argc, wchar_t *argv[])
 {
--- a/OrthancServer/UnitTestsSources/UnitTestsMain.cpp	Thu Sep 04 15:24:37 2025 +0200
+++ b/OrthancServer/UnitTestsSources/UnitTestsMain.cpp	Thu Sep 04 18:19:25 2025 +0200
@@ -47,6 +47,9 @@
 
 #include <dcmtk/dcmdata/dcdeftag.h>
 
+#if defined(_WIN32) || defined(__CYGWIN__)
+#include <windows.h>
+#endif
 
 using namespace Orthanc;
 
@@ -515,6 +518,11 @@
 
 int main(int argc, char **argv)
 {
+#if defined(_WIN32) && !defined(__MINGW32__)
+  // Set Windows console output to UTF-8 (otherwise, strings are considered to be in UTF-16.  For example, Cyrillic UTF-8 strings appear as garbage without that config)
+  SetConsoleOutputCP(CP_UTF8);
+#endif
+
   Logging::Initialize();
   SetGlobalVerbosity(Verbosity_Verbose);
   Toolbox::DetectEndianness();