Added some error checking during file saving.

Closese #1930
pull/1094/merge
Don HO 8 years ago
parent fe7257faf1
commit 38ddd32ac5

@ -1176,7 +1176,11 @@ bool Notepad_plus::fileSave(BufferID id)
fn_bak = fn; fn_bak = fn;
} }
fn_bak += TEXT(".bak"); fn_bak += TEXT(".bak");
::CopyFile(fn, fn_bak.c_str(), FALSE);
if (not ::CopyFile(fn, fn_bak.c_str(), FALSE))
{
return false;
}
} }
else if (backup == bak_verbose) else if (backup == bak_verbose)
{ {
@ -1221,7 +1225,10 @@ bool Notepad_plus::fileSave(BufferID id)
fn_dateTime_bak += tmpbuf; fn_dateTime_bak += tmpbuf;
fn_dateTime_bak += TEXT(".bak"); fn_dateTime_bak += TEXT(".bak");
::CopyFile(fn, fn_dateTime_bak.c_str(), FALSE); if (not ::CopyFile(fn, fn_dateTime_bak.c_str(), FALSE))
{
return false;
}
} }
return doSave(bufferID, buf->getFullPathName(), false); return doSave(bufferID, buf->getFullPathName(), false);
} }

@ -805,22 +805,30 @@ bool FileManager::backupCurrentBuffer()
// Synchronization // Synchronization
// 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 writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent")); HANDLE writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent"));
if (!writeEvent) if (not writeEvent)
{ {
// no thread yet, create a event with non-signaled, to block all threads // no thread yet, create a event with non-signaled, to block all threads
writeEvent = ::CreateEvent(NULL, TRUE, FALSE, TEXT("nppWrittingEvent")); writeEvent = ::CreateEvent(NULL, TRUE, FALSE, TEXT("nppWrittingEvent"));
if (not writeEvent)
{
printStr(TEXT("CreateEvent problem in backupCurrentBuffer()!"));
return false;
}
} }
else else
{ {
if (::WaitForSingleObject(writeEvent, INFINITE) != WAIT_OBJECT_0) if (::WaitForSingleObject(writeEvent, INFINITE) != WAIT_OBJECT_0)
{ {
// problem!!!
printStr(TEXT("WaitForSingleObject problem in backupCurrentBuffer()!")); printStr(TEXT("WaitForSingleObject problem in backupCurrentBuffer()!"));
return false; return false;
} }
// unlocled here, set to non-signaled state, to block all threads // unlocled here, set to non-signaled state, to block all threads
::ResetEvent(writeEvent); if (not ::ResetEvent(writeEvent))
{
printStr(TEXT("ResetEvent problem in backupCurrentBuffer()!"));
return false;
}
} }
UniMode mode = buffer->getUnicodeMode(); UniMode mode = buffer->getUnicodeMode();

Loading…
Cancel
Save