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:
@@ -34,6 +34,8 @@
|
|||||||
#include "wx/apptrait.h"
|
#include "wx/apptrait.h"
|
||||||
#include "wx/dynload.h"
|
#include "wx/dynload.h"
|
||||||
|
|
||||||
|
#include "wx/confbase.h" // for wxExpandEnvVars()
|
||||||
|
|
||||||
#include "wx/msw/private.h" // includes <windows.h>
|
#include "wx/msw/private.h" // includes <windows.h>
|
||||||
#include "wx/msw/missing.h" // CHARSET_HANGUL
|
#include "wx/msw/missing.h" // CHARSET_HANGUL
|
||||||
|
|
||||||
@@ -92,6 +94,11 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// 260 was taken from windef.h
|
||||||
|
#ifndef MAX_PATH
|
||||||
|
#define MAX_PATH 260
|
||||||
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// constants
|
// constants
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -356,6 +363,7 @@ const wxChar* wxGetHomeDir(wxString *pstr)
|
|||||||
{
|
{
|
||||||
wxString& strDir = *pstr;
|
wxString& strDir = *pstr;
|
||||||
|
|
||||||
|
// first branch is for Cygwin
|
||||||
#if defined(__UNIX__)
|
#if defined(__UNIX__)
|
||||||
const wxChar *szHome = wxGetenv("HOME");
|
const wxChar *szHome = wxGetenv("HOME");
|
||||||
if ( szHome == NULL ) {
|
if ( szHome == NULL ) {
|
||||||
@@ -379,7 +387,6 @@ const wxChar* wxGetHomeDir(wxString *pstr)
|
|||||||
#elif defined(__WXWINCE__)
|
#elif defined(__WXWINCE__)
|
||||||
// Nothing
|
// Nothing
|
||||||
#else
|
#else
|
||||||
#ifdef __WIN32__
|
|
||||||
strDir.clear();
|
strDir.clear();
|
||||||
|
|
||||||
// If we have a valid HOME directory, as is used on many machines that
|
// 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() )
|
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 // fall back to the program 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
|
|
||||||
|
|
||||||
wxString strPath;
|
wxString strPath;
|
||||||
::GetModuleFileName(::GetModuleHandle(NULL),
|
::GetModuleFileName(::GetModuleHandle(NULL),
|
||||||
wxStringBuffer(strPath, MAX_PATH), MAX_PATH);
|
wxStringBuffer(strPath, MAX_PATH), MAX_PATH);
|
||||||
|
|
||||||
// extract the dir name
|
// extract the dir name
|
||||||
wxSplitPath(strPath, &strDir, NULL, NULL);
|
wxSplitPath(strPath, &strDir, NULL, NULL);
|
||||||
|
}
|
||||||
#endif // UNIX/Win
|
#endif // UNIX/Win
|
||||||
|
|
||||||
return strDir.c_str();
|
return strDir.c_str();
|
||||||
|
Reference in New Issue
Block a user