lldir.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /**
  2. * @file lldir.h
  3. * @brief Definition of directory utilities class
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewergpl$
  6. *
  7. * Copyright (c) 2000-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLDIR_H
  33. #define LL_LLDIR_H
  34. #include "llstring.h"
  35. // These numbers *may* get serialized, so we need to be explicit
  36. typedef enum ELLPath
  37. {
  38. LL_PATH_NONE = 0,
  39. LL_PATH_USER_SETTINGS = 1,
  40. LL_PATH_APP_SETTINGS = 2,
  41. LL_PATH_PER_ACCOUNT = 3,
  42. LL_PATH_CACHE = 4,
  43. LL_PATH_CHARACTER = 5,
  44. #if 0 // Not used
  45. LL_PATH_MOTIONS = 6,
  46. #endif
  47. LL_PATH_HELP = 7,
  48. LL_PATH_LOGS = 8,
  49. LL_PATH_TEMP = 9,
  50. LL_PATH_SKINS = 10,
  51. LL_PATH_TOP_SKIN = 11,
  52. LL_PATH_CHAT_LOGS = 12,
  53. LL_PATH_PER_ACCOUNT_CHAT_LOGS = 13,
  54. #if 0 // Deprecated
  55. LL_PATH_MOZILLA_PROFILE = 14,
  56. LL_PATH_HTML = 15,
  57. #endif
  58. LL_PATH_EXECUTABLE = 16,
  59. LL_PATH_LAST
  60. } ELLPath;
  61. class LLDir
  62. {
  63. protected:
  64. LOG_CLASS(LLDir);
  65. public:
  66. LLDir();
  67. ///////////////////////////////////////////////////////////////////////////
  68. // OS-specific methods implemented in lldir_<os>.cpp.
  69. void init();
  70. void initAppDirs(const std::string& app_name);
  71. std::string getCurPath();
  72. // Full path and name for the plugin wrapper executable (SLPlugin)
  73. std::string getLLPluginLauncher();
  74. // Full path and name to the plugin DSO for this base_name (i.e.
  75. // 'FOO' -> '/bar/baz/libFOO.so')
  76. std::string getLLPluginFilename(std::string base_name);
  77. ///////////////////////////////////////////////////////////////////////////
  78. // Methods common to all OSes and implemented in lldir.cpp
  79. std::string findFile(const std::string& filename,
  80. const std::string& path1 = LLStringUtil::null,
  81. const std::string& path2 = LLStringUtil::null,
  82. const std::string& path3 = LLStringUtil::null,
  83. const std::string& path4 = LLStringUtil::null) const;
  84. // Full pathname of the executable
  85. LL_INLINE const std::string& getExecutablePathAndName() const
  86. {
  87. return mExecutablePathAndName;
  88. }
  89. // Directory where the executable is located
  90. LL_INLINE const std::string& getExecutableDir() const
  91. {
  92. return mExecutableDir;
  93. }
  94. // Filename of the executable
  95. LL_INLINE const std::string& getExecutableFilename() const
  96. {
  97. return mExecutableFilename;
  98. }
  99. // Directory containing plugins and plugin shell
  100. LL_INLINE const std::string& getLLPluginDir() const
  101. {
  102. return mLLPluginDir;
  103. }
  104. // Application name (SecondLife)
  105. LL_INLINE const std::string& getAppName() const
  106. {
  107. return mAppName;
  108. }
  109. // Current working directory
  110. LL_INLINE const std::string& getWorkingDir() const
  111. {
  112. return mWorkingDir;
  113. }
  114. // Location of read-only data files
  115. LL_INLINE const std::string& getAppRODataDir() const
  116. {
  117. return mAppRODataDir;
  118. }
  119. // Location of the OS-specific user directory
  120. LL_INLINE const std::string& getOSUserDir() const
  121. {
  122. return mOSUserDir;
  123. }
  124. // Location of the OS-specific user application directory
  125. LL_INLINE const std::string& getOSUserAppDir() const
  126. {
  127. return mOSUserAppDir;
  128. }
  129. // Location of the Linden user directory
  130. LL_INLINE const std::string& getLindenUserDir() const
  131. {
  132. return mLindenUserDir;
  133. }
  134. // Location of the chat logs directory
  135. LL_INLINE const std::string& getChatLogsDir() const
  136. {
  137. return mChatLogsDir;
  138. }
  139. // Location of the per-account chat logs directory.
  140. LL_INLINE const std::string& getPerAccountChatLogsDir() const
  141. {
  142. return mPerAccountChatLogsDir;
  143. }
  144. // Common temporary directory
  145. LL_INLINE const std::string& getTempDir() const
  146. {
  147. return mTempDir;
  148. }
  149. // Location of OS-specific cache folder (may be an empty string)
  150. LL_INLINE const std::string& getOSCacheDir() const
  151. {
  152. return mOSCacheDir;
  153. }
  154. // File containing TLS certificate authorities
  155. LL_INLINE const std::string& getCRTFile() const
  156. {
  157. return mCRTFile;
  158. }
  159. // Return true when a "colors_base.xml" file can be found for a skin which
  160. // resides in a 'skin_folder' sub-folder of either the viewer installation
  161. // directory or the user overrides directory. HB
  162. bool hasSkin(const char* skin_folder) const;
  163. LL_INLINE bool hasSkin(const std::string& skin_folder) const
  164. {
  165. return hasSkin(skin_folder.c_str());
  166. }
  167. // Current (active) skin directory.
  168. LL_INLINE const std::string& getSkinDir() const
  169. {
  170. return mSkinDir;
  171. }
  172. // User-specified skin directory with user overrides. E.g.
  173. // ~/.secondlife/skins/silver
  174. LL_INLINE const std::string& getUserSkinDir() const
  175. {
  176. return mUserSkinDir;
  177. }
  178. // User-specified skin directory with user overrides. E.g.
  179. // ~/.secondlife/skins/default
  180. LL_INLINE const std::string& getUserDefaultSkinDir() const
  181. {
  182. return mUserDefaultSkinDir;
  183. }
  184. // Directory for the default skin. e.g.
  185. // /usr/local/CoolVLViewer/skins/default
  186. LL_INLINE const std::string& getDefaultSkinDir() const
  187. {
  188. return mDefaultSkinDir;
  189. }
  190. // Location of the cache.
  191. std::string getCacheDir(bool get_default = false) const;
  192. // Directory containing all the installed skins (not user overrides). E.g.
  193. // /usr/local/CoolVLViewer/skins
  194. std::string getSkinBaseDir() const;
  195. // Expanded filename
  196. std::string getFullPath(ELLPath location, const std::string& subdir1,
  197. const std::string& subdir2,
  198. const std::string& filename) const;
  199. LL_INLINE std::string getFullPath(ELLPath loc,
  200. const std::string& fname) const
  201. {
  202. return getFullPath(loc, LLStringUtil::null, fname);
  203. }
  204. LL_INLINE std::string getFullPath(ELLPath loc, const std::string& subdir,
  205. const std::string& fname) const
  206. {
  207. return getFullPath(loc, LLStringUtil::null, subdir, fname);
  208. }
  209. LL_INLINE std::string getFullPath(ELLPath location) const
  210. {
  211. return getFullPath(location, LLStringUtil::null);
  212. }
  213. // Base and directory name extraction
  214. std::string getBaseFileName(const std::string& filepath,
  215. bool strip_exten = false) const;
  216. std::string getDirName(const std::string& filepath) const;
  217. // Excludes '.', e.g getExtension("foo.wav") == "wav"
  218. std::string getExtension(const std::string& filepath) const;
  219. bool isRelativePath(const std::string& path) const;
  220. // These methods search the various skin paths for the specified file in
  221. // the following order: getUserSkinDir(), getSkinDir(), getDefaultSkinDir()
  222. std::string findSkinnedFilename(const std::string& filename) const;
  223. std::string findSkinnedFilename(const std::string& subdir,
  224. const std::string& filename) const;
  225. std::string findSkinnedFilename(const std::string& subdir1,
  226. const std::string& subdir2,
  227. const std::string& filename) const;
  228. // This is for use with files stored in LL_PATH_PER_ACCOUNT or
  229. // LL_PATH_USER_SETTINGS subdirectories (in this order of priority), or
  230. // even in mOSUserDir if the desired_subdir string starts with '~'. It is
  231. // currently only used for the preprocessor #include mechanism. It ensures
  232. // the file name and sub-directory names are scrubbed and that the latter
  233. // do not allow navigating upwards in the file system.
  234. // In case of failure to find an adequate file, it returns an empty string.
  235. // Any path separators in 'fallback_subdir' and 'filename' should always be
  236. // '/', even for Windows, and in the latter case, they get properly
  237. // replaced with '\' in the returned full path string. HB
  238. std::string getUserFilename(std::string desired_subdir,
  239. std::string fallback_subdir,
  240. std::string filename);
  241. // Returns a random filename in common temporary directory, without a
  242. // ".tmp" extension when passed false.
  243. std::string getTempFilename(bool with_extension = true) const;
  244. // For producing safe download directory or file names from potentially
  245. // unsafe ones
  246. static std::string getForbiddenDirChars();
  247. static std::string getForbiddenFileChars();
  248. static std::string getScrubbedDirName(const std::string& dirname);
  249. static std::string getScrubbedFileName(const std::string& filename);
  250. // Sets the chat logs dir to this user's dir
  251. void setChatLogsDir(const std::string& path);
  252. // Sets the per-account chat log directory.
  253. void setPerAccountChatLogsDir(const std::string& grid,
  254. const std::string& first,
  255. const std::string& last);
  256. // Sets the linden user dir to this user's dir
  257. void setLindenUserDir(const std::string& grid,
  258. const std::string& first,
  259. const std::string& last);
  260. void setSkinFolder(const std::string& skin_folder);
  261. bool setCacheDir(const std::string& path);
  262. void dumpCurrentDirectories();
  263. // Utility routine
  264. std::string buildSLOSCacheDir() const;
  265. protected:
  266. std::string mAppName; // Application name ("SecondLife")
  267. std::string mExecutablePathAndName; // full path + Filename of .exe
  268. std::string mExecutableFilename; // Filename of .exe
  269. std::string mExecutableDir; // Location of executable
  270. std::string mWorkingDir; // Current working directory
  271. std::string mAppRODataDir; // Location for static app data
  272. std::string mOSUserDir; // OS Specific user directory
  273. std::string mOSUserAppDir; // OS Specific user app directory
  274. std::string mLindenUserDir; // Location for user-specific data
  275. std::string mPerAccountChatLogsDir; // Location for chat logs.
  276. std::string mChatLogsDir; // Location for chat logs.
  277. std::string mCRTFile; // Location of the TLS CRT file.
  278. std::string mTempDir; // Temporary files directory.
  279. std::string mCacheDir; // Cache directory as set by user
  280. std::string mDefaultCacheDir; // default cache diretory
  281. std::string mOSCacheDir; // Operating system cache dir
  282. std::string mSkinDir; // Location for current skin info.
  283. std::string mDefaultSkinDir; // Location for default skin info.
  284. std::string mUserSkinDir; // Location for user-modified skin info
  285. std::string mUserDefaultSkinDir; // User-modified default skin info
  286. std::string mLLPluginDir; // Location for plugins
  287. private:
  288. #if LL_WINDOWS
  289. std::string mOSBaseAppDir;
  290. #endif
  291. bool mUsingDefaultSkin; // true when using skin "default"
  292. };
  293. extern LLDir gDirUtil;
  294. #endif // LL_LLDIR_H