stdpaths.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/stdpaths.h
  3. // Purpose: declaration of wxStandardPaths class
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 2004-10-17
  7. // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_STDPATHS_H_
  11. #define _WX_STDPATHS_H_
  12. #include "wx/defs.h"
  13. #include "wx/string.h"
  14. #include "wx/filefn.h"
  15. class WXDLLIMPEXP_FWD_BASE wxStandardPaths;
  16. // ----------------------------------------------------------------------------
  17. // wxStandardPaths returns the standard locations in the file system
  18. // ----------------------------------------------------------------------------
  19. // NB: This is always compiled in, wxUSE_STDPATHS=0 only disables native
  20. // wxStandardPaths class, but a minimal version is always available
  21. class WXDLLIMPEXP_BASE wxStandardPathsBase
  22. {
  23. public:
  24. // possible resources categories
  25. enum ResourceCat
  26. {
  27. // no special category
  28. ResourceCat_None,
  29. // message catalog resources
  30. ResourceCat_Messages,
  31. // end of enum marker
  32. ResourceCat_Max
  33. };
  34. // what should we use to construct paths unique to this application:
  35. // (AppInfo_AppName and AppInfo_VendorName can be combined together)
  36. enum
  37. {
  38. AppInfo_None = 0, // nothing
  39. AppInfo_AppName = 1, // the application name
  40. AppInfo_VendorName = 2 // the vendor name
  41. };
  42. // return the global standard paths object
  43. static wxStandardPaths& Get();
  44. // return the path (directory+filename) of the running executable or
  45. // wxEmptyString if it couldn't be determined.
  46. // The path is returned as an absolute path whenever possible.
  47. // Default implementation only try to use wxApp->argv[0].
  48. virtual wxString GetExecutablePath() const;
  49. // return the directory with system config files:
  50. // /etc under Unix, c:\Documents and Settings\All Users\Application Data
  51. // under Windows, /Library/Preferences for Mac
  52. virtual wxString GetConfigDir() const = 0;
  53. // return the directory for the user config files:
  54. // $HOME under Unix, c:\Documents and Settings\username under Windows,
  55. // ~/Library/Preferences under Mac
  56. //
  57. // only use this if you have a single file to put there, otherwise
  58. // GetUserDataDir() is more appropriate
  59. virtual wxString GetUserConfigDir() const = 0;
  60. // return the location of the applications global, i.e. not user-specific,
  61. // data files
  62. //
  63. // prefix/share/appname under Unix, c:\Program Files\appname under Windows,
  64. // appname.app/Contents/SharedSupport app bundle directory under Mac
  65. virtual wxString GetDataDir() const = 0;
  66. // return the location for application data files which are host-specific
  67. //
  68. // same as GetDataDir() except under Unix where it is /etc/appname
  69. virtual wxString GetLocalDataDir() const;
  70. // return the directory for the user-dependent application data files
  71. //
  72. // $HOME/.appname under Unix,
  73. // c:\Documents and Settings\username\Application Data\appname under Windows
  74. // and ~/Library/Application Support/appname under Mac
  75. virtual wxString GetUserDataDir() const = 0;
  76. // return the directory for user data files which shouldn't be shared with
  77. // the other machines
  78. //
  79. // same as GetUserDataDir() for all platforms except Windows where it is
  80. // the "Local Settings\Application Data\appname" directory
  81. virtual wxString GetUserLocalDataDir() const;
  82. // return the directory where the loadable modules (plugins) live
  83. //
  84. // prefix/lib/appname under Unix, program directory under Windows and
  85. // Contents/Plugins app bundle subdirectory under Mac
  86. virtual wxString GetPluginsDir() const = 0;
  87. // get resources directory: resources are auxiliary files used by the
  88. // application and include things like image and sound files
  89. //
  90. // same as GetDataDir() for all platforms except Mac where it returns
  91. // Contents/Resources subdirectory of the app bundle
  92. virtual wxString GetResourcesDir() const { return GetDataDir(); }
  93. // get localized resources directory containing the resource files of the
  94. // specified category for the given language
  95. //
  96. // in general this is just GetResourcesDir()/lang under Windows and Unix
  97. // and GetResourcesDir()/lang.lproj under Mac but is something quite
  98. // different under Unix for message catalog category (namely the standard
  99. // prefix/share/locale/lang/LC_MESSAGES)
  100. virtual wxString
  101. GetLocalizedResourcesDir(const wxString& lang,
  102. ResourceCat WXUNUSED(category)
  103. = ResourceCat_None) const
  104. {
  105. return GetResourcesDir() + wxFILE_SEP_PATH + lang;
  106. }
  107. // return the "Documents" directory for the current user
  108. //
  109. // C:\Documents and Settings\username\My Documents under Windows,
  110. // $HOME under Unix and ~/Documents under Mac
  111. virtual wxString GetDocumentsDir() const;
  112. // return the directory for the documents files used by this application:
  113. // it's a subdirectory of GetDocumentsDir() constructed using the
  114. // application name/vendor if it exists or just GetDocumentsDir() otherwise
  115. virtual wxString GetAppDocumentsDir() const;
  116. // return the temporary directory for the current user
  117. virtual wxString GetTempDir() const;
  118. // virtual dtor for the base class
  119. virtual ~wxStandardPathsBase();
  120. // Information used by AppendAppInfo
  121. void UseAppInfo(int info)
  122. {
  123. m_usedAppInfo = info;
  124. }
  125. bool UsesAppInfo(int info) const { return (m_usedAppInfo & info) != 0; }
  126. protected:
  127. // Ctor is protected as this is a base class which should never be created
  128. // directly.
  129. wxStandardPathsBase();
  130. // append the path component, with a leading path separator if a
  131. // path separator or dot (.) is not already at the end of dir
  132. static wxString AppendPathComponent(const wxString& dir, const wxString& component);
  133. // append application information determined by m_usedAppInfo to dir
  134. wxString AppendAppInfo(const wxString& dir) const;
  135. // combination of AppInfo_XXX flags used by AppendAppInfo()
  136. int m_usedAppInfo;
  137. };
  138. #if wxUSE_STDPATHS
  139. #if defined(__WINDOWS__)
  140. #include "wx/msw/stdpaths.h"
  141. #define wxHAS_NATIVE_STDPATHS
  142. // We want CoreFoundation paths on both CarbonLib and Darwin (for all ports)
  143. #elif defined(__WXMAC__) || defined(__DARWIN__)
  144. #include "wx/osx/core/stdpaths.h"
  145. #define wxHAS_NATIVE_STDPATHS
  146. #elif defined(__OS2__)
  147. #include "wx/os2/stdpaths.h"
  148. #define wxHAS_NATIVE_STDPATHS
  149. #elif defined(__UNIX__)
  150. #include "wx/unix/stdpaths.h"
  151. #define wxHAS_NATIVE_STDPATHS
  152. #endif
  153. #endif
  154. // ----------------------------------------------------------------------------
  155. // Minimal generic implementation
  156. // ----------------------------------------------------------------------------
  157. // NB: Note that this minimal implementation is compiled in even if
  158. // wxUSE_STDPATHS=0, so that our code can still use wxStandardPaths.
  159. #ifndef wxHAS_NATIVE_STDPATHS
  160. class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
  161. {
  162. public:
  163. void SetInstallPrefix(const wxString& prefix) { m_prefix = prefix; }
  164. wxString GetInstallPrefix() const { return m_prefix; }
  165. virtual wxString GetExecutablePath() const { return m_prefix; }
  166. virtual wxString GetConfigDir() const { return m_prefix; }
  167. virtual wxString GetUserConfigDir() const { return m_prefix; }
  168. virtual wxString GetDataDir() const { return m_prefix; }
  169. virtual wxString GetLocalDataDir() const { return m_prefix; }
  170. virtual wxString GetUserDataDir() const { return m_prefix; }
  171. virtual wxString GetPluginsDir() const { return m_prefix; }
  172. virtual wxString GetDocumentsDir() const { return m_prefix; }
  173. protected:
  174. // Ctor is protected because wxStandardPaths::Get() should always be used
  175. // to access the global wxStandardPaths object of the correct type instead
  176. // of creating one of a possibly wrong type yourself.
  177. wxStandardPaths() { }
  178. private:
  179. wxString m_prefix;
  180. };
  181. #endif // !wxHAS_NATIVE_STDPATHS
  182. #endif // _WX_STDPATHS_H_