stdpaths.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. @see GetAppDocumentsDir()
  80. */
  81. virtual wxString GetAppDocumentsDir() const;
  82. /**
  83. Return the directory containing the system config files.
  84. Example return values:
  85. - Unix: @c /etc
  86. - Windows: @c "C:\Documents and Settings\All Users\Application Data"
  87. - Mac: @c /Library/Preferences
  88. @see wxFileConfig
  89. */
  90. virtual wxString GetConfigDir() const;
  91. /**
  92. Return the location of the applications global, i.e.\ not user-specific,
  93. data files.
  94. Example return values:
  95. - Unix: @c prefix/share/appinfo
  96. - Windows: the directory where the executable file is located
  97. - Mac: @c appinfo.app/Contents/SharedSupport bundle subdirectory
  98. Under Unix (only) it is possible to override the default value returned
  99. from this function by setting the value of @c WX_APPNAME_DATA_DIR
  100. environment variable to the directory to use (where @c APPNAME is the
  101. upper-cased value of wxApp::GetAppName()). This is useful in order to
  102. be able to run applications using this function without installing them
  103. as you can simply set this environment variable to the source directory
  104. location to allow the application to find its files there.
  105. @see GetLocalDataDir()
  106. */
  107. virtual wxString GetDataDir() const;
  108. /**
  109. Return the directory containing the current user's documents.
  110. Example return values:
  111. - Unix: @c ~ (the home directory)
  112. - Windows: @c "C:\Documents and Settings\username\My Documents"
  113. - Mac: @c ~/Documents
  114. @since 2.7.0
  115. @see GetAppDocumentsDir()
  116. */
  117. virtual wxString GetDocumentsDir() const;
  118. /**
  119. Return the directory and the filename for the current executable.
  120. Example return values:
  121. - Unix: @c /usr/local/bin/exename
  122. - Windows: @c "C:\Programs\AppFolder\exename.exe"
  123. - Mac: @c /Applications/exename.app/Contents/MacOS/exename
  124. */
  125. virtual wxString GetExecutablePath() const;
  126. /**
  127. Return the program installation prefix, e.g.\ @c /usr, @c /opt or @c /home/zeitlin.
  128. If the prefix had been previously by SetInstallPrefix(), returns that
  129. value, otherwise tries to determine it automatically (Linux only right now)
  130. and finally returns the default @c /usr/local value if it failed.
  131. @note This function is only available under Unix platforms (but not limited
  132. to wxGTK mentioned below).
  133. @onlyfor{wxos2,wxgtk}
  134. */
  135. wxString GetInstallPrefix() const;
  136. /**
  137. Return the location for application data files which are host-specific and
  138. can't, or shouldn't, be shared with the other machines.
  139. This is the same as GetDataDir() except under Unix where it returns @c /etc/appinfo.
  140. */
  141. virtual wxString GetLocalDataDir() const;
  142. /**
  143. Return the localized resources directory containing the resource files of the
  144. specified category for the given language.
  145. In general this is just the same as @a lang subdirectory of GetResourcesDir()
  146. (or @c lang.lproj under Mac OS X) but is something quite different for
  147. message catalog category under Unix where it returns the standard
  148. @c prefix/share/locale/lang/LC_MESSAGES directory.
  149. @since 2.7.0
  150. */
  151. virtual wxString
  152. GetLocalizedResourcesDir(const wxString& lang,
  153. ResourceCat category = ResourceCat_None) const;
  154. /**
  155. Return the directory where the loadable modules (plugins) live.
  156. Example return values:
  157. - Unix: @c prefix/lib/appinfo
  158. - Windows: the directory of the executable file
  159. - Mac: @c appinfo.app/Contents/PlugIns bundle subdirectory
  160. @see wxDynamicLibrary
  161. */
  162. virtual wxString GetPluginsDir() const;
  163. /**
  164. Return the directory where the application resource files are located.
  165. The resources are the auxiliary data files needed for the application to run
  166. and include, for example, image and sound files it might use.
  167. This function is the same as GetDataDir() for all platforms except Mac OS X.
  168. Example return values:
  169. - Unix: @c prefix/share/appinfo
  170. - Windows: the directory where the executable file is located
  171. - Mac: @c appinfo.app/Contents/Resources bundle subdirectory
  172. @since 2.7.0
  173. @see GetLocalizedResourcesDir()
  174. */
  175. virtual wxString GetResourcesDir() const;
  176. /**
  177. Return the directory for storing temporary files.
  178. To create unique temporary files, it is best to use wxFileName::CreateTempFileName
  179. for correct behaviour when multiple processes are attempting to create temporary files.
  180. @since 2.7.2
  181. */
  182. virtual wxString GetTempDir() const;
  183. /**
  184. Return the directory for the user config files:
  185. - Unix: @c ~ (the home directory)
  186. - Windows: @c "C:\Documents and Settings\username\Application Data"
  187. - Mac: @c ~/Library/Preferences
  188. Only use this method if you have a single configuration file to put in this
  189. directory, otherwise GetUserDataDir() is more appropriate as the latter
  190. adds @c appinfo to the path, unlike this function.
  191. */
  192. virtual wxString GetUserConfigDir() const;
  193. /**
  194. Return the directory for the user-dependent application data files:
  195. - Unix: @c ~/.appinfo
  196. - Windows: @c "C:\Documents and Settings\username\Application Data\appinfo"
  197. - Mac: @c "~/Library/Application Support/appinfo"
  198. */
  199. virtual wxString GetUserDataDir() const;
  200. /**
  201. Return the directory for user data files which shouldn't be shared with
  202. the other machines.
  203. This is the same as GetUserDataDir() for all platforms except Windows where it returns
  204. @c "C:\Documents and Settings\username\Local Settings\Application Data\appinfo"
  205. */
  206. virtual wxString GetUserLocalDataDir() const;
  207. /**
  208. MSW-specific function to customize application directory detection.
  209. This class supposes that data, plugins &c files are located under the
  210. program directory which is the directory containing the application
  211. binary itself. But sometimes this binary may be in a subdirectory of
  212. the main program directory, e.g. this happens in at least the following
  213. common cases:
  214. - The program is in "bin" subdirectory of the installation directory.
  215. - The program is in "debug" subdirectory of the directory containing
  216. sources and data files during development
  217. By calling this function you instruct the class to remove the last
  218. component of the path if it matches its argument. Notice that it may be
  219. called more than once, e.g. you can call both IgnoreAppSubDir("bin") and
  220. IgnoreAppSubDir("debug") to take care of both production and development
  221. cases above but that each call will only remove the last path component.
  222. Finally note that the argument can contain wild cards so you can also
  223. call IgnoreAppSubDir("vc*msw*") to ignore all build directories at once
  224. when using wxWidgets-inspired output directories names.
  225. @since 2.9.1
  226. @see IgnoreAppBuildSubDirs()
  227. @param subdirPattern
  228. The subdirectory containing the application binary which should be
  229. ignored when determining the top application directory. The pattern
  230. is case-insensitive and may contain wild card characters @c '?' and
  231. @c '*'.
  232. */
  233. void IgnoreAppSubDir(const wxString& subdirPattern);
  234. /**
  235. MSW-specific function to ignore all common build directories.
  236. This function calls IgnoreAppSubDir() with all common values for build
  237. directory, e.g. @c "debug" and @c "release".
  238. It is called by the class constructor and so the build directories are
  239. always ignored by default. You may use DontIgnoreAppSubDir() to avoid
  240. ignoring them if this is inappropriate for your application.
  241. @since 2.9.1
  242. */
  243. void IgnoreAppBuildSubDirs();
  244. /**
  245. Returns location of Windows shell special folder.
  246. This function is, by definition, MSW-specific. It can be used to access
  247. pre-defined shell directories not covered by the existing methods of
  248. this class, e.g.:
  249. @code
  250. #ifdef __WXMSW__
  251. // get the location of files waiting to be burned on a CD
  252. wxString cdburnArea =
  253. wxStandardPaths::MSWGetShellDir(CSIDL_CDBURN_AREA);
  254. #endif // __WXMSW__
  255. @endcode
  256. @param csidl
  257. @since 2.9.1
  258. */
  259. static wxString MSWGetShellDir(int csidl);
  260. /**
  261. Lets wxStandardPaths know about the real program installation prefix on a Unix
  262. system. By default, the value returned by GetInstallPrefix() is used.
  263. Although under Linux systems the program prefix may usually be determined
  264. automatically, portable programs should call this function. Usually the prefix
  265. is set during program configuration if using GNU autotools and so it is enough
  266. to pass its value defined in @c config.h to this function.
  267. @note This function is only available under Unix platforms (but not limited
  268. to wxGTK mentioned below).
  269. @onlyfor{wxos2,wxgtk}
  270. */
  271. void SetInstallPrefix(const wxString& prefix);
  272. /**
  273. Controls what application information is used when constructing paths that
  274. should be unique to this program, such as the application data directory, the
  275. plugins directory on Unix, etc.
  276. Valid values for @a info are:
  277. - @c AppInfo_None: don't use neither application nor vendor name in
  278. the paths.
  279. - @c AppInfo_AppName: use the application name in the paths.
  280. - @c AppInfo_VendorName: use the vendor name in the paths, usually
  281. used combined with AppInfo_AppName, i.e. as @code AppInfo_AppName |
  282. AppInfo_VendorName @endcode
  283. By default, only the application name is used.
  284. @since 2.9.0
  285. */
  286. void UseAppInfo(int info);
  287. protected:
  288. /**
  289. Protected default constructor.
  290. This constructor is protected in order to prevent creation of objects
  291. of this class as Get() should be used instead to access the unique
  292. global wxStandardPaths object of the correct type.
  293. */
  294. wxStandardPaths();
  295. };