mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-05 18:16:23 +03:00
0027675: Foundation Classes - handle Unicode path to CSF_UnitsLexicon and CSF_UnitsDefinition on Windows
Units package now uses Unicode-aware functions OSD_OpenStream and OSD_FileStatCTime (introduced for fetching file timestamp).
This commit is contained in:
parent
4aa09e317f
commit
ce0594b85e
@ -19,6 +19,9 @@
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <NCollection_UtfString.hxx>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
// ==============================================
|
||||
// function : OSD_OpenFile
|
||||
// purpose : Opens file
|
||||
@ -160,3 +163,28 @@ void OSD_OpenStream (std::ifstream& theStream,
|
||||
theStream.open (aString.ToCString(), theMode);
|
||||
#endif
|
||||
}
|
||||
|
||||
// ==============================================
|
||||
// function : OSD_FileStatCTime
|
||||
// purpose :
|
||||
// ==============================================
|
||||
Standard_Time OSD_FileStatCTime (const char* theName)
|
||||
{
|
||||
Standard_Time aTime = 0;
|
||||
#if defined(_WIN32)
|
||||
// file name is treated as UTF-8 string and converted to UTF-16 one
|
||||
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
|
||||
struct __stat64 aStat;
|
||||
if (_wstat64 ((const wchar_t* )aFileNameW.ToExtString(), &aStat) == 0)
|
||||
{
|
||||
aTime = (Standard_Time )aStat.st_ctime;
|
||||
}
|
||||
#else
|
||||
struct stat aStat;
|
||||
if (stat (theName, &aStat) == 0)
|
||||
{
|
||||
aTime = (Standard_Time )aStat.st_ctime;
|
||||
}
|
||||
#endif
|
||||
return aTime;
|
||||
}
|
||||
|
@ -80,6 +80,11 @@ __Standard_API void OSD_OpenFileBuf (std::filebuf& theBuff,
|
||||
__Standard_API FILE* OSD_OpenFile (const TCollection_ExtendedString& theName,
|
||||
const char* theMode);
|
||||
|
||||
//! Function retrieves file timestamp.
|
||||
//! @param theName name of file encoded in UTF-8
|
||||
//! @return stat.st_ctime value
|
||||
__Standard_API Standard_Time OSD_FileStatCTime (const char* theName);
|
||||
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
|
@ -22,8 +22,6 @@
|
||||
// Convertir correctement les unites translatees
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <Units.hxx>
|
||||
#include <Units_Measurement.hxx>
|
||||
|
@ -14,16 +14,15 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Units_Lexicon.hxx>
|
||||
|
||||
#include <OSD.hxx>
|
||||
#include <OSD_OpenFile.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
#include <Units_Lexicon.hxx>
|
||||
#include <Units_Token.hxx>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Units_Lexicon,MMgt_TShared)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@ -56,7 +55,8 @@ static inline bool strrightadjust (char *str)
|
||||
|
||||
void Units_Lexicon::Creates(const Standard_CString afilename)
|
||||
{
|
||||
ifstream file(afilename, ios::in);
|
||||
std::ifstream file;
|
||||
OSD_OpenStream (file, afilename, std::ios::in);
|
||||
if(!file) {
|
||||
#ifdef OCCT_DEBUG
|
||||
cout<<"unable to open "<<afilename<<" for input"<<endl;
|
||||
@ -66,9 +66,7 @@ void Units_Lexicon::Creates(const Standard_CString afilename)
|
||||
|
||||
thefilename = new TCollection_HAsciiString(afilename);
|
||||
thesequenceoftokens = new Units_TokensSequence();
|
||||
|
||||
struct stat buf;
|
||||
if(!stat(afilename,&buf)) thetime = buf.st_ctime;
|
||||
thetime = OSD_FileStatCTime (afilename);
|
||||
|
||||
// read file line-by-line; each line has fixed format:
|
||||
// first 30 symbols for prefix or symbol (e.g. "k" for kilo)
|
||||
@ -122,15 +120,10 @@ void Units_Lexicon::Creates(const Standard_CString afilename)
|
||||
|
||||
Standard_Boolean Units_Lexicon::UpToDate() const
|
||||
{
|
||||
struct stat buf;
|
||||
TCollection_AsciiString string = FileName();
|
||||
|
||||
if(!stat(string.ToCString(),&buf)) {
|
||||
if(thetime >= (Standard_Time)buf.st_ctime)
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
return Standard_False;
|
||||
TCollection_AsciiString aPath = FileName();
|
||||
Standard_Time aTime = OSD_FileStatCTime (aPath.ToCString());
|
||||
return aTime != 0
|
||||
&& aTime <= thetime;
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,8 +14,10 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Units_UnitsDictionary.hxx>
|
||||
|
||||
#include <OSD.hxx>
|
||||
#include <OSD_OpenFile.hxx>
|
||||
#include <Standard_Stream.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
@ -31,13 +33,12 @@
|
||||
#include <Units_Token.hxx>
|
||||
#include <Units_TokensSequence.hxx>
|
||||
#include <Units_Unit.hxx>
|
||||
#include <Units_UnitsDictionary.hxx>
|
||||
#include <Units_UnitSentence.hxx>
|
||||
#include <Units_UnitsLexicon.hxx>
|
||||
#include <Units_UnitsSequence.hxx>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Units_UnitsDictionary,MMgt_TShared)
|
||||
|
||||
//=======================================================================
|
||||
@ -69,8 +70,9 @@ void Units_UnitsDictionary::Creates(const Standard_CString afilename)
|
||||
Handle(Units_Unit) unit;
|
||||
Handle(Units_ShiftedUnit) shiftedunit;
|
||||
Handle(Units_Quantity) quantity;
|
||||
|
||||
ifstream file(afilename, ios::in);
|
||||
|
||||
std::ifstream file;
|
||||
OSD_OpenStream (file, afilename, std::ios::in);
|
||||
if(!file) {
|
||||
#ifdef OCCT_DEBUG
|
||||
cout<<"unable to open "<<afilename<<" for input"<<endl;
|
||||
@ -79,9 +81,7 @@ void Units_UnitsDictionary::Creates(const Standard_CString afilename)
|
||||
}
|
||||
|
||||
thefilename = new TCollection_HAsciiString(afilename);
|
||||
|
||||
struct stat buf;
|
||||
if(!stat(afilename,&buf)) thetime = buf.st_ctime;
|
||||
thetime = OSD_FileStatCTime (afilename);
|
||||
|
||||
thequantitiessequence = new Units_QuantitiesSequence();
|
||||
|
||||
@ -314,16 +314,11 @@ void Units_UnitsDictionary::Creates(const Standard_CString afilename)
|
||||
|
||||
Standard_Boolean Units_UnitsDictionary::UpToDate() const
|
||||
{
|
||||
struct stat buf;
|
||||
TCollection_AsciiString string = thefilename->String();
|
||||
if(!stat(string.ToCString(),&buf)) {
|
||||
if(thetime == (Standard_Time)buf.st_ctime) return Standard_True;
|
||||
}
|
||||
|
||||
return Standard_False;
|
||||
Standard_Time aTime = OSD_FileStatCTime (thefilename->String().ToCString());
|
||||
return aTime != 0
|
||||
&& aTime == thetime;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : ActiveUnit
|
||||
//purpose :
|
||||
|
@ -14,17 +14,16 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Units_UnitsLexicon.hxx>
|
||||
|
||||
#include <OSD_OpenFile.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
#include <Units.hxx>
|
||||
#include <Units_Token.hxx>
|
||||
#include <Units_UnitsDictionary.hxx>
|
||||
#include <Units_UnitsLexicon.hxx>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Units_UnitsLexicon,Units_Lexicon)
|
||||
|
||||
//=======================================================================
|
||||
@ -44,11 +43,13 @@ void Units_UnitsLexicon::Creates(const Standard_CString afilename1,
|
||||
const Standard_Boolean amode)
|
||||
{
|
||||
Handle(Units_UnitsDictionary) unitsdictionary;
|
||||
struct stat buf;
|
||||
|
||||
thefilename = new TCollection_HAsciiString(afilename2);
|
||||
|
||||
if(!stat(afilename2,&buf)) thetime = buf.st_ctime;
|
||||
Standard_Time aTime2 = OSD_FileStatCTime (afilename2);
|
||||
if (aTime2 != 0)
|
||||
{
|
||||
thetime = aTime2;
|
||||
}
|
||||
|
||||
Units_Lexicon::Creates(afilename1);
|
||||
|
||||
@ -63,18 +64,15 @@ void Units_UnitsLexicon::Creates(const Standard_CString afilename1,
|
||||
|
||||
Standard_Boolean Units_UnitsLexicon::UpToDate() const
|
||||
{
|
||||
struct stat buf;
|
||||
TCollection_AsciiString string = FileName2();
|
||||
TCollection_AsciiString aPath = FileName2();
|
||||
if (!Units_Lexicon::UpToDate())
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
if(Units_Lexicon::UpToDate())
|
||||
{
|
||||
if(!stat(string.ToCString(),&buf))
|
||||
{
|
||||
if(thetime >= (Standard_Time)buf.st_ctime) return Standard_True;
|
||||
}
|
||||
}
|
||||
|
||||
return Standard_False;
|
||||
Standard_Time aTime = OSD_FileStatCTime (aPath.ToCString());
|
||||
return aTime != 0
|
||||
&& aTime <= thetime;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
Loading…
x
Reference in New Issue
Block a user