Notepads: [Bug] Win+R launch cause file open error

Created on 25 Sep 2019  路  3Comments  路  Source: JasonStein/Notepads

Describe the bug
If user use Win+R and type "Notepads" then hit enter, it cause the "File open Error - Failed to open the file "C:\Users\pnp0a\AppData\Local\Microsoft\WindowsApps\Notepads.exe".
If type "Notepads (filepath)", Notepads launch with blank file. the specified file will not open.

To Reproduce

  1. Type Win+R. "Run" dialog open.
  2. Type "Notepads" and hit enter.
  3. Notepads launched but it shows the error dialog.

Expected behavior
Launch the app without error. If the user specify the file, open it.

Screenshots
image

Desktop (please complete the following information):

  • OS: [Windows 10 1903 18362.356]
  • Version [v0.10.2.0 beta]

Additional context

I have some findings about the issue. Let me describe...
The error was caused by "Parse error" of command line parameter. The parser method "RemoveAppNameFromCommandLineIfAny" failed the parsing and return the application path as file path.

Currently, this method assume the args parameter as following 2 pattern:

  1. Notepads.exe c:\users\pnp0a\documents\hoge.txt
  2. Notepads c:\users\pnp0a\documents\hoge.txt

But, if the user use Win+R, the parameter is like following.

  1. "C:\Users\pnp0a\AppData\Local\Microsoft\WindowsApps\Notepads.exe" c:\users\pnp0a\documents\hoge.txt

RemoveAppNameFromCommandLineIfAny does not suppose the last pattern, then it fails to process.

On my understanding, parsing the command line param with C#, or generate the Application Part and subtract it like as current method , both have some risk but easy to implement.
Most stable way to retrieve only file parameter is simply use the static void Main(string[] args) at Program.cs, I believe. But it requires many of modifications, it's too difficult for me :).

bug

All 3 comments

This is the same root cause for https://github.com/JasonStein/Notepads/issues/198
I need to write a proper command line parser since I started to use multi-instance feature and by default, the command line is not parsed in this case causing the issue.

I wrote a minimum workaround here: https://github.com/JasonStein/Notepads/commit/f9e843b947a0babad1535e179b6259b5dc2d5875
I will revisit this code later when I have time. But this fix should work for all use cases: CMD, PS and RUN

I've tried it and it's OK 馃憤

Was this page helpful?
0 / 5 - 0 ratings