diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 260a4c5a1..fde5afed2 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -5760,26 +5760,7 @@ int Notepad_plus::getQuoteIndexFrom(const char *quoter) const void Notepad_plus::showAllQuotes() const { - /* - HANDLE mutex = ::CreateMutex(NULL, false, TEXT("nppTextWriter")); - for (int i = 0; i < nbQuote; i++) - { - static bool firstTime = true; - if (firstTime) - { - firstTime = false; - } - else - { - WaitForSingleObject(mutex, INFINITE); - - } - ReleaseMutex(mutex); - Sleep(1000); - showQuoteFromIndex(i); - WaitForSingleObject(mutex, INFINITE); - } - */ + } void Notepad_plus::showQuoteFromIndex(int index) const diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 03553c6cc..9bd6f19b0 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -615,12 +615,18 @@ bool FileManager::moveFile(BufferID id, const TCHAR * newFileName) bool FileManager::backupBuffer(BufferID id, const TCHAR * filename) { + // This method is called from 2 differents place, so synchronization is important + HANDLE mutex = ::CreateMutex(NULL, false, TEXT("nppBackupSystem")); + ::WaitForSingleObject(mutex, INFINITE); + Buffer * buffer = getBufferByID(id); TCHAR fullpath[MAX_PATH]; ::GetFullPathName(filename, MAX_PATH, fullpath, NULL); ::GetLongPathName(fullpath, fullpath, MAX_PATH); + bool result = false; + /* time_t currentBakModifTimestamp = buffer->getBackupModifiedTimeStamp(); time_t lastBakModifTimestamp = 0; @@ -687,33 +693,33 @@ bool FileManager::backupBuffer(BufferID id, const TCHAR * filename) // Error, we didn't write the entire document to disk. // Note that fwrite() doesn't return the number of bytes written, but rather the number of ITEMS. - if(items_written != 1) - { - return false; - } - - _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); - /* - if (lastBakModifTimestamp != 0) - buffer->setBackupModifiedTimeStamp(lastBakModifTimestamp); - else + if(items_written == 1) { - struct _stat statBuf; - if (!generic_stat(fullpath, &statBuf)) + + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); + /* + if (lastBakModifTimestamp != 0) + buffer->setBackupModifiedTimeStamp(lastBakModifTimestamp); + else { - buffer->setBackupModifiedTimeStamp(statBuf.st_mtime); + struct _stat statBuf; + if (!generic_stat(fullpath, &statBuf)) + { + buffer->setBackupModifiedTimeStamp(statBuf.st_mtime); + } } - } - */ - - buffer->setModifiedStatus(false); + */ + + buffer->setModifiedStatus(false); - return true; //all done + result = true; //all done + } } - return false; // fopen failed } - - return true; // buffer dirty nut unmodified + else // buffer dirty but unmodified + { + result = true; + } } else // buffer not dirty, sync: delete the backup file { @@ -722,10 +728,12 @@ bool FileManager::backupBuffer(BufferID id, const TCHAR * filename) { // delete backup file - return true; // backup file deleted } - return true; // no backup file to delete + result = true; // no backup file to delete } + + ::ReleaseMutex(mutex); + return result; } bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, generic_string * error_msg)