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

When using Notepad++ as notepad replacement, it doesn't open a file without extension #7902

Closed
kapsiR opened this issue Jan 30, 2020 · 26 comments
Assignees

Comments

@kapsiR
Copy link

kapsiR commented Jan 30, 2020

Description of the Issue

When using Notepad++ as replacement for notepad.exe, the behavior for opening files without extension is weird.

Steps to Reproduce the Issue

Using Notepad++ v7.8.4 x64

  1. Replace default notepad.exe with Notepad++ (See Notepad Replacement)
  2. Create a file without an extension, e.g. README
  3. Try to open that file with notepad.exe
  4. Error (it seems that Notepad++ tries to add .txt if ther is no file extension?!)

Expected Behavior

Open files without extension too when using notepad.exe (e.g. README, LICENSE)

Proposed change

Add an additional check if the file without a file extension does exist or not before adding a .txt extension.
The affected lines of code.

  if ( *PathFindExtension(str.c_str()) == '\0' )
  {
  	str.append(TEXT(".txt")); // If joined path has no extension, Notepad adds a .txt extension
  }

Actual Behavior

Notepad++ looks, if the same file with the .txt extension is available

  1. if yes - it opens the wrong file (e.g. README.txt instead of README)
  2. if no - it asks to create the file with a .txt extension

grafik

grafik

Note: If I open any file without extension directly with Notepad++, it works as expected!

Debug Information

Notepad++ v7.8.4 (64-bit)
Build time : Jan 29 2020 - 01:31:03
Path : C:\Program Files\Notepad++\notepad++.exe
Admin mode : OFF
Local Conf mode : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 1909
OS Build : 18363.592
Plugins : DSpellCheck.dll mimeTools.dll NppConverter.dll NppExport.dll

@garfieldbanks
Copy link

Is it really true that no npp devs have been able to reproduce this bug?

@garfieldbanks
Copy link

Or is it that no one has any idea what causes it to try to append a .txt at the end?

@kapsiR
Copy link
Author

kapsiR commented Mar 11, 2021

This is the line of code, that causes the problem:

str.append(TEXT(".txt")); // If joined path has no extension, Notepad adds a .txt extension

@garfieldbanks
Copy link

So we can just remove that line and commit it and then make a pull request to the main repository? Are you going to make a pull request or should I?

@garfieldbanks
Copy link

Would they accept it? Why does that line even exist?

@kapsiR
Copy link
Author

kapsiR commented Mar 11, 2021

When you look at the comments of the method, the question is, why is Notepad++ mirroring it's behavior and is it necessary?

// 1. Converts /p to -quickPrint if it exists as the first parameter
// 2. Concatenates all remaining parameters to form a file path, adding appending .txt extension if necessary
// This seems to mirror Notepad's behaviour

Maybe @donho can help out here?

@mere-human
Copy link
Contributor

This is the line of code, that causes the problem:

This has been there from the time the function was created. See this commit:
0db3029
So I think it makes sense to change that.

@mere-human
Copy link
Contributor

By the way, is this case affected by "Hide extensions..." Explorer option?
image

@garfieldbanks
Copy link

By the way, is this case affected by "Hide extensions..." Explorer option?

No it is not.

@kapsiR
Copy link
Author

kapsiR commented Mar 11, 2021

I checked the default behavior of Notepad:
grafik

It seems, the "only" issue here is, that it isn't checked if the file really exists.
The behavior of Notepad is intended, but Notepad checks if the file exists and opens it:
grafik

@kapsiR
Copy link
Author

kapsiR commented Mar 11, 2021

I just updated the issue with a Proposed change section 😉

kapsiR added a commit to kapsiR/notepad-plus-plus that referenced this issue Apr 20, 2022
This change aligns the behavior of the original notepad.exe with notepad++.exe when it's used as image hijack for notepad.exe.

Fixes notepad-plus-plus#7902
@donho
Copy link
Member

donho commented May 3, 2022

Has anyone tested the solution of Notepad replacement under Windows 11 with v8.3.3 or v8.4?
It doesn't work for me.

@kapsiR
Copy link
Author

kapsiR commented May 3, 2022

@donho I'll try to set up a quick test environment in the evening...

@kapsiR
Copy link
Author

kapsiR commented May 3, 2022

@donho It does not work by default on Windows 11, there is an additional DWORD that has to be set (changed):

"UseFilter"=dword:00000000

With this change, it works as before with Windows 10

Update
I did some further tests - sadly that's not entirely true:

  • It does not work if you e.g. double click a .txt file
  • It works if you type notepad.exe in the commandline, e.g. notepad.exe testfile.txt
  • It works if you uninstall the Notepad Store app

The problem seems to have something to do with the new notepad app:
"C:\Program Files\WindowsApps\Microsoft.WindowsNotepad_10.2102.13.0_x64__8wekyb3d8bbwe\Notepad\Notepad.exe"

Update again
This is the documentation regarding the redirection of notepad.exe to the app version of notepad:
https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#disable-the-redirection

Users can turn off the redirection and launch your unpackaged app executable via these options:

  • They can uninstall the MSIX-packaged version of your app.
  • The user can disable the AppExecutionAlias entry for your MSIX-packaged app in the App execution aliases page in Settings.

App execution aliases

@kapsiR
Copy link
Author

kapsiR commented May 3, 2022

@donho As you can see it is not that easy for Windows 11. (the easiest solution would be to delete the Windows Notepad Store App)

Nevertheless it would be cool to get the fix merged for all other Windows versions... 🙏

@rdipardo
Copy link
Contributor

rdipardo commented May 4, 2022

From this related thread:

See zufuliu/notepad2#347 (comment)

As reported in issue zufuliu/notepad2#367, following changes are required on Windows 11 (no need to uninstall UWP-based notepad).

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe
    Debugger                                REG_SZ      "C:\\Program Files\\Notepad++\\notepad++.exe -notepadStyleCmdline -z"
    UseFilter                               REG_DWORD   0
    0
        AppExecutionAliasRedirect           REG_DWORD   1
        AppExecutionAliasRedirectPackages   REG_SZ      *
        FilterFullPath                      REG_SZ      "notepad++.exe"
    1
        AppExecutionAliasRedirect           REG_DWORD   1
        AppExecutionAliasRedirectPackages   REG_SZ      *
        FilterFullPath                      REG_SZ      "notepad++.exe"
    2
        AppExecutionAliasRedirect           REG_DWORD   1
        AppExecutionAliasRedirectPackages   REG_SZ      *
        FilterFullPath                      REG_SZ      "notepad++.exe"

@rdipardo
Copy link
Contributor

rdipardo commented May 4, 2022

Also:

Hey guys, below you'll find a version of the .reg file for Windows 11 with Notepad++ 32-bits:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
"Debugger"="c:\\Program Files (x86)\\Notepad++\\notepad++.exe -notepadStyleCmdline -z"
"UseFilter"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe\0]
"AppExecutionAliasRedirect"=dword:00000001
"AppExecutionAliasRedirectPackages"="*"
"FilterFullPath"="notepad++.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe\1]
"AppExecutionAliasRedirect"=dword:00000001
"AppExecutionAliasRedirectPackages"="*"
"FilterFullPath"="notepad++.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe\2]
"AppExecutionAliasRedirect"=dword:00000001
"AppExecutionAliasRedirectPackages"="*"
"FilterFullPath"="notepad++.exe"

@kapsiR
Copy link
Author

kapsiR commented May 4, 2022

@rdipardo I tried this on Win11 (OS Build 22000.613) and sadly it didn't work

@donho
Copy link
Member

donho commented Jun 28, 2022

I wonder if we should keep supporting Notepad replacement solution, since it becomes more complex under Windows11 (and surly the future Windows' versions).

@pryrt What do you think?

@kapsiR
Copy link
Author

kapsiR commented Jun 28, 2022

In my opinion, it should still be an option, because:

  • of all the Windows 10 users out there
  • there is an relatively easy solution for Windows 11 users if they uninstall the store app

@pryrt
Copy link
Contributor

pryrt commented Jun 28, 2022

@donho,

I tend to agree with @kapsiR : given how long the feature has been available, I am sure that users who have grown accustomed to that implementation would be upset if you took away that long-standing feature.

I would prefer to just add documentation to the user manual which shows the win11 workarounds that @kapsiR had highlighted.

I used to wonder why people would use the hack, rather than File Associations or the more modern Open With mechanism.
But I learned a year or two ago that there are apps out there that call notepad.exe Path\To\Filename.txt rather than launching the default app for that extension, thus bypassing file-associations and OpenWith selections -- they use notepad.exe directly as an "external editor" to display log files, or do editing tasks that don't work well in their native GUI... and in those situations, being able to use the hack to replace MS notepad makes sense.

@kapsiR
Copy link
Author

kapsiR commented Oct 3, 2022

@donho Sorry for bothering (again) but did you made any decision regarding this PR?

@donho
Copy link
Member

donho commented Jan 21, 2023

@kapsiR

3. Try to open that file with notepad.exe

Sorry for the late reply.
I'm always trying reproduce this bug in order to validate your PR.
By "Try to open that file with notepad.exe" could you provide the detail instructions for this step?
C:\Program Files\Notepad++>notepad C:\repos\notepad-plus-plus\LICENSE opens the file LICENSE in Notepad++ with no problem.

@donho
Copy link
Member

donho commented Jan 22, 2023

After a closer look, I do believe this bug has been fixed in 6c3659f

@donho donho closed this as completed Jan 22, 2023
@kapsiR
Copy link
Author

kapsiR commented Jan 23, 2023

After a closer look, I do believe this bug has been fixed in 6c3659f

@donho Thanks for taking your time to have another look here, I tested the behavior with the latest 0d22c4d and it works indeed! 🥳🙏🏼

@fubaWoW
Copy link

fubaWoW commented Mar 13, 2023

hi there,
i tried to open a File without Extension and it results in notepad++ try to append ".txt" to the file, but why?

i use this Registry Settings:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
"Debugger"="\"C:\\Program Files\\Notepad++\\notepad++.exe\" -notepadStyleCmdline -z"
"UseFilter"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe\0]
"AppExecutionAliasRedirect"=dword:00000001
"AppExecutionAliasRedirectPackages"="*"
"FilterFullPath"="notepad++.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe\1]
"AppExecutionAliasRedirect"=dword:00000001
"AppExecutionAliasRedirectPackages"="*"
"FilterFullPath"="notepad++.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe\2]
"AppExecutionAliasRedirect"=dword:00000001
"AppExecutionAliasRedirectPackages"="*"
"FilterFullPath"="notepad++.exe"

Also tried without the Sub-Keys 0, 1 and 2 -> no difference!

Example, Run (Win + R) this:

"%SystemRoot%\system32\NOTEPAD.EXE" C:\Program Files (x86)\RivaTuner Statistics Server\Profiles\Global

will result in this:

---------------------------
Create new file
---------------------------
"C:\Program Files (x86)\RivaTuner Statistics Server\Profiles\Global.txt" doesn't exist. Create it?
---------------------------
Yes   No   
---------------------------

also when open a "*.reg" file by "Edit" in the Windows Context menu will result in this:

---------------------------
ERROR
---------------------------
Cannot open file " ".
---------------------------
OK   
---------------------------

BUT the file will still open?

Open *.bat, *.ini or *.xml files with "Edit" from the Windows Context menu works without errors on the other hand?!

any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants