[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:
parent
7cbcc1f902
commit
97c7395059
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue