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
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -354,8 +361,9 @@ error:
|
|||||||
|
|
||||||
const wxChar* wxGetHomeDir(wxString *pstr)
|
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 ) {
|
||||||
@@ -371,34 +379,33 @@ const wxChar* wxGetHomeDir(wxString *pstr)
|
|||||||
strDir << wxT('/');
|
strDir << wxT('/');
|
||||||
|
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
// Cygwin returns unix type path but that does not work well
|
// Cygwin returns unix type path but that does not work well
|
||||||
static wxChar windowsPath[MAX_PATH];
|
static wxChar windowsPath[MAX_PATH];
|
||||||
cygwin_conv_to_full_win32_path(strDir, windowsPath);
|
cygwin_conv_to_full_win32_path(strDir, windowsPath);
|
||||||
strDir = windowsPath;
|
strDir = windowsPath;
|
||||||
#endif
|
#endif
|
||||||
#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
|
||||||
// have unix utilities on them, we should use that.
|
// have unix utilities on them, we should use that.
|
||||||
const wxChar *szHome = wxGetenv(wxT("HOME"));
|
const wxChar *szHome = wxGetenv(wxT("HOME"));
|
||||||
|
|
||||||
if ( szHome != NULL )
|
if ( szHome != NULL )
|
||||||
{
|
{
|
||||||
strDir = szHome;
|
strDir = szHome;
|
||||||
}
|
}
|
||||||
else // no HOME, try HOMEDRIVE/PATH
|
else // no HOME, try HOMEDRIVE/PATH
|
||||||
{
|
{
|
||||||
szHome = wxGetenv(wxT("HOMEDRIVE"));
|
szHome = wxGetenv(wxT("HOMEDRIVE"));
|
||||||
if ( szHome != NULL )
|
if ( szHome != NULL )
|
||||||
strDir << szHome;
|
strDir << szHome;
|
||||||
szHome = wxGetenv(wxT("HOMEPATH"));
|
szHome = wxGetenv(wxT("HOMEPATH"));
|
||||||
|
|
||||||
if ( szHome != NULL )
|
if ( szHome != NULL )
|
||||||
{
|
{
|
||||||
strDir << szHome;
|
strDir << szHome;
|
||||||
|
|
||||||
// the idea is that under NT these variables have default values
|
// the idea is that under NT these variables have default values
|
||||||
@@ -408,44 +415,38 @@ const wxChar* wxGetHomeDir(wxString *pstr)
|
|||||||
// to set HOMEPATH to something other than "\\", we suppose that he
|
// to set HOMEPATH to something other than "\\", we suppose that he
|
||||||
// knows what he is doing and use the supplied value.
|
// knows what he is doing and use the supplied value.
|
||||||
if ( wxStrcmp(szHome, wxT("\\")) == 0 )
|
if ( wxStrcmp(szHome, wxT("\\")) == 0 )
|
||||||
strDir.clear();
|
strDir.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( strDir.empty() )
|
if ( strDir.empty() )
|
||||||
{
|
{
|
||||||
// If we have a valid USERPROFILE directory, as is the case in
|
// If we have a valid USERPROFILE directory, as is the case in
|
||||||
// Windows NT, 2000 and XP, we should use that as our home directory.
|
// Windows NT, 2000 and XP, we should use that as our home directory.
|
||||||
szHome = wxGetenv(wxT("USERPROFILE"));
|
szHome = wxGetenv(wxT("USERPROFILE"));
|
||||||
|
|
||||||
if ( szHome != NULL )
|
if ( szHome != NULL )
|
||||||
strDir = szHome;
|
strDir = szHome;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
//else: fall back to the prograrm directory
|
strDir = wxExpandEnvVars(strDir);
|
||||||
#else // Win16
|
}
|
||||||
// Win16 has no idea about home, so use the executable directory instead
|
else // fall back to the program directory
|
||||||
#endif // WIN16/32
|
{
|
||||||
|
wxString strPath;
|
||||||
// 260 was taken from windef.h
|
::GetModuleFileName(::GetModuleHandle(NULL),
|
||||||
#ifndef MAX_PATH
|
wxStringBuffer(strPath, MAX_PATH), MAX_PATH);
|
||||||
#define MAX_PATH 260
|
|
||||||
#endif
|
|
||||||
|
|
||||||
wxString strPath;
|
|
||||||
::GetModuleFileName(::GetModuleHandle(NULL),
|
|
||||||
wxStringBuffer(strPath, MAX_PATH), MAX_PATH);
|
|
||||||
|
|
||||||
// extract the dir name
|
|
||||||
wxSplitPath(strPath, &strDir, NULL, NULL);
|
|
||||||
|
|
||||||
|
// extract the dir name
|
||||||
|
wxSplitPath(strPath, &strDir, NULL, NULL);
|
||||||
|
}
|
||||||
#endif // UNIX/Win
|
#endif // UNIX/Win
|
||||||
|
|
||||||
return strDir.c_str();
|
return strDir.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxChar *wxGetUserHome(const wxString& WXUNUSED(user))
|
wxChar *wxGetUserHome(const wxString& WXUNUSED(user))
|
||||||
|
Reference in New Issue
Block a user