Notepad2e
Notepad2e copied to clipboard
Favorites dialog and paths with variables
Started in https://github.com/ProgerXP/Notepad2e/issues/249#issuecomment-585396108.
Shortcut, path = "%userprofile%\test.txt". Doesn't work (worked before).
Works for me on Windows 7. Can you show your LNK? Do you run it by double click or directly call Notepad2e from command line?
Shortcut, path = Notepad2e.exe ... "%userprofile%\test.txt". Doesn't work.
It looks like the case with incorrect parameters does not refer to this issue and should be fixed separately.
I just want consistent behaviour regardless if the path is taken from argv[0] or argv[-1] and also to preserve Notepad2 behaviour. Create these LNK files:
%systemdrive%\test.txt"C:\Notepad2e.exe" /g -1 %systemdrive%\test.txt"C:\Notepad2e.exe" /g -1 C:\test.txt
You will see that from within the Favorites dialog 1st and 3rd work but 2nd doesn't work. Of course, if launching these LNKs from Explorer they all work. So the question is why 2nd doesn't work? If %var% expansion were not performed then neither 1st nor 2nd would work but if it is performed then both 1st and 2nd must work. Yet 1st works, 2nd doesn't.
There is a difference for cases 1 and 2 related to difference in behavior of IShellLink::GetPath vs IShellLink::GetArguments (these are used to retrieve LNK properties).
The point is: by default GetPath returns valid file path (environment variables are expanded). While GetArguments retrieves command line parameters as is.
SLGP_RAWPATH Retrieves the raw path name. A raw path is something that might not exist and may include environment variables that need to be expanded.
Local tests for GetPath using SLGP_RAWPATH flag gave the same unwanted behavior: case 1 no longer works without expandenv option set (#193).
Please confirm if we should change current behavior.
Please check my reasoning.
GetPath and GetArguments are both used in PathGetLnkPath. However, note this difference in behaviour:
- if GetArguments is used, then pszResPath receives a "raw" path which is later expanded with ExpandEnvironmentStringsEx before returning
- if GetPath is used, then double expansion happens: first GetPath itself is doing it (as per your explanation as SLGP_RAWPATH is not used) and then PathGetLnkPath is doing it again before returning just like with GetArguments
This is incorrect - imagine that there are environment variables: VAR_A (foo%VAR_B%foo) and VAR_B (bar) and you are opening a file named VAR_A. If you're doing so using GetArguments, Notepad2 will try to open foo%VAR_B%foo but if GetPath is used then it will open foobarfoo.
To summarize, there should never be double expansion of variables. In the case of PathGetLnkPath I don't understand why SLGP_RAWPATH is not used because it's obvious that this function is doing its own normalization.
Local tests for
GetPathusingSLGP_RAWPATHflag gave the same unwanted behavior: case 1 no longer works withoutexpandenvoption set (#193).
How can it be if GetPath returns %systemdrive%\test.txt which gets expanded by the following ExpandEnvironmentStringsEx?
How can it be if GetPath returns
%systemdrive%\test.txtwhich gets expanded by the followingExpandEnvironmentStringsEx?
ExpandEnvironmentStrinsEx is a wrapper function (not a part of WinAPI) and does nothing when expandenv option is not set:
