# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

path.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_PATH_H
00027 #define NL_PATH_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/time_nl.h"
00031 
00032 #include <map>
00033 #include <string>
00034 #include <vector>
00035 
00036 #include "nel/misc/common.h"
00037 
00038 namespace NLMISC {
00039 
00041 struct EPathNotFound : public Exception
00042 {
00043         EPathNotFound (const std::string& filename) : Exception ("Path not found for " + filename) { }
00044 };
00045 
00054 class CPath
00055 {
00056 public:
00073         static void                     addSearchPath (const std::string &path, bool recurse, bool alternative);
00074 
00076         static void                     addSearchPath (const std::string &path) { addSearchPath (path, false, true); }
00077 
00079         static void                     addSearchFile (const std::string &file, bool remap = false, const std::string &virtual_ext = "");
00080 
00082         static void                     addSearchListFile (const std::string &filename, bool recurse, bool alternative);
00083         
00085         static void                     addSearchBigFile (const std::string &filename, bool recurse, bool alternative);
00086 
00088         static void                     removeAllAlternativeSearchPath ();
00089 
00105         static std::string      lookup (const std::string &filename, bool throwException = true, bool displayWarning = true, bool lookupInLocalDirectory = true);
00106 
00116         static bool                     exists (const std::string &filename);
00117 
00118 
00121         static void clearMap ();
00122 
00132         static void remapExtension (const std::string &ext1, const std::string &ext2, bool substitute);
00133 
00134         static void display ();
00135 
00139         static std::string      standardizePath (const std::string &path, bool addFinalSlash = true);
00140 
00146         static std::string      standardizeDosPath (const std::string &path);
00147 
00148 
00156         static void                     getPathContent (const std::string &path, bool recurse, bool wantDir, bool wantFile, std::vector<std::string> &result);
00157 
00168         static std::string getFullPath (const std::string &path, bool addFinalSlash = true);
00169 
00172         static std::string getCurrentPath ();
00173 
00176         static void getFileList(const std::string &extension, std::vector<std::string> &filenames);
00177 
00178 private:
00179 
00180         static CPath *getInstance ();
00181 
00182         static CPath *_Instance;
00183 
00184         // All path in this vector must have a terminated '/'
00185         std::vector<std::string> _AlternativePaths;
00186 
00187         struct CFileEntry
00188         {
00189                 CFileEntry (std::string path, bool remapped, std::string ext) : Path(path), Remapped(remapped), Extension(ext) { }
00190                 std::string     Path;
00191                 bool            Remapped;               // true if the file is remapped
00192                 std::string     Extension;              // extention of the file
00193         };
00194 
00198         std::map<std::string, CFileEntry> _Files;
00199 
00201         std::vector<std::pair<std::string, std::string> > _Extensions;
00202 
00203         sint                            findExtension (const std::string &ext1, const std::string &ext2);
00204         static void                     insertFileInMap (const std::string &filename, const std::string &filepath, bool remap, const std::string &extension);
00205 };
00206 
00207 
00208 
00215 struct CFile
00216 {
00221         static std::string getFilename (const std::string &filename);
00222 
00227         static std::string getPath (const std::string &filename);
00228 
00233         static bool isDirectory (const std::string &filename);
00234 
00240         static bool fileExists (const std::string &filename);
00241 
00247         static bool isExists (const std::string& filename);
00248 
00254         static std::string findNewFile (const std::string &filename);
00255 
00260         static int getLastSeparator (const std::string &filename);
00261 
00262         static std::string getFilenameWithoutExtension (const std::string &filename);
00263         static std::string getExtension (const std::string &filename);
00264 
00270         static uint32   getFileSize (const std::string &filename);
00271 
00277         static uint32   getFileModificationDate(const std::string &filename);
00278 
00284         static uint32   getFileCreationDate(const std::string &filename);
00285 
00297         static void addFileChangeCallback (const std::string &filename, void (*)(const std::string &filename));
00298 
00306         static void checkFileChange (TTime frequency = 1000);
00307 
00313         static bool copyFile(const char *dest, const char *src, bool failIfExists = false);
00314 
00318         static bool moveFile(const char *dest, const char *src);
00319 
00323         static bool     createDirectory(const std::string &dirname);
00324 
00325 };
00326 
00327 
00328 
00329 
00330 } // NLMISC
00331 
00332 
00333 #endif // NL_PATH_H
00334 
00335 /* End of path.h */