Signed-off-by: Zebediah Figura z.figura12@gmail.com --- I'm not actually sure if this patch is worth having. It's not needed for GOG Galaxy 2, which calls SetEnvironmentStringsW() with an environment already containing these variables (so I'm not quite sure what the point is in the first place...)
Broadly, I'm not sure to what degree arbitrary Win32 API functions should be expected to work when the entire environment is wiped. For example, GetTempPath() predictably falls back to C:\windows\system32, but GetUserName() works fine (and would not in Wine without this patch).
dlls/ntdll/env.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index 3acf7f52d5b..452b10b0582 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -996,10 +996,26 @@ NTSTATUS WINAPI RtlQueryEnvironmentVariable_U(PWSTR env, */ void WINAPI RtlSetCurrentEnvironment(PWSTR new_env, PWSTR* old_env) { - WCHAR *prev; + static const WCHAR wineW[] = {'W','I','N','E'}; + WCHAR *prev, *p;
TRACE("(%p %p)\n", new_env, old_env);
+ /* ensure that special Wine-internal variables are still defined */ + + for (p = new_env; *p; p += wcslen( p ) + 1) + { + if (!wcsncmp( p, wineW, 4 )) + { + const WCHAR *value = wcschr( p, '=' ) + 1; + UNICODE_STRING var_string, value_string; + var_string.Buffer = p; + var_string.Length = (value - 1 - p) * sizeof(WCHAR); + RtlInitUnicodeString( &value_string, value ); + RtlSetEnvironmentVariable( &new_env, &var_string, &value_string ); + } + } + RtlAcquirePebLock();
prev = NtCurrentTeb()->Peb->ProcessParameters->Environment;