void Buffer::updateTimeStamp() { struct _stat buf; time_t timeStamp = (generic_stat(_fullPathName.c_str(), &buf)==0)?buf.st_mtime:0; if (timeStamp != _timeStamp) { _timeStamp = timeStamp; doNotify(BufferChangeTimestamp); } };
void Buffer::reload() { struct _stat buf; if (PathFileExists(_fullPathName.c_str()) && not generic_stat(_fullPathName.c_str(), &buf)) { _timeStamp = buf.st_mtime; _currentStatus = DOC_NEEDRELOAD; doNotify(BufferChangeTimestamp | BufferChangeStatus); } }
int Buffer::getFileLength() const { if (_currentStatus == DOC_UNNAMED) return -1; struct _stat buf; if (PathFileExists(_fullPathName.c_str())) { if (!generic_stat(_fullPathName.c_str(), &buf)) return buf.st_size; } return -1; }
generic_string Buffer::getFileTime(fileTimeType ftt) { if (_currentStatus == DOC_UNNAMED) return TEXT(""); struct _stat buf; if (PathFileExists(_fullPathName.c_str())) { if (!generic_stat(_fullPathName.c_str(), &buf)) { time_t rawtime = ftt==ft_created?buf.st_ctime:ftt==ft_modified?buf.st_mtime:buf.st_atime; tm *timeinfo = localtime(&rawtime); const int temBufLen = 64; TCHAR tmpbuf[temBufLen]; generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d %H:%M:%S"), timeinfo); return tmpbuf; } } return TEXT(""); }
bool Buffer::checkFileState() //eturns true if the status has been changed (it can change into DOC_REGULAR too). false otherwise { if (_currentStatus == DOC_UNNAMED) //unsaved document cannot change by environment return false; struct _stat buf; bool isWow64Off = false; NppParameters *pNppParam = NppParameters::getInstance(); if (!PathFileExists(_fullPathName.c_str())) { pNppParam->safeWow64EnableWow64FsRedirection(FALSE); isWow64Off = true; } bool isOK = false; if (_currentStatus != DOC_DELETED && !PathFileExists(_fullPathName.c_str())) //document has been deleted { _currentStatus = DOC_DELETED; _isFileReadOnly = false; _isDirty = true; //dirty sicne no match with filesystem _timeStamp = 0; doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); isOK = true; } else if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName.c_str())) { //document has returned from its grave if (!generic_stat(_fullPathName.c_str(), &buf)) { _isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); _currentStatus = DOC_MODIFIED; _timeStamp = buf.st_mtime; doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); isOK = true; } } else if (!generic_stat(_fullPathName.c_str(), &buf)) { 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; mask |= BufferChangeReadonly; } if (_timeStamp != buf.st_mtime) { _timeStamp = buf.st_mtime; mask |= BufferChangeTimestamp; _currentStatus = DOC_MODIFIED; mask |= BufferChangeStatus; //status always 'changes', even if from modified to modified } if (mask != 0) { doNotify(mask); isOK = true; } isOK = false; } if (isWow64Off) { pNppParam->safeWow64EnableWow64FsRedirection(TRUE); //isWow64Off = false; } return isOK; }