[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); ::Sleep(3000);
//printInt(i++); //printInt(i++);
// if current document is dirty, write it in the backup system MainFileManager->backupCurrentBuffer();
Buffer *currentBuffer = notepad_plus->getCurrentBuffer();
MainFileManager->backupBuffer((BufferID)currentBuffer, currentBuffer->getFullPathName());
} }
return TRUE; return TRUE;
} }

View File

@ -82,11 +82,16 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case SCN_SAVEPOINTLEFT: case SCN_SAVEPOINTLEFT:
{ {
Buffer * buf = 0; Buffer * buf = 0;
if (isFromPrimary) { if (isFromPrimary)
{
buf = _mainEditView.getCurrentBuffer(); buf = _mainEditView.getCurrentBuffer();
} else if (isFromSecondary) { }
else if (isFromSecondary)
{
buf = _subEditView.getCurrentBuffer(); buf = _subEditView.getCurrentBuffer();
} else { }
else
{
//Done by invisibleEditView? //Done by invisibleEditView?
BufferID id = BUFFER_INVALID; BufferID id = BUFFER_INVALID;
if (notification->nmhdr.hwndFrom == _invisibleEditView.getHSelf()) { if (notification->nmhdr.hwndFrom == _invisibleEditView.getHSelf()) {
@ -104,6 +109,12 @@ BOOL Notepad_plus::notify(SCNotification *notification)
} }
bool isDirty = notification->nmhdr.code == SCN_SAVEPOINTLEFT; bool isDirty = notification->nmhdr.code == SCN_SAVEPOINTLEFT;
buf->setDirty(isDirty); buf->setDirty(isDirty);
/*
if (notification->nmhdr.code == SCN_SAVEPOINTREACHED)
{
MainFileManager->backupCurrentBuffer();
}
*/
break; break;
} }

View File

@ -613,18 +613,13 @@ bool FileManager::moveFile(BufferID id, const TCHAR * newFileName)
return true; 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 // This method is called from 2 differents place, so synchronization is important
HANDLE mutex = ::CreateMutex(NULL, false, TEXT("nppBackupSystem")); HANDLE mutex = ::CreateMutex(NULL, false, TEXT("nppBackupSystem"));
::WaitForSingleObject(mutex, INFINITE); ::WaitForSingleObject(mutex, INFINITE);
Buffer * buffer = getBufferByID(id); Buffer * buffer = _pNotepadPlus->getCurrentBuffer();
TCHAR fullpath[MAX_PATH];
::GetFullPathName(filename, MAX_PATH, fullpath, NULL);
::GetLongPathName(fullpath, fullpath, MAX_PATH);
bool result = false; bool result = false;
/* /*
@ -656,6 +651,29 @@ bool FileManager::backupBuffer(BufferID id, const TCHAR * filename)
int encoding = buffer->getEncoding(); 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")); FILE *fp = UnicodeConvertor.fopen(fullpath, TEXT("wb"));
if (fp) if (fp)
{ {

View File

@ -95,7 +95,7 @@ public:
bool reloadBuffer(BufferID id); bool reloadBuffer(BufferID id);
bool reloadBufferDeferred(BufferID id); bool reloadBufferDeferred(BufferID id);
bool saveBuffer(BufferID id, const TCHAR * filename, bool isCopy = false, generic_string * error_msg = NULL); 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 deleteFile(BufferID id);
bool moveFile(BufferID id, const TCHAR * newFilename); bool moveFile(BufferID id, const TCHAR * newFilename);
bool createEmptyFile(const TCHAR * path); bool createEmptyFile(const TCHAR * path);