#include <wx/stdpaths.h>
wxStandardPaths returns the standard locations in the file system and should be used by applications to find their data files in a portable way.
Note that you must not create objects of class wxStandardPaths directly, but use the global standard paths object returned by wxStandardPaths::Get() (which can be of a type derived from wxStandardPaths and not of exactly this type) and call the methods you need on it. The object returned by Get() may be customized by overriding wxAppTraits::GetStandardPaths() methods.
In the description of the methods below, the example return values are given for the Unix, Windows and macOS systems, however please note that these are just the examples and the actual values may differ. For example, under Windows: the system administrator may change the standard directories locations, e.g. the Windows directory may be named "W:\Win2003"
instead of the default "C:\Windows"
.
Notice that in the examples below the string appinfo
may be either just the application name (as returned by wxApp::GetAppName()) or a combination of the vendor name (wxApp::GetVendorName()) and the application name, with a path separator between them. By default, only the application name is used, use UseAppInfo() to change this.
The other placeholders should be self-explanatory: the string username
should be replaced with the value the name of the currently logged in user. and prefix
is only used under Unix and is /usr/local
by default but may be changed using wxStandardPaths::SetInstallPrefix().
The directories returned by the methods of this class may or may not exist. If they don't exist, it's up to the caller to create them, wxStandardPaths doesn't do it.
Finally note that these functions only work with standardly packaged applications. I.e. under Unix you should follow the standard installation conventions and under Mac you should create your application bundle according to the Apple guidelines. Again, this class doesn't help you to do it.
This class is MT-safe: its methods may be called concurrently from different threads without additional locking.
Public Types | |
enum | ResourceCat { ResourceCat_None , ResourceCat_Messages } |
Possible values for category parameter of GetLocalizedResourcesDir(). More... | |
enum | Dir { Dir_Cache , Dir_Documents , Dir_Desktop , Dir_Downloads , Dir_Music , Dir_Pictures , Dir_Videos } |
Possible values for userDir parameter of GetUserDir(). More... | |
enum | FileLayout { FileLayout_Classic , FileLayout_XDG } |
Possible values for SetFileLayout() argument. More... | |
enum | ConfigFileConv { ConfigFileConv_Dot , ConfigFileConv_Ext } |
Possible values for MakeConfigFileName() naming convention argument. More... | |
Public Member Functions | |
void | DontIgnoreAppSubDir () |
MSW-specific function undoing the effect of IgnoreAppSubDir() calls. More... | |
virtual wxString | GetAppDocumentsDir () const |
Return the directory for the document files used by this application. More... | |
virtual wxString | GetConfigDir () const |
Return the directory containing the system config files. More... | |
virtual wxString | GetDataDir () const |
Return the location of the applications global, i.e. not user-specific, data files. More... | |
virtual wxString | GetDocumentsDir () const |
Same as calling GetUserDir() with Dir_Documents parameter. More... | |
virtual wxString | GetExecutablePath () const |
Return the directory and the filename for the current executable. More... | |
wxString | GetInstallPrefix () const |
Return the program installation prefix, e.g. /usr , /opt or /home/zeitlin . More... | |
virtual wxString | GetLocalDataDir () const |
Return the location for application data files which are host-specific and can't, or shouldn't, be shared with the other machines. More... | |
virtual wxString | GetLocalizedResourcesDir (const wxString &lang, ResourceCat category=ResourceCat_None) const |
Return the localized resources directory containing the resource files of the specified category for the given language. More... | |
virtual wxString | GetPluginsDir () const |
Return the directory where the loadable modules (plugins) live. More... | |
virtual wxString | GetResourcesDir () const |
Return the directory where the application resource files are located. More... | |
virtual wxString | GetTempDir () const |
Return the directory for storing temporary files, for the current user. More... | |
virtual wxString | GetUserConfigDir () const |
Return the directory for the user config files. More... | |
virtual wxString | GetUserDataDir () const |
Return the directory for the user-dependent application data files: More... | |
virtual wxString | GetUserDir (Dir userDir) const |
Return the path of the specified user data directory. More... | |
virtual wxString | GetUserLocalDataDir () const |
Return the directory for user data files which shouldn't be shared with the other machines. More... | |
void | IgnoreAppSubDir (const wxString &subdirPattern) |
MSW-specific function to customize application directory detection. More... | |
void | IgnoreAppBuildSubDirs () |
MSW-specific function to ignore all common build directories. More... | |
void | SetInstallPrefix (const wxString &prefix) |
Lets wxStandardPaths know about the real program installation prefix on a Unix system. More... | |
void | UseAppInfo (int info) |
Controls what application information is used when constructing paths that should be unique to this program, such as the application data directory, the plugins directory on Unix, etc. More... | |
void | SetFileLayout (FileLayout layout) |
Sets the current file layout. More... | |
FileLayout | GetFileLayout () const |
Returns the current file layout. More... | |
virtual wxString | MakeConfigFileName (const wxString &basename, ConfigFileConv conv=ConfigFileConv_Ext) const |
Return the file name which would be used by wxFileConfig if it were constructed with basename. More... | |
Static Public Member Functions | |
static wxStandardPaths & | Get () |
Returns reference to the unique global standard paths object. More... | |
static wxString | MSWGetShellDir (int csidl) |
Returns location of Windows shell special folder. More... | |
Protected Member Functions | |
wxStandardPaths () | |
Protected default constructor. More... | |
Possible values for MakeConfigFileName() naming convention argument.
The values in this enum are only used under Unix and only when using the classic Unix convention for file layout, in XDG mode, XDG naming convention is used unconditionally.
Enumerator | |
---|---|
ConfigFileConv_Dot | Use the class Unix dot-file convention. Prepend the dot to the file base name. This value is ignored when in XDG mode, where MakeConfigFileName() always behaves as if ConfigFileConv_Ext was specified. |
ConfigFileConv_Ext | Use This convention is always used in XDG mode. |
enum wxStandardPaths::Dir |
Possible values for userDir parameter of GetUserDir().
Possible values for SetFileLayout() argument.
The elements of this enum correspond to the different file layout standards under Unix systems.
Enumerator | |
---|---|
FileLayout_Classic | Use the classic file layout. User configuration and data files are located directly in the home directory. This is the default behaviour for compatibility reasons. |
FileLayout_XDG | Use a XDG styled file layout. File layout follows the XDG Base Directory Specification (see https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html). This is the recommended layout for new applications. |
Possible values for category parameter of GetLocalizedResourcesDir().
Enumerator | |
---|---|
ResourceCat_None | No special category, this is the default. |
ResourceCat_Messages | Message catalog resources category. |
|
protected |
Protected default constructor.
This constructor is protected in order to prevent creation of objects of this class as Get() should be used instead to access the unique global wxStandardPaths object of the correct type.
void wxStandardPaths::DontIgnoreAppSubDir | ( | ) |
MSW-specific function undoing the effect of IgnoreAppSubDir() calls.
After a call to this function the program directory will be exactly the directory containing the main application binary, i.e. it undoes the effect of any previous IgnoreAppSubDir() calls including the ones done indirectly by IgnoreAppBuildSubDirs() called from the class constructor.
|
static |
Returns reference to the unique global standard paths object.
|
virtual |
Return the directory for the document files used by this application.
If the application-specific directory doesn't exist, this function returns GetDocumentsDir().
Example return values:
~/appinfo
"C:\Users\username\Documents\appinfo"
or "C:\Documents and Settings\username\My Documents\appinfo"
~/Documents/appinfo
|
virtual |
Return the directory containing the system config files.
Example return values:
/etc
"C:\ProgramData\appinfo"
or "C:\Documents and Settings\All Users\Application Data\appinfo"
/Library/Preferences
appinfo
which makes it inconsistent with other ports.
|
virtual |
Return the location of the applications global, i.e. not user-specific, data files.
Example return values:
prefix/share/appinfo
appinfo.app/Contents/SharedSupport
bundle subdirectoryUnder Unix (only) it is possible to override the default value returned from this function by setting the value of WX_APPNAME_DATA_DIR
environment variable to the directory to use (where 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.
|
virtual |
Same as calling GetUserDir() with Dir_Documents parameter.
|
virtual |
Return the directory and the filename for the current executable.
Example return values:
/usr/local/bin/exename
"C:\Programs\AppFolder\exename.exe"
/Applications/exename
.app/Contents/MacOS/exename FileLayout wxStandardPaths::GetFileLayout | ( | ) | const |
wxString wxStandardPaths::GetInstallPrefix | ( | ) | const |
Return the program installation prefix, e.g. /usr
, /opt
or /home/zeitlin
.
If the prefix had been previously by SetInstallPrefix(), returns that value, otherwise tries to determine it automatically (Linux only right now) and finally returns the default /usr/local
value if it failed.
|
virtual |
Return the location for application data files which are host-specific and can't, or shouldn't, be shared with the other machines.
This is the same as GetDataDir() except under Unix where it returns /etc/appinfo
.
|
virtual |
Return the localized resources directory containing the resource files of the specified category for the given language.
In general this is just the same as lang subdirectory of GetResourcesDir() (or lang.lproj
under macOS) but is something quite different for message catalog category under Unix where it returns the standard prefix/share/locale/lang/LC_MESSAGES
directory.
|
virtual |
Return the directory where the loadable modules (plugins) live.
Example return values:
prefix/lib/appinfo
appinfo.app/Contents/PlugIns
bundle subdirectory
|
virtual |
Return the directory where the application resource files are located.
The resources are the auxiliary data files needed for the application to run and include, for example, image and sound files it might use.
This function is the same as GetDataDir() for all platforms except macOS. Example return values:
prefix/share/appinfo
appinfo.app/Contents/Resources
bundle subdirectory
|
virtual |
Return the directory for storing temporary files, for the current user.
Same as wxFileName::GetTempDir(). To create unique temporary files, it is best to use wxFileName::CreateTempFileName() for correct behaviour when multiple processes are attempting to create temporary files.
|
virtual |
Return the directory for the user config files.
This directory is:
~
(the home directory) or XDG_CONFIG_HOME
depending on GetFileLayout() return value"C:\Users\username\AppData\Roaming"
or "C:\Documents and Settings\username\Application Data"
~/Library/Preferences
Only use this method if you have a single configuration file to put in this directory, otherwise GetUserDataDir() is more appropriate as the latter adds appinfo
to the path, unlike this function.
|
virtual |
Return the directory for the user-dependent application data files:
~/
.appinfo"C:\Users\username\AppData\Roaming\appinfo"
or "C:\Documents and Settings\username\Application Data\appinfo"
"~/Library/Application Support/appinfo"
Return the path of the specified user data directory.
If the value could not be determined the users home directory is returned.
FileLayout_XDG
hadn't been called.
|
virtual |
Return the directory for user data files which shouldn't be shared with the other machines.
This is the same as GetUserDataDir() for all platforms except Windows where it returns "C:\Users\username\AppData\Local\appinfo"
or "C:\Documents and Settings\username\Local Settings\Application Data\appinfo"
void wxStandardPaths::IgnoreAppBuildSubDirs | ( | ) |
MSW-specific function to ignore all common build directories.
This function calls IgnoreAppSubDir() with all common values for build directory, e.g. "debug"
and "release"
.
It is called by the class constructor and so the build directories are always ignored by default. You may use DontIgnoreAppSubDir() to avoid ignoring them if this is inappropriate for your application.
void wxStandardPaths::IgnoreAppSubDir | ( | const wxString & | subdirPattern | ) |
MSW-specific function to customize application directory detection.
This class supposes that data, plugins &c files are located under the program directory which is the directory containing the application binary itself. But sometimes this binary may be in a subdirectory of the main program directory, e.g. this happens in at least the following common cases:
By calling this function you instruct the class to remove the last component of the path if it matches its argument. Notice that it may be called more than once, e.g. you can call both IgnoreAppSubDir("bin") and IgnoreAppSubDir("debug") to take care of both production and development cases above but that each call will only remove the last path component. Finally note that the argument can contain wild cards so you can also call IgnoreAppSubDir("vc*msw*") to ignore all build directories at once when using wxWidgets-inspired output directories names.
subdirPattern | The subdirectory containing the application binary which should be ignored when determining the top application directory. The pattern is case-insensitive and may contain wild card characters ' ?' and '*' . |
|
virtual |
Return the file name which would be used by wxFileConfig if it were constructed with basename.
conv is used to construct the name of the file under Unix and only matters when using the class file layout, i.e. if SetFileLayout() had not been called with FileLayout_XDG
argument. In this case, this argument is used to determine whether to use an extension or a leading dot. When following XDG specification, the function always appends the extension, regardless of conv value. Finally, this argument is not used at all under non-Unix platforms.
|
static |
Returns location of Windows shell special folder.
This function is, by definition, MSW-specific. It can be used to access pre-defined shell directories not covered by the existing methods of this class, e.g.:
csidl |
void wxStandardPaths::SetFileLayout | ( | FileLayout | layout | ) |
Sets the current file layout.
The default layout is FileLayout_Classic
for compatibility, however newer applications are encouraged to set it to FileLayout_XDG
on program startup.
void wxStandardPaths::SetInstallPrefix | ( | const wxString & | prefix | ) |
Lets wxStandardPaths know about the real program installation prefix on a Unix system.
By default, the value returned by GetInstallPrefix() is used.
Although under Linux systems the program prefix may usually be determined automatically, portable programs should call this function. Usually the prefix is set during program configuration if using GNU autotools and so it is enough to pass its value defined in config.h
to this function.
void wxStandardPaths::UseAppInfo | ( | int | info | ) |
Controls what application information is used when constructing paths that should be unique to this program, such as the application data directory, the plugins directory on Unix, etc.
Valid values for info are:
AppInfo_None
: use neither application nor vendor name in the paths.AppInfo_AppName
: use the application name in the paths.AppInfo_VendorName
: use the vendor name in the paths, usually used combined with AppInfo_AppName
, i.e. as AppInfo_AppName | AppInfo_VendorName
.By default, only the application name is used.