From 982f52224c29562cac5813567c598b5211456e1b Mon Sep 17 00:00:00 2001 From: xomx Date: Wed, 26 Jun 2024 19:17:31 +0200 Subject: [PATCH] Add the possibility for opening a shortcut file if change file ext Do not recognize files without lnk-extension as Windows shortcuts. Fix also https://github.com/notepad-plus-plus/notepad-plus-plus/pull/15211#issuecomment-2156495651 Fix #9643, fix #11089, fix #10139, close #15364 --- PowerEditor/src/MISC/Common/Common.cpp | 3 +++ PowerEditor/src/NppIO.cpp | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 134ada74a..52367ff62 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -1549,6 +1549,9 @@ bool isUnsupportedFileName(const generic_string& fileName) if (pos != std::string::npos) fileNameOnly = fileNameOnly.substr(pos + 1); + // upperize because the std::find is case sensitive unlike the Windows OS filesystem + std::transform(fileNameOnly.begin(), fileNameOnly.end(), fileNameOnly.begin(), ::towupper); + const std::vector reservedWin32NamespaceDeviceList{ TEXT("CON"), TEXT("PRN"), TEXT("AUX"), TEXT("NUL"), TEXT("COM1"), TEXT("COM2"), TEXT("COM3"), TEXT("COM4"), TEXT("COM5"), TEXT("COM6"), TEXT("COM7"), TEXT("COM8"), TEXT("COM9"), diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index fa65fb7b0..6755249f1 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -126,8 +126,14 @@ DWORD WINAPI Notepad_plus::monitorFileOnChange(void * params) return EXIT_SUCCESS; } -bool resolveLinkFile(generic_string& linkFilePath) +bool resolveLinkFile(std::wstring& linkFilePath) { + // upperize for the following comparison because the ends_with is case sensitive unlike the Windows OS filesystem + std::wstring linkFilePathUp = linkFilePath; + std::transform(linkFilePathUp.begin(), linkFilePathUp.end(), linkFilePathUp.begin(), ::towupper); + if (!linkFilePathUp.ends_with(L".LNK")) + return false; // we will not check the renamed shortcuts like "file.lnk.txt" + bool isResolved = false; IShellLink* psl = nullptr;