mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-01-12 17:50:34 +05:00
Run SALOME with UNICODE path
This commit is contained in:
parent
98ec6be586
commit
0b4f557c95
@ -50,8 +50,13 @@ Driver_Mesh::Status DriverDAT_R_SMDS_Mesh::Perform()
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* OUVERTURE DU FICHIER EN LECTURE *
|
* 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();
|
char *file2Read = (char *)myFile.c_str();
|
||||||
FILE* aFileId = fopen(file2Read, "r");
|
FILE* aFileId = fopen(file2Read, "r");
|
||||||
|
#endif
|
||||||
if ( !aFileId ) {
|
if ( !aFileId ) {
|
||||||
fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
|
fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
|
||||||
return DRS_FAIL;
|
return DRS_FAIL;
|
||||||
|
@ -38,9 +38,14 @@ Driver_Mesh::Status DriverDAT_W_SMDS_Mesh::Perform()
|
|||||||
Status aResult = DRS_OK;
|
Status aResult = DRS_OK;
|
||||||
|
|
||||||
int nbNodes, nbCells;
|
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();
|
char *file2Read = (char *)myFile.c_str();
|
||||||
FILE* aFileId = fopen(file2Read, "w+");
|
FILE* aFileId = fopen(file2Read, "w+");
|
||||||
|
#endif
|
||||||
if ( !aFileId )
|
if ( !aFileId )
|
||||||
{
|
{
|
||||||
fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
|
fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
|
||||||
|
@ -26,7 +26,9 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "libmesh5.h"
|
#include "libmesh5.h"
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/*----------------------------------------------------------*/
|
/*----------------------------------------------------------*/
|
||||||
/* Defines */
|
/* Defines */
|
||||||
@ -190,7 +192,10 @@ int GmfOpenMesh(const char *FilNam, int mod, ...)
|
|||||||
GmfMshSct *msh;
|
GmfMshSct *msh;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int k;
|
int k;
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
wchar_t* encoded = 0;
|
||||||
|
int size_needed = 0;
|
||||||
|
#endif
|
||||||
if(!GmfIniFlg)
|
if(!GmfIniFlg)
|
||||||
{
|
{
|
||||||
for(i=0;i<=MaxMsh;i++)
|
for(i=0;i<=MaxMsh;i++)
|
||||||
@ -262,13 +267,27 @@ int GmfOpenMesh(const char *FilNam, int mod, ...)
|
|||||||
va_end(VarArg);
|
va_end(VarArg);
|
||||||
|
|
||||||
/* Create the name string and open the file */
|
/* Create the name string and open the 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"rb")))
|
||||||
|
#else
|
||||||
if (!(msh->hdl = fopen(msh->FilNam, "rb")))
|
if (!(msh->hdl = fopen(msh->FilNam, "rb")))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
free (msh);
|
free (msh);
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
free(encoded);
|
||||||
|
#endif
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
free(encoded);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Read the endian coding tag, the mesh version and the mesh dimension (mandatory kwd) */
|
/* Read the endian coding tag, the mesh version and the mesh dimension (mandatory kwd) */
|
||||||
|
|
||||||
if(msh->typ & Bin)
|
if(msh->typ & Bin)
|
||||||
@ -401,13 +420,26 @@ int GmfOpenMesh(const char *FilNam, int mod, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create the mesh file */
|
/* 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")))
|
if(!(msh->hdl = fopen(msh->FilNam, "wb")))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
free (msh);
|
free (msh);
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
free(encoded);
|
||||||
|
#endif
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
free(encoded);
|
||||||
|
#endif
|
||||||
GmfMshTab[ MshIdx ] = msh;
|
GmfMshTab[ MshIdx ] = msh;
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,7 +238,12 @@ Driver_Mesh::Status DriverSTL_R_SMDS_Mesh::readAscii(SMESH_File& theFile) const
|
|||||||
theFile.close();
|
theFile.close();
|
||||||
|
|
||||||
// Open the file
|
// Open the file
|
||||||
|
#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");
|
FILE* file = fopen(myFile.c_str(), "r");
|
||||||
|
#endif
|
||||||
|
|
||||||
// count the number of lines
|
// count the number of lines
|
||||||
Standard_Integer nbLines = 0;
|
Standard_Integer nbLines = 0;
|
||||||
|
@ -102,7 +102,12 @@ Driver_Mesh::Status DriverUNV_R_SMDS_Mesh::Perform()
|
|||||||
{
|
{
|
||||||
Kernel_Utils::Localizer loc;
|
Kernel_Utils::Localizer loc;
|
||||||
Status aResult = DRS_OK;
|
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());
|
std::ifstream in_stream(myFile.c_str());
|
||||||
|
#endif
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,12 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
|
|||||||
{
|
{
|
||||||
Kernel_Utils::Localizer loc;
|
Kernel_Utils::Localizer loc;
|
||||||
Status aResult = DRS_OK;
|
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());
|
std::ofstream out_stream(myFile.c_str());
|
||||||
|
#endif
|
||||||
try{
|
try{
|
||||||
|
|
||||||
UNV164::Write( out_stream ); // unit system
|
UNV164::Write( out_stream ); // unit system
|
||||||
|
@ -92,10 +92,10 @@ namespace MED
|
|||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
size_t length = strlen(fileName.c_str()) + sizeof(char);
|
int size_needed = MultiByteToWideChar(CP_UTF8, 0, fileName.c_str(), strlen(fileName.c_str()), NULL, 0);
|
||||||
wchar_t* path = new wchar_t[length];
|
wchar_t* path = new wchar_t[size_needed + 1];
|
||||||
memset(path, '\0', length);
|
MultiByteToWideChar(CP_UTF8, 0, fileName.c_str(), strlen(fileName.c_str()), path, size_needed);
|
||||||
mbstowcs(path, fileName.c_str(), length);
|
path[size_needed] = '\0';
|
||||||
#else
|
#else
|
||||||
cosnt char* path = xmlPath.c_str();
|
cosnt char* path = xmlPath.c_str();
|
||||||
#endif
|
#endif
|
||||||
|
@ -82,16 +82,14 @@ bool SMESH_File::open()
|
|||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
const wchar_t* name = Kernel_Utils::decode(_name.data());
|
std::wstring aName = Kernel_Utils::utf8_decode_s(_name);
|
||||||
|
const wchar_t* name = aName.c_str();
|
||||||
#else
|
#else
|
||||||
char* name = name.data();
|
char* name = name.data();
|
||||||
#endif
|
#endif
|
||||||
_file = CreateFile(name, GENERIC_READ, FILE_SHARE_READ,
|
_file = CreateFile(name, GENERIC_READ, FILE_SHARE_READ,
|
||||||
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
bool ok = ( _file != INVALID_HANDLE_VALUE );
|
bool ok = ( _file != INVALID_HANDLE_VALUE );
|
||||||
#ifdef UNICODE
|
|
||||||
delete name;
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
_file = ::open(_name.data(), O_RDONLY );
|
_file = ::open(_name.data(), O_RDONLY );
|
||||||
bool ok = ( _file >= 0 );
|
bool ok = ( _file >= 0 );
|
||||||
@ -178,7 +176,12 @@ bool SMESH_File::remove()
|
|||||||
close();
|
close();
|
||||||
|
|
||||||
boost::system::error_code err;
|
boost::system::error_code err;
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
std::wstring name = Kernel_Utils::utf8_decode_s(_name);
|
||||||
|
boofs::remove(name.c_str(), err);
|
||||||
|
#else
|
||||||
boofs::remove( _name, err );
|
boofs::remove( _name, err );
|
||||||
|
#endif
|
||||||
_error = err.message();
|
_error = err.message();
|
||||||
|
|
||||||
return !err;
|
return !err;
|
||||||
@ -195,7 +198,12 @@ long SMESH_File::size()
|
|||||||
if ( _size >= 0 ) return _size; // size of an open file
|
if ( _size >= 0 ) return _size; // size of an open file
|
||||||
|
|
||||||
boost::system::error_code err;
|
boost::system::error_code err;
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
std::wstring name = Kernel_Utils::utf8_decode_s(_name);
|
||||||
|
boost::uintmax_t size = boofs::file_size(name.c_str(), err);
|
||||||
|
#else
|
||||||
boost::uintmax_t size = boofs::file_size( _name, err );
|
boost::uintmax_t size = boofs::file_size( _name, err );
|
||||||
|
#endif
|
||||||
_error = err.message();
|
_error = err.message();
|
||||||
|
|
||||||
return !err ? (long) size : -1;
|
return !err ? (long) size : -1;
|
||||||
@ -210,7 +218,13 @@ long SMESH_File::size()
|
|||||||
bool SMESH_File::exists()
|
bool SMESH_File::exists()
|
||||||
{
|
{
|
||||||
boost::system::error_code err;
|
boost::system::error_code err;
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
std::wstring name = Kernel_Utils::utf8_decode_s(_name);
|
||||||
|
bool res = boofs::exists(name.c_str(), err);
|
||||||
|
#else
|
||||||
bool res = boofs::exists(_name, err);
|
bool res = boofs::exists(_name, err);
|
||||||
|
#endif
|
||||||
|
|
||||||
_error = err.message();
|
_error = err.message();
|
||||||
|
|
||||||
return err ? false : res;
|
return err ? false : res;
|
||||||
@ -225,7 +239,12 @@ bool SMESH_File::exists()
|
|||||||
bool SMESH_File::isDirectory()
|
bool SMESH_File::isDirectory()
|
||||||
{
|
{
|
||||||
boost::system::error_code err;
|
boost::system::error_code err;
|
||||||
|
#if defined(WIN32) && defined(UNICODE)
|
||||||
|
std::wstring name = Kernel_Utils::utf8_decode_s(_name);
|
||||||
|
bool res = boofs::is_directory(name.c_str(), err);
|
||||||
|
#else
|
||||||
bool res = boofs::is_directory( _name, err );
|
bool res = boofs::is_directory( _name, err );
|
||||||
|
#endif
|
||||||
_error = err.message();
|
_error = err.message();
|
||||||
|
|
||||||
return err ? false : res;
|
return err ? false : res;
|
||||||
@ -302,7 +321,8 @@ bool SMESH_File::openForWriting()
|
|||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
const wchar_t* name = Kernel_Utils::decode(_name.data());
|
std::wstring aName = Kernel_Utils::utf8_decode_s(_name);
|
||||||
|
const wchar_t* name = aName.c_str();
|
||||||
#else
|
#else
|
||||||
char* name = name.data();
|
char* name = name.data();
|
||||||
#endif
|
#endif
|
||||||
@ -313,11 +333,7 @@ bool SMESH_File::openForWriting()
|
|||||||
OPEN_ALWAYS, // CREATE NEW or OPEN EXISTING
|
OPEN_ALWAYS, // CREATE NEW or OPEN EXISTING
|
||||||
FILE_ATTRIBUTE_NORMAL, // normal file
|
FILE_ATTRIBUTE_NORMAL, // normal file
|
||||||
NULL); // no attr. template
|
NULL); // no attr. template
|
||||||
#ifdef UNICODE
|
|
||||||
delete name;
|
|
||||||
#endif
|
|
||||||
return ( _file != INVALID_HANDLE_VALUE );
|
return ( _file != INVALID_HANDLE_VALUE );
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
_file = ::open( _name.c_str(),
|
_file = ::open( _name.c_str(),
|
||||||
|
Loading…
Reference in New Issue
Block a user