Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single file instance sometimes fails #378

Closed
zufuliu opened this issue Sep 21, 2021 · 3 comments
Closed

Single file instance sometimes fails #378

zufuliu opened this issue Sep 21, 2021 · 3 comments

Comments

@zufuliu
Copy link
Owner

zufuliu commented Sep 21, 2021

Currently it doesn't work for using Notepad2 as external tool for Cppcheck (see wiki https://github.com/zufuliu/notepad2/wiki/Command-Line-Switches#cppcheck). Enable argument dump in ParseCommandLine() shows following arguments are parsed by Cppcheck (note the double slashes):

 -g 4610 D:\\notepad2\\scite\\src\\SciTEBase.cxx

In EnumWndProc2() the passed file path is compared against final path name (GetFinalPathNameByHandle() in EditLoadFile()), which is then diffs.

Following is a quick fix for ActivatePrevInst():

diff --git a/src/Notepad2.c b/src/Notepad2.c
index f3550510..e4564d74 100644
--- a/src/Notepad2.c
+++ b/src/Notepad2.c
@@ -7769,6 +7769,11 @@ BOOL ActivatePrevInst(void) {
 		}
 
 		GetLongPathNameEx(lpFileArg, MAX_PATH);
+		{
+			WCHAR tchTmp[MAX_PATH];
+			GetFullPathName(lpFileArg, MAX_PATH, tchTmp, NULL);
+			lstrcpy(lpFileArg, tchTmp);
+		}
 
 		HWND hwnd = NULL;
 		EnumWindows(EnumWndProc2, (LPARAM)&hwnd);

There maybe other cases where the name diffs, a better solution is needed, possible just open the file and get the final path.

@zufuliu zufuliu added this to the v4.21.11 milestone Sep 21, 2021
@zufuliu
Copy link
Owner Author

zufuliu commented Sep 21, 2021

GetFullPathName() does not fix \\?\ prefixed path (see https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces).

@zufuliu
Copy link
Owner Author

zufuliu commented Sep 25, 2021

Fixed by 2c3b8d6.
Cppcheck bug reported to https://sourceforge.net/p/cppcheck/discussion/general/thread/b548fc603b/.

@zufuliu zufuliu closed this as completed Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant