mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-22 21:34:58 +02:00
[NEW_FEATURE] Automatic Backup System (in progress).
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1226 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
162de3ff6c
commit
f8142f4aad
@ -630,10 +630,6 @@ bool FileManager::moveFile(BufferID id, const TCHAR * newFileName)
|
|||||||
|
|
||||||
bool FileManager::backupCurrentBuffer()
|
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 = _pNotepadPlus->getCurrentBuffer();
|
Buffer * buffer = _pNotepadPlus->getCurrentBuffer();
|
||||||
bool result = false;
|
bool result = false;
|
||||||
bool hasModifForSession = false;
|
bool hasModifForSession = false;
|
||||||
@ -642,6 +638,28 @@ bool FileManager::backupCurrentBuffer()
|
|||||||
{
|
{
|
||||||
if (buffer->isModified()) // buffer dirty and modified, write the backup file
|
if (buffer->isModified()) // buffer dirty and modified, write the backup file
|
||||||
{
|
{
|
||||||
|
// Synchronization
|
||||||
|
// This method is called from 2 differents place, so synchronization is important
|
||||||
|
HANDLE writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent"));
|
||||||
|
if (!writeEvent)
|
||||||
|
{
|
||||||
|
// no thread yet, create a event with non-signaled, to block all threads
|
||||||
|
writeEvent = ::CreateEvent(NULL, TRUE, FALSE, TEXT("nppWrittingEvent"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (::WaitForSingleObject(writeEvent, INFINITE) != WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
|
// problem!!!
|
||||||
|
printStr(TEXT("WaitForSingleObject problem in backupCurrentBuffer()!"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlocled here, set to non-signaled state, to block all threads
|
||||||
|
::ResetEvent(writeEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
UniMode mode = buffer->getUnicodeMode();
|
UniMode mode = buffer->getUnicodeMode();
|
||||||
if (mode == uniCookie)
|
if (mode == uniCookie)
|
||||||
mode = uni8Bit; //set the mode to ANSI to prevent converter from adding BOM and performing conversions, Scintilla's data can be copied directly
|
mode = uni8Bit; //set the mode to ANSI to prevent converter from adding BOM and performing conversions, Scintilla's data can be copied directly
|
||||||
@ -720,16 +738,20 @@ bool FileManager::backupCurrentBuffer()
|
|||||||
}
|
}
|
||||||
UnicodeConvertor.fclose();
|
UnicodeConvertor.fclose();
|
||||||
|
|
||||||
// Error, we didn't write the entire document to disk.
|
|
||||||
// Note that fwrite() doesn't return the number of bytes written, but rather the number of ITEMS.
|
// Note that fwrite() doesn't return the number of bytes written, but rather the number of ITEMS.
|
||||||
if(items_written == 1)
|
if(items_written == 1) // backup file has been saved
|
||||||
{
|
{
|
||||||
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
|
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
|
||||||
buffer->setModifiedStatus(false);
|
buffer->setModifiedStatus(false);
|
||||||
hasModifForSession = true;
|
hasModifForSession = true;
|
||||||
result = true; //all done
|
result = true; //all done
|
||||||
|
|
||||||
|
::SetEvent(writeEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// set to signaled state
|
||||||
|
::SetEvent(writeEvent);
|
||||||
|
::CloseHandle(writeEvent);
|
||||||
}
|
}
|
||||||
else // buffer dirty but unmodified
|
else // buffer dirty but unmodified
|
||||||
{
|
{
|
||||||
@ -751,18 +773,34 @@ bool FileManager::backupCurrentBuffer()
|
|||||||
result = true; // no backup file to delete
|
result = true; // no backup file to delete
|
||||||
}
|
}
|
||||||
//printStr(TEXT("backup sync"));
|
//printStr(TEXT("backup sync"));
|
||||||
|
/*
|
||||||
if (hasModifForSession)
|
if (hasModifForSession)
|
||||||
_pNotepadPlus->saveCurrentSession();
|
_pNotepadPlus->saveCurrentSession();
|
||||||
|
*/
|
||||||
|
|
||||||
::ReleaseMutex(mutex);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileManager::deleteCurrentBufferBackup()
|
bool FileManager::deleteCurrentBufferBackup()
|
||||||
{
|
{
|
||||||
HANDLE mutex = ::CreateMutex(NULL, false, TEXT("nppBackupSystem"));
|
HANDLE writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent"));
|
||||||
::WaitForSingleObject(mutex, INFINITE);
|
if (!writeEvent)
|
||||||
|
{
|
||||||
|
// no thread yet, create a event with non-signaled, to block all threads
|
||||||
|
writeEvent = ::CreateEvent(NULL, TRUE, FALSE, TEXT("nppWrittingEvent"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (::WaitForSingleObject(writeEvent, INFINITE) != WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
|
// problem!!!
|
||||||
|
printStr(TEXT("pb!!!"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlocled here, set to non-signaled state, to block all threads
|
||||||
|
::ResetEvent(writeEvent);
|
||||||
|
}
|
||||||
|
|
||||||
Buffer * buffer = _pNotepadPlus->getCurrentBuffer();
|
Buffer * buffer = _pNotepadPlus->getCurrentBuffer();
|
||||||
bool result = true;
|
bool result = true;
|
||||||
@ -774,12 +812,34 @@ bool FileManager::deleteCurrentBufferBackup()
|
|||||||
buffer->setBackupFileName(TEXT(""));
|
buffer->setBackupFileName(TEXT(""));
|
||||||
result = (::DeleteFile(file2Delete.c_str()) != 0);
|
result = (::DeleteFile(file2Delete.c_str()) != 0);
|
||||||
}
|
}
|
||||||
::ReleaseMutex(mutex);
|
|
||||||
|
// set to signaled state
|
||||||
|
::SetEvent(writeEvent);
|
||||||
|
::CloseHandle(writeEvent);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, generic_string * error_msg)
|
bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, generic_string * error_msg)
|
||||||
{
|
{
|
||||||
|
HANDLE writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent"));
|
||||||
|
if (!writeEvent)
|
||||||
|
{
|
||||||
|
// no thread yet, create a event with non-signaled, to block all threads
|
||||||
|
writeEvent = ::CreateEvent(NULL, TRUE, FALSE, TEXT("nppWrittingEvent"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (::WaitForSingleObject(writeEvent, INFINITE) != WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
|
// problem!!!
|
||||||
|
printStr(TEXT("pb!!!"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlocled here, set to non-signaled state, to block all threads
|
||||||
|
::ResetEvent(writeEvent);
|
||||||
|
}
|
||||||
|
|
||||||
Buffer * buffer = getBufferByID(id);
|
Buffer * buffer = getBufferByID(id);
|
||||||
bool isHidden = false;
|
bool isHidden = false;
|
||||||
bool isSys = false;
|
bool isSys = false;
|
||||||
@ -854,6 +914,10 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
|
|||||||
{
|
{
|
||||||
if(error_msg != NULL)
|
if(error_msg != NULL)
|
||||||
*error_msg = TEXT("Failed to save file.\nNot enough space on disk to save file?");
|
*error_msg = TEXT("Failed to save file.\nNot enough space on disk to save file?");
|
||||||
|
|
||||||
|
// set to signaled state
|
||||||
|
::SetEvent(writeEvent);
|
||||||
|
::CloseHandle(writeEvent);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -866,6 +930,10 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
|
|||||||
if (isCopy)
|
if (isCopy)
|
||||||
{
|
{
|
||||||
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
|
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
|
||||||
|
|
||||||
|
// set to signaled state
|
||||||
|
::SetEvent(writeEvent);
|
||||||
|
::CloseHandle(writeEvent);
|
||||||
return true; //all done
|
return true; //all done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -877,8 +945,14 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
|
|||||||
//_pscratchTilla->markSavedLines();
|
//_pscratchTilla->markSavedLines();
|
||||||
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
|
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault);
|
||||||
|
|
||||||
|
// set to signaled state
|
||||||
|
::SetEvent(writeEvent);
|
||||||
|
::CloseHandle(writeEvent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// set to signaled state
|
||||||
|
::SetEvent(writeEvent);
|
||||||
|
::CloseHandle(writeEvent);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1556,6 +1556,10 @@
|
|||||||
RelativePath="..\src\resource.h"
|
RelativePath="..\src\resource.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\WinControls\Preference\resource.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\src\WinControls\StaticDialog\RunDlg\RunDlg.h"
|
RelativePath="..\src\WinControls\StaticDialog\RunDlg\RunDlg.h"
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user