diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 06514164b..66e6ad925 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -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 { @@ -635,7 +656,7 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode) } else if (res == IDCANCEL) { - return false; + return false; } } } @@ -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 { diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 6217c86e3..f37ca3a12 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -742,11 +742,18 @@ bool FileManager::backupCurrentBuffer() // Session changes, save it 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)