From 20d7486abee00a45066883e59d1fc167e7990fcc Mon Sep 17 00:00:00 2001 From: rnv Date: Thu, 7 May 2020 17:14:56 +0300 Subject: [PATCH] Fix the problem with saving a file with several meshes under Windows. --- src/MEDWrapper/MED_Wrapper.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/MEDWrapper/MED_Wrapper.cxx b/src/MEDWrapper/MED_Wrapper.cxx index 7a7e968a8..81d3ba9ec 100644 --- a/src/MEDWrapper/MED_Wrapper.cxx +++ b/src/MEDWrapper/MED_Wrapper.cxx @@ -28,6 +28,10 @@ #include #include +#ifdef WIN32 +#include +#endif + #include #ifdef _DEBUG_ @@ -100,6 +104,23 @@ namespace MED { if (myCount++ == 0) { const char* aFileName = myFileName.c_str(); +#ifdef WIN32 + if (med_access_mode(theMode) == MED_ACC_RDWR) { + // Force removing readonly attribute from a file under Windows, because of a bug in the HDF5 + std::string aReadOlnyRmCmd = "attrib -r \"" + myFileName + "\"> nul 2>&1"; +#ifdef UNICODE + const char* to_decode = aReadOlnyRmCmd.c_str(); + int size_needed = MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), NULL, 0); + wchar_t* awReadOlnyRmCmd = new wchar_t[size_needed + 1]; + MultiByteToWideChar(CP_UTF8, 0, to_decode, strlen(to_decode), awReadOlnyRmCmd, size_needed); + awReadOlnyRmCmd[size_needed] = '\0'; + _wsystem(awReadOlnyRmCmd); + delete[] awReadOlnyRmCmd; +#else + system(aReadOlnyRmCmd.c_str()); +#endif + } +#endif myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), myMajor, myMinor, MED_RELEASE_NUM); } if (theErr) -- 2.39.2