Create til::env to help with refreshing environment variables#14839
Create til::env to help with refreshing environment variables#14839DHowett merged 22 commits intomicrosoft:mainfrom
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.
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.
@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. |
lhecker
left a comment
There was a problem hiding this comment.
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.
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...
zadjii-msft
left a comment
There was a problem hiding this comment.
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.
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. |

Adds a helper that replicates how the
RegenerateUserEnvironment()method in
shell32.dllbehaves.Co-authored-by: Michael Niksa [email protected]