From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a03072.html | 2811 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2811 insertions(+) create mode 100644 docs/doxygen/nel/a03072.html (limited to 'docs/doxygen/nel/a03072.html') diff --git a/docs/doxygen/nel/a03072.html b/docs/doxygen/nel/a03072.html new file mode 100644 index 00000000..9aef0a9a --- /dev/null +++ b/docs/doxygen/nel/a03072.html @@ -0,0 +1,2811 @@ + + +NeL: NLMISC::CPath class Reference + + + +
+

NLMISC::CPath Class Reference

#include <path.h> +

+


Detailed Description

+Utility class for searching files in differents paths.
Warning:
addSearchPath(), clearMap() and remapExtension() are not reentrant.

+all path and files are *case sensitive* on linux.

+
Author:
Vianney Lecroart

+Nevrax France

+
Date:
2001
+ +

+ +

+Definition at line 55 of file path.h. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Static Public Member Functions

void addIgnoredDoubleFile (const std::string &ignoredFile)
void addSearchBigFile (const std::string &filename, bool recurse, bool alternative, class NLMISC::IProgressCallback *progressCallBack=NULL)
void addSearchFile (const std::string &file, bool remap=false, const std::string &virtual_ext="", class NLMISC::IProgressCallback *progressCallBack=NULL)
void addSearchListFile (const std::string &filename, bool recurse, bool alternative)
void addSearchPath (const std::string &path)
void addSearchPath (const std::string &path, bool recurse, bool alternative, class IProgressCallback *progressCallBack=NULL)
void clearMap ()
void display ()
bool exists (const std::string &filename)
std::string getCurrentPath ()
void getFileList (const std::string &extension, std::vector< std::string > &filenames)
std::string getFullPath (const std::string &path, bool addFinalSlash=true)
void getPathContent (const std::string &path, bool recurse, bool wantDir, bool wantFile, std::vector< std::string > &result, class IProgressCallback *progressCallBack=NULL, bool showEverything=false)
bool isMemoryCompressed ()
void loadRemappedFiles (const std::string &file)
std::string lookup (const std::string &filename, bool throwException=true, bool displayWarning=true, bool lookupInLocalDirectory=true)
bool makePathRelative (const char *basePath, std::string &relativePath)
void memoryCompress ()
void memoryUncompress ()
void remapExtension (const std::string &ext1, const std::string &ext2, bool substitute)
void remapFile (const std::string &file1, const std::string &file2)
void removeAllAlternativeSearchPath ()
bool setCurrentPath (const char *)
std::string standardizeDosPath (const std::string &path)
std::string standardizePath (const std::string &path, bool addFinalSlash=true)

Private Member Functions

 CPath ()
sint findExtension (const std::string &ext1, const std::string &ext2)

Static Private Member Functions

CPathgetInstance ()
void insertFileInMap (const std::string &filename, const std::string &filepath, bool remap, const std::string &extension)
CMCFileEntryMCfind (const std::string &filename)

Private Attributes

char * _AllFileNames
std::vector< std::string > _AlternativePaths
std::vector< std::pair< std::string,
+ std::string > > 
_Extensions
 first ext1, second ext2 (ext1 could remplace ext2)

std::map< std::string, CFileEntry_Files
std::vector< CMCFileEntry_MCFiles
bool _MemoryCompressed
std::map< std::string, std::string > _RemappedFiles
std::vector< std::string > IgnoredFiles
CStaticStringMapper SSMext
CStaticStringMapper SSMpath

Static Private Attributes

CPath_Instance = NULL
+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + +
NLMISC::CPath::CPath  )  [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 223 of file path.h. +

+References _MemoryCompressed. +

+

00224         {
+00225                 _MemoryCompressed = false;
+00226         }
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CPath::addIgnoredDoubleFile const std::string &  ignoredFile  )  [static]
+
+ + + + + +
+   + + +

+If File in this list is added more than one in an addSearchPath, it doesn't launch a warning. +

+Definition at line 1133 of file path.cpp. +

+References uint. +

+

01134 {
+01135         NL_ALLOC_CONTEXT (MiPath);
+01136         CPath::getInstance ()->IgnoredFiles.push_back(ignoredFile);
+01137 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CPath::addSearchBigFile const std::string &  filename,
bool  recurse,
bool  alternative,
class NLMISC::IProgressCallback progressCallBack = NULL
[static]
+
+ + + + + +
+   + + +

+Same as AddSearchPath but with a big file "c:/test.nbf" all files name contain in the big file will be included (the extention (Nel Big File) is used to know that it's a big file) +

+Definition at line 1025 of file path.cpp. +

+References nlwarning. +

+

01026 {
+01027  //#ifndef NL_OS_WINDOWS
+01028   //    nlerror( "BNP currently not supported on Unix" ); // test of BNP failed on Linux
+01029   //#endif
+01030 
+01031         // Check if filename is not empty
+01032         if (sBigFilename.empty())
+01033         {
+01034                 nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): can't add empty file, skip it", sBigFilename.c_str(), recurse, alternative);
+01035                 return;
+01036         }
+01037         // Check if the file exists
+01038         if (!CFile::isExists (sBigFilename))
+01039         {
+01040                 nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): '%s' is not found, skip it", sBigFilename.c_str(), recurse, alternative, sBigFilename.c_str());
+01041                 return;
+01042         }
+01043         // Check if it s a file
+01044         if (CFile::isDirectory (sBigFilename))
+01045         {
+01046                 nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): '%s' is not a file, skip it", sBigFilename.c_str(), recurse, alternative, sBigFilename.c_str());
+01047                 return;
+01048         }
+01049         // Open and read the big file header
+01050         CPath *inst = CPath::getInstance();
+01051         nlassert(!inst->_MemoryCompressed);
+01052 
+01053         FILE *Handle = fopen (sBigFilename.c_str(), "rb");
+01054         if (Handle == NULL)
+01055         {
+01056                 nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): can't open file, skip it", sBigFilename.c_str(), recurse, alternative);
+01057                 return;
+01058         }
+01059 
+01060         // add the link with the CBigFile singleton
+01061         if (CBigFile::getInstance().add (sBigFilename, BF_ALWAYS_OPENED | BF_CACHE_FILE_ON_OPEN))
+01062         {
+01063                 // also add the bigfile name in the map to retreive the full path of a .bnp when we want modification date of the bnp for example
+01064                 insertFileInMap (CFile::getFilename (sBigFilename), sBigFilename, false, CFile::getExtension(sBigFilename));
+01065 
+01066                 // parse the big file to add file in the map
+01067                 uint32 nFileSize=CFile::getFileSize (Handle);
+01068                 //nlfseek64 (Handle, 0, SEEK_END);
+01069                 //uint32 nFileSize = ftell (Handle);
+01070                 nlfseek64 (Handle, nFileSize-4, SEEK_SET);
+01071                 uint32 nOffsetFromBegining;
+01072                 fread (&nOffsetFromBegining, sizeof(uint32), 1, Handle);
+01073                 nlfseek64 (Handle, nOffsetFromBegining, SEEK_SET);
+01074                 uint32 nNbFile;
+01075                 fread (&nNbFile, sizeof(uint32), 1, Handle);
+01076                 for (uint32 i = 0; i < nNbFile; ++i)
+01077                 {
+01078                         // Progress bar
+01079                         if (progressCallBack)
+01080                         {
+01081                                 progressCallBack->progress ((float)i/(float)nNbFile);
+01082                                 progressCallBack->pushCropedValues ((float)i/(float)nNbFile, (float)(i+1)/(float)nNbFile);
+01083                         }
+01084 
+01085                         char FileName[256];
+01086                         uint8 nStringSize;
+01087                         fread (&nStringSize, 1, 1, Handle);
+01088                         fread (FileName, 1, nStringSize, Handle);
+01089                         FileName[nStringSize] = 0;
+01090                         uint32 nFileSize2;
+01091                         fread (&nFileSize2, sizeof(uint32), 1, Handle);
+01092                         uint32 nFilePos;
+01093                         fread (&nFilePos, sizeof(uint32), 1, Handle);
+01094                         string sTmp = strlwr(string(FileName));
+01095                         if (sTmp.empty())
+01096                         {
+01097                                 nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): can't add empty file, skip it", sBigFilename.c_str(), recurse, alternative);
+01098                                 continue;
+01099                         }
+01100                         string bigfilenamealone = CFile::getFilename (sBigFilename);
+01101                         string filenamewoext = CFile::getFilenameWithoutExtension (sTmp);
+01102                         string ext = strlwr(CFile::getExtension(sTmp));
+01103 
+01104                         insertFileInMap (sTmp, bigfilenamealone + "@" + sTmp, false, ext);
+
+                        for (uint j = 0; j < inst->_Extensions.size (); j++)
+                        {
+                                if (inst->_Extensions[j].first == ext)
+                                {
+                                        // need to remap
+                                        insertFileInMap (filenamewoext+"."+inst->_Extensions[j].second, 
+01105                                                                         bigfilenamealone + "@" + sTmp, 
+                                                                        true, 
+                                                                        inst->_Extensions[j].first);
+                                }
+                        }
+
+                        // Progress bar
+                        if (progressCallBack)
+                        {
+                                progressCallBack->popCropedValues ();
+                        }
+                }
+        }
+        else
+        {
+                nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): can't add the big file", sBigFilename.c_str(), recurse, alternative);
+01106         }
+01107 
+01108         fclose (Handle);
+01109 }
+01110 
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CPath::addSearchFile const std::string &  file,
bool  remap = false,
const std::string &  virtual_ext = "",
class NLMISC::IProgressCallback progressCallBack = NULL
[static]
+
+ + + + + +
+   + + +

