Salome HOME
Run SALOME with UNICODE path on Windows platform.
authorrnv <rnv@opencascade.com>
Thu, 21 Feb 2019 08:36:33 +0000 (11:36 +0300)
committerrnv <rnv@opencascade.com>
Mon, 11 Mar 2019 09:55:04 +0000 (12:55 +0300)
20 files changed:
src/Basics/Basics_DirUtils.cxx
src/Basics/Basics_Utils.cxx
src/Basics/Basics_Utils.hxx
src/Container/Container_i.cxx
src/DF/CMakeLists.txt
src/DF/testDF.cxx
src/HDFPersist/CMakeLists.txt
src/HDFPersist/HDFascii.cc
src/HDFPersist/HDFconvert.cc
src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx
src/SALOMEDS/SALOMEDS_AttributeStudyProperties.cxx
src/SALOMEDS/SALOMEDS_Study.cxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx
src/SALOMELocalTrace/LocalTraceBufferPool.cxx
src/TOOLSDS/SALOMEDS_Tool.cxx
src/Utils/Utils_ExceptHandlers.cxx
src/Utils/Utils_Identity.cxx

index aa147cf4c0509561d7787676b56d1644ade98995..daa4b8f55567d6ed3cb697e7a232b363b17baedd 100644 (file)
@@ -22,6 +22,7 @@
 //  Module : SALOME
 //
 #include "Basics_DirUtils.hxx"
+#include "Basics_Utils.hxx"
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -72,8 +73,14 @@ namespace Kernel_Utils
 
   std::string GetTmpDirByEnv( const std::string& tmp_path_env )
   {
+#if defined WIN32 && defined UNICODE
+   std::wstring w_tmp_path_env = utf8_decode_s( tmp_path_env );
+   wchar_t* val = _wgetenv( w_tmp_path_env.c_str() );
+   std::string dir = val ? utf8_encode_s(val) : "";
+#else 
     char* val = getenv( tmp_path_env.c_str() );
-    std::string dir = val ? val : "";
+       std::string dir = val ? val : "";
+#endif
     return GetTmpDirByPath( dir );
   }
 
@@ -83,6 +90,15 @@ namespace Kernel_Utils
     if ( aTmpDir == "" || !IsExists( aTmpDir ))
     {
 #ifdef WIN32
+#ifdef UNICODE
+         wchar_t *wTmp_dir = _wgetenv( L"TEMP" );
+         if ( wTmp_dir == NULL ) {
+                       wTmp_dir = _wgetenv(L"TMP");
+                       if (wTmp_dir == NULL)
+                               wTmp_dir = L"C:\\";
+         }
+         aTmpDir = utf8_encode_s( wTmp_dir );
+#else
       char *Tmp_dir = getenv("TEMP");
       if ( Tmp_dir == NULL )
       {
@@ -94,6 +110,7 @@ namespace Kernel_Utils
       }
       else
         aTmpDir = Tmp_dir;
+#endif
 #else
       aTmpDir = "/tmp/";
 #endif
@@ -121,12 +138,16 @@ namespace Kernel_Utils
 
     if ( aDir.back() != _separator_ ) aDir += _separator_;
 
-#ifdef WIN32
-    CreateDirectory( aDir.c_str(), NULL );
+#ifdef WIN32   
+#ifdef UNICODE
+       std::wstring aDirToCreate = utf8_decode_s(aDir);
+#else
+       std::string aDirToCreate = aDir;
+#endif
+    CreateDirectory( aDirToCreate.c_str(), NULL );
 #else
     mkdir( aDir.c_str(), 0x1ff );
 #endif
-
     return aDir;
   }
 
@@ -179,7 +200,11 @@ namespace Kernel_Utils
   //============================================================================ 
   bool IsExists(const std::string& thePath) 
   {
+#if defined WIN32 && defined UNICODE
+       int status = _waccess( utf8_decode_s( thePath).c_str(), F_OK );
+#else
     int status = access ( thePath.c_str() , F_OK ); 
+#endif
     if (status != 0) return false;
     return true;
   }
@@ -188,10 +213,15 @@ namespace Kernel_Utils
   // function : IsWritable
   // purpose  : Returns True(False) if the path is (not) writable
   //============================================================================ 
