NLMISC::CPath Class Reference

Utility class for searching files in different paths. More...

#include <path.h>

List of all members.

Static Public Member Functions

static void addSearchPath (const std::string &path, bool recurse, bool alternative, class IProgressCallback *progressCallBack=NULL)
 Adds a search path.
static void addSearchPath (const std::string &path)
 Used only for compatibility with the old CPath.
static void addSearchFile (const std::string &file, bool remap=false, const std::string &virtual_ext="", class NLMISC::IProgressCallback *progressCallBack=NULL)
 Same as AddSearchPath but with a file "c:/autoexec.bat" this file only will included.
static void addSearchListFile (const std::string &filename, bool recurse, bool alternative)
 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).
static void addSearchBigFile (const std::string &filename, bool recurse, bool alternative, class NLMISC::IProgressCallback *progressCallBack=NULL)
 Same as AddSearchPath but with a big file "c:/test.nbf" all files name contained in the big file will be included (the extention (Nel Big File) is used to know that it's a big file).
static void addSearchXmlpackFile (const std::string &sXmlpackFilename, bool recurse, bool alternative, class NLMISC::IProgressCallback *progressCallBack=NULL)
 Same as AddSearchPath but with a xml pack file "c:/test.xml_pack" all files name contained in the xml pack will be included.
static void removeAllAlternativeSearchPath ()
 Remove all search path contains in the alternative directories.
static void removeBigFiles (const std::vector< std::string > &bnpFilenames)
static std::string lookup (const std::string &filename, bool throwException=true, bool displayWarning=true, bool lookupInLocalDirectory=true)
 Returns the long name (path + filename) for the specified file.
static bool exists (const std::string &filename)
 Return if a file is present in the lookup map.
static void clearMap ()
 Clears the map that contains all cached files (Use this function to take into account new files).
static void remapExtension (const std::string &ext1, const std::string &ext2, bool substitute)
 Add a remapping function to allow file extension substitution.
static void remapFile (const std::string &file1, const std::string &file2)
 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").
static void loadRemappedFiles (const std::string &file)
 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
.
static void display ()
static std::string standardizePath (const std::string &path, bool addFinalSlash=true)
 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.
static std::string standardizeDosPath (const std::string &path)
 Replace / with \ for dos process.
static void getPathContent (const std::string &path, bool recurse, bool wantDir, bool wantFile, std::vector< std::string > &result, class IProgressCallback *progressCallBack=NULL, bool showEverything=false)
 List all files in a directory.
static std::string getFullPath (const std::string &path, bool addFinalSlash=true)
 Get the full path based on a file/path and the current directory.
static std::string getCurrentPath ()
 Returns the current path of the application.
static bool setCurrentPath (const std::string &path)
 Set the current path of the application.
static void getFileList (const std::string &extension, std::vector< std::string > &filenames)
 Create a list of file having the requested extension.
static void getFileListByName (const std::string &extension, const std::string &name, std::vector< std::string > &filenames)
 Create a list of file having the requested string in the filename and the requested extension.
static bool makePathRelative (const char *basePath, std::string &relativePath)
 Make a path relative to another if possible, else doesn't change it.
static void addIgnoredDoubleFile (const std::string &ignoredFile)
 If File in this list is added more than one in an addSearchPath, it doesn't launch a warning.
static void memoryCompress ()
 For the moment after memoryCompress you cant addsearchpath anymore.
static void memoryUncompress ()
static bool isMemoryCompressed ()
static std::string getWindowsDirectory ()
 Get the ms windows directory (in standardized way with end slash), or returns an empty string on other os.
static void releaseInstance ()

Private Member Functions

 NLMISC_SAFE_SINGLETON_DECL_PTR (CPath)
 CPath ()

Private Attributes

CFileContainer _FileContainer
 The container used by the standard CPath.

Detailed Description

Utility class for searching files in different paths.

Change in jun 2007 : now the implementation code is in CFileContainer, the CPath class is just a wrapper class that contains one instance of CFileContainer.

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 333 of file path.h.


Constructor & Destructor Documentation

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

Definition at line 521 of file path.h.


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 1372 of file path.cpp.

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 contained 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 1177 of file path.cpp.

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 1058 of file path.cpp.

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 1145 of file path.cpp.

static 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 357 of file path.h.

References addSearchPath().

Referenced by addSearchPath().

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 pre-cached (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 repository.

When Alternative is false, all added file names must be unique 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.k 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 914 of file path.cpp.

void NLMISC::CPath::addSearchXmlpackFile ( const std::string &  sXmlpackFilename,
bool  recurse,
bool  alternative,
class NLMISC::IProgressCallback progressCallBack = NULL 
) [static]

Same as AddSearchPath but with a xml pack file "c:/test.xml_pack" all files name contained in the xml pack will be included.

Definition at line 1286 of file path.cpp.

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 226 of file path.cpp.

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

Definition at line 1450 of file path.cpp.

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 529 of file path.cpp.

Referenced by CEGUI::NeLResourceProvider::loadRawDataContainer(), and NLMISC::CSheetId::loadSheetId().

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

Returns the current path of the application.

Definition at line 618 of file path.cpp.

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

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 110 of file path.cpp.

Referenced by loadForm().

void NLMISC::CPath::getFileListByName ( const std::string &  extension,
const std::string &  name,
std::vector< std::string > &  filenames 
) [static]

Create a list of file having the requested string in the filename and the requested extension.

Definition at line 168 of file path.cpp.

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 652 of file path.cpp.

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

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 directories 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 795 of file path.cpp.

Referenced by NLMISC::CWordsDictionary::init(), NL3D::CAnimationSet::loadFromFiles(), and NL3D::CShapeBankUser::preLoadShapesFromDirectory().

std::string NLMISC::CPath::getWindowsDirectory (  )  [static]

Get the ms windows directory (in standardized way with end slash), or returns an empty string on other os.

Definition at line 1649 of file path.cpp.

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

Definition at line 510 of file path.h.

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 376 of file path.cpp.

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");

*********************************************** WARNING: This Method is NOT thread safe user must ensure that no mutator is called on CPath while async loading ***********************************************

Definition at line 408 of file path.cpp.

Referenced by NLMISC::CI18N::_readTextFile(), NL3D::CAnimationSetUser::addAnimation(), NLMISC::CFile::addFileChangeCallback(), NL3D::CAnimationSetUser::addSkeletonWeight(), NL3D::CTextureFile::buildBitmapFromFile(), NLMISC::cbInvalidEntityNamesFilename(), NL3D::CFontGenerator::CFontGenerator(), NL3D::UAnimation::createAnimation(), NL3D::CDriverUser::createAnimationSet(), NLMISC::CFile::getFileCreationDate(), NLMISC::CFile::getFileModificationDate(), NLMISC::getMD5(), NL3D::GetTextureSize(), NLSOUND::CAudioMixerUser::init(), NL3D::CInstanceGroupUser::init(), NL3D::CLandscapeIGManager::initIG(), NL3D::CInstanceLighter::light(), NL3D::CInstanceLighter::lightIgSimple(), NL3D::CZoneLighter::lightWater(), NL3D::CShapeBank::load(), NL3D::CLandscapeUser::loadBankFiles(), NL3D::CSceneUser::loadCLodShapeBank(), loadForm(), loadForm2(), loadFormNoPackedSheet(), loadFormNoPackedSheet2(), CEGUI::NeLTexture::loadFromFile(), NL3D::CDriverUser::loadHLSBank(), CEGUI::NeLResourceProvider::loadRawDataContainer(), NL3D::CShader::loadShaderFile(), NL3D::CVegetableShape::loadShape(), NLMISC::CSheetId::loadSheetId(), NL3D::CTileSet::loadTileVegetableDesc(), NLMISC::CFile::removeFileChangeCallback(), NLMISC::CConfigFile::reparse(), NLSOUND::CAsyncFileManagerSound::CLoadWavFile::run(), NL3D::CZoneLoadingTask::run(), NL3D::CAsyncFileManager3D::CIGLoad::run(), NL3D::CAsyncFileManager3D::CMeshLoad::run(), NLPACS::CRetrieverBank::serial(), and NLMISC::CFile::setFileModificationDate().

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 2311 of file path.cpp.

References standardizePath().

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

For the moment after memoryCompress you cant addsearchpath anymore.

Definition at line 1551 of file path.cpp.

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

Definition at line 1626 of file path.cpp.

NLMISC::CPath::NLMISC_SAFE_SINGLETON_DECL_PTR ( CPath   )  [private]
void NLMISC::CPath::releaseInstance (  )  [static]
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 267 of file path.cpp.

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 350 of file path.cpp.

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

Remove all search path contains in the alternative directories.

Definition at line 902 of file path.cpp.

void NLMISC::CPath::removeBigFiles ( const std::vector< std::string > &  bnpFilenames  )  [static]

Definition at line 1494 of file path.cpp.

bool NLMISC::CPath::setCurrentPath ( const std::string &  path  )  [static]

Set the current path of the application.

Definition at line 634 of file path.cpp.

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

Replace / with \ for dos process.

Use only this function if can't do another way. For example, 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 591 of file path.cpp.

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 563 of file path.cpp.

Referenced by NLMISC::CLibrary::addLibPath(), NLMISC::CLibrary::addLibPaths(), NLMISC::changeLogDirectory(), NLMISC::CopyMoveFile(), NLNET::CModuleManager::loadModuleLibrary(), makePathRelative(), NLMISC::CConfigFile::reparse(), NLPACS::CRetrieverBank::saveRetrievers(), and NLPACS::CRetrieverBank::saveShortBank().


Member Data Documentation

The container used by the standard CPath.

Definition at line 526 of file path.h.


The documentation for this class was generated from the following files:

Generated on Thu Jan 7 08:30:18 2010 for NeL by  doxygen 1.6.1