mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-27 07:44:24 +02:00
Fix backup file renaming bug for untitled tabs
Fix #16043, close #16047
This commit is contained in:
parent
3921812175
commit
b962835fef
@ -2108,9 +2108,7 @@ bool Notepad_plus::fileRename(BufferID id)
|
|||||||
return success;
|
return success;
|
||||||
|
|
||||||
wstring newBackUpFileName = oldBackUpFileName;
|
wstring newBackUpFileName = oldBackUpFileName;
|
||||||
|
newBackUpFileName.replace(newBackUpFileName.rfind(oldFileNamePath), oldFileNamePath.length(), tabNewNameStr);
|
||||||
size_t index = newBackUpFileName.find_last_of(oldFileNamePath) - oldFileNamePath.length() + 1;
|
|
||||||
newBackUpFileName.replace(index, oldFileNamePath.length(), tabNewNameStr);
|
|
||||||
|
|
||||||
if (doesFileExist(newBackUpFileName.c_str()))
|
if (doesFileExist(newBackUpFileName.c_str()))
|
||||||
::ReplaceFile(newBackUpFileName.c_str(), oldBackUpFileName.c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS | REPLACEFILE_IGNORE_ACL_ERRORS, 0, 0);
|
::ReplaceFile(newBackUpFileName.c_str(), oldBackUpFileName.c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS | REPLACEFILE_IGNORE_ACL_ERRORS, 0, 0);
|
||||||
@ -2171,6 +2169,7 @@ bool Notepad_plus::fileRenameUntitledPluginAPI(BufferID id, const wchar_t* tabNe
|
|||||||
scnN.nmhdr.idFrom = (uptr_t)bufferID;
|
scnN.nmhdr.idFrom = (uptr_t)bufferID;
|
||||||
_pluginsManager.notify(&scnN);
|
_pluginsManager.notify(&scnN);
|
||||||
|
|
||||||
|
wstring oldName = buf->getFullPathName();
|
||||||
buf->setFileName(tabNewNameStr.c_str());
|
buf->setFileName(tabNewNameStr.c_str());
|
||||||
|
|
||||||
scnN.nmhdr.code = NPPN_FILERENAMED;
|
scnN.nmhdr.code = NPPN_FILERENAMED;
|
||||||
@ -2179,15 +2178,14 @@ bool Notepad_plus::fileRenameUntitledPluginAPI(BufferID id, const wchar_t* tabNe
|
|||||||
bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode();
|
bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode();
|
||||||
if (isSnapshotMode)
|
if (isSnapshotMode)
|
||||||
{
|
{
|
||||||
wstring oldName = buf->getFullPathName();
|
|
||||||
wstring oldBackUpFileName = buf->getBackupFileName();
|
wstring oldBackUpFileName = buf->getBackupFileName();
|
||||||
if (oldBackUpFileName.empty())
|
if (oldBackUpFileName.empty())
|
||||||
return false;
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
wstring newBackUpFileName = oldBackUpFileName;
|
wstring newBackUpFileName = oldBackUpFileName;
|
||||||
|
newBackUpFileName.replace(newBackUpFileName.rfind(oldName), oldName.length(), tabNewNameStr);
|
||||||
size_t index = newBackUpFileName.find_last_of(oldName) - oldName.length() + 1;
|
|
||||||
newBackUpFileName.replace(index, oldName.length(), tabNewNameStr);
|
|
||||||
|
|
||||||
if (doesFileExist(newBackUpFileName.c_str()))
|
if (doesFileExist(newBackUpFileName.c_str()))
|
||||||
::ReplaceFile(newBackUpFileName.c_str(), oldBackUpFileName.c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS | REPLACEFILE_IGNORE_ACL_ERRORS, 0, 0);
|
::ReplaceFile(newBackUpFileName.c_str(), oldBackUpFileName.c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS | REPLACEFILE_IGNORE_ACL_ERRORS, 0, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user