-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
#include "HDFOI.hxx"
+#include "Basics_Utils.hxx"
+
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
//============================================================================
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;
{
//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 {
}
#ifdef WIN32
- //fuction CreateDirectory create only final directory, but not intermediate
- CreateDirectory(aTmpDir.c_str(), NULL);
- CreateDirectory(aDir.c_str(), NULL);
+#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(aTmpDirToCreate.c_str(), NULL);
+ CreateDirectory(aDirToCreate.c_str(), NULL);
#else
mkdir(aDir.c_str(), 0x1ff);
#endif
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;
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
}