-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021 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
#include <boost/filesystem.hpp>
+#include <Basics_Utils.hxx>
+
namespace boofs = boost::filesystem;
//================================================================================
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
+ std::wstring aName = Kernel_Utils::utf8_decode_s(_name);
+ const wchar_t* name = aName.c_str();
+#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 );
#else
close();
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 );
+#endif
_error = err.message();
return !err;
if ( _size >= 0 ) return _size; // size of an open file
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 );
+#endif
_error = err.message();
- return err ? -1 : (long) size;
+ return !err ? (long) size : -1;
}
//================================================================================
bool SMESH_File::exists()
{
boost::system::error_code err;
- bool res = boofs::exists( _name, 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);
+#endif
+
_error = err.message();
return err ? false : res;
bool SMESH_File::isDirectory()
{
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 );
+#endif
_error = err.message();
return err ? false : res;
bool SMESH_File::getInts(std::vector<int>& ints)
{
- int i = 0;
+ size_t i = 0;
while ( i < ints.size() )
{
while ( !isdigit( *_pos ) && !eof()) ++_pos;
bool SMESH_File::openForWriting()
{
-#ifdef WIN32
+ close();
- _file = CreateFile( _name.c_str(), // name of the write
+#ifdef WIN32
+#ifdef UNICODE
+ std::wstring aName = Kernel_Utils::utf8_decode_s(_name);
+ const wchar_t* name = aName.c_str();
+#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
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
return ( _file != INVALID_HANDLE_VALUE );
-
#else
_file = ::open( _name.c_str(),
#else
ssize_t nbWritten = ::write( _file, data, size );
- return ( nbWritten == size );
+ return ( nbWritten == (ssize_t) size );
#endif
}