Added a FileSystemUtil function to return the system home directory

This commit is contained in:
Leon Styhre 2023-07-31 17:49:58 +02:00
parent a95e161d12
commit 3472c6f852
2 changed files with 26 additions and 0 deletions

View file

@ -208,6 +208,31 @@ namespace Utils
return homePath;
}
std::string getSystemHomeDirectory()
{
#if defined(_WIN64)
// On Windows we need to check HOMEDRIVE and HOMEPATH.
std::wstring envHomeDrive;
std::wstring envHomePath;
#if defined(_MSC_VER) // MSVC compiler.
wchar_t* buffer;
if (!_wdupenv_s(&buffer, nullptr, L"HOMEDRIVE"))
envHomeDrive = buffer;
if (!_wdupenv_s(&buffer, nullptr, L"HOMEPATH"))
envHomePath = buffer;
#else
envHomeDrive = _wgetenv(L"HOMEDRIVE");
envHomePath = _wgetenv(L"HOMEPATH");
#endif
if (envHomeDrive.length() && envHomePath.length())
return getGenericPath(Utils::String::wideStringToString(envHomeDrive) + "/" +
Utils::String::wideStringToString(envHomePath));
#else
return getenv("HOME");
#endif
return "";
}
std::string getCWDPath()
{
// Return current working directory.

View file

@ -25,6 +25,7 @@ namespace Utils
StringList getPathList(const std::string& path);
void setHomePath(const std::string& path);
std::string getHomePath();
std::string getSystemHomeDirectory();
std::string getCWDPath();
std::string getPathToBinary(const std::string& executable);
void setExePath(const std::string& path);