Add limited support for long pathnames on the command line (#15828) by mgroeber9110 · Pull Request #17440 · notepad-plus-plus/notepad-plus-plus

This is my first attempt at implementing the idea I mentioned in #15828 for a "cheap" way of adding initial support for long (>260) pathnames to the code. I have been using a similar workaround in an external batch file for some time now, and it has turned out to be useful enough for my case.

This change does two things:

  • Use a variable-sized buffer for making pathnames absolute (by querying the required size beforehand), instead of a fixed-size one, to avoid failing for long paths.
  • If the resulting name is too long, use the GetShortPathName function to retrieve a path using 8+3 names instead of the written-out forms. Because Notepad++ is not marked as long-path-aware in the manifest, this requires prefixing paths temporarily with either \\?\ (for local drives) or \\?\UNC\ (for UNC paths) to request long path support.

This still does not cover all possible cases, as paths may still be too long even after the shortening (or some file systems might not have short names at all), but it has the advantage of requiring minimal code changes, and fitting entirely into relativeFilePathToFullFilePath.

A future change could make the entire code long path proof, as @softmgr describes, and apply the shortening only to legacy plugins that may not be compatible with long paths.