]> git.saurik.com Git - wxWidgets.git/commitdiff
[ 1590221 ] wxStandardPaths::GetExecutablePath
authorRobert Roebling <robert@roebling.de>
Sun, 12 Nov 2006 12:58:10 +0000 (12:58 +0000)
committerRobert Roebling <robert@roebling.de>
Sun, 12 Nov 2006 12:58:10 +0000 (12:58 +0000)
    Required for optimised stackwalker patch.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43340 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/stdpaths.tex
include/wx/mac/corefoundation/stdpaths.h
include/wx/msw/stdpaths.h
include/wx/palmos/stdpaths.h
include/wx/stdpaths.h
include/wx/unix/stdpaths.h
samples/console/console.cpp
src/common/stdpbase.cpp
src/mac/corefoundation/stdpaths_cf.cpp
src/msw/stdpaths.cpp
src/unix/stdpaths.cpp

index 4ef4821098a4caa2d300ae36ab4f4edded390e6d..62a2ab82ea32f37b6a78c6856f76a37b7cf6d217 100644 (file)
@@ -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
index 9950bdbbd76521dfd6e50457c161449dbd4565c9..b4b2a88dc88583ad7e3ee63cc8a648c31b0746f2 100644 (file)
@@ -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;
index 56bae840f50963784e43278862c97555e310a529..d8f15d43c99371999b011d68d39fe4bd680fc839 100644 (file)
@@ -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;
index b650979ed99969ab95077ee35b83aae14cc5f906..8fdf87618b9d4ae34b0c3f2df9c246fafecb2e36 100644 (file)
@@ -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; }
index 80d3a8e89d3f36b26b5ff52e2100ca36291d6c91..7828b69e625c77eb35b13a81ac0bb73bee493ded 100644 (file)
@@ -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; }
index dee1224b061832ae74dad10abd3d012082ce6836..ed37b43ae456f73e4a449b83605a0dd10485cd78 100644 (file)
@@ -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;
index 90548b244556dbccea560b9bdad53da1dfeef28b..8c405aab049109d14201099ccf52b3b36c04e109 100644 (file)
     #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
 
index dd9fb2801fb3458ab5a1f0b53c4a707a5d1d657e..3aacd46b8a83812cf92c793558b7759023d622c2 100644 (file)
@@ -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;
index 451acd14dfc235de373c50c145356572d1d7cf28..12c4e3db0467c63f1d6983147db92190cf16142e 100644 (file)
@@ -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__
index 611d49a1989b0fdf199e146b2a2ab07bf178abc5..96fe3e23e77453ea16a27f008322c0ff4eccd78a 100644 (file)
@@ -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));
index 06a2e3078105e3dfb82516775447c0e4bc13f75a..edbaef8fed99b4429730254420305a71a79f9aab 100644 (file)
@@ -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() )
     {