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
This commit is contained in:
Don Ho 2024-12-12 03:43:31 +01:00
parent dc583bf34e
commit 10ae99e790

View File

@ -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<int32_t*>(&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)