[ 1590221 ] wxStandardPaths::GetExecutablePath
Required for optimised stackwalker patch. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43340 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
6cd5337946
commit
ac7ad70d4c
@ -111,6 +111,21 @@ Example return values:
|
||||
\newsince{2.7.0}
|
||||
|
||||
|
||||
\membersection{wxStandardPaths::GetExecutablePath}\label{wxstandardpathsgetexecutablepath}
|
||||
|
||||
\constfunc{wxString}{GetExecutablePath}{\void}
|
||||
|
||||
Return the directory and the filename for the current executable.
|
||||
|
||||
Example return values:
|
||||
\begin{itemize}
|
||||
\item Unix: \texttt{/usr/local/bin/exename}
|
||||
\item Windows: \texttt{C:$\backslash$Programs$\backslash$AppFolder$\backslash$exename.exe}
|
||||
\item Mac: \texttt{/Programs/exename}
|
||||
\end{itemize}
|
||||
|
||||
|
||||
|
||||
\membersection{wxStandardPaths::GetInstallPrefix}\label{wxstandardpathsgetinstallprefix}
|
||||
|
||||
\constfunc{wxString}{GetInstallPrefix}{\void}
|
||||
@ -253,7 +268,7 @@ all platforms except Windows where it returns
|
||||
\textbf{Note:} This function is only available under Unix.
|
||||
|
||||
Lets wxStandardPaths know about the real program installation prefix on a Unix
|
||||
system. By default, the value returned by
|
||||
system. By default, the value returned by
|
||||
\helpref{GetInstallPrefix}{wxstandardpathsgetinstallprefix} is used.
|
||||
|
||||
Although under Linux systems the program prefix may usually be determined
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
void SetBundle(wxCFBundleRef bundle);
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual wxString GetExecutablePath() const;
|
||||
virtual wxString GetConfigDir() const;
|
||||
virtual wxString GetUserConfigDir() const;
|
||||
virtual wxString GetDataDir() const;
|
||||
|
@ -20,6 +20,7 @@ class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
|
||||
{
|
||||
public:
|
||||
// implement base class pure virtuals
|
||||
virtual wxString GetExecutablePath() const;
|
||||
virtual wxString GetConfigDir() const;
|
||||
virtual wxString GetUserConfigDir() const;
|
||||
virtual wxString GetDataDir() const;
|
||||
|
@ -21,6 +21,7 @@ class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
|
||||
public:
|
||||
void SetInstallPrefix(const wxString& prefix) { m_prefix = prefix; }
|
||||
wxString GetInstallPrefix() const { return m_prefix; }
|
||||
virtual wxString GetExecutablePath() const { return m_prefix; }
|
||||
virtual wxString GetConfigDir() const { return m_prefix; }
|
||||
virtual wxString GetUserConfigDir() const { return m_prefix; }
|
||||
virtual wxString GetDataDir() const { return m_prefix; }
|
||||
|
@ -43,6 +43,11 @@ public:
|
||||
// return the global standard paths object
|
||||
static wxStandardPathsBase& Get();
|
||||
|
||||
// return the path (directory+filename) of the running executable or
|
||||
// wxEmptyString if it couldn't be determined.
|
||||
// The path is returned as an absolute path whenever possible.
|
||||
// Default implementation only try to use wxApp->argv[0].
|
||||
virtual wxString GetExecutablePath() const;
|
||||
|
||||
// return the directory with system config files:
|
||||
// /etc under Unix, c:\Documents and Settings\All Users\Application Data
|
||||
@ -152,6 +157,8 @@ class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
|
||||
public:
|
||||
void SetInstallPrefix(const wxString& prefix) { m_prefix = prefix; }
|
||||
wxString GetInstallPrefix() const { return m_prefix; }
|
||||
|
||||
virtual wxString GetExecutablePath() const { return m_prefix; }
|
||||
virtual wxString GetConfigDir() const { return m_prefix; }
|
||||
virtual wxString GetUserConfigDir() const { return m_prefix; }
|
||||
virtual wxString GetDataDir() const { return m_prefix; }
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual wxString GetExecutablePath() const;
|
||||
virtual wxString GetConfigDir() const;
|
||||
virtual wxString GetUserConfigDir() const;
|
||||
virtual wxString GetDataDir() const;
|
||||
|
@ -88,7 +88,27 @@
|
||||
#define TEST_WCHAR
|
||||
#define TEST_ZIP
|
||||
#else // #if TEST_ALL
|
||||
<<<<<<< console.cpp
|
||||
<<<<<<< console.cpp
|
||||
<<<<<<< console.cpp
|
||||
<<<<<<< console.cpp
|
||||
<<<<<<< console.cpp
|
||||
#define TEST_MIME
|
||||
=======
|
||||
#define TEST_STDPATHS
|
||||
>>>>>>> 1.197
|
||||
=======
|
||||
#define TEST_MODULE
|
||||
>>>>>>> 1.199
|
||||
=======
|
||||
#define TEST_INFO_FUNCTIONS
|
||||
>>>>>>> 1.201
|
||||
=======
|
||||
#define TEST_STDPATHS
|
||||
>>>>>>> 1.203
|
||||
=======
|
||||
#define TEST_FILE
|
||||
>>>>>>> 1.204
|
||||
#endif
|
||||
|
||||
// some tests are interactive, define this to run them
|
||||
@ -2799,6 +2819,7 @@ static void TestStandardPaths()
|
||||
wxPrintf(_T("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str());
|
||||
wxPrintf(_T("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str());
|
||||
wxPrintf(_T("Documents dir:\t\t%s\n"), stdp.GetDocumentsDir().c_str());
|
||||
wxPrintf(_T("Executable path:\t%s\n"), stdp.GetExecutablePath().c_str());
|
||||
wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str());
|
||||
wxPrintf(_T("Resources dir:\t\t%s\n"), stdp.GetResourcesDir().c_str());
|
||||
wxPrintf(_T("Localized res. dir:\t%s\n"),
|
||||
@ -4367,9 +4388,9 @@ int main(int argc, char **argv)
|
||||
wxLog::AddTraceMask(_T("mime"));
|
||||
#if TEST_ALL
|
||||
TestMimeEnum();
|
||||
#endif
|
||||
TestMimeOverride();
|
||||
TestMimeAssociate();
|
||||
#endif
|
||||
TestMimeFilename();
|
||||
#endif // TEST_MIME
|
||||
|
||||
|
@ -53,6 +53,27 @@ wxStandardPathsBase& wxStandardPathsBase::Get()
|
||||
return traits->GetStandardPaths();
|
||||
}
|
||||
|
||||
wxString wxStandardPathsBase::GetExecutablePath() const
|
||||
{
|
||||
if ( !wxTheApp || !wxTheApp->argv )
|
||||
return wxEmptyString;
|
||||
|
||||
wxString argv0 = wxTheApp->argv[0];
|
||||
if (wxIsAbsolutePath(argv0))
|
||||
return argv0;
|
||||
|
||||
// Search PATH.environment variable...
|
||||
wxPathList pathlist;
|
||||
pathlist.AddEnvList(wxT("PATH"));
|
||||
wxString path = pathlist.FindAbsoluteValidPath(argv0);
|
||||
if ( path.empty() )
|
||||
return argv0; // better than nothing
|
||||
|
||||
wxFileName filename(path);
|
||||
filename.Normalize();
|
||||
return filename.GetFullPath();
|
||||
}
|
||||
|
||||
wxStandardPathsBase& wxAppTraitsBase::GetStandardPaths()
|
||||
{
|
||||
return gs_stdPaths;
|
||||
|
@ -151,6 +151,22 @@ wxString wxStandardPathsCF::GetDataDir() const
|
||||
return GetFromFunc(CFBundleCopySharedSupportURL);
|
||||
}
|
||||
|
||||
wxString wxStandardPathsCF::GetExecutablePath() const
|
||||
{
|
||||
ProcessInfoRec processinfo;
|
||||
ProcessSerialNumber procno ;
|
||||
FSSpec fsSpec;
|
||||
|
||||
procno.highLongOfPSN = NULL ;
|
||||
procno.lowLongOfPSN = kCurrentProcess ;
|
||||
processinfo.processInfoLength = sizeof(ProcessInfoRec);
|
||||
processinfo.processName = NULL;
|
||||
processinfo.processAppSpec = &fsSpec;
|
||||
|
||||
GetProcessInformation( &procno , &processinfo ) ;
|
||||
return wxMacFSSpec2MacFilename(&fsSpec);
|
||||
}
|
||||
|
||||
wxString wxStandardPathsCF::GetLocalDataDir() const
|
||||
{
|
||||
#ifdef __WXMAC__
|
||||
|
@ -274,6 +274,11 @@ wxString wxStandardPaths::GetDocumentsDir() const
|
||||
// public functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString wxStandardPaths::GetExecutablePath() const
|
||||
{
|
||||
return wxGetFullModuleName();
|
||||
}
|
||||
|
||||
wxString wxStandardPaths::GetConfigDir() const
|
||||
{
|
||||
return AppendAppName(DoGetDirectory(CSIDL_COMMON_APPDATA));
|
||||
|
@ -106,11 +106,9 @@ wxStandardPaths::GetLocalizedResourcesDir(const wxChar *lang,
|
||||
// wxStandardPaths implementation for Unix
|
||||
// ============================================================================
|
||||
|
||||
void wxStandardPaths::DetectPrefix()
|
||||
wxString wxStandardPaths::GetExecutablePath() const
|
||||
{
|
||||
#ifdef __LINUX__
|
||||
// under Linux, we can try to infer the prefix from the location of the
|
||||
// executable
|
||||
wxString exeStr;
|
||||
|
||||
char buf[4096];
|
||||
@ -137,6 +135,17 @@ void wxStandardPaths::DetectPrefix()
|
||||
wxGetEnv(wxT(" "), &exeStr);
|
||||
}
|
||||
|
||||
if ( !exeStr.empty() )
|
||||
return exeStr;
|
||||
#endif // __LINUX__
|
||||
|
||||
return wxStandardPathsBase::GetExecutablePath();
|
||||
}
|
||||
|
||||
void wxStandardPaths::DetectPrefix()
|
||||
{
|
||||
// we can try to infer the prefix from the location of the executable
|
||||
wxString exeStr = GetExecutablePath();
|
||||
if ( !exeStr.empty() )
|
||||
{
|
||||
// consider that we're in the last "bin" subdirectory of our prefix
|
||||
@ -144,7 +153,6 @@ void wxStandardPaths::DetectPrefix()
|
||||
if ( pos != wxString::npos )
|
||||
m_prefix.assign(exeStr, 0, pos);
|
||||
}
|
||||
#endif // __LINUX__
|
||||
|
||||
if ( m_prefix.empty() )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user