From 122c5a8406384799065f580f7088bbc1bb44b748 Mon Sep 17 00:00:00 2001 From: rnv Date: Tue, 30 May 2017 12:04:37 +0300 Subject: [PATCH] Unicode paths on Windows platform. --- src/Basics/Basics_Utils.cxx | 19 +++++++++++++++++++ src/Basics/Basics_Utils.hxx | 7 +++++++ src/HDFPersist/CMakeLists.txt | 8 +++++++- src/HDFPersist/HDFascii.cc | 12 +++++++++++- .../SALOMEDSImpl_StudyManager.cxx | 5 +++-- src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx | 1 - src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx | 1 - 7 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/Basics/Basics_Utils.cxx b/src/Basics/Basics_Utils.cxx index 73b4e800e..410a51f2e 100644 --- a/src/Basics/Basics_Utils.cxx +++ b/src/Basics/Basics_Utils.cxx @@ -138,4 +138,23 @@ namespace Kernel_Utils #endif #endif +#ifdef WIN32 + +//Converts char* to windows wchar_t* +wchar_t* ConvertToWideChar(const char* multibytearray) { + int wchars_num = MultiByteToWideChar( CP_UTF8 , 0 , multibytearray , -1, NULL , 0 ); + wchar_t* wstr = new wchar_t[wchars_num]; + MultiByteToWideChar( CP_UTF8 , 0 , multibytearray , -1, wstr , wchars_num ); + return wstr; +} + +//Converts std::string to windows std::wstring +std::wstring ConvertToWideString(std::string multibytearray) { + wchar_t* wstr = ConvertToWideChar(multibytearray.c_str()); + std::wstring result(wstr); + delete[] wstr; + return result; +} +#endif + } diff --git a/src/Basics/Basics_Utils.hxx b/src/Basics/Basics_Utils.hxx index 5843afb75..4ee692bb0 100644 --- a/src/Basics/Basics_Utils.hxx +++ b/src/Basics/Basics_Utils.hxx @@ -65,6 +65,13 @@ namespace Kernel_Utils BASICS_EXPORT int setenv(const char*, const char*, int); #endif #endif + +#ifdef WIN32 + //Converts char* to windows wchar_t* + BASICS_EXPORT wchar_t* ConvertToWideChar(const char* multibytearray); + //Converts std::string to windows std::wstring + BASICS_EXPORT std::wstring ConvertToWideString(std::string multibytearray); +#endif } diff --git a/src/HDFPersist/CMakeLists.txt b/src/HDFPersist/CMakeLists.txt index 58f9f9224..954cf6640 100755 --- a/src/HDFPersist/CMakeLists.txt +++ b/src/HDFPersist/CMakeLists.txt @@ -20,6 +20,7 @@ INCLUDE_DIRECTORIES( ${HDF5_INCLUDE_DIRS} ${MPI_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/../Basics ) FILE(GLOB SalomeHDFPersist_SOURCES_C "${CMAKE_CURRENT_SOURCE_DIR}/HDF*.c") @@ -28,7 +29,12 @@ SET(SalomeHDFPersist_SOURCES ${SalomeHDFPersist_SOURCES_C} ${SalomeHDFPersist_SO ADD_DEFINITIONS(${HDF5_DEFINITIONS}) ADD_LIBRARY(SalomeHDFPersist ${SalomeHDFPersist_SOURCES}) -TARGET_LINK_LIBRARIES(SalomeHDFPersist ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${PLATFORM_LIBS}) +SET(SalomeHDFPersist_libraries ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${PLATFORM_LIBS}) +IF(WIN32) + SET(SalomeHDFPersist_libraries ${SalomeHDFPersist_libraries} SALOMEBasics) +ENDIF() +TARGET_LINK_LIBRARIES(SalomeHDFPersist ${SalomeHDFPersist_libraries}) + INSTALL(TARGETS SalomeHDFPersist EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") diff --git a/src/HDFPersist/HDFascii.cc b/src/HDFPersist/HDFascii.cc index 3060d9a24..1b7937313 100644 --- a/src/HDFPersist/HDFascii.cc +++ b/src/HDFPersist/HDFascii.cc @@ -35,6 +35,7 @@ #include #ifdef WIN32 +#include #include #include #include @@ -86,7 +87,16 @@ void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long siz //============================================================================ bool HDFascii::isASCII(const char* thePath) { int fd; - if(!(fd = open(thePath, O_RDONLY))) return false; +#ifdef WIN32 + wchar_t* wstr = Kernel_Utils::ConvertToWideChar(thePath); + if(!(fd = _wopen(wstr, O_RDONLY))) { + delete wstr; + return false; + } + delete wstr; +#else + if(!(fd = open(thePath, O_RDONLY))) return false; +#endif char* aBuffer = new char[9]; aBuffer[8] = (char)0; read(fd, aBuffer, 8); diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx index d05604ea5..0c20166e8 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx @@ -913,12 +913,13 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const std::string& aStudyUrl, if(buffer[aLen-1] == '\n') buffer[aLen-1] = char(0); #ifdef WIN32 aCmd = "move /Y \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\""; + std::wstring wstr = Kernel_Utils::ConvertToWideString(aCmd); + errors = _wsystem(wstr.c_str()); #else aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\""; + errors = system(aCmd.c_str()); #endif - errors = system(aCmd.c_str()); } - delete []buffer; fclose(fp); diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx index 61eed7dda..270b57cf3 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx @@ -382,4 +382,3 @@ std::string SALOMEDSImpl_Tool::GetUserName() - diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx index 16cbbaf57..12c92683d 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx @@ -78,7 +78,6 @@ public: //Returns a name of the user static std::string GetUserName(); - }; #endif -- 2.39.2