Change timestamp functions from _stat to GetFileAttributes,

should work with 2003 and 2005 compilers.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@287 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
harrybharry 2008-07-11 16:59:07 +00:00
parent 096f030843
commit 96299bc218
3 changed files with 51 additions and 27 deletions

View File

@ -81,10 +81,20 @@ void Buffer::determinateFormat(char *data) {
long Buffer::_recentTagCtr = 0; long Buffer::_recentTagCtr = 0;
void Buffer::updateTimeStamp() { void Buffer::updateTimeStamp() {
struct _stat buf; if (isUntitled()) {
time_t timeStamp = (_stat(_fullPathName, &buf)==0)?buf.st_mtime:0; //Cannot check the time for non-existant files
return;
}
FILETIME timeStamp;
WIN32_FILE_ATTRIBUTE_DATA fad;
BOOL res = ::GetFileAttributesEx(_fullPathName, GetFileExInfoStandard, &fad);
timeStamp = fad.ftLastWriteTime;
if (!res) {
//Failure!
return;
}
if (timeStamp != _timeStamp) { if (timeStamp.dwLowDateTime != _timeStamp.dwLowDateTime || timeStamp.dwHighDateTime != _timeStamp.dwHighDateTime) {
_timeStamp = timeStamp; _timeStamp = timeStamp;
doNotify(BufferChangeTimestamp); doNotify(BufferChangeTimestamp);
} }
@ -143,7 +153,8 @@ void Buffer::setFileName(const char *fn, LangType defaultLang)
} }
bool Buffer::checkFileState() { //returns true if the status has been changed (it can change into DOC_REGULAR too). false otherwise bool Buffer::checkFileState() { //returns true if the status has been changed (it can change into DOC_REGULAR too). false otherwise
struct _stat buf; FILETIME timeStamp;
WIN32_FILE_ATTRIBUTE_DATA fad;
if (_currentStatus == DOC_UNNAMED) //unsaved document cannot change by environment if (_currentStatus == DOC_UNNAMED) //unsaved document cannot change by environment
return false; return false;
@ -152,36 +163,40 @@ bool Buffer::checkFileState() { //returns true if the status has been changed (i
{ {
_currentStatus = DOC_DELETED; _currentStatus = DOC_DELETED;
_isFileReadOnly = false; _isFileReadOnly = false;
_isDirty = true; //dirty sicne no match with filesystem _isDirty = true; //dirty since no match with filesystem
_timeStamp = 0; _timeStamp.dwLowDateTime = 0;
_timeStamp.dwHighDateTime = 0;
doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp);
return true; return true;
} }
if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName)) BOOL res = ::GetFileAttributesEx(_fullPathName, GetFileExInfoStandard, &fad);
{ //document has returned from its grave timeStamp = fad.ftLastWriteTime;
if (!_stat(_fullPathName, &buf)) bool readOnly = (fad.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0;
{
_isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE));
_currentStatus = DOC_MODIFIED; if (!res) {
_timeStamp = buf.st_mtime; //Failed getting attributes, the file may have been deleted
doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp);
return true;
}
} }
if (!_stat(_fullPathName, &buf)) if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName))
{ //document has returned from its grave
_isFileReadOnly = readOnly;
_currentStatus = DOC_MODIFIED;
_timeStamp = timeStamp;
doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp);
return true;
}
if (res)
{ {
int mask = 0; //status always 'changes', even if from modified to modified int mask = 0;
bool isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); if (readOnly != _isFileReadOnly) {
if (isFileReadOnly != _isFileReadOnly) { _isFileReadOnly = readOnly;
_isFileReadOnly = isFileReadOnly;
mask |= BufferChangeReadonly; mask |= BufferChangeReadonly;
} }
if (_timeStamp != buf.st_mtime) { if (timeStamp.dwLowDateTime != _timeStamp.dwLowDateTime || timeStamp.dwHighDateTime != _timeStamp.dwHighDateTime) {
_timeStamp = buf.st_mtime; _timeStamp = timeStamp;
mask |= BufferChangeTimestamp; mask |= BufferChangeTimestamp;
_currentStatus = DOC_MODIFIED; _currentStatus = DOC_MODIFIED;
mask |= BufferChangeStatus; //status always 'changes', even if from modified to modified mask |= BufferChangeStatus; //status always 'changes', even if from modified to modified

View File

@ -133,7 +133,7 @@ public :
//Destructor makes sure its purged //Destructor makes sure its purged
Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const char *fileName) //type must be either DOC_REGULAR or DOC_UNNAMED Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const char *fileName) //type must be either DOC_REGULAR or DOC_UNNAMED
: _pManager(pManager), _id(id), _isDirty(false), _doc(doc), _isFileReadOnly(false), _isUserReadOnly(false), _recentTag(-1), _references(0), : _pManager(pManager), _id(id), _isDirty(false), _doc(doc), _isFileReadOnly(false), _isUserReadOnly(false), _recentTag(-1), _references(0),
_canNotify(false), _timeStamp(0), _needReloading(false) _canNotify(false), _needReloading(false)
{ {
NppParameters *pNppParamInst = NppParameters::getInstance(); NppParameters *pNppParamInst = NppParameters::getInstance();
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings();
@ -143,6 +143,8 @@ public :
_userLangExt[0] = 0; _userLangExt[0] = 0;
_fullPathName[0] = 0; _fullPathName[0] = 0;
_fileName = NULL; _fileName = NULL;
_timeStamp.dwLowDateTime = 0;
_timeStamp.dwHighDateTime = 0;
setFileName(fileName, ndds._lang); setFileName(fileName, ndds._lang);
updateTimeStamp(); updateTimeStamp();
checkFileState(); checkFileState();
@ -258,7 +260,7 @@ public :
return _currentStatus; return _currentStatus;
}; };
time_t getTimeStamp() const { FILETIME getTimeStamp() const {
return _timeStamp; return _timeStamp;
}; };
@ -356,7 +358,8 @@ private :
//Environment properties //Environment properties
DocFileStatus _currentStatus; DocFileStatus _currentStatus;
time_t _timeStamp; // 0 if it's a new doc //time_t _timeStamp; // 0 if it's a new doc
FILETIME _timeStamp; // 0 if it's a new doc
bool _isFileReadOnly; bool _isFileReadOnly;
char _fullPathName[MAX_PATH]; char _fullPathName[MAX_PATH];
char * _fileName; //points to filename part in _fullPathName char * _fileName; //points to filename part in _fullPathName

View File

@ -232,6 +232,9 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
<File <File
RelativePath="..\src\ScitillaComponent\UserDefineDialog.cpp"> RelativePath="..\src\ScitillaComponent\UserDefineDialog.cpp">
</File> </File>
<File
RelativePath="..\src\ScitillaComponent\xmlMatchedTagsHighlighter.cpp">
</File>
</Filter> </Filter>
<Filter <Filter
Name="TinyXML" Name="TinyXML"
@ -459,6 +462,9 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
<File <File
RelativePath="..\src\ScitillaComponent\UserDefineResource.h"> RelativePath="..\src\ScitillaComponent\UserDefineResource.h">
</File> </File>
<File
RelativePath="..\src\ScitillaComponent\xmlMatchedTagsHighlighter.h">
</File>
</Filter> </Filter>
<Filter <Filter
Name="TinyXML" Name="TinyXML"