-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2019 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 "MED_Utilities.hxx"
#include "MED_Wrapper.hxx"
+#include <Basics_Utils.hxx>
+
#include <stdio.h>
#include <errno.h>
#include <sstream>
MESSAGE("create an empty med file of the right version, for append " << version);
static const unsigned char empty_32[] = EMPTY_FILE_32;
static const unsigned char empty_33[] = EMPTY_FILE_33;
+#ifdef WIN32
+#ifdef UNICODE
+ std::wstring aFilename = Kernel_Utils::utf8_decode_s(fileName);
+#else
+ std::wstring aFilename = fileName;
+#endif
+ std::ofstream ofs(aFilename, std::ios::binary);
+#else
std::ofstream ofs(fileName);
+#endif
if (version == 32)
ofs.write(reinterpret_cast<const char *>(empty_32),sizeof(empty_32));
else if (version == 33)
ofs.write(reinterpret_cast<const char *>(empty_33),sizeof(empty_33));
+ ofs.flush();
+ ofs.close();
return true;
}
// -------------------------------------------------------------------------------------------------------------------
{
#ifdef WIN32
#ifdef UNICODE
- size_t length = strlen(fileName.c_str()) + sizeof(char);
- wchar_t* path = new wchar_t[length];
- memset(path, '\0', length);
- mbstowcs(path, fileName.c_str(), length);
+ int size_needed = MultiByteToWideChar(CP_UTF8, 0, fileName.c_str(), strlen(fileName.c_str()), NULL, 0);
+ wchar_t* path = new wchar_t[size_needed + 1];
+ MultiByteToWideChar(CP_UTF8, 0, fileName.c_str(), strlen(fileName.c_str()), path, size_needed);
+ path[size_needed] = '\0';
#else
- cosnt char* path = xmlPath.c_str();
+ cosnt char* path = xmlPath.c_str();
#endif
- bool res = (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES);
+ bool res = (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES);
#ifdef UNICODE
- delete path;
+ delete path;
#endif
- return res;
+ return res;
#else
return (access(fileName.c_str(), F_OK) == 0);
#endif
ok = true;
else {
int medVersion = 10*major + minor;
- for (int ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
+ for (size_t ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
if (medVersionsOK[ii] == medVersion) {
ok =true;
break;
{
bool isCreated = false;
if (!CheckCompatibility(fileName, true))
- {
- remove(fileName.c_str());
- isCreated = true;
- }
+ {
+ remove(fileName.c_str());
+ isCreated = true;
+ }
int minor = -1;
if (isCreated)
+ {
+ med_int wantedMajor = MED_MAJOR_NUM;
+ med_int wantedMinor = MED_MINOR_NUM;
+ if (theVersion > 0)
{
- med_int wantedMajor = MED_MAJOR_NUM;
- med_int wantedMinor = MED_MINOR_NUM;
- if (theVersion > 0)
- {
- wantedMajor = theVersion/10;
- wantedMinor = theVersion%10;
- }
- if (wantedMajor == MED_MAJOR_NUM) // the med file will be actually created
- {
- if (wantedMinor < MED_MINOR_NUM)
- minor = wantedMinor;
- }
- else // an empty existing med file of the right version will be used for append
+ wantedMajor = theVersion/10;
+ wantedMinor = theVersion%10;
+ }
+ if (wantedMajor == MED_MAJOR_NUM) // the med file will be actually created
+ {
+ if (wantedMinor < MED_MINOR_NUM)
+ minor = wantedMinor;
+ }
+ else // an empty existing med file of the right version will be used for append
+ {
+ int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE;
+ bool isVersionOK = false;
+ for (size_t ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
+ if (medVersionsOK[ii] == theVersion)
{
- int medVersionsOK[] = MED_VERSIONS_APPEND_COMPATIBLE;
- bool isVersionOK = false;
- for (int ii=0; ii < sizeof(medVersionsOK)/sizeof(int); ii++)
- if (medVersionsOK[ii] == theVersion)
- {
- isVersionOK =true;
- break;
- }
- if (isVersionOK) // copy an empty existing med file of the right version, for append
- CreateEmptyMEDFile(fileName, theVersion);
+ isVersionOK =true;
+ break;
}
+ if (isVersionOK) // copy an empty existing med file of the right version, for append
+ CreateEmptyMEDFile(fileName, theVersion);
}
+ }
return new MED::TWrapper(fileName, minor);
}
}