-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Simplify WindowEmperor::HandleCommandlineArgs #16592
Conversation
#include "resource.h" | ||
#include "NotificationIcon.h" | ||
#include <til/env.h> |
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.
There didn't seem to be a system to the newlines between the includes, so I removed them. Let me know if I should revert this.
// so we can open a new window with the same state. | ||
STARTUPINFOW si; | ||
GetStartupInfoW(&si); | ||
const uint32_t showWindow = WI_IsFlagSet(si.dwFlags, STARTF_USESHOWWINDOW) ? si.wShowWindow : 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.
FYI There's one slight difference between this implementation and the way nCmdShow
is generated. __scrt_get_show_window_mode
's default value is SW_SHOWDEFAULT
. I believe in our case that difference doesn't really matter though.
This comment was marked as off-topic.
This comment was marked as off-topic.
This simplifies the function in two ways: * Passing `nCmdShow` from `wWinMain` alleviates the need to interpret the return value of `GetStartupInfoW`. * `til::env::from_current_environment()` calls `GetEnvironmentStringsW` to get the environment variables, while `to_string()` turns it back. Calling the latter directly alleviates the need for this round-trip. (cherry picked from commit a39ac59) Service-Card-Id: 91643114 Service-Version: 1.18
This simplifies the function in two ways: * Passing `nCmdShow` from `wWinMain` alleviates the need to interpret the return value of `GetStartupInfoW`. * `til::env::from_current_environment()` calls `GetEnvironmentStringsW` to get the environment variables, while `to_string()` turns it back. Calling the latter directly alleviates the need for this round-trip. (cherry picked from commit a39ac59) Service-Card-Id: 91643115 Service-Version: 1.19
#16592 passes the return value of `GetEnvironmentStringsW` directly to the `hstring` constructor even though the former returns a double-null terminated string and the latter expects a regular one. This PR fixes the issue by using a basic strlen() loop to compute the length ourselves. It's still theoretically beneficial over the previous code, but now it's rather bitter since the code isn't particularly short anymore and so the biggest benefit is gone. Closes #16623 ## Validation Steps Performed * Validated the `env` string in a debugger ✅ It's 1 character shorter than the old `til::env` string. That's fine however, since any `HSTRING` is always null-terminated anyways and so we get an extra null-terminator for free. * `wt powershell` works ✅
#16592 passes the return value of `GetEnvironmentStringsW` directly to the `hstring` constructor even though the former returns a double-null terminated string and the latter expects a regular one. This PR fixes the issue by using a basic strlen() loop to compute the length ourselves. It's still theoretically beneficial over the previous code, but now it's rather bitter since the code isn't particularly short anymore and so the biggest benefit is gone. Closes #16623 ## Validation Steps Performed * Validated the `env` string in a debugger ✅ It's 1 character shorter than the old `til::env` string. That's fine however, since any `HSTRING` is always null-terminated anyways and so we get an extra null-terminator for free. * `wt powershell` works ✅ (cherry picked from commit c669afe) Service-Card-Id: 91719861 Service-Version: 1.18
#16592 passes the return value of `GetEnvironmentStringsW` directly to the `hstring` constructor even though the former returns a double-null terminated string and the latter expects a regular one. This PR fixes the issue by using a basic strlen() loop to compute the length ourselves. It's still theoretically beneficial over the previous code, but now it's rather bitter since the code isn't particularly short anymore and so the biggest benefit is gone. Closes #16623 ## Validation Steps Performed * Validated the `env` string in a debugger ✅ It's 1 character shorter than the old `til::env` string. That's fine however, since any `HSTRING` is always null-terminated anyways and so we get an extra null-terminator for free. * `wt powershell` works ✅ (cherry picked from commit c669afe) Service-Card-Id: 91719863 Service-Version: 1.20
#16592 passes the return value of `GetEnvironmentStringsW` directly to the `hstring` constructor even though the former returns a double-null terminated string and the latter expects a regular one. This PR fixes the issue by using a basic strlen() loop to compute the length ourselves. It's still theoretically beneficial over the previous code, but now it's rather bitter since the code isn't particularly short anymore and so the biggest benefit is gone. Closes #16623 ## Validation Steps Performed * Validated the `env` string in a debugger ✅ It's 1 character shorter than the old `til::env` string. That's fine however, since any `HSTRING` is always null-terminated anyways and so we get an extra null-terminator for free. * `wt powershell` works ✅ (cherry picked from commit c669afe) Service-Card-Id: 91719862 Service-Version: 1.19
This simplifies the function in two ways:
nCmdShow
fromwWinMain
alleviates the need to interpretthe return value of
GetStartupInfoW
.til::env::from_current_environment()
callsGetEnvironmentStringsW
to get the environment variables, while
to_string()
turns it back.Calling the latter directly alleviates the need for this round-trip.