/indra/llvfs/lldir.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 172 lines · 110 code · 24 blank · 38 comment · 0 complexity · 733d1c89d026464b107ff062a7709052 MD5 · raw file

  1. /**
  2. * @file lldir.h
  3. * @brief Definition of directory utilities class
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLDIR_H
  27. #define LL_LLDIR_H
  28. #if LL_SOLARIS
  29. #include <sys/param.h>
  30. #define MAX_PATH MAXPATHLEN
  31. #endif
  32. // these numbers *may* get serialized (really??), so we need to be explicit
  33. typedef enum ELLPath
  34. {
  35. LL_PATH_NONE = 0,
  36. LL_PATH_USER_SETTINGS = 1,
  37. LL_PATH_APP_SETTINGS = 2,
  38. LL_PATH_PER_SL_ACCOUNT = 3, // returns/expands to blank string if we don't know the account name yet
  39. LL_PATH_CACHE = 4,
  40. LL_PATH_CHARACTER = 5,
  41. LL_PATH_HELP = 6,
  42. LL_PATH_LOGS = 7,
  43. LL_PATH_TEMP = 8,
  44. LL_PATH_SKINS = 9,
  45. LL_PATH_TOP_SKIN = 10,
  46. LL_PATH_CHAT_LOGS = 11,
  47. LL_PATH_PER_ACCOUNT_CHAT_LOGS = 12,
  48. LL_PATH_USER_SKIN = 14,
  49. LL_PATH_LOCAL_ASSETS = 15,
  50. LL_PATH_EXECUTABLE = 16,
  51. LL_PATH_DEFAULT_SKIN = 17,
  52. LL_PATH_FONTS = 18,
  53. LL_PATH_LAST
  54. } ELLPath;
  55. class LLDir
  56. {
  57. public:
  58. LLDir();
  59. virtual ~LLDir();
  60. // app_name - Usually SecondLife, used for creating settings directories
  61. // in OS-specific location, such as C:\Documents and Settings
  62. // app_read_only_data_dir - Usually the source code directory, used
  63. // for test applications to read newview data files.
  64. virtual void initAppDirs(const std::string &app_name,
  65. const std::string& app_read_only_data_dir = "") = 0;
  66. virtual S32 deleteFilesInDir(const std::string &dirname, const std::string &mask);
  67. // pure virtual functions
  68. virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask) = 0;
  69. virtual std::string getCurPath() = 0;
  70. virtual BOOL fileExists(const std::string &filename) const = 0;
  71. const std::string findFile(const std::string& filename, const std::vector<std::string> filenames) const;
  72. const std::string findFile(const std::string& filename, const std::string& searchPath1 = "", const std::string& searchPath2 = "", const std::string& searchPath3 = "") const;
  73. virtual std::string getLLPluginLauncher() = 0; // full path and name for the plugin shell
  74. virtual std::string getLLPluginFilename(std::string base_name) = 0; // full path and name to the plugin DSO for this base_name (i.e. 'FOO' -> '/bar/baz/libFOO.so')
  75. const std::string &getExecutablePathAndName() const; // Full pathname of the executable
  76. const std::string &getAppName() const; // install directory under progams/ ie "SecondLife"
  77. const std::string &getExecutableDir() const; // Directory where the executable is located
  78. const std::string &getExecutableFilename() const;// Filename of .exe
  79. const std::string &getWorkingDir() const; // Current working directory
  80. const std::string &getAppRODataDir() const; // Location of read-only data files
  81. const std::string &getOSUserDir() const; // Location of the os-specific user dir
  82. const std::string &getOSUserAppDir() const; // Location of the os-specific user app dir
  83. const std::string &getLindenUserDir() const; // Location of the Linden user dir.
  84. const std::string &getChatLogsDir() const; // Location of the chat logs dir.
  85. const std::string &getPerAccountChatLogsDir() const; // Location of the per account chat logs dir.
  86. const std::string &getTempDir() const; // Common temporary directory
  87. const std::string getCacheDir(bool get_default = false) const; // Location of the cache.
  88. const std::string &getOSCacheDir() const; // location of OS-specific cache folder (may be empty string)
  89. const std::string &getCAFile() const; // File containing TLS certificate authorities
  90. const std::string &getDirDelimiter() const; // directory separator for platform (ie. '\' or '/' or ':')
  91. const std::string &getSkinDir() const; // User-specified skin folder.
  92. const std::string &getUserSkinDir() const; // User-specified skin folder with user modifications. e.g. c:\documents and settings\username\application data\second life\skins\curskin
  93. const std::string &getDefaultSkinDir() const; // folder for default skin. e.g. c:\program files\second life\skins\default
  94. const std::string getSkinBaseDir() const; // folder that contains all installed skins (not user modifications). e.g. c:\program files\second life\skins
  95. const std::string &getLLPluginDir() const; // Directory containing plugins and plugin shell
  96. // Expanded filename
  97. std::string getExpandedFilename(ELLPath location, const std::string &filename) const;
  98. std::string getExpandedFilename(ELLPath location, const std::string &subdir, const std::string &filename) const;
  99. std::string getExpandedFilename(ELLPath location, const std::string &subdir1, const std::string &subdir2, const std::string &filename) const;
  100. // Base and Directory name extraction
  101. std::string getBaseFileName(const std::string& filepath, bool strip_exten = false) const;
  102. std::string getDirName(const std::string& filepath) const;
  103. std::string getExtension(const std::string& filepath) const; // Excludes '.', e.g getExtension("foo.wav") == "wav"
  104. // these methods search the various skin paths for the specified file in the following order:
  105. // getUserSkinDir(), getSkinDir(), getDefaultSkinDir()
  106. std::string findSkinnedFilename(const std::string &filename) const;
  107. std::string findSkinnedFilename(const std::string &subdir, const std::string &filename) const;
  108. std::string findSkinnedFilename(const std::string &subdir1, const std::string &subdir2, const std::string &filename) const;
  109. // random filename in common temporary directory
  110. std::string getTempFilename() const;
  111. // For producing safe download file names from potentially unsafe ones
  112. static std::string getScrubbedFileName(const std::string uncleanFileName);
  113. static std::string getForbiddenFileChars();
  114. virtual void setChatLogsDir(const std::string &path); // Set the chat logs dir to this user's dir
  115. virtual void setPerAccountChatLogsDir(const std::string &username); // Set the per user chat log directory.
  116. virtual void setLindenUserDir(const std::string &username); // Set the linden user dir to this user's dir
  117. virtual void setSkinFolder(const std::string &skin_folder);
  118. virtual bool setCacheDir(const std::string &path);
  119. virtual void dumpCurrentDirectories();
  120. // Utility routine
  121. std::string buildSLOSCacheDir() const;
  122. protected:
  123. std::string mAppName; // install directory under progams/ ie "SecondLife"
  124. std::string mExecutablePathAndName; // full path + Filename of .exe
  125. std::string mExecutableFilename; // Filename of .exe
  126. std::string mExecutableDir; // Location of executable
  127. std::string mWorkingDir; // Current working directory
  128. std::string mAppRODataDir; // Location for static app data
  129. std::string mOSUserDir; // OS Specific user directory
  130. std::string mOSUserAppDir; // OS Specific user app directory
  131. std::string mLindenUserDir; // Location for Linden user-specific data
  132. std::string mPerAccountChatLogsDir; // Location for chat logs.
  133. std::string mChatLogsDir; // Location for chat logs.
  134. std::string mCAFile; // Location of the TLS certificate authority PEM file.
  135. std::string mTempDir;
  136. std::string mCacheDir; // cache directory as set by user preference
  137. std::string mDefaultCacheDir; // default cache diretory
  138. std::string mOSCacheDir; // operating system cache dir
  139. std::string mDirDelimiter;
  140. std::string mSkinBaseDir; // Base for skins paths.
  141. std::string mSkinDir; // Location for current skin info.
  142. std::string mDefaultSkinDir; // Location for default skin info.
  143. std::string mUserSkinDir; // Location for user-modified skin info.
  144. std::string mLLPluginDir; // Location for plugins and plugin shell
  145. };
  146. void dir_exists_or_crash(const std::string &dir_name);
  147. extern LLDir *gDirUtilp;
  148. #endif // LL_LLDIR_H