+Same as AddSearchPath but with a file "c:/autoexec.bat" this file only will included. wildwards *doesn't* work +

+Definition at line 929 of file path.cpp. +

+References file. +

+

00930 {
+00931         NL_ALLOC_CONTEXT (MiPath);
+00932         CPath *inst = CPath::getInstance();
+00933         nlassert(!inst->_MemoryCompressed);
+00934 
+00935         string newFile = standardizePath(file, false);
+00936 
+00937         // check empty file
+00938         if (newFile.empty())
+00939         {
+00940                 nlwarning ("PATH: CPath::addSearchFile(%s, %d, %s): can't add empty file, skip it", file.c_str(), remap, virtual_ext.c_str());
+00941                 return;
+00942         }
+00943 
+00944         // check if the file exists
+00945         if (!CFile::isExists (newFile))
+00946         {
+00947                 nlwarning ("PATH: CPath::addSearchFile(%s, %d, %s): '%s' is not found, skip it", file.c_str(), remap, virtual_ext.c_str(), newFile.c_str());
+00948                 return;
+00949         }
+00950 
+00951         // check if it s a file
+00952         if (CFile::isDirectory (newFile))
+00953         {
+00954                 nlwarning ("PATH: CPath::addSearchFile(%s, %d, %s): '%s' is not a file, skip it", file.c_str(), remap, virtual_ext.c_str(), newFile.c_str());
+00955                 return;
+00956         }
+00957 
+00958         // check if it s a big file
+00959         if (CFile::getExtension(newFile) == "bnp")
+00960         {
+00961                 NL_DISPLAY_PATH ("PATH: CPath::addSearchFile(%s, %d, %s): '%s' is a big file, add it", file.c_str(), remap, virtual_ext.c_str(), newFile.c_str());
+00962                 addSearchBigFile(file, false, false, progressCallBack);
+00963                 return;
+00964         }
+00965 
+00966         string filenamewoext = CFile::getFilenameWithoutExtension (newFile);
+00967         string filename, ext;
+00968 
+00969         if (virtual_ext.empty())
+00970         {
+00971                 filename = CFile::getFilename (newFile);
+00972                 ext = CFile::getExtension (filename);
+00973         }
+00974         else
+00975         {
+00976                 filename = filenamewoext + "." + virtual_ext;
+00977                 ext = CFile::getExtension (newFile);
+00978         }
+00979 
+00980         insertFileInMap (filename, newFile, remap, ext);
+00981 
+00982         if (!remap && !ext.empty())
+00983         {
+00984                 // now, we have to see extension and insert in the map the remapped files
+00985                 for (uint i = 0; i < inst->_Extensions.size (); i++)
+00986                 {
+00987                         if (inst->_Extensions[i].first == strlwr(ext))
+00988                         {
+00989                                 // need to remap
+00990                                 addSearchFile (newFile, true, inst->_Extensions[i].second, progressCallBack);
+00991                         }
+00992                 }
+00993         }
+00994 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CPath::addSearchListFile const std::string &  filename,
bool  recurse,
bool  alternative
[static]
+
+ + + + + +
+   + + +

+Same as AddSearchPath but with a path file "c:/test.pth" all files name contain in this file will be included (the extention is used to know that it's a path file) +

+Definition at line 996 of file path.cpp. +

+

00997 {
+00998         NL_ALLOC_CONTEXT (MiPath);
+00999         // check empty file
+01000         if (filename.empty())
+01001         {
+01002                 nlwarning ("PATH: CPath::addSearchListFile(%s, %d, %d): can't add empty file, skip it", filename.c_str(), recurse, alternative);
+01003                 return;
+01004         }
+01005 
+01006         // check if the file exists
+01007         if (!CFile::isExists (filename))
+01008         {
+01009                 nlwarning ("PATH: CPath::addSearchListFile(%s, %d, %d): '%s' is not found, skip it", filename.c_str(), recurse, alternative, filename.c_str());
+01010                 return;
+01011         }
+01012 
+01013         // check if it s a file
+01014         if (CFile::isDirectory (filename))
+01015         {
+01016                 nlwarning ("PATH: CPath::addSearchListFile(%s, %d, %d): '%s' is not a file, skip it", filename.c_str(), recurse, alternative, filename.c_str());
+01017                 return;
+01018         }
+01019 
+01020         // TODO lire le fichier et ajouter les fichiers qui sont dedans
+01021 
+01022 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CPath::addSearchPath const std::string &  path  )  [inline, static]
+
+ + + + + +
+   + + +

+Used only for compatibility with the old CPath. In this case, we don't use the map to have the same behavior as the old CPath +

+Definition at line 78 of file path.h. +

+References addSearchPath(). +

+

00078 { addSearchPath (path, false, true, NULL); }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CPath::addSearchPath const std::string &  path,
bool  recurse,
bool  alternative,
class IProgressCallback progressCallBack = NULL
[static]
+
+ + + + + +
+   + + +

+Adds a search path. The path is a directory "c:/temp" all files in the directory will be included (and recursively if asked)

+Alternative directories are not precached (instead of non Alternative files) and will used when a file is not found in the standard directories. For example, local data will be in the cached directories and server repository files will be in the Alternative files. If a new file is not found in the local data, we'll try to find it on the repositrory.

+When Alternative is false, all added file names must be uniq or a warning will be display. In the Alternative directories, it could have more than one file with the same name.

+

Warning:
the path you provide is case sensitive, you must be sure that the path name is exactly the same
+
Parameters:
+ + + + + +
path the path name. The separator for directories could be '/' or '\' (bit '\' will be translate into '/' in the function).
recurse true if you want the function recurse in sub-directories.
Alternative true if you want to add the path in the Alternative directories.
progressCallBack is a progression callback interface pointer.
+
+ +

+Definition at line 807 of file path.cpp. +

+Referenced by addSearchPath(). +

+

00808 {
+00809         NL_ALLOC_CONTEXT (MiPath);
+00810         H_AUTO_INST(addSearchPath);
+00811 
+00812         CPath *inst = CPath::getInstance();
+00813         nlassert(!inst->_MemoryCompressed);
+00814 
+00815         // check empty directory
+00816         if (path.empty())
+00817         {
+00818                 nlwarning ("PATH: CPath::addSearchPath(%s, %d, %d): can't add empty directory, skip it", path.c_str(), recurse, alternative);
+00819                 return;
+00820         }
+00821 
+00822         // check if it s a directory
+00823         if (!CFile::isDirectory (path))
+00824         {
+00825                 nlinfo ("PATH: CPath::addSearchPath(%s, %d, %d): '%s' is not a directory, I'll call addSearchFile()", path.c_str(), recurse, alternative, path.c_str());
+00826                 addSearchFile (path, false, "", progressCallBack);
+00827                 return;
+00828         }
+00829 
+00830         string newPath = standardizePath(path);
+00831 
+00832         // check if it s a directory
+00833         if (!CFile::isExists (newPath))
+00834         {
+00835                 nlwarning ("PATH: CPath::addSearchPath(%s, %d, %d): '%s' is not found, skip it", path.c_str(), recurse, alternative, newPath.c_str());
+00836                 return;
+00837         }
+00838 
+00839         nlinfo ("PATH: CPath::addSearchPath(%s, %d, %d): adding the path '%s'", path.c_str(), recurse, alternative, newPath.c_str());
+00840 
+00841         NL_DISPLAY_PATH("PATH: CPath::addSearchPath(%s, %d, %d): try to add '%s'", path.c_str(), recurse, alternative, newPath.c_str());
+00842 
+00843         if (alternative)
+00844         {
+00845                 vector<string> pathsToProcess;
+00846 
+00847                 // add the current path
+00848                 pathsToProcess.push_back (newPath);
+00849 
+00850                 if (recurse)
+00851                 {
+00852                         // find all path and subpath
+00853                         getPathContent (newPath, recurse, true, false, pathsToProcess, progressCallBack);
+00854                 }
+00855 
+00856                 for (uint p = 0; p < pathsToProcess.size(); p++)
+00857                 {
+00858                         // check if the path not already in the vector
+00859                         uint i;
+00860                         for (i = 0; i < inst->_AlternativePaths.size(); i++)
+00861                         {
+00862                                 if (inst->_AlternativePaths[i] == pathsToProcess[p])
+00863                                         break;
+00864                         }
+00865                         if (i == inst->_AlternativePaths.size())
+00866                         {
+00867                                 // add them in the alternative directory
+00868                                 inst->_AlternativePaths.push_back (pathsToProcess[p]);
+00869                                 NL_DISPLAY_PATH("PATH: CPath::addSearchPath(%s, %d, %d): path '%s' added", newPath.c_str(), recurse, alternative, pathsToProcess[p].c_str());
+00870                         }
+00871                         else
+00872                         {
+00873                                 nlwarning ("PATH: CPath::addSearchPath(%s, %d, %d): path '%s' already added", newPath.c_str(), recurse, alternative, pathsToProcess[p].c_str());
+00874                         }
+00875                 }
+00876         }
+00877         else
+00878         {
+00879                 vector<string> filesToProcess;
+00880 
+00881                 // Progree bar
+00882                 if (progressCallBack)
+00883                 {
+00884                         progressCallBack->progress (0);
+00885                         progressCallBack->pushCropedValues (0, 0.5f);
+00886                 }
+00887 
+00888                 // find all files in the path and subpaths
+00889                 getPathContent (newPath, recurse, false, true, filesToProcess, progressCallBack);
+00890 
+00891                 // Progree bar
+00892                 if (progressCallBack)
+00893                 {
+00894                         progressCallBack->popCropedValues ();
+00895                         progressCallBack->progress (0.5);
+00896                         progressCallBack->pushCropedValues (0.5f, 1);
+00897                 }
+00898 
+00899                 // add them in the map
+00900                 for (uint f = 0; f < filesToProcess.size(); f++)
+00901                 {
+00902                         // Progree bar
+00903                         if (progressCallBack)
+00904                         {
+00905                                 progressCallBack->progress ((float)f/(float)filesToProcess.size());
+00906                                 progressCallBack->pushCropedValues ((float)f/(float)filesToProcess.size(), (float)(f+1)/(float)filesToProcess.size());
+00907                         }
+00908 
+00909                         string filename = CFile::getFilename (filesToProcess[f]);
+00910                         string filepath = CFile::getPath (filesToProcess[f]);
+00911 //                      insertFileInMap (filename, filepath, false, CFile::getExtension(filename));
+00912                         addSearchFile (filesToProcess[f], false, "", progressCallBack);
+00913 
+00914                         // Progree bar
+00915                         if (progressCallBack)
+00916                         {
+00917                                 progressCallBack->popCropedValues ();
+00918                         }
+00919                 }
+00920 
+00921                 // Progree bar
+00922                 if (progressCallBack)
+00923                 {
+00924                         progressCallBack->popCropedValues ();
+00925                 }
+00926         }
+00927 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CPath::clearMap  )  [static]
+
+ + + + + +
+   + + +

+Clears the map that contains all cached files (Use this function to take into account new files). +

+Definition at line 153 of file path.cpp. +

+References _Files, _MemoryCompressed, NL_DISPLAY_PATH, and nlassert. +

+

00154 {
+00155         CPath *inst = CPath::getInstance();
+00156         nlassert(!inst->_MemoryCompressed);
+00157         inst->_Files.clear ();
+00158         CBigFile::getInstance().removeAll ();
+00159         NL_DISPLAY_PATH("PATH: CPath::clearMap(): map directory cleared");
+00160 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CPath::display  )  [static]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1195 of file path.cpp. +

+

01196 {
+01197         CPath *inst = CPath::getInstance ();
+01198         nlinfo ("PATH: Contents of the map:");
+01199         nlinfo ("PATH: %-25s %-5s %-5s %s", "filename", "ext", "remap", "full path");
+01200         nlinfo ("PATH: ----------------------------------------------------");
+01201         if (inst->_MemoryCompressed)
+01202         {
+01203                 for (uint i = 0; i < inst->_MCFiles.size(); ++i)
+01204                 {
+01205                         const CMCFileEntry &fe = inst->_MCFiles[i];
+01206                         string ext = inst->SSMext.get(fe.idExt);
+01207                         string path = inst->SSMpath.get(fe.idPath);
+01208                         nlinfo ("PATH: %-25s %-5s %-5d %s", fe.Name, ext.c_str(), fe.Remapped, path.c_str());
+01209                 }
+01210         }
+01211         else
+01212         {
+01213                 for (map<string, CFileEntry>::iterator it = inst->_Files.begin(); it != inst->_Files.end (); it++)
+01214                 {
+01215                         string ext = inst->SSMext.get((*it).second.idExt);
+01216                         string path = inst->SSMpath.get((*it).second.idPath);
+01217                         nlinfo ("PATH: %-25s %-5s %-5d %s", (*it).first.c_str(), ext.c_str(), (*it).second.Remapped, path.c_str());
+01218                 }
+01219         }
+01220         nlinfo ("PATH: ");
+01221         nlinfo ("PATH: Contents of the alternative directory:");
+01222         for (uint i = 0; i < inst->_AlternativePaths.size(); i++)
+01223         {
+01224                 nlinfo ("PATH: '%s'", inst->_AlternativePaths[i].c_str ());
+01225         }
+01226         nlinfo ("PATH: ");
+01227         nlinfo ("PATH: Contents of the remapped entension table:");
+01228         for (uint j = 0; j < inst->_Extensions.size(); j++)
+01229         {
+01230                 nlinfo ("PATH: '%s' -> '%s'", inst->_Extensions[j].first.c_str (), inst->_Extensions[j].second.c_str ());
+01231         }
+01232         nlinfo ("PATH: End of display");
+01233 }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CPath::exists const std::string &  filename  )  [static]
+
+ + + + + +
+   + + +

+Return if a file is present in the lookup map. The function changes filename into lower case and removes ended spaces before searching.

+

Warning:
This function checks *only* in the map, not in local dir or alternative dir
+
Parameters:
+ + + +
filename the file name you are seeking. (ex: "test.txt")
lookupInLocalDirectory if true, the lookup() will first try to open the file without path.
+
+
Returns:
true if the filename exists in the map used by lookup to know where the file is, false otherwise
+ +

+Definition at line 421 of file path.cpp. +

+

00422 {
+00423         // Try to find in the map directories
+00424         CPath *inst = CPath::getInstance();
+00425         string str = strlwr(filename);
+00426 
+00427         // Remove end spaces
+00428         while ((!str.empty()) && (str[str.size()-1] == ' '))
+00429         {
+00430                 str.resize (str.size()-1);
+00431         }
+00432 
+00433 
+00434         if (inst->_MemoryCompressed)
+00435         {
+00436                 CMCFileEntry *pMCFE = MCfind(str);
+00437                 // If found in the vector, returns it
+00438                 if (pMCFE != NULL)
+00439                         return true;
+00440         }
+00441         else
+00442         {
+00443                 map<string, CFileEntry>::iterator it = inst->_Files.find (str);
+00444                 // If found in the map, returns it
+00445                 if (it != inst->_Files.end())
+00446                         return true;
+00447         }
+00448 
+00449         return false;
+00450 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
sint NLMISC::CPath::findExtension const std::string &  ext1,
const std::string &  ext2
[private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 177 of file path.cpp. +

+References _Extensions, sint, and uint. +

+Referenced by remapExtension(). +

+

00178 {
+00179         CPath *inst = CPath::getInstance();
+00180         for (uint i = 0; i < inst->_Extensions.size (); i++)
+00181         {
+00182                 if (inst->_Extensions[i].first == ext1 && inst->_Extensions[i].second == ext2)
+00183                 {
+00184                         return i;
+00185                 }
+00186         }
+00187         return -1;
+00188 }
+
+

+ + + + +
+ + + + + + + + + +
std::string NLMISC::CPath::getCurrentPath  )  [static]
+
+ + + + + +
+   + + +

+Returns the current path of the applicated. +

+Definition at line 504 of file path.cpp. +

+References buffer. +

+

00505 {
+00506         char buffer [10000];
+00507 
+00508 #ifdef NL_OS_WINDOWS
+00509         return standardizePath(_getcwd(buffer, 10000), false);
+00510 #else
+00511         return standardizePath(getcwd(buffer, 10000), false);
+00512 #endif
+00513 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLMISC::CPath::getFileList const std::string &  extension,
std::vector< std::string > &  filenames
[static]
+
+ + + + + +
+   + + +

+Create a list of file having the requested extension. +

+Definition at line 87 of file path.cpp. +

+References _Files, _MCFiles, _MemoryCompressed, NLMISC::CStaticStringMapper::get(), getInstance(), and SSMext. +

+Referenced by loadForm(). +

+

00088 {
+00089         CPath *inst = getInstance();
+00090 
+00091         if (!inst->_MemoryCompressed)
+00092         {
+00093                 std::map<std::string, CFileEntry>::iterator first(inst->_Files.begin()), last(inst->_Files.end());
+00094 
+00095                 if( !extension.empty() )
+00096                 {
+00097                         for (; first != last; ++ first)
+00098                         {
+00099                                 string ext = inst->SSMext.get(first->second.idExt);
+00100                                 if (ext == extension)
+00101                                 {
+00102                                         filenames.push_back(first->first);
+00103                                 }
+00104                         }
+00105                 }
+00106                 // if extension is empty we keep all files
+00107                 else
+00108                 {
+00109                         for (; first != last; ++ first)
+00110                         {
+00111                                 filenames.push_back(first->first);
+00112                         }
+00113                 }
+00114         }
+00115         else
+00116         {
+00117                 // compressed memory version
+00118                 std::vector<CPath::CMCFileEntry>::iterator first(inst->_MCFiles.begin()), last(inst->_MCFiles.end());
+00119 
+00120                 if( !extension.empty() )
+00121                 {
+00122                         for (; first != last; ++ first)
+00123                         {
+00124                                 string ext = inst->SSMext.get(first->idExt);
+00125                                 if (ext == extension)
+00126                                 {
+00127                                         filenames.push_back(first->Name);
+00128                                 }
+00129                         }
+00130                 }
+00131                 // if extension is empty we keep all files
+00132                 else
+00133                 {
+00134                         for (; first != last; ++ first)
+00135                         {
+00136                                 filenames.push_back(first->Name);
+00137                         }
+00138                 }
+00139         }
+00140 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
std::string NLMISC::CPath::getFullPath const std::string &  path,
bool  addFinalSlash = true
[static]
+
+ + + + + +
+   + + +

+Get the full path based on a file/path and the current directory. Example, imagine that the current path is c: and toto is a directory getFullPath ("toto") returns "c:/temp/toto/" getFullPath ("../toto") returns "c:/temp/../toto/" getFullPath ("d:\dir\toto") returns "d:/dir/toto/" getFullPath ("\toto") returns "c:/toto/" getFullPath ("") returns "c:/temp/"

+

Parameters:
+ + +
path the path
+
+
Returns:
the full path
+ +

+Definition at line 525 of file path.cpp. +

+Referenced by NLMISC::CConfigFile::reparse(). +

+

00526 {
+00527         string currentPath = standardizePath (getCurrentPath ());
+00528         string sPath = standardizePath (path, addFinalSlash);
+00529 
+00530         // current path
+00531         if (path.empty() || sPath == "." || sPath == "./")
+00532         {
+00533                 return currentPath;
+00534         }
+00535 
+00536         // windows full path
+00537         if (path.size() >= 2 && path[1] == ':')
+00538         {
+00539                 return sPath;
+00540         }
+00541 
+00542         if (path.size() >= 2 && (path[0] == '/' || path[0] == '\\') && (path[1] == '/' || path[1] == '\\'))
+00543         {
+00544                 return sPath;
+00545         }
+00546 
+00547 
+00548         // from root
+00549         if (path [0] == '/' || path[0] == '\\')
+00550         {
+00551                 if (currentPath.size() > 2 && currentPath[1] == ':')
+00552                 {
+00553                         return currentPath.substr(0,3) + sPath.substr(1);
+00554                 }
+00555                 else
+00556                 {
+00557                         return sPath;
+00558                 }
+00559         }
+00560 
+00561         // default case
+00562         return currentPath + sPath;
+00563 }
+
+

+ + + + +
+ + + + + + + + + +
CPath * NLMISC::CPath::getInstance  )  [static, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 142 of file path.cpp. +

+Referenced by getFileList(), and isMemoryCompressed(). +

+

00143 {
+00144         if (_Instance == NULL)
+00145         {
+00146 #undef new
+00147                 _Instance = new CPath;
+00148 #define new NL_NEW
+00149         }
+00150         return _Instance;
+00151 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CPath::getPathContent const std::string &  path,
bool  recurse,
bool  wantDir,
bool  wantFile,
std::vector< std::string > &  result,
class IProgressCallback progressCallBack = NULL,
bool  showEverything = false
[static]
+
+ + + + + +
+   + + +

+List all files in a directory.

Parameters:
+ + + + + + + + +
path path where files are scanned. No-op if empty
recurse true if want to recurs directories
wantDir true if want to add directorires in result
wantFile true if want to add files in result
result list of string where directories/files names are added.
progressCallBack is a progression callback interface pointer.
showEverything false skips *.log files and CVS directories
+
+ +

+Definition at line 688 of file path.cpp. +

+References NL_DISPLAY_PATH. +

+Referenced by NL3D::CAnimationSet::loadFromFiles(). +

+

00689 {                       
+00690         if(     path.empty() )
+00691         {
+00692                 NL_DISPLAY_PATH("PATH: CPath::getPathContent(): Empty input Path");
+00693                 return;
+00694         }
+00695 
+00696 #ifndef NL_OS_WINDOWS
+00697         BasePathgetPathContent = CPath::standardizePath (path);
+00698 #endif
+00699 
+00700         DIR *dir = opendir (path.c_str());
+00701 
+00702         if (dir == NULL)
+00703         {
+00704                 NL_DISPLAY_PATH("PATH: CPath::getPathContent(%s, %d, %d, %d): could not open the directory", path.c_str(), recurse, wantDir, wantFile);
+00705                 return;
+00706         }
+00707 
+00708         // contains path that we have to recurs into
+00709         vector<string> recursPath;
+00710 
+00711         while (true)
+00712         {
+00713                 dirent *de = readdir(dir);
+00714                 if (de == NULL)
+00715                 {
+00716                         NL_DISPLAY_PATH("PATH: CPath::getPathContent(%s, %d, %d, %d): end of directory", path.c_str(), recurse, wantDir, wantFile);
+00717                         break;
+00718                 }
+00719 
+00720                 string fn = getname (de);
+00721 
+00722                 // skip . and ..
+00723                 if (fn == "." || fn == "..")
+00724                         continue;
+00725 
+00726                 if (isdirectory(de))
+00727                 {
+00728                         // skip CVS directory
+00729                         if ((!showEverything) && (fn == "CVS"))
+00730                         {
+00731                                 NL_DISPLAY_PATH("PATH: CPath::getPathContent(%s, %d, %d, %d): skip CVS directory", path.c_str(), recurse, wantDir, wantFile);
+00732                                 continue;
+00733                         }
+00734 
+00735                         string stdName = standardizePath(standardizePath(path) + fn);
+00736                         if (recurse)
+00737                         {
+00738                                 NL_DISPLAY_PATH("PATH: CPath::getPathContent(%s, %d, %d, %d): need to recurse into '%s'", path.c_str(), recurse, wantDir, wantFile, stdName.c_str());
+00739                                 recursPath.push_back (stdName);
+00740                         }
+00741 
+00742                         if (wantDir)
+00743                         {
+00744                                 NL_DISPLAY_PATH("PATH: CPath::getPathContent(%s, %d, %d, %d): adding path '%s'", path.c_str(), recurse, wantDir, wantFile, stdName.c_str());
+00745                                 result.push_back (stdName);
+00746                         }
+00747                 }
+00748                 if (wantFile && isfile(de))
+00749                 {
+00750                         if ( (!showEverything) && (fn.size() >= 4 && fn.substr (fn.size()-4) == ".log"))
+00751                         {
+00752                                 NL_DISPLAY_PATH("PATH: CPath::getPathContent(%s, %d, %d, %d): skip *.log files (%s)", path.c_str(), recurse, wantDir, wantFile, fn.c_str());
+00753                                 continue;
+00754                         }
+00755 
+00756 /*                      int lastSep = CFile::getLastSeparator(path);
+00757                         #ifdef NL_OS_WINDOWS
+00758                                 char sep = lastSep == std::string::npos ? '\\'
+00759                                                                                                             : path[lastSep];
+00760                         #else
+00761                                 char sep = lastSep == std::string::npos ? '/'
+00762                                                                                                                 : path[lastSep];
+00763                         #endif
+00764 */                      
+00765                         string stdName = standardizePath(path) + getname(de);
+00766                         
+00767                                 
+00768                         NL_DISPLAY_PATH("PATH: CPath::getPathContent(%s, %d, %d, %d): adding file '%s'", path.c_str(), recurse, wantDir, wantFile, stdName.c_str());
+00769                         result.push_back (stdName);
+00770                 }
+00771         }
+00772 
+00773         closedir (dir);
+00774 
+00775 #ifndef NL_OS_WINDOWS
+00776         BasePathgetPathContent = "";
+00777 #endif
+00778 
+00779         // let s recurse
+00780         for (uint i = 0; i < recursPath.size (); i++)
+00781         {               
+00782                 // Progress bar
+00783                 if (progressCallBack)
+00784                 {
+00785                         progressCallBack->progress ((float)i/(float)recursPath.size ());
+00786                         progressCallBack->pushCropedValues ((float)i/(float)recursPath.size (), (float)(i+1)/(float)recursPath.size ());
+00787                 }
+00788 
+00789                 getPathContent (recursPath[i], recurse, wantDir, wantFile, result, progressCallBack);
+00790 
+00791                 // Progress bar
+00792                 if (progressCallBack)
+00793                 {
+00794                         progressCallBack->popCropedValues ();
+00795                 }
+00796         }
+00797 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CPath::insertFileInMap const std::string &  filename,
const std::string &  filepath,
bool  remap,
const std::string &  extension
[static, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1139 of file path.cpp. +

+Referenced by remapExtension(). +

+

01140 {
+01141         NL_ALLOC_CONTEXT (MiPath);
+01142         CPath *inst = CPath::getInstance();
+01143         nlassert(!inst->_MemoryCompressed);
+01144         // find if the file already exist
+01145         map<string, CFileEntry>::iterator it = inst->_Files.find (strlwr(filename));
+01146         if (it != inst->_Files.end ())
+01147         {
+01148                 string path = inst->SSMpath.get((*it).second.idPath);
+01149                 if (path.find("@") != string::npos && filepath.find("@") == string::npos)
+                {
+                        // if there's a file in a big file and a file in a path, the file in path wins
+                        // replace with the new one
+                        nlinfo ("PATH: CPath::insertFileInMap(%s, %s, %d, %s): already inserted from '%s' but special case so overide it", filename.c_str(), filepath.c_str(), remap, extension.c_str(), path.c_str());
+01150                         string sTmp = filepath.substr(0,filepath.rfind('/')+1);
+01151                         (*it).second.idPath = inst->SSMpath.add(sTmp);
+01152                         (*it).second.Remapped = remap;
+01153                         (*it).second.idExt = inst->SSMext.add(extension);
+01154                         (*it).second.Name = filename;
+01155                 }
+01156                 else
+01157                 {
+01158                         for(uint i = 0; i < inst->IgnoredFiles.size(); i++)
+01159                         {
+01160                                 // if we don't want to display a warning, skip it
+01161                                 if(filename == inst->IgnoredFiles[i])
+01162                                         return;
+01163                         }
+01164                         // if the path is the same, don't warn
+01165                         string path2 = inst->SSMpath.get((*it).second.idPath);
+01166                         string sPathOnly = filepath.substr(0,filepath.rfind('@')+1);
+01167                         if (path2 == sPathOnly)
+01168                                 return;
+01169                         nlwarning ("PATH: CPath::insertFileInMap(%s, %s, %d, %s): already inserted from '%s', skip it", filename.c_str(), filepath.c_str(), remap, extension.c_str(), path2.c_str());
+01170                 }
+01171         }
+01172         else
+01173         {
+01174                 CFileEntry fe;
+01175                 fe.idExt = inst->SSMext.add(extension);
+01176                 fe.Remapped = remap;
+01177                 string sTmp;
+01178                 if (filepath.find("@") == string::npos)
+                        sTmp = filepath.substr(0,filepath.rfind('/')+1);
+                else
+                        sTmp = filepath.substr(0,filepath.rfind('@')+1);
+
+                fe.idPath = inst->SSMpath.add(sTmp);
+                fe.Name = filename;
+
+                inst->_Files.insert (make_pair(strlwr(filename), fe));
+                NL_DISPLAY_PATH("PATH: CPath::insertFileInMap(%s, %s, %d, %s): added", strlwr(filename).c_str(), filepath.c_str(), remap, strlwr(extension).c_str());
+01179         }
+01180 }
+01181 
+

+ + + + +
+ + + + + + + + + +
bool NLMISC::CPath::isMemoryCompressed  )  [inline, static]
+
+ + + + + +
+   + + +

+ +

+Definition at line 215 of file path.h. +

+References _MemoryCompressed, and getInstance(). +

+

00215 { return getInstance()->_MemoryCompressed; }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CPath::loadRemappedFiles const std::string &  file  )  [static]
+
+ + + + + +
+   + + +

+Load a file containing the remapped file (you must have done addsearchpath, this method use lookup) Format is remapped_name_file, real_file separators are , and
+ +

+Definition at line 293 of file path.cpp. +

+References NLMISC::CIFile::eof(), file, NLMISC::CIFile::getline(), lookup(), NLMISC::CIFile::open(), remapFile(), NLMISC::removeAllUnusedChar(), and NLMISC::CIFile::setCacheFileOnOpen(). +

+

00294 {
+00295         NL_ALLOC_CONTEXT (MiPath);
+00296         string fullName = lookup(file, false, true, true);
+00297         CIFile f;
+00298         f.setCacheFileOnOpen (true);
+00299 
+00300         if (!f.open (fullName))
+00301                 return;
+00302 
+00303         char sTmp[514];
+00304         string str;
+00305         
+00306         while (!f.eof())
+00307         {
+00308                 f.getline(sTmp, 512);
+00309                 str = sTmp;
+00310                 if (str.find(','))
+00311                 {
+00312                         removeAllUnusedChar(str);
+00313                         if (!str.empty())
+00314                                 remapFile( str.substr(0,str.find(',')), str.substr(str.find(',')+1, str.size()) );
+00315                 }
+00316         }
+00317 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
string NLMISC::CPath::lookup const std::string &  filename,
bool  throwException = true,
bool  displayWarning = true,
bool  lookupInLocalDirectory = true
[static]
+
+ + + + + +
+   + + +

+Returns the long name (path + filename) for the specified file. The directory separator is always '/'. First, the lookup() lookups in standard directories (Alternative=false). If not found, it lookups in the Alternative directories. If not found the lookup() returns empty string "" (and generate an exception if throwException is true)

+The filename is not case sensitive so if the real filename is "FooBAR.Jpg" and you call lookup("fOOBar.jPg"), it'll return the real filename "FooBAR.Jpg"

+

Parameters:
+ + + + + +
filename the file name you are seeking. (ex: "test.txt")
throwException used for backward compatibility, set to true to generate an EPathNotFound.
displayWarning set to false if you don't want the function displays a warning if the file is not found
lookupInLocalDirectory if true, the lookup() will first try to open the file without path.
+
+
Returns:
empty string if file is not found or the full path + file name (ex: "c:/temp/test.txt");
+ +

+Definition at line 320 of file path.cpp. +

+Referenced by NL3D::CAnimationSetUser::addAnimation(), NLSOUND::CAudioMixerUser::init(), loadForm(), loadRemappedFiles(), and NLPACS::CRetrieverBank::serial(). +

+

00321 {
+00322         // If the file already contains a @, it means that a lookup already proceed and returning a big file, do nothing
+00323         if (filename.find ("@") != string::npos)
+        {
+                NL_DISPLAY_PATH("PATH: CPath::lookup(%s):       already found", filename.c_str());
+00324                 return filename;
+00325         }
+00326 
+00327         // Try to find in the map directories
+00328         CPath *inst = CPath::getInstance();
+00329         string str = strlwr(filename);
+00330 
+00331         // Remove end spaces
+00332         while ((!str.empty()) && (str[str.size()-1] == ' '))
+00333         {
+00334                 str.resize (str.size()-1);
+00335         }
+00336 
+00337         map<string, string>::iterator itss = inst->_RemappedFiles.find(str);
+00338         if (itss != inst->_RemappedFiles.end())
+00339                 str = itss->second;
+00340 
+00341         if (inst->_MemoryCompressed)
+00342         {
+00343                 CMCFileEntry *pMCFE = MCfind(str);
+00344                 // If found in the map, returns it
+00345                 if (pMCFE != NULL)
+00346                 {
+00347                         string fname, path = inst->SSMpath.get(pMCFE->idPath);
+00348                         if (pMCFE->Remapped)
+00349                                 fname = CFile::getFilenameWithoutExtension(pMCFE->Name) + "." + inst->SSMext.get(pMCFE->idExt);
+00350                         else
+00351                                 fname = pMCFE->Name;
+00352 
+00353                         NL_DISPLAY_PATH("PATH: CPath::lookup(%s): found in the map directory: '%s'", fname.c_str(), path.c_str());
+00354                         return path + fname;
+00355                 }
+00356         }
+00357         else // NOT memory compressed
+00358         {
+00359                 map<string, CFileEntry>::iterator it = inst->_Files.find (str);
+00360                 // If found in the map, returns it
+00361                 if (it != inst->_Files.end())
+00362                 {
+00363                         string fname, path = inst->SSMpath.get((*it).second.idPath);
+00364                         if (it->second.Remapped)
+00365                                 fname = CFile::getFilenameWithoutExtension((*it).second.Name) + "." + inst->SSMext.get((*it).second.idExt);
+00366                         else
+00367                                 fname = (*it).second.Name;
+00368 
+00369                         NL_DISPLAY_PATH("PATH: CPath::lookup(%s): found in the map directory: '%s'", fname.c_str(), path.c_str());
+00370                         return path + fname;
+00371                 }
+00372         }
+00373         
+00374 
+00375         // Try to find in the alternative directories
+00376         for (uint i = 0; i < inst->_AlternativePaths.size(); i++)
+00377         {
+00378                 string s = inst->_AlternativePaths[i] + filename;
+00379                 if ( CFile::fileExists(s) )
+00380                 {
+00381                         NL_DISPLAY_PATH("PATH: CPath::lookup(%s): found in the alternative directory: '%s'", filename.c_str(), s.c_str());
+00382                         return s;
+00383                 }
+00384                 
+00385                 // try with the remapping
+00386                 for (uint j = 0; j < inst->_Extensions.size(); j++)
+00387                 {
+00388                         if (strlwr(CFile::getExtension (filename)) == inst->_Extensions[j].second)
+00389                         {
+00390                                 string rs = inst->_AlternativePaths[i] + CFile::getFilenameWithoutExtension (filename) + "." + inst->_Extensions[j].first;
+00391                                 if ( CFile::fileExists(rs) )
+00392                                 {
+00393                                         NL_DISPLAY_PATH("PATH: CPath::lookup(%s): found in the alternative directory: '%s'", filename.c_str(), rs.c_str());
+00394                                         return rs;
+00395                                 }
+00396                         }
+00397                 }
+00398         }
+00399 
+00400         // Try to find in the current directory
+00401         if ( lookupInLocalDirectory && CFile::fileExists(filename) )
+00402         {
+00403                 NL_DISPLAY_PATH("PATH: CPath::lookup(%s): found in the current directory: '%s'", filename.c_str(), filename.c_str());
+00404                 return filename;
+00405         }
+00406 
+00407         // Not found
+00408         if (displayWarning)
+00409         {
+00410                 nlwarning ("PATH: CPath::lookup(%s): file not found", filename.c_str());
+00411         }
+00412 
+00413         if (throwException)
+00414                 throw EPathNotFound (filename);
+00415 
+00416         return "";
+00417 }
+00418 
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
bool NLMISC::CPath::makePathRelative const char *  basePath,
std::string &  relativePath
[static]
+
+ + + + + +
+   + + +

+Make a path relative to another if possible, else doesn't change it.

Parameters:
+ + + +
basePath is the base path to be relative to.
relativePath is the path to make relative to basePath. return true if relativePath as been done relative to basePath, false is relativePath has not been changed.
+
+ +

+Definition at line 1674 of file path.cpp. +

+

01675 {
+01676         // Standard path with final slash
+01677         string tmp = standardizePath (basePath, true);
+01678         string src = standardizePath (relativePath, true);
+01679         string prefix;
+01680 
+01681         while (1)
+01682         {
+01683                 // Compare with relativePath
+01684                 if (strncmp (tmp.c_str (), src.c_str (), tmp.length ()) == 0)
+01685                 {
+01686                         // Troncate
+01687                         uint size = tmp.length ();
+01688 
+01689                         // Same path ?
+01690                         if (size == src.length ())
+01691                         {
+01692                                 relativePath = ".";
+01693                                 return true;
+01694                         }
+01695 
+01696                         relativePath = prefix+relativePath.substr (size, relativePath.length () - size);
+01697                         return true;
+01698                 }
+01699 
+01700                 // Too small ?
+01701                 if (tmp.length ()<2)
+01702                         break;
+01703 
+01704                 // Remove last directory
+01705                 uint lastPos = tmp.rfind ('/', tmp.length ()-2);
+01706                 uint previousPos = tmp.find ('/');
+01707                 if ((lastPos == previousPos) || (lastPos == string::npos))
+01708                         break;
+01709 
+01710                 // Troncate
+01711                 tmp = tmp.substr (0, lastPos+1);
+01712 
+01713                 // New prefix
+01714                 prefix += "../";
+01715         }
+01716         
+01717         return false;
+01718 }
+
+

+ + + + +
+ + + + + + + + + + +
CPath::CMCFileEntry * NLMISC::CPath::MCfind const std::string &  filename  )  [static, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 162 of file path.cpp. +

+References _MCFiles, _MemoryCompressed, nlassert, and NLMISC::CPath::CMCFileComp::specialCompare(). +

+

00163 {
+00164         CPath *inst = CPath::getInstance();
+00165         nlassert(inst->_MemoryCompressed);
+00166         vector<CMCFileEntry>::iterator it;
+00167         it = lower_bound(inst->_MCFiles.begin(), inst->_MCFiles.end(), filename.c_str(), CMCFileComp());
+00168         if (it != inst->_MCFiles.end())
+00169         {
+00170                 CMCFileComp FileComp;
+00171                 if (FileComp.specialCompare(*it, filename.c_str()) == 0)
+00172                         return &(*it);
+00173         }
+00174         return NULL;
+00175 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CPath::memoryCompress  )  [static]
+
+ + + + + +
+   + + +

+For the moment after memoryCompress you cant addsearchpath anymore +

+Definition at line 1235 of file path.cpp. +

+References _AllFileNames, _MCFiles, NLMISC::CStaticStringMapper::get(), NLMISC::CPath::CFileEntry::idExt, NLMISC::CPath::CFileEntry::idPath, NLMISC::CPath::CFileEntry::Name, nlassert, NLMISC::CPath::CFileEntry::Remapped, and SSMpath. +

+

01236 { 
+01237         NL_ALLOC_CONTEXT (MiPath);
+01238         CPath *inst = CPath::getInstance();
+01239 
+01240         inst->SSMext.memoryCompress();
+01241         inst->SSMpath.memoryCompress();
+01242         uint nDbg = inst->_Files.size();
+01243         nlinfo ("PATH: Number of file : %d", nDbg);
+01244         nDbg = inst->SSMext.getCount();
+01245         nlinfo ("PATH: Number of different extension : %d", nDbg);
+01246         nDbg = inst->SSMpath.getCount();
+01247         nlinfo ("PATH: Number of different path : %d", nDbg);
+01248 
+01249         // Convert from _Files to _MCFiles
+01250         uint nSize = 0, nNb = 0;
+01251         map<string,CFileEntry>::iterator it = inst->_Files.begin();
+01252         while (it != inst->_Files.end())
+01253         {
+01254                 string sTmp = inst->SSMpath.get(it->second.idPath);
+01255                 if ((sTmp.find('@') != string::npos) && !it->second.Remapped)
+01256                 {
+01257                         // This is a file included in a bigfile (so the name is in the bigfile manager)
+01258                 }
+01259                 else
+01260                 {
+01261                         nSize += it->second.Name.size() + 1;
+01262                 }
+01263                 nNb++;
+01264                 it++;
+01265         }
+01266 
+01267         inst->_AllFileNames = new char[nSize];
+01268         memset(inst->_AllFileNames, 0, nSize);
+01269         inst->_MCFiles.resize(nNb);
+01270 
+01271         it = inst->_Files.begin();
+01272         nSize = 0;
+01273         nNb = 0;
+01274         while (it != inst->_Files.end())
+01275         {
+01276                 CFileEntry &rFE = it->second;
+01277                 string sTmp = inst->SSMpath.get(rFE.idPath);
+01278                 if ((sTmp.find('@') != string::npos) && !rFE.Remapped)
+01279                 {
+01280                         // This is a file included in a bigfile (so the name is in the bigfile manager)
+01281                         sTmp = sTmp.substr(0, sTmp.size()-1);
+01282                         inst->_MCFiles[nNb].Name = CBigFile::getInstance().getFileNamePtr(rFE.Name, sTmp);
+01283                         nlassert(inst->_MCFiles[nNb].Name != NULL);
+01284                 }
+01285                 else
+01286                 {
+01287                         strcpy(inst->_AllFileNames+nSize, rFE.Name.c_str());
+01288                         inst->_MCFiles[nNb].Name = inst->_AllFileNames+nSize;
+01289                         nSize += rFE.Name.size() + 1;
+01290                 }
+01291                 
+01292                 inst->_MCFiles[nNb].idExt = rFE.idExt;
+01293                 inst->_MCFiles[nNb].idPath = rFE.idPath;
+01294                 inst->_MCFiles[nNb].Remapped = rFE.Remapped;
+01295 
+01296                 nNb++;
+01297                 it++;
+01298         }
+01299 
+01300         contReset(inst->_Files);
+01301         inst->_MemoryCompressed = true;
+01302 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CPath::memoryUncompress  )  [static]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1304 of file path.cpp. +

+References uint32. +

+

01305 {
+01306         CPath *inst = CPath::getInstance ();
+01307         inst->SSMext.memoryUncompress(); 
+01308         inst->SSMpath.memoryUncompress();       
+01309         inst->_MemoryCompressed = false;
+01310 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CPath::remapExtension const std::string &  ext1,
const std::string &  ext2,
bool  substitute
[static]
+
+ + + + + +
+   + + +

+Add a remapping function to allow file extension substitution.

    +
  • eg remapExtension("dds", "tga", true) Where the boolean indicates whether the "dds" should replace a "tga" if one exists - again - a warning should be generated if the two are present.
+

+ie: If you have a file called pic.dds and you call remapExtension("dds", "tga", true), if you call lookup("pic.tga"), it'll return "pic.dds" +

+Definition at line 190 of file path.cpp. +

+References _Extensions, _Files, _MemoryCompressed, file, findExtension(), NLMISC::CStaticStringMapper::get(), insertFileInMap(), NL_DISPLAY_PATH, nlassert, nlwarning, sint, SSMext, SSMpath, NLMISC::strlwr(), and uint32. +

+

00191 {
+00192         NL_ALLOC_CONTEXT (MiPath);
+00193         CPath *inst = CPath::getInstance();
+00194         nlassert(!inst->_MemoryCompressed);
+00195 
+00196         string ext1lwr = strlwr (ext1);
+00197         string ext2lwr = strlwr (ext2);
+00198 
+00199         if (ext1lwr.empty() || ext2lwr.empty())
+00200         {
+00201                 nlwarning ("PATH: CPath::remapExtension(%s, %s, %d): can't remap empty extension", ext1lwr.c_str(), ext2lwr.c_str(), substitute);
+00202         }
+00203 
+00204         if (ext1lwr == "bnp" || ext2lwr == "bnp")
+00205         {
+00206                 nlwarning ("PATH: CPath::remapExtension(%s, %s, %d): you can't remap a big file", ext1lwr.c_str(), ext2lwr.c_str(), substitute);
+00207         }
+00208 
+00209         if (!substitute)
+00210         {
+00211                 // remove the mapping from the mapping list
+00212                 sint n = inst->findExtension (ext1lwr, ext2lwr);
+00213                 nlassert (n != -1);
+00214                 inst->_Extensions.erase (inst->_Extensions.begin() + n);
+00215 
+00216                 // remove mapping in the map
+00217                 map<string, CFileEntry>::iterator it = inst->_Files.begin();
+00218                 map<string, CFileEntry>::iterator nit = it;
+00219                 while (it != inst->_Files.end ())
+00220                 {
+00221                         nit++;
+00222                         string ext = inst->SSMext.get((*it).second.idExt);
+00223                         if ((*it).second.Remapped && ext == ext2lwr)
+00224                         {
+00225                                 inst->_Files.erase (it);
+00226                         }
+00227                         it = nit;
+00228                 }
+00229                 NL_DISPLAY_PATH("PATH: CPath::remapExtension(%s, %s, %d): extension removed", ext1lwr.c_str(), ext2lwr.c_str(), substitute);
+00230         }
+00231         else
+00232         {
+00233                 sint n = inst->findExtension (ext1lwr, ext2lwr);
+00234                 if (n != -1)
+00235                 {
+00236                         nlwarning ("PATH: CPath::remapExtension(%s, %s, %d): remapping already set", ext1lwr.c_str(), ext2lwr.c_str(), substitute);
+00237                         return;
+00238                 }
+00239 
+00240                 // adding mapping into the mapping list
+00241                 inst->_Extensions.push_back (make_pair (ext1lwr, ext2lwr));
+00242 
+00243                 // adding mapping into the map
+00244                 vector<string> newFiles;
+00245                 map<string, CFileEntry>::iterator it = inst->_Files.begin();
+00246                 while (it != inst->_Files.end ())
+00247                 {
+00248                         string ext = inst->SSMext.get((*it).second.idExt);
+00249                         if (!(*it).second.Remapped && ext == ext1lwr)
+00250                         {
+00251                                 // find if already exist
+00252                                 uint32 pos = (*it).first.find_last_of (".");
+00253                                 if (pos != string::npos)
+00254                                 {
+00255                                         string file = (*it).first.substr (0, pos + 1);
+00256                                         file += ext2lwr;
+00257 
+00258 // TODO perhaps a problem because I insert in the current map that i parcours
+00259                                         string path = inst->SSMpath.get((*it).second.idPath);
+00260                                         insertFileInMap (file, path+file, true, ext1lwr);
+00261                                 }
+00262                         }
+00263                         it++;
+00264                 }
+00265                 NL_DISPLAY_PATH("PATH: CPath::remapExtension(%s, %s, %d): extension added", ext1lwr.c_str(), ext2lwr.c_str(), substitute);
+00266         }
+00267 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLMISC::CPath::remapFile const std::string &  file1,
const std::string &  file2
[static]
+
+ + + + + +
+   + + +

+Add file remapping ie: If you have a file called pic.dds, and call remapFile("picture.dds", "pic.dds") calling lookup("picture.dds") will in fact call lookup("pic.dds") +

+Definition at line 270 of file path.cpp. +

+References _RemappedFiles, and NLMISC::strlwr(). +

+Referenced by loadRemappedFiles(). +

+

00271 {
+00272         NL_ALLOC_CONTEXT (MiPath);
+00273         CPath *inst = CPath::getInstance();
+00274         if (file1.empty()) return;
+00275         if (file2.empty()) return;
+00276         inst->_RemappedFiles[strlwr(file1)] = strlwr(file2);
+00277 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CPath::removeAllAlternativeSearchPath  )  [static]
+
+ + + + + +
+   + + +

+Remove all search path contains in the alternative directories +

+Definition at line 799 of file path.cpp. +

+

00800 {
+00801         CPath *inst = CPath::getInstance();
+00802         inst->_AlternativePaths.clear ();
+00803         NL_DISPLAY_PATH("PATH: CPath::RemoveAllAternativeSearchPath(): removed");
+00804 }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CPath::setCurrentPath const char *   )  [static]
+
+ + + + + +
+   + + +

+Set the current path of the applicated. +

+Definition at line 515 of file path.cpp. +

+

00516 {
+00517 #ifdef NL_OS_WINDOWS
+00518         return _chdir(newDir) == 0;
+00519 #else
+00520         // todo : check this compiles under linux. Thanks (Hulud)
+00521         return chdir(newDir) == 0;
+00522 #endif
+00523 }
+
+

+ + + + +
+ + + + + + + + + + +
std::string NLMISC::CPath::standardizeDosPath const std::string &  path  )  [static]
+
+ + + + + +
+   + + +

+Remplace / with \ for fucking dos process. Use only this function if can't do another way. For exemple, if you do a system("copy data/toto data/tata"); it'll not work because dos doesn't understand /. But in the majority of case, / working (it works for fopen for example) +

+Definition at line 482 of file path.cpp. +

+References uint. +

+

00483 {
+00484         string newPath;
+00485 
+00486         for (uint i = 0; i < path.size(); i++)
+00487         {
+00488                 if (path[i] == '/')
+00489                         newPath += '\\';
+00490                 // Yoyo: supress toLower. Not usefull!?!
+00491                 /*else if (isupper(path[i]))
+00492                         newPath += tolower(path[i]);*/
+00493                 else
+00494                         newPath += path[i];
+00495         }
+00496 
+00497         if (CFile::isExists(path) && CFile::isDirectory(path) && newPath[newPath.size()-1] != '\\')
+00498                 newPath += '\\';
+00499 
+00500         return newPath;
+00501 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
string NLMISC::CPath::standardizePath const std::string &  path,
bool  addFinalSlash = true
[static]
+
+ + + + + +
+   + + +

+Take a path and put it in the portable format and add a terminated / if needed ie: "C:\\Game/dir1" will become "C:/Game/dir1/" or "C:/Game/dir1" if addFinalSlash is false +

+Definition at line 452 of file path.cpp. +

+References uint. +

+Referenced by NLMISC::CConfigFile::reparse(). +

+

00453 {
+00454         string newPath;
+00455         // check empty path
+00456         if (path.empty()) return "";
+00457 
+00458         // don't transform the first \\ for windows network path
+00459 //      if (path.size() >= 2 && path[0] == '\\' && path[1] == '\\')
+00460 //      {
+00461 //              newPath += "\\\\";
+00462 //              i = 2;
+00463 //      }
+00464         
+00465         for (uint i = 0; i < path.size(); i++)
+00466         {
+00467                 // don't transform the first \\ for windows network path
+00468                 if (path[i] == '\\')
+00469                         newPath += '/';
+00470                 else
+00471                         newPath += path[i];
+00472         }
+00473 
+00474         // add terminal slash
+00475         if (addFinalSlash && newPath[path.size()-1] != '/')
+00476                 newPath += '/';
+00477 
+00478         return newPath;
+00479 }
+
+


Field Documentation

+

+ + + + +
+ + +
char* NLMISC::CPath::_AllFileNames [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 267 of file path.h. +

+Referenced by memoryCompress().

+

+ + + + +
+ + +
std::vector<std::string> NLMISC::CPath::_AlternativePaths [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 229 of file path.h.

+

+ + + + +
+ + +
std::vector<std::pair<std::string, std::string> > NLMISC::CPath::_Extensions [private] +
+
+ + + + + +
+   + + +

+first ext1, second ext2 (ext1 could remplace ext2) +

+ +

+Definition at line 302 of file path.h. +

+Referenced by findExtension(), and remapExtension().

+

+ + + + +
+ + +
std::map<std::string, CFileEntry> NLMISC::CPath::_Files [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 254 of file path.h. +

+Referenced by clearMap(), getFileList(), and remapExtension().

+

+ + + + +
+ + +
CPath * NLMISC::CPath::_Instance = NULL [static, private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 80 of file path.cpp.

+

+ + + + +
+ + +
std::vector<CMCFileEntry> NLMISC::CPath::_MCFiles [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 270 of file path.h. +

+Referenced by getFileList(), MCfind(), and memoryCompress().

+

+ + + + +
+ + +
bool NLMISC::CPath::_MemoryCompressed [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 239 of file path.h. +

+Referenced by clearMap(), CPath(), getFileList(), isMemoryCompressed(), MCfind(), and remapExtension().

+

+ + + + +
+ + +
std::map<std::string, std::string> NLMISC::CPath::_RemappedFiles [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 233 of file path.h. +

+Referenced by remapFile().

+

+ + + + +
+ + +
std::vector<std::string> NLMISC::CPath::IgnoredFiles [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 231 of file path.h.

+

+ + + + +
+ + +
CStaticStringMapper NLMISC::CPath::SSMext [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 240 of file path.h. +

+Referenced by getFileList(), and remapExtension().

+

+ + + + +
+ + +
CStaticStringMapper NLMISC::CPath::SSMpath [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 241 of file path.h. +

+Referenced by memoryCompress(), and remapExtension().

+


The documentation for this class was generated from the following files: +
Generated on Tue Mar 16 13:27:22 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1