From 7e353903b82a8035ead20759db8ec32a4ff88d94 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 13 Jul 2023 01:58:43 +0200 Subject: [PATCH] Add more info on save session error message For the future debugging using. Related: #13859 Close #13893 --- PowerEditor/src/Parameters.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index dbd6db06c..2107300b0 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -3478,11 +3478,16 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName) // Backup session file before overriting it TCHAR backupPathName[MAX_PATH]{}; + BOOL doesBackupCopyExist = FALSE; if (PathFileExists(sessionPathName)) { _tcscpy(backupPathName, sessionPathName); _tcscat(backupPathName, TEXT(".inCaseOfCorruption.bak")); - CopyFile(sessionPathName, backupPathName, FALSE); + doesBackupCopyExist = CopyFile(sessionPathName, backupPathName, FALSE); + if (!doesBackupCopyExist) + { + ::MessageBox(nullptr, GetLastErrorAsString(0).c_str(), L"Session file backup error", MB_OK); + } } TiXmlDocument* pXmlSessionDoc = new TiXmlDocument(sessionPathName); @@ -3582,7 +3587,11 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName) bool sessionSaveOK = pXmlSessionDoc->SaveFile(); - if (sessionSaveOK) + if (!sessionSaveOK) + { + ::MessageBox(nullptr, sessionPathName, L"Error of saving session XML file", MB_OK | MB_APPLMODAL | MB_ICONWARNING); + } + else { // Double checking: prevent written session file corrupted while writting TiXmlDocument* pXmlSessionCheck = new TiXmlDocument(sessionPathName); @@ -3592,13 +3601,9 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName) if (!sessionSaveOK) { - if (backupPathName[0]) // session backup file exists, restore it + if (doesBackupCopyExist) // session backup file exists, restore it { - _pNativeLangSpeaker->messageBox("ErrorOfSavingSessionFile", - nullptr, - TEXT("The old session file will be restored."), - TEXT("Error of saving session file"), - MB_OK | MB_APPLMODAL | MB_ICONWARNING); + ::MessageBox(nullptr, backupPathName, L"Saving session error - restore backup", MB_OK | MB_APPLMODAL | MB_ICONWARNING); wstring sessionPathNameFail2Load = sessionPathName; sessionPathNameFail2Load += L".fail2Load";