-  bool IsWritable(const std::string& thePath) 
+  bool IsWritable(const std::string& thePath)
   {
-#ifdef WIN32 
-    if (  GetFileAttributes (  thePath.c_str()  ) == 0xFFFFFFFF  ) { 
+#ifdef WIN32
+#ifdef UNICODE
+         std::wstring aPathToCheck = utf8_decode_s( thePath );
+#else
+         std::string aPathToCheck = thePath;
+#endif
+    if (  GetFileAttributes ( aPathToCheck.c_str()  ) == 0xFFFFFFFF  ) {
       if (  GetLastError () == FILE_ATTRIBUTE_READONLY ) {
         return false;
       }
@@ -271,7 +301,13 @@ namespace Kernel_Utils
 
 #ifdef WIN32
     WIN32_FIND_DATA aFileData;
-    HANDLE hFile = FindFirstFile( thePath.c_str(), &aFileData );
+#ifdef UNICODE
+       std::wstring aPathToCheck = utf8_decode_s(thePath);
+#else
+       std::string aPathToCheck = thePath;
+#endif
+
+    HANDLE hFile = FindFirstFile( aPathToCheck.c_str(), &aFileData );
     if ( hFile == INVALID_HANDLE_VALUE )
     {
       //empty dir
index 0567251474c2a686cf387a0d9b72a57e394890d5..cd18da5fa8b631cd754d49e961e9afa80fb2273c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -40,13 +40,13 @@ namespace Kernel_Utils
   {
     int ls = 100, r = 1;
     char *s;
-    
+
     while (ls < 10000 && r)
       {
         ls *= 2;
         s = new char[ls];
         r = gethostname(s, ls-1);//threadsafe see man 7 pthread
-        switch (r) 
+        switch (r)
           {
           case 0:
             break;
@@ -58,29 +58,29 @@ namespace Kernel_Utils
           case ENAMETOOLONG:
 #endif
 #ifdef WIN32
-          case WSAEFAULT:  
+          case WSAEFAULT:
 #endif
             delete [] s;
             continue;
           }
-        
+
       }
-    
+
     if (r != 0)
       {
         s = new char[50];
         strcpy(s, "localhost");
       }
-    
+
     // remove all after '.'
     char *aDot = (strchr(s,'.'));
     if (aDot) aDot[0] = '\0';
-    
+
     std::string p = s;
     delete [] s;
     return p;
   }
-  
+
   Localizer::Localizer()
   {
     myCurLocale = setlocale(LC_NUMERIC, 0);
@@ -168,4 +168,40 @@ namespace Kernel_Utils
   #endif
 #endif
 
+#if defined(WIN32)
+  // Convert a wide Unicode string to an UTF8 string
+  char* utf8_encode(const wchar_t* encoded)
+  {
+         if (encoded == NULL) return NULL;
+         int size_needed = WideCharToMultiByte(CP_UTF8, 0, encoded, std::wcslen(encoded), NULL, 0, NULL, NULL);
+         char* strTo = new char[ size_needed + 1 ];
+         WideCharToMultiByte(CP_UTF8, 0, encoded, std::wcslen(encoded), strTo, size_needed, NULL, NULL);
+         strTo[size_needed] = '\0';
+         return strTo;
+  }
+  // Convert an UTF8 string to a wide Unicode String
+  wchar_t* utf8_decode(const char* decoded)
+  {
+         if (decoded == NULL) return NULL;
+         int size_needed = MultiByteToWideChar(CP_UTF8, 0, decoded, strlen(decoded), NULL, 0);
+         wchar_t* wstrTo = new wchar_t[ size_needed + 1 ];
+         MultiByteToWideChar(CP_UTF8, 0, decoded, strlen(decoded), wstrTo, size_needed);
+         wstrTo[size_needed] = '\0';
+         return wstrTo;
+  }
+  // Convert a wide Unicode std::wstring to an UTF8 string
+  std::string utf8_encode_s(const std::wstring& encoded) {
+         char* anEncoded = utf8_encode(encoded.c_str());
+         std::string res = std::string(anEncoded);
+         delete [] anEncoded;
+         return res;
+  }
+  // Convert an UTF8 std::string to a wide Unicode std::wstring
+  std::wstring utf8_decode_s(const std::string& decoded) {
+         wchar_t* aDecoded = utf8_decode(decoded.c_str());
+         std::wstring res = std::wstring(aDecoded);
+         delete [] aDecoded;
+         return res;
+  }
+#endif
 }
index d06b30bafd9b8ba72a0c6b697f3a74bd48e8e142..ddb351d3bc788b30cc9d35b6895db04a2b56d474 100644 (file)
@@ -61,6 +61,13 @@ namespace Kernel_Utils
   BASICS_EXPORT const char* encode(const wchar_t* decoded);
   BASICS_EXPORT std::string encode_s(const wchar_t* decoded);
 
+#ifdef WIN32
+  BASICS_EXPORT char* utf8_encode(const wchar_t* encoded);
+  BASICS_EXPORT wchar_t* utf8_decode(const char* decoded);
+  BASICS_EXPORT std::string utf8_encode_s(const std::wstring& encoded);
+  BASICS_EXPORT std::wstring utf8_decode_s(const std::string& decoded);
+#endif
+
   //! Get predefined GUID
   BASICS_EXPORT std::string GetGUID( GUIDtype );
 #ifndef WIN32
index 0c8a0a48bc857f9805db34e7c33a37564387de68..213a778cfff5118fe9a6ad8bdcfa75289cba9ea9 100644 (file)
@@ -554,7 +554,12 @@ Engines_Container_i::load_component_CppImplementation(const char* componentName,
   }
 #else
   HINSTANCE handle;
-  handle = LoadLibrary( impl_name.c_str() );
+#ifdef UNICODE
+  std::wstring libToLoad = Kernel_Utils::utf8_decode_s( impl_name );
+#else
+  std::string libToLoad = impl_name;
+#endif
+  handle = LoadLibrary(libToLoad.c_str() );
   if ( !handle )
   {
     reason="ImplementationNotFound";
index 2e2208c179a0035c591d2f21a1f103d1c0804cf2..f309b8ab59abfe1b3c61479559b6dcbd36fcfafe 100644 (file)
@@ -19,6 +19,7 @@
 
 INCLUDE_DIRECTORIES(
   ${Boost_INCLUDE_DIR}
+  ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
 )
 ADD_DEFINITIONS(${BOOST_DEFINITIONS})
 
@@ -35,7 +36,7 @@ ADD_LIBRARY(DF ${DF_SOURCES})
 INSTALL(TARGETS DF EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
 
 ADD_EXECUTABLE(testDF testDF.cxx)
-TARGET_LINK_LIBRARIES(testDF DF)
+TARGET_LINK_LIBRARIES(testDF DF SALOMEBasics)
 INSTALL(TARGETS testDF DESTINATION ${SALOME_INSTALL_BINS})
 
 FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
index b387227f92638d14657e8d017dfbd5492917dbf4..67363f52baa0ba42468a6ef02b6a66763a75dedb 100644 (file)
@@ -34,6 +34,9 @@
 #include "DF_Container.hxx"
 #include "DF_ChildIterator.hxx"
 
+#include "Basics_Utils.hxx"
+#include "Basics_DirUtils.hxx"
+
 #ifndef WIN32
 #include <unistd.h>
 #include <sys/time.h>
@@ -86,12 +89,21 @@ void GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, in
 std::string GetUserName()
 {
 #ifdef WIN32
-  char*  pBuff = new char[UNLEN + 1];
+#ifdef UNICODE
+       wchar_t*  pBuff = new wchar_t[UNLEN + 1];
+#else
+       char*  pBuff = new char[UNLEN + 1];
+#endif
   DWORD  dwSize = UNLEN + 1;
   std::string retVal;
   GetUserName ( pBuff, &dwSize );
-  std::string theTmpUserName(pBuff,(int)dwSize -1 );
+#ifdef UNICODE
+  std::wstring theTmpUserName(pBuff, (int)dwSize - 1);
+  retVal = Kernel_Utils::utf8_encode_s(theTmpUserName);
+#else
+  std::string theTmpUserName(pBuff, (int)dwSize - 1);
   retVal = theTmpUserName;
+#endif
   delete [] pBuff;
   return retVal;
 #else
@@ -142,17 +154,7 @@ std::string GetDirFromPath(const std::string& thePath) {
 
 bool Exists(const std::string thePath) 
 {
-#ifdef WIN32 
-  if (  GetFileAttributes (  thePath.c_str()  ) == 0xFFFFFFFF  ) { 
-    if (  GetLastError () != ERROR_FILE_NOT_FOUND  ) {
-      return false;
-    }
-  }
-#else 
-  int status = access ( thePath.c_str() , F_OK ); 
-  if (status != 0) return false;
-#endif
-  return true;
+       return Kernel_Utils::IsExists( thePath );
 }
 
 
index 028802aa257737832e4a5bfd3847cd91c9c2cb44..8f3c2bcbcb767f1ae5ac88d5e74c04aa354ceb71 100644 (file)
@@ -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,7 @@ 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})
+TARGET_LINK_LIBRARIES(SalomeHDFPersist ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${PLATFORM_LIBS} SALOMEBasics)
 INSTALL(TARGETS SalomeHDFPersist EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
 
 FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
index d95f788dc8917b70fc47a40e8132d1eb10af0d09..b595d3c1d6281ffbca8e79a136861e66b46b1897 100644 (file)
@@ -28,6 +28,8 @@
 //
 #include "HDFOI.hxx"
 
+#include "Basics_Utils.hxx"
+
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
@@ -86,14 +88,17 @@ void WriteSimpleData( FILE* fp, HDFdataset *hdf_dataset, hdf_type type, long siz
 //============================================================================
 bool HDFascii::isASCII(const char* thePath) {
   int fd;
+#if defined(WIN32) && defined(UNICODE)
+  const wchar_t * aPath = Kernel_Utils::utf8_decode(thePath);
+  if (!(fd = _wopen(aPath, O_RDONLY))) return false;
+#else
   if(!(fd = open(thePath, O_RDONLY))) return false;
+#endif
   char* aBuffer = new char[9];
   aBuffer[8] = (char)0;
   read(fd, aBuffer, 8); 
   close(fd);
-
   bool res = (strcmp(aBuffer, ASCIIHDF_ID) == 0);
-
   delete [] aBuffer;
 
   return res;
@@ -691,9 +696,17 @@ std::string GetTmpDir()
 {
  //Find a temporary directory to store a file
   std::string aTmpDir;
+#if defined(UNICODE)
+  wchar_t *Tmp_dir = _wgetenv(L"SALOME_TMP_DIR");
+#else
   char *Tmp_dir = getenv("SALOME_TMP_DIR");
+#endif
   if(Tmp_dir != NULL) {
+#if defined(UNICODE)
+       aTmpDir = Kernel_Utils::utf8_encode_s(Tmp_dir);
+#else
     aTmpDir = std::string(Tmp_dir);
+#endif
     if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
   }
   else {
@@ -723,9 +736,16 @@ std::string GetTmpDir()
   }
 
 #ifdef WIN32
+#if defined(UNICODE)
+  std::wstring aTmpDirToCreate = Kernel_Utils::utf8_decode_s(aTmpDir);
+  std::wstring aDirToCreate = Kernel_Utils::utf8_decode_s(aDir);
+#else
+  std::string aTmpDirToCreate = aTmpDir;
+  std::string aDirToCreate = aDir;
+#endif
   //function CreateDirectory create only final directory, but not intermediate
-  CreateDirectory(aTmpDir.c_str(), NULL);
-  CreateDirectory(aDir.c_str(), NULL);
+  CreateDirectory(aTmpDirToCreate.c_str(), NULL);
+  CreateDirectory(aDirToCreate.c_str(), NULL);
 #else
   mkdir(aDir.c_str(), 0x1ff); 
 #endif
@@ -789,7 +809,12 @@ void read_float64(FILE* fp, hdf_float64* value)
 bool Exists(const std::string thePath) 
 {
 #ifdef WIN32 
- if (  GetFileAttributes (  thePath.c_str()  ) == 0xFFFFFFFF  ) { 
+#if defined(UNICODE)
+       std::wstring aPathToCheck = Kernel_Utils::utf8_decode_s( thePath );
+#else
+       std::string aPathToCheck = thePath;
+#endif
+ if (  GetFileAttributes ( aPathToCheck.c_str()  ) == 0xFFFFFFFF  ) {
     DWORD errorId = GetLastError ();
     if ( errorId == ERROR_FILE_NOT_FOUND || errorId == ERROR_PATH_NOT_FOUND )
       return false;
@@ -804,9 +829,16 @@ bool Exists(const std::string thePath)
 void Move(const std::string& fName, const std::string& fNameDst)
 { 
 #ifdef WIN32
-  MoveFileEx (fName.c_str(), fNameDst.c_str(),MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
+#if defined(UNICODE)
+       std::wstring fNameToMove = Kernel_Utils::utf8_decode_s( fName );
+       std::wstring fNameDestination = Kernel_Utils::utf8_decode_s( fNameDst );
+#else
+       std::string fNameToMove = fName;
+       std::string fNameDestination = fNameDst;
+#endif
+  MoveFileEx ( fNameToMove.c_str(), fNameDestination.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED );
 #else
-  rename(fName.c_str(), fNameDst.c_str());
+  rename( fName.c_str(), fNameDst.c_str() );
 #endif
 }
 
index a96f12a36d59d24a2bde15b10b41d04f3545437e..99fc091ce5a548079affbf5f29230ca0adbae96a 100644 (file)
@@ -68,9 +68,13 @@ int HDFConvert::FromAscii(const std::string& file, const HDFcontainerObject & hd
 #elif defined WIN32
 
 #define SHMEMSIZE 4096
-
+#ifdef UNICODE
+  std::wstring empty = L"";
+#else
+  std::string empty = "";
+#endif
   HANDLE hMapObject = CreateFileMapping( 
-           INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, SHMEMSIZE, "");
+           INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, SHMEMSIZE, empty.c_str() );
   if (hMapObject != NULL) {
   // Get a pointer to the file-mapped shared memory.
   buffer = ( char* ) MapViewOfFile( 
index d8422714299f41dc0bf02e1fd57eefc4d4e613a5..8f8c20d2ee44c1b8bfca28b74d855475ce38b680 100644 (file)
 #include <map>
 #include "utilities.h"
 
+#include <Basics_Utils.hxx>
+
 #ifdef WIN32
 # include <process.h>
+# include <windows.h>
+#include <fcntl.h>  
+#include <sys/types.h>  
+#include <sys/stat.h> 
+#include <io.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <wchar.h>
 #else
 # include <unistd.h>
 #endif
@@ -826,9 +837,13 @@ SALOME_ModuleCatalogImpl::Private::_parse_xml_file(const char* file,
   ParserComponents    _moduleList;
  
   SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler(_pathList,_moduleList,typeMap,typeList);
-
+#if defined(WIN32)
+  const wchar_t* w_file = Kernel_Utils::utf8_decode(file);
+  FILE* aFile  = _wfopen(w_file, L"r");
+#else
   FILE* aFile = fopen(file, "r");
-
+#endif
+  
   if (aFile != NULL)
     {
       xmlDocPtr aDoc = xmlReadFile(file, NULL, 0);
index cc9396c5b3b61e6ec091cf588cf684cb6a7244f8..3f758950c889a50e8bccd4bf3a5d26a68f71ec76 100644 (file)
@@ -62,8 +62,12 @@ std::string SALOMEDS_AttributeStudyProperties::GetUserName()
   }
 #ifndef WIN32
   else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserName();
+#else
+#ifdef UNICODE
+  else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserNameW();
 #else
   else aName = ((SALOMEDS::AttributeStudyProperties_var)SALOMEDS::AttributeStudyProperties::_narrow(_corba_impl))->GetUserNameA();
+#endif
 #endif
   return aName;
 }
index 1905d7d25e5476db936131d6370562222d8f05b5..2a14971d7f632ed0283c3130f02e220456d8bd80 100644 (file)
@@ -130,7 +130,7 @@ bool SALOMEDS_Study::Open(const std::string& theStudyUrl)
 {
   if(CORBA::is_nil(_corba_impl))
     return false;
-  std::wstring wtheStudyUrl = std::wstring(theStudyUrl.begin(), theStudyUrl.end());
+  std::wstring wtheStudyUrl = Kernel_Utils::decode_s( theStudyUrl );
   
   if (!_corba_impl->Open( (wchar_t*)wtheStudyUrl.c_str() ) )
     return false;
index 93ba73d5e543bc3b0a9ca1549c65d1deda3eb6b7..6573f4e0d5a82566db5ef55224f892f77fee6cd3 100644 (file)
@@ -401,9 +401,8 @@ bool SALOMEDS_Study_i::Open(const wchar_t* aWUrl)
 
   Unexpect aCatch(SalomeException);
   MESSAGE("Begin of SALOMEDS_Study_i::Open");
-  
   std::string aUrl = Kernel_Utils::encode_s(aWUrl);
-  bool res = _impl->Open(std::string(aUrl));
+  bool res = _impl->Open( aUrl );
 
   // update desktop title with new study name
   //NameChanged();
index b6ee7985dfb090fc27d60f1bc459e9e0744a5b51..ad3954ed80d47178b83c6b9e701683bab2d11eb5 100644 (file)
 #ifdef WIN32
 #include <windows.h>
 static HMODULE _libHandle = 0;
+#ifdef UNICODE
+#define SALOMEDS_LIB_NAME L"SalomeDS.dll"
+#else
 #define SALOMEDS_LIB_NAME "SalomeDS.dll"
+#endif
 #else
 #include <dlfcn.h>
 static void* _libHandle = NULL;
index 3e63782aea1e43a23031b6a71c52750e777358e6..62a2ea30d83161523a894d0f67aea54be02ee0d4 100644 (file)
@@ -777,10 +777,20 @@ bool SALOMEDSImpl_Study::Impl_SaveAs(const std::string& aStudyUrl,
 #else
   aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile;
 #endif
+#if defined(WIN32) && defined(UNICODE)
+  std::wstring awCmd = Kernel_Utils::utf8_decode_s(aCmd);
+  _wsystem( awCmd.c_str() );
+#else  
   system(aCmd.c_str());
+#endif
 
   // Iterate and move files in the temporary directory
+#if defined(WIN32) && defined(UNICODE)
+  std::wstring awTmpFile = Kernel_Utils::utf8_decode_s(aTmpFile);
+  FILE* fp = _wfopen(awTmpFile.c_str(), L"rb");
+#else
   FILE* fp = fopen(aTmpFile.c_str(), "rb");
+#endif
   if (!fp) {
     URL( anOldName ); // VSR: restore previous url if operation is failed
     return false;
@@ -796,7 +806,12 @@ bool SALOMEDSImpl_Study::Impl_SaveAs(const std::string& aStudyUrl,
 #else
     aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\"";
 #endif
+#if defined(WIN32) && defined(UNICODE)
+       std::wstring awCmd = Kernel_Utils::utf8_decode_s(aCmd);
+    errors = _wsystem(awCmd.c_str());
+#else  
     errors = system(aCmd.c_str());
+#endif
   }
 
   delete []buffer;
@@ -804,14 +819,27 @@ bool SALOMEDSImpl_Study::Impl_SaveAs(const std::string& aStudyUrl,
 
   // Perform cleanup
 #ifdef WIN32
-  DeleteFileA(aTmpFile.c_str());
+#ifdef UNICODE
+  std::wstring aTmpFileToDelete = Kernel_Utils::utf8_decode_s(aTmpFile);
+#else
+  std::string aTmpFileToDelete = aTmpFile;
+#endif
+  DeleteFile(aTmpFileToDelete.c_str());
 #else
   unlink(aTmpFile.c_str());
 #endif
 
 #ifdef WIN32
-  RemoveDirectoryA(aTmpFileDir.c_str());
-  RemoveDirectoryA(aStudyTmpDir.c_str());
+#ifdef UNICODE
+  std::wstring aTmpFileDirToDelete = Kernel_Utils::utf8_decode_s( aTmpFileDir );
+  std::wstring aStudyTmpDirToDelete = Kernel_Utils::utf8_decode_s( aStudyTmpDir );
+#else
+  std::string aTmpFileDirToDelete = aTmpFileDir;
+  std::string aStudyTmpDirToDelete = aStudyTmpDir;
+#endif  
+  RemoveDirectory( aTmpFileDirToDelete.c_str() );
+  RemoveDirectory( aStudyTmpDirToDelete.c_str() );
 #else
   rmdir(aTmpFileDir.c_str());
   rmdir(aStudyTmpDir.c_str());
@@ -2091,7 +2119,12 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
 
   //Create a file that will contain a main Study script
   std::fstream fp;
+#if defined(WIN32) && defined(UNICODE)
+  std::wstring aConverterFN = Kernel_Utils::utf8_decode_s(aFileName);
+  fp.open(aConverterFN.c_str(), std::ios::out);
+#else
   fp.open(aFileName.c_str(), std::ios::out);
+#endif
 
 #ifdef WIN32
   bool isOpened = fp.is_open();
@@ -2209,7 +2242,12 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
       aFileName += aScriptName+ std::string(".py");
       aSeqOfFileNames.push_back(aFileName);
 
+#if defined(WIN32) && defined(UNICODE)
+      std::wstring aConverterFN2 = Kernel_Utils::utf8_decode_s(aFileName);
+      fp2.open(aConverterFN2.c_str(), std::ios::out);
+#else
       fp2.open(aFileName.c_str(), std::ios::out);
+#endif
 
 #ifdef WIN32
       isOpened = fp2.is_open();
index bf95cf018cdf7f076befb590e851e511de23be2e..cbf835c955db27d74ad4e581926f706eec359c13 100644 (file)
@@ -34,6 +34,9 @@
 #include <iterator>
 #include <sstream>
 
+#include "Basics_DirUtils.hxx"
+#include "Basics_Utils.hxx"
+
 #include "SALOMEDSImpl_Tool.hxx"
 
 #ifndef WIN32
 
 bool SALOMEDS_Exists(const std::string thePath)
 {
-#ifdef WIN32 
-  if (  GetFileAttributes (  thePath.c_str()  ) == 0xFFFFFFFF  ) { 
-    if (  GetLastError () == ERROR_FILE_NOT_FOUND  ) {
-      return false;
-    }
-  }
-#else 
-  int status = access ( thePath.c_str() , F_OK ); 
-  if (status != 0) return false;
-#endif
-  return true;
+       return Kernel_Utils::IsExists( thePath );
 }
 
-
-
-
 //============================================================================
 // function : GetTempDir
 // purpose  : Return a temp directory to store created files like "/tmp/sub_dir/"
 //============================================================================
 std::string SALOMEDSImpl_Tool::GetTmpDir()
 {
-  //Find a temporary directory to store a file
-
-  std::string aTmpDir;
-
-  char *Tmp_dir = getenv("SALOME_TMP_DIR");
-  if ( Tmp_dir != NULL && SALOMEDS_Exists( Tmp_dir ))
-  {
-    aTmpDir = Tmp_dir;
-#ifdef WIN32
-    if ( aTmpDir.back() != '\\') aTmpDir += '\\';
-#else
-    if ( aTmpDir.back() != '/') aTmpDir += '/';
-#endif
-  }
-  else
-  {
-#ifdef WIN32
-    aTmpDir = "C:\\";
-#else
-    aTmpDir = "/tmp/";
-#endif
-  }
-
-  srand( (unsigned int)time( NULL ));
-  int aRND = 999 + (int) (100000.0*rand() / (RAND_MAX+1.0)); //Get a random number to present a name of a sub directory
-  char buffer[127];
-  sprintf( buffer, "%d", aRND );
-  std::string aSubDir( buffer );
-  if ( aSubDir.size() <= 1 ) aSubDir = "123409876";
-
-  aTmpDir += aSubDir; //Get RND sub directory
-
-  std::string aDir = aTmpDir;
-
-  for ( aRND = 0; SALOMEDS_Exists( aDir ); aRND++ )
-  {
-    sprintf(buffer, "%d", aRND);
-    aDir = aTmpDir + buffer;  //Build a unique directory name
-  }
-
-#ifdef WIN32
-  if ( aDir.back() != '\\') aDir += '\\';
-#else
-  if ( aDir.back() != '/' ) aDir += '/';
-#endif
-
-
-#ifdef WIN32
-  CreateDirectory( aDir.c_str(), NULL );
-#else
-  mkdir( aDir.c_str(), 0x1ff );
-#endif
-
-  return aDir;
+  return Kernel_Utils::GetTmpDirByEnv("SALOME_TMP_DIR");
 }
 
 //============================================================================
@@ -147,7 +84,12 @@ void SALOMEDSImpl_Tool::RemoveTemporaryFiles(const std::string& theDirectory,
     if(!SALOMEDS_Exists(aFile)) continue;
 
 #ifdef WIN32
-    DeleteFile(aFile.c_str());
+#if defined(UNICODE)
+       std::wstring aFileToDelete = Kernel_Utils::utf8_decode_s(aFile);
+#else
+       std::string aFileToDelete = aFile;
+#endif
+    DeleteFile( aFileToDelete.c_str() );
 #else 
     unlink(aFile.c_str());
 #endif
@@ -156,7 +98,12 @@ void SALOMEDSImpl_Tool::RemoveTemporaryFiles(const std::string& theDirectory,
   if(IsDirDeleted) {
     if(SALOMEDS_Exists(aDirName)) {
 #ifdef WIN32
-      RemoveDirectory(aDirName.c_str());
+#if defined(UNICODE)
+               std::wstring aDirToDelete = Kernel_Utils::utf8_decode_s(aDirName);
+#else
+               std::string aDirToDelete = aDirName;
+#endif
+      RemoveDirectory(aDirToDelete.c_str());
 #else
       rmdir(aDirName.c_str());
 #endif
index 46acee2c11d7c4b5c381f6fbfd927ff93afeffc6..d4f66776ff775f9d51a6b4b1d54aa60e917a97f6 100644 (file)
@@ -121,8 +121,8 @@ LocalTraceBufferPool* LocalTraceBufferPool::instance()
               handle = dlopen( impl_name.c_str() , RTLD_LAZY | RTLD_GLOBAL ) ;
 #else
               HINSTANCE handle;
-              std::string impl_name = std::string ("lib") + traceKind + std::string(".dll");
-              handle = LoadLibrary( impl_name.c_str() );
+              std::string impl_name = std::string ("lib") + traceKind + std::string(".dll");                                
+              handle = LoadLibraryA( impl_name.c_str() );
 #endif
               if ( handle )
                 {
index 95906c30e1cee99626bd84af25080b0b78873b00..d83e243b246d6fa1d92dcd8ff01a568f2df136b9 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "utilities.h"
 #include "Basics_DirUtils.hxx"
+#include "Basics_Utils.hxx"
 
 #ifndef WIN32
 #include <sys/time.h>
 
 bool Exists(const std::string thePath) 
 {
-#ifdef WIN32 
-  if (  GetFileAttributes (  thePath.c_str()  ) == 0xFFFFFFFF  ) { 
-    if (  GetLastError () == ERROR_FILE_NOT_FOUND  ) {
-      return false;
-    }
-  }
-#else 
-  int status = access ( thePath.c_str() , F_OK ); 
-  if (status != 0) return false;
-#endif
-  return true;
+       return Kernel_Utils::IsExists(thePath);
 }
 
 
@@ -143,7 +134,12 @@ void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory,
     if(!Exists(aFile)) continue;
 
 #ifdef WIN32
-    DeleteFile(aFile.c_str());
+#if defined(UNICODE)
+       std::wstring aFileToDelete = Kernel_Utils::utf8_decode_s(aFile);
+#else
+       std::string aFileToDelete = aFile;
+#endif
+    DeleteFile(aFileToDelete.c_str());
 #else 
     unlink(aFile.c_str());
 #endif
@@ -152,7 +148,12 @@ void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory,
   if(IsDirDeleted) {
     if(Exists(aDirName)) {
 #ifdef WIN32
-      RemoveDirectory(aDirName.c_str());
+#if defined(UNICODE)
+               std::wstring aDirToDelete = Kernel_Utils::utf8_decode_s(aDirName);
+#else
+               std::string aDirToDelete = aDirName;
+#endif
+      RemoveDirectory(aDirToDelete.c_str());
 #else
       rmdir(aDirName.c_str());
 #endif
@@ -197,7 +198,11 @@ namespace
         std::string aFullPath = aTmpDir + theFiles[i];
         if(!Exists(aFullPath)) continue;
 #ifdef WIN32
+#ifdef UNICODE
+               std::ifstream aFile(Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary);
+#else
         std::ifstream aFile(aFullPath.c_str(), std::ios::binary);
+#endif
 #else
         std::ifstream aFile(aFullPath.c_str());
 #endif
@@ -214,7 +219,8 @@ namespace
     
     if ( aNbFiles == 0 ) return (new SALOMEDS::TMPFile);
     aBufferSize += 4;      //4 bytes for a number of the files that will be written to the stream;
-    unsigned char* aBuffer = new unsigned char[aBufferSize];  
+       unsigned char* aBuffer = new unsigned char[aBufferSize];
+
     if(aBuffer == NULL)
       return (new SALOMEDS::TMPFile);
     
@@ -227,12 +233,16 @@ namespace
     aCurrentPos = 4;
     
     for(i=0; i<aLength; i++) {
-      std::ifstream *aFile;
+         std::ifstream *aFile;
       if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true
         std::string aFullPath = aTmpDir + theFiles[i];
         if(!Exists(aFullPath)) continue;
 #ifdef WIN32
+#ifdef UNICODE
+               aFile = new std::ifstream (Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary);
+#else
         aFile = new std::ifstream(aFullPath.c_str(), std::ios::binary);
+#endif
 #else
         aFile = new std::ifstream(aFullPath.c_str());
 #endif  
@@ -255,7 +265,7 @@ namespace
         aCurrentPos += 8;
         
         aFile->seekg(0, std::ios::beg);
-        aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]);
+               aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]);
         aFile->close();
         delete(aFile);
         aCurrentPos += aFileSize[i];
@@ -307,7 +317,6 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream,
 
   //Get a temporary directory for saving a file
   std::string aTmpDir = theToDirectory;
-
   unsigned char *aBuffer = (unsigned char*)theStream.NP_data();
 
   if(aBuffer == NULL)
@@ -346,11 +355,15 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream,
       
       std::string aFullPath = aTmpDir + aFileName;
 #ifdef WIN32
+#ifdef UNICODE
+         std::ofstream aFile(Kernel_Utils::utf8_decode_s(aFullPath).c_str(), std::ios::binary);
+#else
       std::ofstream aFile(aFullPath.c_str(), std::ios::binary);
+#endif
 #else
       std::ofstream aFile(aFullPath.c_str());
 #endif
-      aFile.write((char *)(aBuffer+aCurrentPos), aFileSize); 
+         aFile.write((char *)(aBuffer + aCurrentPos), aFileSize);
       aFile.close();  
       aCurrentPos += aFileSize;
     }
index 5a1be7cbeb8e8747629a1fc7a60b1e4585b2708d..59886a18e20201100666c7007a56e65b39f3f074 100644 (file)
@@ -48,7 +48,8 @@
 void printBacktrace(std::stringstream& txt)
 {
        typedef USHORT(WINAPI *CaptureStackBackTraceType)(__in ULONG, __in ULONG, __out PVOID*, __out_opt PULONG);
-       CaptureStackBackTraceType func = (CaptureStackBackTraceType)(GetProcAddress(LoadLibrary("kernel32.dll"), "RtlCaptureStackBackTrace"));
+
+       CaptureStackBackTraceType func = (CaptureStackBackTraceType)(GetProcAddress(LoadLibraryA("kernel32.dll"), "RtlCaptureStackBackTrace"));
 
        if (func == NULL)
                return;
index 88094f18aee7abf7c901a088acb6fc851953a91c..853b27e797fdc3b23a2a91049795e914d4d83df1 100644 (file)
@@ -89,15 +89,26 @@ const char* const get_pwname( void )
 #include <direct.h>
 #include <process.h>
 
+#include "Basics_Utils.hxx"
+
 const char* duplicate( const char *const str ) ;
 
 const char* get_uname( void )
 {
-        static std::string hostName(4096, 0);
+#ifdef UNICODE
+           std::wstring hostName(4096, 0);
+#else
+           static std::string hostName(4096, 0);
+#endif
         static DWORD nSize = hostName.length();
         static int res = ::GetComputerNameEx(ComputerNameDnsFullyQualified, &hostName[0], &nSize);
         ASSERT( res );
+#ifdef UNICODE
+               static std::string aRes = Kernel_Utils::utf8_encode_s(hostName);
+               return aRes.c_str();
+#else
         return hostName.c_str();
+#endif
 }
 
 const char* get_adip( void )
@@ -127,11 +138,20 @@ const char* get_adip( void )
 
 const char* const get_pwname( void )
 {
-  static std::string retVal(4096, 0);
+#ifdef UNICODE
+       std::wstring retVal(4096, 0);
+#else
+       static std::string retVal(4096, 0);
+#endif
   static DWORD  dwSize = retVal.length() + 1;
   static int res = GetUserName( &retVal[0], &dwSize );
   ASSERT( res );
+#ifdef UNICODE
+  static std::string aRes = Kernel_Utils::utf8_encode_s(retVal);
+  return aRes.c_str();
+#else
   return retVal.c_str();
+#endif
 }
 
 PSID getuid() {