Skip to content

Commit

Permalink
[NEW_FEATURE] Automatic Backup System (in progress).
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1205 f5eea248-9336-0410-98b8-ebc06183d4e3
  • Loading branch information
donho committed Mar 29, 2014
1 parent 7cbcc1f commit 97c7395
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
4 changes: 1 addition & 3 deletions PowerEditor/src/Notepad_plus.cpp
Expand Up @@ -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;
}
Expand Down
17 changes: 14 additions & 3 deletions PowerEditor/src/NppNotification.cpp
Expand Up @@ -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()) {
Expand All @@ -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;
}

Expand Down
32 changes: 25 additions & 7 deletions PowerEditor/src/ScitillaComponent/Buffer.cpp
Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/ScitillaComponent/Buffer.h
Expand Up @@ -95,7 +95,7 @@ class FileManager {
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);
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp
Expand Up @@ -296,7 +296,7 @@ bool FunctionCallTip::loadFunction() {
_curFunction = funcNode;
break;
}
else
else
{
//name matches, but not a function, abort the entire procedure
return false;
Expand Down

0 comments on commit 97c7395

Please sign in to comment.