[NEW_FEATURE] Automatic Backup System (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1205 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2014-03-29 00:01:33 +00:00
parent 7cbcc1f902
commit 97c7395059
5 changed files with 42 additions and 15 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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);

View File

@ -296,7 +296,7 @@ bool FunctionCallTip::loadFunction() {
_curFunction = funcNode;
break;
}
else
else
{
//name matches, but not a function, abort the entire procedure
return false;