]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Run SALOME on Windows with unicode path. rnv/unicode_path
authorrnv <rnv@opencascade.com>
Tue, 5 Mar 2019 08:36:54 +0000 (11:36 +0300)
committerrnv <rnv@opencascade.com>
Tue, 5 Mar 2019 08:36:54 +0000 (11:36 +0300)
src/DriverDAT/DriverDAT_R_SMDS_Mesh.cxx
src/DriverDAT/DriverDAT_W_SMDS_Mesh.cxx
src/DriverGMF/libmesh5.c
src/DriverSTL/DriverSTL_R_SMDS_Mesh.cxx
src/DriverUNV/DriverUNV_R_SMDS_Mesh.cxx
src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx

index 5d2956c578588d79636d27d4821fbdd77ed6e7b2..f34cd106df3bf62c56bc77490febc27499b305d4 100644 (file)
@@ -50,8 +50,13 @@ Driver_Mesh::Status DriverDAT_R_SMDS_Mesh::Perform()
   /****************************************************************************
    *                      OUVERTURE DU FICHIER EN LECTURE                      *
    ****************************************************************************/
+#if defined(WIN32) && defined(UNICODE)
+  std::wstring file2Read = Kernel_Utils::utf8_decode_s(myFile);
+  FILE* aFileId = _wfopen(file2Read.c_str(), L"r");
+#else
   char *file2Read = (char *)myFile.c_str();
   FILE* aFileId = fopen(file2Read, "r");
+#endif
   if ( !aFileId ) {
     fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
     return DRS_FAIL;
index 403dad4f5634748cf6a0d38af896efa95deb158b..beb0b8b76ebefc1f868f714459df7f4abb5faf9d 100644 (file)
@@ -38,9 +38,14 @@ Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform()
   Status aResult = DRS_OK;
 
   int nbNodes, nbCells;
+#if defined(WIN32) && defined(UNICODE)
+  std::wstring file2Read = Kernel_Utils::utf8_decode_s(myFile);
+  FILE* aFileId = _wfopen(file2Read.c_str(), L"w+");
 
+#else
   char *file2Read = (char *)myFile.c_str();
   FILE* aFileId = fopen(file2Read, "w+");
+#endif
   if ( !aFileId )
   {
     fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
index c7d6c52ea5fd3e8fec7c5f296a094557fd8fe4ab..889b69747137b6fd6b4eb4054a9390dba741f1c4 100644 (file)
@@ -26,7 +26,9 @@
 #include <math.h>
 #include <ctype.h>
 #include "libmesh5.h"
-
+#ifdef WIN32
+#include <windows.h>
+#endif
 
 /*----------------------------------------------------------*/
 /* Defines                                                                                                      */
@@ -190,7 +192,10 @@ int GmfOpenMesh(const char *FilNam, int mod, ...)
         GmfMshSct *msh;
         char *ptr;
         int k;
-
+#if defined(WIN32) && defined(UNICODE)
+               wchar_t* encoded = 0;
+               int size_needed = 0;
+#endif
         if(!GmfIniFlg)
         {
                 for(i=0;i<=MaxMsh;i++)
@@ -262,13 +267,27 @@ int GmfOpenMesh(const char *FilNam, int mod, ...)
                 va_end(VarArg);
 
                 /* Create the name string and open the file */
-
-                if(!(msh->hdl = fopen(msh->FilNam, "rb")))
+#if defined(WIN32) && defined(UNICODE)
+                               size_needed = MultiByteToWideChar(CP_UTF8, 0, msh->FilNam, strlen(msh->FilNam), NULL, 0);
+                               encoded = malloc((size_needed + 1)*sizeof(wchar_t));
+                               MultiByteToWideChar(CP_UTF8, 0, msh->FilNam, strlen(msh->FilNam), encoded, size_needed);
+                               encoded[size_needed] = '\0';
+                               if (!(msh->hdl = _wfopen(encoded, L"rb")))
+#else
+                               if (!(msh->hdl = fopen(msh->FilNam, "rb")))
+#endif
                 {
                         free (msh);
+#if defined(WIN32) && defined(UNICODE)
+                                               free(encoded);
+#endif
                         return(0);
                 }
 
+#if defined(WIN32) && defined(UNICODE)
+                               free(encoded);
+#endif
+
                 /* Read the endian coding tag, the mesh version and the mesh dimension (mandatory kwd) */
 
                 if(msh->typ & Bin)
@@ -401,13 +420,26 @@ int GmfOpenMesh(const char *FilNam, int mod, ...)
                 }
 
                 /* Create the mesh file */
-
+#if defined(WIN32) && defined(UNICODE)
+                               size_needed = MultiByteToWideChar(CP_UTF8, 0, msh->FilNam, strlen(msh->FilNam), NULL, 0);
+                               encoded = malloc((size_needed + 1) * sizeof(wchar_t));
+                               MultiByteToWideChar(CP_UTF8, 0, msh->FilNam, strlen(msh->FilNam), encoded, size_needed);
+                               encoded[size_needed] = '\0';
+                               if (!(msh->hdl = _wfopen(encoded, L"wb")))
+#else
                 if(!(msh->hdl = fopen(msh->FilNam, "wb")))
+#endif
                 {
                         free (msh);
+#if defined(WIN32) && defined(UNICODE)
+                                               free(encoded);
+#endif
                         return(0);
                 }
 
+#if defined(WIN32) && defined(UNICODE)
+                               free(encoded);
+#endif
                 GmfMshTab[ MshIdx ] = msh;
 
 
index f1e1ea6ac7448e88fe4bb87138951043810e9eba..355c35617edbb2db410e940a9b3652106556174e 100644 (file)
@@ -238,7 +238,12 @@ Driver_Mesh::Status DriverSTL_R_SMDS_Mesh::readAscii(SMESH_File& theFile) const
   theFile.close();
 
   // Open the file
-  FILE* file = fopen( myFile.c_str(),"r");
+#if defined(WIN32) && defined(UNICODE)
+  std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
+  FILE* file = _wfopen( aFile.c_str(), L"r");
+#else
+  FILE* file = fopen(myFile.c_str(), "r");  
+#endif  
 
   // count the number of lines
   Standard_Integer nbLines = 0;
index 6ebc03eeb46e1b9657f9615c36601a2aa1612923..4e22f6bacf34dcc2a4a378874ff89e9463735a33 100644 (file)
@@ -102,7 +102,12 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
 {
   Kernel_Utils::Localizer loc;
   Status aResult = DRS_OK;
+#if defined(WIN32) && defined(UNICODE)
+  std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
+  std::ifstream in_stream(aFile.c_str());
+#else
   std::ifstream in_stream(myFile.c_str());
+#endif
   try
   {
     {
index 02ec7588ba394e0240ddb864feb2e4cbc98e75d8..30d7e2ab46b3ba7b1aa2dcea78382aff30aede98 100644 (file)
@@ -45,7 +45,12 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
 {
   Kernel_Utils::Localizer loc;
   Status aResult = DRS_OK;
+#if defined(WIN32) && defined(UNICODE)
+  std::wstring aFile = Kernel_Utils::utf8_decode_s(myFile);
+  std::ofstream out_stream(aFile.c_str());
+#else
   std::ofstream out_stream(myFile.c_str());
+#endif
   try{
 
     UNV164::Write( out_stream ); // unit system