expand the value of HOME env var in wxGetHomeDir() because it may contain env vars inside it

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24568 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-11-15 15:42:40 +00:00
parent c7952709e9
commit 2dc357ea28

View File

@@ -34,6 +34,8 @@
#include "wx/apptrait.h"
#include "wx/dynload.h"
#include "wx/confbase.h" // for wxExpandEnvVars()
#include "wx/msw/private.h" // includes <windows.h>
#include "wx/msw/missing.h" // CHARSET_HANGUL
@@ -92,6 +94,11 @@
#endif
#endif
// 260 was taken from windef.h
#ifndef MAX_PATH
#define MAX_PATH 260
#endif
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
@@ -356,6 +363,7 @@ const wxChar* wxGetHomeDir(wxString *pstr)
{
wxString& strDir = *pstr;
// first branch is for Cygwin
#if defined(__UNIX__)
const wxChar *szHome = wxGetenv("HOME");
if ( szHome == NULL ) {
@@ -379,7 +387,6 @@ const wxChar* wxGetHomeDir(wxString *pstr)
#elif defined(__WXWINCE__)
// Nothing
#else
#ifdef __WIN32__
strDir.clear();
// If we have a valid HOME directory, as is used on many machines that
@@ -424,25 +431,19 @@ const wxChar* wxGetHomeDir(wxString *pstr)
if ( !strDir.empty() )
{
return strDir.c_str();
// sometimes the value of HOME may be "%USERPROFILE%", so reexpand the
// value once again, it shouldn't hurt anyhow
strDir = wxExpandEnvVars(strDir);
}
//else: fall back to the prograrm directory
#else // Win16
// Win16 has no idea about home, so use the executable directory instead
#endif // WIN16/32
// 260 was taken from windef.h
#ifndef MAX_PATH
#define MAX_PATH 260
#endif
else // fall back to the program directory
{
wxString strPath;
::GetModuleFileName(::GetModuleHandle(NULL),
wxStringBuffer(strPath, MAX_PATH), MAX_PATH);
// extract the dir name
wxSplitPath(strPath, &strDir, NULL, NULL);
}
#endif // UNIX/Win
return strDir.c_str();