Commit c639af64 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

_SHExpandEnvironmentStrings should return input string if no % found

to expand, and should call ExpandEnvironmentStringsW if it doesn't handle an environment variable directly. Based on a patch from Dan Kegel.
parent 1b17b258
...@@ -1138,7 +1138,7 @@ static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix, ...@@ -1138,7 +1138,7 @@ static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,
(LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ)) (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
{ {
path[dwPathLen / sizeof(WCHAR)] = '\0'; path[dwPathLen / sizeof(WCHAR)] = '\0';
if (dwType == REG_EXPAND_SZ) if (dwType == REG_EXPAND_SZ && path[0] == '%')
{ {
WCHAR szTemp[MAX_PATH]; WCHAR szTemp[MAX_PATH];
...@@ -1437,20 +1437,17 @@ static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName, ...@@ -1437,20 +1437,17 @@ static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
return hr; return hr;
} }
/* Attempts to expand a subset of environment variables from szSrc into szDest, /* Attempts to expand environment variables from szSrc into szDest, which is
* which is assumed to be MAX_PATH characters in length. Unlike the standard * assumed to be MAX_PATH characters in length. Before referring to the
* ExpandEnvironmentStringsW, doesn't actually refer to the environment, for * environment, handles a few variables directly, because the environment
* two reasons: * variables may not be set when this is called (as during Wine's installation
* - the environment variables may not be set when this is called (as during * when default values are being written to the registry).
* Wine's installation when default values are being written to the registry) * The directly handled environment variables, and their source, are:
* - the user perhaps shouldn't be able to override the location of certain
* directories through modifying the environment
* The supported environment variables, and their source, are:
* - ALLUSERSPROFILE, USERPROFILE: reads from the registry * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
* - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
* path * path
* Also unlike ExpandEnvironmentStringsW, only expands a single variable, and * If one of the directly handled environment variables is expanded, only
* only in the beginning of szSrc. * expands a single variable, and only in the beginning of szSrc.
*/ */
static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest) static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
{ {
...@@ -1462,6 +1459,13 @@ static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest) ...@@ -1462,6 +1459,13 @@ static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
if (!szSrc || !szDest) return E_INVALIDARG; if (!szSrc || !szDest) return E_INVALIDARG;
/* short-circuit if there's nothing to expand */
if (szSrc[0] != '%')
{
strcpyW(szDest, szSrc);
hr = S_OK;
goto end;
}
/* Get the profile prefix, we'll probably be needing it */ /* Get the profile prefix, we'll probably be needing it */
hr = _SHOpenProfilesKey(&key); hr = _SHOpenProfilesKey(&key);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
...@@ -1514,9 +1518,14 @@ static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest) ...@@ -1514,9 +1518,14 @@ static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
} }
else else
{ {
WARN("asked for unsupported environment variable in path %s\n", DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
debugstr_w(szTemp));
hr = E_INVALIDARG; if (ret > MAX_PATH)
hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
else if (ret == 0)
hr = HRESULT_FROM_WIN32(GetLastError());
else
hr = S_OK;
} }
if (SUCCEEDED(hr) && szDest[0] == '%') if (SUCCEEDED(hr) && szDest[0] == '%')
strcpyW(szTemp, szDest); strcpyW(szTemp, szDest);
...@@ -1526,6 +1535,7 @@ static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest) ...@@ -1526,6 +1535,7 @@ static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
szTemp[0] = '\0'; szTemp[0] = '\0';
} }
} }
end:
if (key) if (key)
RegCloseKey(key); RegCloseKey(key);
TRACE("returning 0x%08lx (input was %s, output is %s)\n", hr, TRACE("returning 0x%08lx (input was %s, output is %s)\n", hr,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment