PageRenderTime 30ms CodeModel.GetById 2ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 27#ifndef LL_LLDIR_H
 28#define LL_LLDIR_H
 29
 30#if LL_SOLARIS
 31#include <sys/param.h>
 32#define MAX_PATH MAXPATHLEN
 33#endif
 34
 35// these numbers *may* get serialized (really??), so we need to be explicit
 36typedef enum ELLPath
 37{
 38	LL_PATH_NONE = 0,
 39	LL_PATH_USER_SETTINGS = 1,
 40	LL_PATH_APP_SETTINGS = 2,	
 41	LL_PATH_PER_SL_ACCOUNT = 3, // returns/expands to blank string if we don't know the account name yet
 42	LL_PATH_CACHE = 4,	
 43	LL_PATH_CHARACTER = 5,	
 44	LL_PATH_HELP = 6,		
 45	LL_PATH_LOGS = 7,
 46	LL_PATH_TEMP = 8,
 47	LL_PATH_SKINS = 9,
 48	LL_PATH_TOP_SKIN = 10,
 49	LL_PATH_CHAT_LOGS = 11,
 50	LL_PATH_PER_ACCOUNT_CHAT_LOGS = 12,
 51	LL_PATH_USER_SKIN = 14,
 52	LL_PATH_LOCAL_ASSETS = 15,
 53	LL_PATH_EXECUTABLE = 16,
 54	LL_PATH_DEFAULT_SKIN = 17,
 55	LL_PATH_FONTS = 18,
 56	LL_PATH_LAST
 57} ELLPath;
 58
 59
 60class LLDir
 61{
 62 public:
 63	LLDir();
 64	virtual ~LLDir();
 65
 66	// app_name - Usually SecondLife, used for creating settings directories
 67	// in OS-specific location, such as C:\Documents and Settings
 68	// app_read_only_data_dir - Usually the source code directory, used
 69	// for test applications to read newview data files.
 70	virtual void initAppDirs(const std::string &app_name, 
 71		const std::string& app_read_only_data_dir = "") = 0;
 72
 73	virtual S32 deleteFilesInDir(const std::string &dirname, const std::string &mask);
 74
 75// pure virtual functions
 76	virtual U32 countFilesInDir(const std::string &dirname, const std::string &mask) = 0;
 77
 78	virtual std::string getCurPath() = 0;
 79	virtual BOOL fileExists(const std::string &filename) const = 0;
 80
 81	const std::string findFile(const std::string& filename, const std::vector<std::string> filenames) const; 
 82	const std::string findFile(const std::string& filename, const std::string& searchPath1 = "", const std::string& searchPath2 = "", const std::string& searchPath3 = "") const;
 83
 84	virtual std::string getLLPluginLauncher() = 0; // full path and name for the plugin shell
 85	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')
 86
 87	const std::string &getExecutablePathAndName() const;	// Full pathname of the executable
 88	const std::string &getAppName() const;			// install directory under progams/ ie "SecondLife"
 89	const std::string &getExecutableDir() const;	// Directory where the executable is located
 90	const std::string &getExecutableFilename() const;// Filename of .exe
 91	const std::string &getWorkingDir() const; // Current working directory
 92	const std::string &getAppRODataDir() const;	// Location of read-only data files
 93	const std::string &getOSUserDir() const;		// Location of the os-specific user dir
 94	const std::string &getOSUserAppDir() const;	// Location of the os-specific user app dir
 95	const std::string &getLindenUserDir() const;	// Location of the Linden user dir.
 96	const std::string &getChatLogsDir() const;	// Location of the chat logs dir.
 97	const std::string &getPerAccountChatLogsDir() const;	// Location of the per account chat logs dir.
 98	const std::string &getTempDir() const;			// Common temporary directory
 99	const std::string  getCacheDir(bool get_default = false) const;	// Location of the cache.
100	const std::string &getOSCacheDir() const;		// location of OS-specific cache folder (may be empty string)
101	const std::string &getCAFile() const;			// File containing TLS certificate authorities
102	const std::string &getDirDelimiter() const;	// directory separator for platform (ie. '\' or '/' or ':')
103	const std::string &getSkinDir() const;		// User-specified skin folder.
104	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
105	const std::string &getDefaultSkinDir() const;	// folder for default skin. e.g. c:\program files\second life\skins\default
106	const std::string getSkinBaseDir() const;		// folder that contains all installed skins (not user modifications). e.g. c:\program files\second life\skins
107	const std::string &getLLPluginDir() const;		// Directory containing plugins and plugin shell
108
109	// Expanded filename
110	std::string getExpandedFilename(ELLPath location, const std::string &filename) const;
111	std::string getExpandedFilename(ELLPath location, const std::string &subdir, const std::string &filename) const;
112	std::string getExpandedFilename(ELLPath location, const std::string &subdir1, const std::string &subdir2, const std::string &filename) const;
113
114	// Base and Directory name extraction
115	std::string getBaseFileName(const std::string& filepath, bool strip_exten = false) const;
116	std::string getDirName(const std::string& filepath) const;
117	std::string getExtension(const std::string& filepath) const; // Excludes '.', e.g getExtension("foo.wav") == "wav"
118
119	// these methods search the various skin paths for the specified file in the following order:
120	// getUserSkinDir(), getSkinDir(), getDefaultSkinDir()
121	std::string findSkinnedFilename(const std::string &filename) const;
122	std::string findSkinnedFilename(const std::string &subdir, const std::string &filename) const;
123	std::string findSkinnedFilename(const std::string &subdir1, const std::string &subdir2, const std::string &filename) const;
124
125	// random filename in common temporary directory
126	std::string getTempFilename() const;
127
128	// For producing safe download file names from potentially unsafe ones
129	static std::string getScrubbedFileName(const std::string uncleanFileName);
130	static std::string getForbiddenFileChars();
131
132	virtual void setChatLogsDir(const std::string &path);		// Set the chat logs dir to this user's dir
133	virtual void setPerAccountChatLogsDir(const std::string &username);		// Set the per user chat log directory.
134	virtual void setLindenUserDir(const std::string &username);		// Set the linden user dir to this user's dir
135	virtual void setSkinFolder(const std::string &skin_folder);
136	virtual bool setCacheDir(const std::string &path);
137
138	virtual void dumpCurrentDirectories();
139	
140	// Utility routine
141	std::string buildSLOSCacheDir() const;
142
143protected:
144	std::string mAppName;               // install directory under progams/ ie "SecondLife"   
145	std::string mExecutablePathAndName; // full path + Filename of .exe
146	std::string mExecutableFilename;    // Filename of .exe
147	std::string mExecutableDir;	 	 // Location of executable
148	std::string mWorkingDir;	 	 // Current working directory
149	std::string mAppRODataDir;			 // Location for static app data
150	std::string mOSUserDir;			 // OS Specific user directory
151	std::string mOSUserAppDir;			 // OS Specific user app directory
152	std::string mLindenUserDir;		 // Location for Linden user-specific data
153	std::string mPerAccountChatLogsDir;		 // Location for chat logs.
154	std::string mChatLogsDir;		 // Location for chat logs.
155	std::string mCAFile;				 // Location of the TLS certificate authority PEM file.
156	std::string mTempDir;
157	std::string mCacheDir;			// cache directory as set by user preference
158	std::string mDefaultCacheDir;	// default cache diretory
159	std::string mOSCacheDir;		// operating system cache dir
160	std::string mDirDelimiter;
161	std::string mSkinBaseDir;			// Base for skins paths.
162	std::string mSkinDir;			// Location for current skin info.
163	std::string mDefaultSkinDir;			// Location for default skin info.
164	std::string mUserSkinDir;			// Location for user-modified skin info.
165	std::string mLLPluginDir;			// Location for plugins and plugin shell
166};
167
168void dir_exists_or_crash(const std::string &dir_name);
169
170extern LLDir *gDirUtilp;
171
172#endif // LL_LLDIR_H