From 97c73950593558a52b3575f8a54017cf0766ad9e Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 29 Mar 2014 00:01:33 +0000 Subject: [PATCH] [NEW_FEATURE] Automatic Backup System (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1205 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 4 +-- PowerEditor/src/NppNotification.cpp | 17 ++++++++-- PowerEditor/src/ScitillaComponent/Buffer.cpp | 32 +++++++++++++++---- PowerEditor/src/ScitillaComponent/Buffer.h | 2 +- .../src/ScitillaComponent/FunctionCallTip.cpp | 2 +- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index fde5afed2..acc7bf0e3 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -5793,9 +5793,7 @@ DWORD WINAPI Notepad_plus::backupDocument(void *param) ::Sleep(3000); //printInt(i++); - // if current document is dirty, write it in the backup system - Buffer *currentBuffer = notepad_plus->getCurrentBuffer(); - MainFileManager->backupBuffer((BufferID)currentBuffer, currentBuffer->getFullPathName()); + MainFileManager->backupCurrentBuffer(); } return TRUE; } diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 8bc52da78..50a43c518 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -82,11 +82,16 @@ BOOL Notepad_plus::notify(SCNotification *notification) case SCN_SAVEPOINTLEFT: { Buffer * buf = 0; - if (isFromPrimary) { + if (isFromPrimary) + { buf = _mainEditView.getCurrentBuffer(); - } else if (isFromSecondary) { + } + else if (isFromSecondary) + { buf = _subEditView.getCurrentBuffer(); - } else { + } + else + { //Done by invisibleEditView? BufferID id = BUFFER_INVALID; if (notification->nmhdr.hwndFrom == _invisibleEditView.getHSelf()) { @@ -104,6 +109,12 @@ BOOL Notepad_plus::notify(SCNotification *notification) } bool isDirty = notification->nmhdr.code == SCN_SAVEPOINTLEFT; buf->setDirty(isDirty); +/* + if (notification->nmhdr.code == SCN_SAVEPOINTREACHED) + { + MainFileManager->backupCurrentBuffer(); + } +*/ break; } diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 9bd6f19b0..9074344f2 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -613,18 +613,13 @@ bool FileManager::moveFile(BufferID id, const TCHAR * newFileName) return true; } -bool FileManager::backupBuffer(BufferID id, const TCHAR * filename) +bool FileManager::backupCurrentBuffer() { // 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); - + Buffer * buffer = _pNotepadPlus->getCurrentBuffer(); bool result = false; /* @@ -656,6 +651,29 @@ bool FileManager::backupBuffer(BufferID id, const TCHAR * filename) int encoding = buffer->getEncoding(); + + generic_string backupFilePath = NppParameters::getInstance()->getUserPath(); + if (buffer->getBackupFileName() == TEXT("")) + { + // Create file name + if (buffer->isUntitled()) + { + + } + else + { + + } + + // Set created file name in buffer + //backupFilePath += + } + + + TCHAR fullpath[MAX_PATH]; + ::GetFullPathName(backupFilePath.c_str(), MAX_PATH, fullpath, NULL); + ::GetLongPathName(fullpath, fullpath, MAX_PATH); + FILE *fp = UnicodeConvertor.fopen(fullpath, TEXT("wb")); if (fp) { diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index be9453a33..34d70e576 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -95,7 +95,7 @@ public: bool reloadBuffer(BufferID id); bool reloadBufferDeferred(BufferID id); bool saveBuffer(BufferID id, const TCHAR * filename, bool isCopy = false, generic_string * error_msg = NULL); - bool backupBuffer(BufferID id, const TCHAR * filename); + bool backupCurrentBuffer(); bool deleteFile(BufferID id); bool moveFile(BufferID id, const TCHAR * newFilename); bool createEmptyFile(const TCHAR * path); diff --git a/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp b/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp index 5f3c4934a..b6807e9d2 100644 --- a/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp +++ b/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp @@ -296,7 +296,7 @@ bool FunctionCallTip::loadFunction() { _curFunction = funcNode; break; } - else + else { //name matches, but not a function, abort the entire procedure return false;