stdpaths.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: stdpaths.h
  3. // Purpose: interface of wxStandardPaths
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxStandardPaths
  9. wxStandardPaths returns the standard locations in the file system and should be
  10. used by applications to find their data files in a portable way.
  11. Note that you must not create objects of class wxStandardPaths directly,
  12. but use the global standard paths object returned by wxStandardPaths::Get()
  13. (which can be of a type derived from wxStandardPaths and not of exactly
  14. this type) and call the methods you need on it. The object returned by
  15. Get() may be customized by overriding wxAppTraits::GetStandardPaths()
  16. methods.
  17. In the description of the methods below, the example return values are given
  18. for the Unix, Windows and Mac OS X systems, however please note that these are
  19. just the examples and the actual values may differ. For example, under Windows:
  20. the system administrator may change the standard directories locations, e.g.
  21. the Windows directory may be named @c "W:\Win2003" instead of
  22. the default @c "C:\Windows".
  23. Notice that in the examples below the string @c appinfo may be either just
  24. the application name (as returned by wxApp::GetAppName()) or a combination
  25. of the vendor name (wxApp::GetVendorName()) and the application name, with
  26. a path separator between them. By default, only the application name is
  27. used, use UseAppInfo() to change this.
  28. The other placeholders should be self-explanatory: the string @c username
  29. should be replaced with the value the name of the currently logged in user.
  30. and @c prefix is only used under Unix and is @c /usr/local by default but
  31. may be changed using wxStandardPaths::SetInstallPrefix().
  32. The directories returned by the methods of this class may or may not exist.
  33. If they don't exist, it's up to the caller to create them, wxStandardPaths doesn't
  34. do it.
  35. Finally note that these functions only work with standardly packaged
  36. applications. I.e. under Unix you should follow the standard installation
  37. conventions and under Mac you should create your application bundle according
  38. to the Apple guidelines. Again, this class doesn't help you to do it.
  39. This class is MT-safe: its methods may be called concurrently from different
  40. threads without additional locking.
  41. @library{wxbase}
  42. @category{file}
  43. @see wxFileConfig
  44. */
  45. class wxStandardPaths
  46. {
  47. public:
  48. /// Possible values for category parameter of GetLocalizedResourcesDir().
  49. enum ResourceCat
  50. {
  51. /// No special category, this is the default.
  52. ResourceCat_None,
  53. /// Message catalog resources category.
  54. ResourceCat_Messages
  55. };
  56. /**
  57. MSW-specific function undoing the effect of IgnoreAppSubDir() calls.
  58. After a call to this function the program directory will be exactly the
  59. directory containing the main application binary, i.e. it undoes the
  60. effect of any previous IgnoreAppSubDir() calls including the ones done
  61. indirectly by IgnoreAppBuildSubDirs() called from the class
  62. constructor.
  63. @since 2.9.1
  64. */
  65. void DontIgnoreAppSubDir();
  66. /**
  67. Returns reference to the unique global standard paths object.
  68. */
  69. static wxStandardPaths& Get();
  70. /**
  71. Return the directory for the document files used by this application.
  72. If the application-specific directory doesn't exist, this function
  73. returns GetDocumentsDir().
  74. Example return values:
  75. - Unix: @c ~/appinfo
  76. - Windows: @c "C:\Documents and Settings\username\My Documents\appinfo"
  77. - Mac: @c ~/Documents/appinfo
  78. @since 2.9.0
  79. */
  80. virtual wxString GetAppDocumentsDir() const;
  81. /**
  82. Return the directory containing the system config files.
  83. Example return values:
  84. - Unix: @c /etc
  85. - Windows: @c "C:\Documents and Settings\All Users\Application Data"
  86. - Mac: @c /Library/Preferences
  87. @see wxFileConfig
  88. */
  89. virtual wxString GetConfigDir() const;
  90. /**
  91. Return the location of the applications global, i.e.\ not user-specific,
  92. data files.
  93. Example return values:
  94. - Unix: @c prefix/share/appinfo
  95. - Windows: the directory where the executable file is located
  96. - Mac: @c appinfo.app/Contents/SharedSupport bundle subdirectory
  97. Under Unix (only) it is possible to override the default value returned
  98. from this function by setting the value of @c WX_APPNAME_DATA_DIR
  99. environment variable to the directory to use (where @c APPNAME is the
  100. upper-cased value of wxApp::GetAppName()). This is useful in order to
  101. be able to run applications using this function without installing them
  102. as you can simply set this environment variable to the source directory
  103. location to allow the application to find its files there.
  104. @see GetLocalDataDir()
  105. */
  106. virtual wxString GetDataDir() const;
  107. /**
  108. Return the directory containing the current user's documents.
  109. Example return values:
  110. - Unix: @c ~ (the home directory)
  111. - Windows: @c "C:\Documents and Settings\username\My Documents"
  112. - Mac: @c ~/Documents
  113. @since 2.7.0
  114. @see GetAppDocumentsDir()
  115. */
  116. virtual wxString GetDocumentsDir() const;
  117. /**
  118. Return the directory and the filename for the current executable.
  119. Example return values:
  120. - Unix: @c /usr/local/bin/exename
  121. - Windows: @c "C:\Programs\AppFolder\exename.exe"
  122. - Mac: @c /Applications/exename.app/Contents/MacOS/exename
  123. */
  124. virtual wxString GetExecutablePath() const;
  125. /**
  126. Return the program installation prefix, e.g.\ @c /usr, @c /opt or @c /home/zeitlin.
  127. If the prefix had been previously by SetInstallPrefix(), returns that
  128. value, otherwise tries to determine it automatically (Linux only right now)
  129. and finally returns the default @c /usr/local value if it failed.
  130. @note This function is only available under Unix platforms (but not limited
  131. to wxGTK mentioned below).
  132. @onlyfor{wxos2,wxgtk}
  133. */
  134. wxString GetInstallPrefix() const;
  135. /**
  136. Return the location for application data files which are host-specific and
  137. can't, or shouldn't, be shared with the other machines.
  138. This is the same as GetDataDir() except under Unix where it returns @c /etc/appinfo.
  139. */
  140. virtual wxString GetLocalDataDir() const;
  141. /**
  142. Return the localized resources directory containing the resource files of the
  143. specified category for the given language.
  144. In general this is just the same as @a lang subdirectory of GetResourcesDir()
  145. (or @c lang.lproj under Mac OS X) but is something quite different for
  146. message catalog category under Unix where it returns the standard
  147. @c prefix/share/locale/lang/LC_MESSAGES directory.
  148. @since 2.7.0
  149. */
  150. virtual wxString
  151. GetLocalizedResourcesDir(const wxString& lang,
  152. ResourceCat category = ResourceCat_None) const;
  153. /**
  154. Return the directory where the loadable modules (plugins) live.
  155. Example return values:
  156. - Unix: @c prefix/lib/appinfo
  157. - Windows: the directory of the executable file
  158. - Mac: @c appinfo.app/Contents/PlugIns bundle subdirectory
  159. @see wxDynamicLibrary
  160. */
  161. virtual wxString GetPluginsDir() const;
  162. /**
  163. Return the directory where the application resource files are located.
  164. The resources are the auxiliary data files needed for the application to run
  165. and include, for example, image and sound files it might use.
  166. This function is the same as GetDataDir() for all platforms except Mac OS X.
  167. Example return values:
  168. - Unix: @c prefix/share/appinfo
  169. - Windows: the directory where the executable file is located
  170. - Mac: @c appinfo.app/Contents/Resources bundle subdirectory
  171. @since 2.7.0
  172. @see GetLocalizedResourcesDir()
  173. */
  174. virtual wxString GetResourcesDir() const;
  175. /**
  176. Return the directory for storing temporary files.
  177. To create unique temporary files, it is best to use wxFileName::CreateTempFileName
  178. for correct behaviour when multiple processes are attempting to create temporary files.
  179. @since 2.7.2
  180. */
  181. virtual wxString GetTempDir() const;
  182. /**
  183. Return the directory for the user config files:
  184. - Unix: @c ~ (the home directory)
  185. - Windows: @c "C:\Documents and Settings\username\Application Data"
  186. - Mac: @c ~/Library/Preferences
  187. Only use this method if you have a single configuration file to put in this
  188. directory, otherwise GetUserDataDir() is more appropriate as the latter
  189. adds @c appinfo to the path, unlike this function.
  190. */
  191. virtual wxString GetUserConfigDir() const;
  192. /**
  193. Return the directory for the user-dependent application data files:
  194. - Unix: @c ~/.appinfo
  195. - Windows: @c "C:\Documents and Settings\username\Application Data\appinfo"
  196. - Mac: @c "~/Library/Application Support/appinfo"
  197. */
  198. virtual wxString GetUserDataDir() const;
  199. /**
  200. Return the directory for user data files which shouldn't be shared with
  201. the other machines.
  202. This is the same as GetUserDataDir() for all platforms except Windows where it returns
  203. @c "C:\Documents and Settings\username\Local Settings\Application Data\appinfo"
  204. */
  205. virtual wxString GetUserLocalDataDir() const;
  206. /**
  207. MSW-specific function to customize application directory detection.
  208. This class supposes that data, plugins &c files are located under the
  209. program directory which is the directory containing the application
  210. binary itself. But sometimes this binary may be in a subdirectory of
  211. the main program directory, e.g. this happens in at least the following
  212. common cases:
  213. - The program is in "bin" subdirectory of the installation directory.
  214. - The program is in "debug" subdirectory of the directory containing
  215. sources and data files during development
  216. By calling this function you instruct the class to remove the last
  217. component of the path if it matches its argument. Notice that it may be
  218. called more than once, e.g. you can call both IgnoreAppSubDir("bin") and
  219. IgnoreAppSubDir("debug") to take care of both production and development
  220. cases above but that each call will only remove the last path component.
  221. Finally note that the argument can contain wild cards so you can also
  222. call IgnoreAppSubDir("vc*msw*") to ignore all build directories at once
  223. when using wxWidgets-inspired output directories names.
  224. @since 2.9.1
  225. @see IgnoreAppBuildSubDirs()
  226. @param subdirPattern
  227. The subdirectory containing the application binary which should be
  228. ignored when determining the top application directory. The pattern
  229. is case-insensitive and may contain wild card characters @c '?' and
  230. @c '*'.
  231. */
  232. void IgnoreAppSubDir(const wxString& subdirPattern);
  233. /**
  234. MSW-specific function to ignore all common build directories.
  235. This function calls IgnoreAppSubDir() with all common values for build
  236. directory, e.g. @c "debug" and @c "release".
  237. It is called by the class constructor and so the build directories are
  238. always ignored by default. You may use DontIgnoreAppSubDir() to avoid
  239. ignoring them if this is inappropriate for your application.
  240. @since 2.9.1
  241. */
  242. void IgnoreAppBuildSubDirs();
  243. /**
  244. Returns location of Windows shell special folder.
  245. This function is, by definition, MSW-specific. It can be used to access
  246. pre-defined shell directories not covered by the existing methods of
  247. this class, e.g.:
  248. @code
  249. #ifdef __WXMSW__
  250. // get the location of files waiting to be burned on a CD
  251. wxString cdburnArea =
  252. wxStandardPaths::MSWGetShellDir(CSIDL_CDBURN_AREA);
  253. #endif // __WXMSW__
  254. @endcode
  255. @param csidl
  256. @since 2.9.1
  257. */
  258. static wxString MSWGetShellDir(int csidl);
  259. /**
  260. Lets wxStandardPaths know about the real program installation prefix on a Unix
  261. system. By default, the value returned by GetInstallPrefix() is used.
  262. Although under Linux systems the program prefix may usually be determined
  263. automatically, portable programs should call this function. Usually the prefix
  264. is set during program configuration if using GNU autotools and so it is enough
  265. to pass its value defined in @c config.h to this function.
  266. @note This function is only available under Unix platforms (but not limited
  267. to wxGTK mentioned below).
  268. @onlyfor{wxos2,wxgtk}
  269. */
  270. void SetInstallPrefix(const wxString& prefix);
  271. /**
  272. Controls what application information is used when constructing paths that
  273. should be unique to this program, such as the application data directory, the
  274. plugins directory on Unix, etc.
  275. Valid values for @a info are:
  276. - @c AppInfo_None: don't use neither application nor vendor name in
  277. the paths.
  278. - @c AppInfo_AppName: use the application name in the paths.
  279. - @c AppInfo_VendorName: use the vendor name in the paths, usually
  280. used combined with AppInfo_AppName, i.e. as @code AppInfo_AppName |
  281. AppInfo_VendorName @endcode
  282. By default, only the application name is used.
  283. @since 2.9.0
  284. */
  285. void UseAppInfo(int info);
  286. protected:
  287. /**
  288. Protected default constructor.
  289. This constructor is protected in order to prevent creation of objects
  290. of this class as Get() should be used instead to access the unique
  291. global wxStandardPaths object of the correct type.
  292. */
  293. wxStandardPaths();
  294. };