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:
parent
096f030843
commit
96299bc218
|
@ -81,10 +81,20 @@ void Buffer::determinateFormat(char *data) {
|
|||
long Buffer::_recentTagCtr = 0;
|
||||
|
||||
void Buffer::updateTimeStamp() {
|
||||
struct _stat buf;
|
||||
time_t timeStamp = (_stat(_fullPathName, &buf)==0)?buf.st_mtime:0;
|
||||
if (isUntitled()) {
|
||||
//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;
|
||||
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
|
||||
struct _stat buf;
|
||||
FILETIME timeStamp;
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
|
||||
if (_currentStatus == DOC_UNNAMED) //unsaved document cannot change by environment
|
||||
return false;
|
||||
|
@ -152,36 +163,40 @@ bool Buffer::checkFileState() { //returns true if the status has been changed (i
|
|||
{
|
||||
_currentStatus = DOC_DELETED;
|
||||
_isFileReadOnly = false;
|
||||
_isDirty = true; //dirty sicne no match with filesystem
|
||||
_timeStamp = 0;
|
||||
_isDirty = true; //dirty since no match with filesystem
|
||||
_timeStamp.dwLowDateTime = 0;
|
||||
_timeStamp.dwHighDateTime = 0;
|
||||
doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName))
|
||||
{ //document has returned from its grave
|
||||
if (!_stat(_fullPathName, &buf))
|
||||
{
|
||||
_isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE));
|
||||
BOOL res = ::GetFileAttributesEx(_fullPathName, GetFileExInfoStandard, &fad);
|
||||
timeStamp = fad.ftLastWriteTime;
|
||||
bool readOnly = (fad.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0;
|
||||
|
||||
_currentStatus = DOC_MODIFIED;
|
||||
_timeStamp = buf.st_mtime;
|
||||
doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp);
|
||||
return true;
|
||||
}
|
||||
if (!res) {
|
||||
//Failed getting attributes, the file may have been deleted
|
||||
}
|
||||
|
||||
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
|
||||
bool isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE));
|
||||
if (isFileReadOnly != _isFileReadOnly) {
|
||||
_isFileReadOnly = isFileReadOnly;
|
||||
int mask = 0;
|
||||
if (readOnly != _isFileReadOnly) {
|
||||
_isFileReadOnly = readOnly;
|
||||
mask |= BufferChangeReadonly;
|
||||
}
|
||||
|
||||
if (_timeStamp != buf.st_mtime) {
|
||||
_timeStamp = buf.st_mtime;
|
||||
if (timeStamp.dwLowDateTime != _timeStamp.dwLowDateTime || timeStamp.dwHighDateTime != _timeStamp.dwHighDateTime) {
|
||||
_timeStamp = timeStamp;
|
||||
mask |= BufferChangeTimestamp;
|
||||
_currentStatus = DOC_MODIFIED;
|
||||
mask |= BufferChangeStatus; //status always 'changes', even if from modified to modified
|
||||
|
|
|
@ -133,7 +133,7 @@ public :
|
|||
//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
|
||||
: _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();
|
||||
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings();
|
||||
|
@ -143,6 +143,8 @@ public :
|
|||
_userLangExt[0] = 0;
|
||||
_fullPathName[0] = 0;
|
||||
_fileName = NULL;
|
||||
_timeStamp.dwLowDateTime = 0;
|
||||
_timeStamp.dwHighDateTime = 0;
|
||||
setFileName(fileName, ndds._lang);
|
||||
updateTimeStamp();
|
||||
checkFileState();
|
||||
|
@ -258,7 +260,7 @@ public :
|
|||
return _currentStatus;
|
||||
};
|
||||
|
||||
time_t getTimeStamp() const {
|
||||
FILETIME getTimeStamp() const {
|
||||
return _timeStamp;
|
||||
};
|
||||
|
||||
|
@ -356,7 +358,8 @@ private :
|
|||
|
||||
//Environment properties
|
||||
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;
|
||||
char _fullPathName[MAX_PATH];
|
||||
char * _fileName; //points to filename part in _fullPathName
|
||||
|
|
|
@ -232,6 +232,9 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
|
|||
<File
|
||||
RelativePath="..\src\ScitillaComponent\UserDefineDialog.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\ScitillaComponent\xmlMatchedTagsHighlighter.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="TinyXML"
|
||||
|
@ -459,6 +462,9 @@ IF NOT EXIST ..\bin\userDefineLang.xml COPY ..\src\userDefineLang.xml ..\bin\use
|
|||
<File
|
||||
RelativePath="..\src\ScitillaComponent\UserDefineResource.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\ScitillaComponent\xmlMatchedTagsHighlighter.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="TinyXML"
|
||||
|
|
Loading…
Reference in New Issue