From: rnv Date: Tue, 30 May 2017 09:04:37 +0000 (+0300) Subject: Unicode paths on Windows platform. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Frnv%2Funicode_paths;p=modules%2Fkernel.git Unicode paths on Windows platform. --- 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