-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Make opening the settings file more robust #1841
Conversation
@@ -445,7 +445,12 @@ namespace winrt::TerminalApp::implementation | |||
co_await winrt::resume_background(); | |||
|
|||
const auto settingsPath = CascadiaSettings::GetSettingsPath(); | |||
ShellExecute(nullptr, L"open", settingsPath.c_str(), nullptr, nullptr, SW_SHOW); | |||
|
|||
HINSTANCE res = ShellExecute(nullptr, nullptr, settingsPath.c_str(), nullptr, nullptr, SW_SHOW); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the "try something else when the first one fails," but why did you drop the "open" verb?
Also can you leave a comment back to this page https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea that explains why the result code checking is so horrific for this API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think dropping the open verb is also documented there:
NULL
The default verb is used, if available. If not, the "open" verb is used. If neither verb is available, the system uses the first verb listed in the registry.
That seems strictly better. GVim registers the edit verb (which we learned in #1789!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to explain this in the commit message. Gvim only sets up the registry for the "edit" verb so it does not work with the "open" verb. Setting this to NULL solves the issue as well.
NULL
The default verb is used, if available. If not, the "open" verb is used. If neither verb is available, > the system uses the first verb listed in the registry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miniksa if you're concerned about the oddities of the ShellExecute return value, it might make sense to use ShellExecuteEx instead because that returns true or false.
As to why it's so odd, it made more sense in 16 bits.
This fixes two issues. * Opens the assigned default application regardless of its configuration. Gvim for example only reacts to the "edit" verb so when selected as default application won't open. Using nullptr results in using the first specified application. This fixes #1789 * If no application is assigned for json files fall back to notepad See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea for more details especially why the result code checking is so horrific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing the work and investigation here!
src/cascadia/TerminalApp/App.cpp
Outdated
ShellExecute(nullptr, L"open", settingsPath.c_str(), nullptr, nullptr, SW_SHOW); | ||
|
||
HINSTANCE res = ShellExecute(nullptr, nullptr, settingsPath.c_str(), nullptr, nullptr, SW_SHOW); | ||
if ((INT_PTR)res <= 32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In additional to Michael's comment, I'd prefer a static_cast<intptr_t>()
versus a C cast, but I'm otherwise totally willing to approve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me change this and push again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well apparently only
(reinterpret_cast<intptr_t>(res)
works, which I think does the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this some more I think that reinterpret_cast just works since it does not check anything and the static cast fails, hence I will keep it as it is. Feel free to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with fixing the c-style cast, but otherwise this is a great fix, thanks!
I tried that before and could not get static_cast to work at all. reinterpret_cast was working but I do not feel comfortable using it here. |
I did find a "fix" for that. but it looks akward....
This should get rid if the compiler warnings I get otherwise. Should I add this or leave it like it is right now? |
Hi anything else that I can do to get this merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me. Thanks!
* Make opening the settings file more robust This fixes two issues. * Opens the assigned default application regardless of its configuration. Gvim for example only reacts to the "edit" verb so when selected as default application won't open. Using nullptr results in using the first specified application. This fixes microsoft#1789 * If no application is assigned for json files fall back to notepad See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea for more details especially why the result code checking is so horrific. * Fix c-style cast
🎉 Handy links: |
This fixes two issues.
Gvim for example only reacts to the "edit" verb so when selected as default application won't open.
Using nullptr results in using the first specified application.
This fixes Settings do not open if json files are assigned to gvim #1789
See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea for more details
especially why the result code checking is so horrific.
Summary of the Pull Request
References
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed