00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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;
00192 std::string Extension;
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 }
00331
00332
00333 #endif // NL_PATH_H
00334
00335