[BUG_FIXED] Fix a saving issue in session snapshot & periodic backup feature while backup file is deleted or read-only.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1247 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/trunk
Don Ho 11 years ago
parent e40f8a2d7d
commit 908d12a061

@ -619,7 +619,28 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
{
if (isSnapshotMode)
{
if (buf->getBackupFileName() == TEXT("") || !::PathFileExists(buf->getBackupFileName().c_str())) //backup file has been deleted from outside
{
// warning user and save it if user want it.
activateBuffer(id, MAIN_VIEW);
if(!activateBuffer(id, SUB_VIEW))
switchEditViewTo(MAIN_VIEW);
TCHAR pattern[140] = TEXT("Your backup file cannot be found (deleted from outside).\rSave it otherwise your data will be lost\rDo you wan to save file \"%s\" ?");
TCHAR phrase[512];
wsprintf(phrase, pattern, buf->getFullPathName());
int res = doActionOrNot(TEXT("Save"), phrase, MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL);
//int res = doSaveOrNot(buf->getFullPathName());
if (res == IDYES)
{
if (!fileSave(id))
return false; //abort entire procedure
}
else if (res == IDCANCEL)
{
return false;
}
}
}
else
{
@ -652,7 +673,27 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
{
if (isSnapshotMode)
{
if (buf->getBackupFileName() == TEXT("") || !::PathFileExists(buf->getBackupFileName().c_str())) //backup file has been deleted from outside
{
// warning user and save it if user want it.
activateBuffer(id, SUB_VIEW);
switchEditViewTo(SUB_VIEW);
TCHAR pattern[140] = TEXT("Your backup file cannot be found (deleted from outside).\rSave it otherwise your data will be lost\rDo you wan to save file \"%s\" ?");
TCHAR phrase[512];
wsprintf(phrase, pattern, buf->getFullPathName());
int res = doActionOrNot(TEXT("Save"), phrase, MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL);
//int res = doSaveOrNot(buf->getFullPathName());
if (res == IDYES)
{
if (!fileSave(id))
return false; //abort entire procedure
}
else if (res == IDCANCEL)
{
return false;
}
}
}
else
{

@ -743,11 +743,18 @@ bool FileManager::backupCurrentBuffer()
hasModifForSession = true;
}
TCHAR fullpath[MAX_PATH];
::GetFullPathName(backupFilePath.c_str(), MAX_PATH, fullpath, NULL);
::GetLongPathName(fullpath, fullpath, MAX_PATH);
// Make sure the backup file is not read only
DWORD dwFileAttribs = ::GetFileAttributes(fullpath);
if (dwFileAttribs & FILE_ATTRIBUTE_READONLY) // if file is read only, remove read only attribute
{
dwFileAttribs ^= FILE_ATTRIBUTE_READONLY;
::SetFileAttributes(fullpath, dwFileAttribs);
}
FILE *fp = UnicodeConvertor.fopen(fullpath, TEXT("wb"));
if (fp)
{

Loading…
Cancel
Save