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

Simplify WindowEmperor::HandleCommandlineArgs #16592

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Jan 23, 2024

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.

@lhecker lhecker added the Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. label Jan 23, 2024
#include "resource.h"
#include "NotificationIcon.h"
#include <til/env.h>
Copy link
Member Author

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;
Copy link
Member Author

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.

@Uvaistd24

This comment was marked as off-topic.

@DHowett DHowett merged commit a39ac59 into main Jan 25, 2024
17 of 19 checks passed
@DHowett DHowett deleted the dev/lhecker/window-emperor-minor branch January 25, 2024 22:51
DHowett pushed a commit that referenced this pull request Jan 26, 2024
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
DHowett pushed a commit that referenced this pull request Jan 29, 2024
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
lhecker added a commit that referenced this pull request Jan 30, 2024
lhecker added a commit that referenced this pull request Jan 30, 2024
DHowett pushed a commit that referenced this pull request Jan 31, 2024
#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 ✅
DHowett pushed a commit that referenced this pull request Jan 31, 2024
#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
DHowett pushed a commit that referenced this pull request Jan 31, 2024
#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
DHowett pushed a commit that referenced this pull request Jan 31, 2024
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc.
Projects
Development

Successfully merging this pull request may close these issues.

4 participants