Salome HOME
Update copyrights
[modules/smesh.git] / src / SMESHUtils / SMESH_File.cxx
index 10c1f533f1d4a238613f739a18aa51a1233d453c..9cd05397b9d343fd42747beffdceb84c5e7db531 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -36,6 +36,8 @@
 
 #include <boost/filesystem.hpp>
 
+#include <Basics_Utils.hxx>
+
 namespace boofs = boost::filesystem;
 
 //================================================================================
@@ -75,13 +77,21 @@ SMESH_File::~SMESH_File()
 
 bool SMESH_File::open()
 {
-  int length = size();
+  long length = size();
   if ( !_map && length > 0 )
   {
 #ifdef WIN32
-    _file = CreateFile(_name.data(), GENERIC_READ, FILE_SHARE_READ,
+#ifdef UNICODE
+         const wchar_t* name = Kernel_Utils::decode(_name.data());
+#else
+         char* name = name.data();
+#endif
+    _file = CreateFile(name, GENERIC_READ, FILE_SHARE_READ,
                        NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
     bool ok = ( _file != INVALID_HANDLE_VALUE );
+#ifdef UNICODE
+       delete name;
+#endif
 #else
     _file = ::open(_name.data(), O_RDONLY );
     bool ok = ( _file >= 0 );
@@ -188,7 +198,7 @@ long SMESH_File::size()
   boost::uintmax_t size = boofs::file_size( _name, err );
   _error = err.message();
 
-  return err ? -1 : (long) size;
+  return !err ? (long) size : -1;
 }
 
 //================================================================================
@@ -291,14 +301,21 @@ bool SMESH_File::getInts(std::vector<int>& ints)
 bool SMESH_File::openForWriting()
 {
 #ifdef WIN32
-
-  _file = CreateFile( _name.c_str(),          // name of the write
+#ifdef UNICODE
+       const wchar_t* name = Kernel_Utils::decode(_name.data());
+#else
+       char* name = name.data();
+#endif
+  _file = CreateFile( name,          // name of the write
                       GENERIC_WRITE,          // open for writing
                       0,                      // do not share
                       NULL,                   // default security
                       OPEN_ALWAYS,            // CREATE NEW or OPEN EXISTING
                       FILE_ATTRIBUTE_NORMAL,  // normal file
                       NULL);                  // no attr. template
+#ifdef UNICODE
+  delete name;
+#endif
   return ( _file != INVALID_HANDLE_VALUE );
 
 #else