/************************************************************************* * @ [SHLWAPI.466] */ BOOL WINAPI PathUnExpandEnvStringsForUserW(HANDLE hToken, LPCWSTR pszPath, LPWSTR pszUnExpanded, INT cchUnExpanded) { static const WCHAR szAPPDATA[] = { '%','A','P','P','D','A','T','A','%', 0 }; static const WCHAR szUSERPROFILE[] = { '%','U','S','E','R','P','R','O','F','I','L','E','%', 0 }; static const WCHAR szALLUSERSPROFILE[] = { '%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%', 0 }; static const WCHAR szProgramFiles[] = { '%','P','r','o','g','r','a','m','F','i','l','e','s','%', 0 }; static LPCWSTR szEnvs[] = { szAPPDATA, szUSERPROFILE, szALLUSERSPROFILE, szProgramFiles }; INT i, cchValue, cchPath, cchEnv; WCHAR szValue[MAX_PATH]; TRACE("(%p,%s,%p,%d)\n", hToken, debugstr_w(pszPath), pszUnExpanded, cchUnExpanded); if (cchUnExpanded <= 0) return FALSE; for (i = 0; i < (INT)_countof(szEnvs); ++i) { /* expand szEnvs[i] to szValue */ if (!ExpandEnvironmentStringsW(szEnvs[i], szValue, _countof(szValue))) continue; /* compare strings */ cchValue = (INT)wcslen(szValue); if (CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, szValue, cchValue, pszPath, cchValue) != 2) continue; /* check length */ cchPath = lstrlenW(pszPath); cchEnv = lstrlenW(szEnvs[i]); if (cchUnExpanded < cchPath - cchValue + cchEnv + 1) return FALSE; /* concatenate szEnvs[i] and pszPath[cchValue] and store it to pszUnExpanded */ wcscpy(pszUnExpanded, szEnvs[i]); wcscat(pszUnExpanded, &pszPath[cchValue]); return TRUE; } return FALSE; } /************************************************************************* * @ [SHLWAPI.465] */ BOOL WINAPI PathUnExpandEnvStringsForUserA(HANDLE hToken, LPCSTR pszPath, LPSTR pszUnExpanded, INT cchUnExpanded) { BOOL bRet; WCHAR szPathW[MAX_PATH], szUnExpandedW[MAX_PATH]; TRACE("(%p,%s,%p,%d)\n", hToken, pszPath, pszUnExpanded, cchUnExpanded); MultiByteToWideChar(CP_ACP, 0, pszPath, -1, szPathW, _countof(szPathW)); szUnExpandedW[0] = 0; bRet = PathUnExpandEnvStringsForUserW(hToken, szPathW, szUnExpandedW, _countof(szUnExpandedW)); WideCharToMultiByte(CP_ACP, 0, szPathW, -1, pszUnExpanded, cchUnExpanded, 0, 0); return bRet; }