\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}
\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
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;
{
public:
// implement base class pure virtuals
+ virtual wxString GetExecutablePath() const;
virtual wxString GetConfigDir() const;
virtual wxString GetUserConfigDir() const;
virtual wxString GetDataDir() const;
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; }
// 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
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; }
// implement base class pure virtuals
+ virtual wxString GetExecutablePath() const;
virtual wxString GetConfigDir() const;
virtual wxString GetUserConfigDir() const;
virtual wxString GetDataDir() const;
#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
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"),
wxLog::AddTraceMask(_T("mime"));
#if TEST_ALL
TestMimeEnum();
+ #endif
TestMimeOverride();
TestMimeAssociate();
- #endif
TestMimeFilename();
#endif // TEST_MIME
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;
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__
// public functions
// ----------------------------------------------------------------------------
+wxString wxStandardPaths::GetExecutablePath() const
+{
+ return wxGetFullModuleName();
+}
+
wxString wxStandardPaths::GetConfigDir() const
{
return AppendAppName(DoGetDirectory(CSIDL_COMMON_APPDATA));
// 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];
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
if ( pos != wxString::npos )
m_prefix.assign(exeStr, 0, pos);
}
-#endif // __LINUX__
if ( m_prefix.empty() )
{