-
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
Create til::env to help with refreshing environment variables #14839
Conversation
This comment has been minimized.
This comment has been minimized.
Hmm, the environment blocks produced by
|
So on my work PC, which has
This suggests |
} | ||
else | ||
{ | ||
set_user_environment_var(valueName, std::wstring{ data }); |
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.
this will expand it even during pass 1 for a REG_SZ
; is that definitely what we want? I suspect it is, because the environment is strange
src/inc/til/env.h
Outdated
static constexpr std::wstring_view os2LibPath{ L"Os2LibPath" }; | ||
bool is_path_var(std::wstring_view input) | ||
{ | ||
return !_wcsicmp(input.data(), path.data()) || !_wcsicmp(input.data(), libPath.data()) || !_wcsicmp(input.data(), os2LibPath.data()); |
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.
@lhecker may be able to recommend a cleaner way to do this
All comments should now hopefully be addressed |
Test failures are flaky feature tests. |
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'm not too happy about the amount of string copies, but I'd be happy to merge this anyways. I'd love to see some or all of my comments to be addressed though.
// length will receive the number of bytes including trailing null byte. Convert to a number of wchar_t's. | ||
// AdaptFixedSizeToAllocatedResult will then resize buffer to valueLengthNeededWithNull. | ||
// We're rounding up to prevent infinite loops if the data isn't a REG_SZ and length isn't divisible by 2. | ||
*valueLengthNeededWithNul = (length + sizeof(wchar_t) - 1) / sizeof(wchar_t); |
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.
This function is a little bit cheeky since RegQueryValueExW
returns binary data, but this assumes the caller is trying to get a wide string. I think it's kind of fine though...
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.
Assuming that the underlying algorithm that @miniksa wrote for regenerating the environment is correct (I have no reason to believe it isn't), then the rest of this looks good to me.
I'd love if @miniksa could give this another once over, but the Terminal ain't his day job anymore 😥
Sorry it took us so long to get around to this! You caught us at a particularly busy couple months 😅 Looking forward to shipping this (and the follow up 😉)
inline HRESULT GetComputerNameW(string_type& result) WI_NOEXCEPT | ||
{ | ||
return wil::AdaptFixedSizeToAllocatedResult<string_type, initialBufferLength>(result, | ||
[&](_Out_writes_(valueLength) PWSTR value, size_t valueLength, _Out_ size_t* valueLengthNeededWithNul) -> HRESULT { |
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.
holy indenting batman. This is totally a nit, but I'd pull that lambda out to a local, just for the sake of some sensible indenting
That is waiting in the wings and is a grand total of 22 additional lines. |
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.
block to review
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'S GO! YEAH!
Adds a helper that replicates how the
RegenerateUserEnvironment()
method in
shell32.dll
behaves.Co-authored-by: Michael Niksa [email protected]