From 10ae99e7909ed26b06f55f1edb5396a7acd481a0 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 12 Dec 2024 03:43:31 +0100 Subject: [PATCH] Fix unsaved documents lost on next launch if portable npp change path When Notepad++ portable version changes its path (move/rename), the periode backup files (unsaved documents) are lost on the next session, due to the absolute paths in session files. This commit fixes the issue by ensuring the backup path matches with such documents. Fix #1587, fix #15886, close #15942 --- PowerEditor/src/Parameters.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 1768dfcac..c7a96d118 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -2430,7 +2430,20 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session& s langName = (childNode->ToElement())->Attribute(L"lang"); int encoding = -1; const wchar_t *encStr = (childNode->ToElement())->Attribute(L"encoding", &encoding); - const wchar_t *backupFilePath = (childNode->ToElement())->Attribute(L"backupFilePath"); + + const wchar_t *pBackupFilePath = (childNode->ToElement())->Attribute(L"backupFilePath"); + std::wstring currentBackupFilePath = NppParameters::getInstance().getUserPath() + L"\\backup\\"; + if (pBackupFilePath) + { + std::wstring backupFilePath = pBackupFilePath; + if (!backupFilePath.starts_with(currentBackupFilePath)) + { + // reconstruct backupFilePath + wchar_t* fn = PathFindFileName(pBackupFilePath); + currentBackupFilePath += fn; + pBackupFilePath = currentBackupFilePath.c_str(); + } + } FILETIME fileModifiedTimestamp{}; (childNode->ToElement())->Attribute(L"originalFileLastModifTimestamp", reinterpret_cast(&fileModifiedTimestamp.dwLowDateTime)); @@ -2446,7 +2459,7 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session& s if (boolStrPinned) isPinned = _wcsicmp(L"yes", boolStrPinned) == 0; - sessionFileInfo sfi(fileName, langName, encStr ? encoding : -1, isUserReadOnly, isPinned, position, backupFilePath, fileModifiedTimestamp, mapPosition); + sessionFileInfo sfi(fileName, langName, encStr ? encoding : -1, isUserReadOnly, isPinned, position, pBackupFilePath, fileModifiedTimestamp, mapPosition); const wchar_t* intStrTabColour = (childNode->ToElement())->Attribute(L"tabColourId"); if (intStrTabColour)