From 306a5d95154602e34bd752aa18859931018d26d5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 8 Oct 2009 22:38:03 +0000 Subject: [PATCH] Add a WX_APPNAME_DATA_DIR hack for wxStandardPaths::GetDataDir(). Applications using wxStandardPaths::GetDataDir() to find their files under Unix can't be ran without being installed as they look for their data files under $prefix/share/appname. Make it possible to override this location by setting WX_APPNAME_DATA_DIR environment variable to allow running them without installation. Notice that this shouldn't present any security risk unless the application is SUID (which would be a very bad idea anyhow). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62337 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 5 +++++ interface/wx/stdpaths.h | 9 +++++++++ src/unix/stdpaths.cpp | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index b853af9f33..a93b1946c9 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -405,6 +405,11 @@ All: - wxDateTime timezone functions now dynamic (no caching). - Added wxHttp::GetCookie and wxHttp::HasCookies (dodge). +Unix: + +- Allow to use WX_APPNAME_DATA_DIR environment var to override the return value + of wxStandardPaths::GetDataDir(). + All (GUI): - Added support for showing bitmaps in wxButton. diff --git a/interface/wx/stdpaths.h b/interface/wx/stdpaths.h index 22a36bdb30..d443cd773c 100644 --- a/interface/wx/stdpaths.h +++ b/interface/wx/stdpaths.h @@ -103,11 +103,20 @@ public: /** Return the location of the applications global, i.e. not user-specific, data files. + Example return values: - Unix: @c prefix/share/appinfo - Windows: the directory where the executable file is located - Mac: @c appinfo.app/Contents/SharedSupport bundle subdirectory + Under Unix (only) it is possible to override the default value returned + from this function by setting the value of @c WX_APPNAME_DATA_DIR + environment variable to the directory to use (where @c APPNAME is the + upper-cased value of wxApp::GetAppName()). This is useful in order to + be able to run applications using this function without installing them + as you can simply set this environment variable to the source directory + location to allow the application to find its files there. + @see GetLocalDataDir() */ virtual wxString GetDataDir() const; diff --git a/src/unix/stdpaths.cpp b/src/unix/stdpaths.cpp index a3ff34dff4..c127fc3d66 100644 --- a/src/unix/stdpaths.cpp +++ b/src/unix/stdpaths.cpp @@ -191,6 +191,16 @@ wxString wxStandardPaths::GetConfigDir() const wxString wxStandardPaths::GetDataDir() const { + // allow to override the location of the data directory by setting + // WX_APPNAME_DATA_DIR environment variable: this is very useful in + // practice for running well-written (and so using wxStandardPaths to find + // their files) wx applications without installing them + static const wxString + envOverride(getenv("WX_" + wxTheApp->GetAppName().Upper() + "_DATA_DIR")); + + if ( !envOverride.empty() ) + return envOverride; + return AppendAppInfo(GetInstallPrefix() + wxT("/share")); } -- 2.45.2