git-for-windows/7-Zip

I want to add "%userprofile%" to the InstallPath

heetbeet opened this issue · 2 comments

I want to expand this part to work with %userprofile% (or maybe even any environment variables), but I don't know how to actually retrieve environment variables in C++ (well, not without adding extra bloat like std::).

My question is: are there any functionality already in the codebase to access environment variables? Where can I find it?

dscho commented

I am guessing you want to imitate

if (installPath.Find(L"%%S") >= 0)
{
FString s2 = fullPath;
int sep = s2.ReverseFind_PathSepar();
if (sep > 0) {
s2.DeleteFrom(sep + 1);
NName::NormalizeDirPathPrefix(s2);
sep = s2.Len();
if (sep > 0 && IS_PATH_SEPAR(s2[sep - 1]))
s2.DeleteFrom(sep - 1);
}
installPath.Replace(L"%%S", fs2us(s2));
}
to implement that feature.

And retrieving an environment variable is as easy as calling GetEnvironmentVariable(). There is one precedent for this in the current code:

DWORD ttt = GetEnvironmentVariableW(L"ProgramW6432", path, MAX_PATH);

Thanks for the info