My Project
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
ParaEngine::CFileManager Class Reference

this is the main file interface exposed by ParaEngine. More...

#include <FileManager.h>

Inheritance diagram for ParaEngine::CFileManager:
ParaEngine::ISearchPathManager ParaEngine::IAttributeFields ParaEngine::IObject ParaEngine::CRefCounted

Public Member Functions

 ATTRIBUTE_DEFINE_CLASS (CFileManager)
 
virtual int InstallFields (CAttributeClass *pClass, bool bOverride)
 this class should be implemented if one wants to add new attribute. More...
 
virtual IAttributeFieldsGetChildAttributeObject (const std::string &sName)
 get attribute by child object. More...
 
virtual int GetChildAttributeObjectCount (int nColumnIndex=0)
 get the number of child objects (row count) in the given column. More...
 
virtual IAttributeFieldsGetChildAttributeObject (int nRowIndex, int nColumnIndex=0)
 
PE_CORE_DECL bool OpenArchive (const string &path, bool bUseRelativePath=false)
 add archive to manager More...
 
PE_CORE_DECL bool OpenArchiveEx (const string &path, const string &sRootDir)
 add archive to manager More...
 
PE_CORE_DECL void CloseArchive (const string &path)
 close an archive. More...
 
PE_CORE_DECL CArchiveGetArchive (const string &path)
 get archive by filename
 
PE_CORE_DECL void LoadFile (CParaFile *pFile, const char *fileName)
 load a file by name. More...
 
PE_CORE_DECL bool OpenFile (const char *filename, FileHandle &handle)
 Open a file for immediate reading.
 
PE_CORE_DECL DWORD GetFileSize (FileHandle &handle)
 get uncompressed file size. More...
 
PE_CORE_DECL bool ReadFile (FileHandle &handle, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead)
 read file. More...
 
PE_CORE_DECL bool ReadFileRaw (FileHandle &handle, LPVOID *lppBuffer, LPDWORD pnCompressedSize, LPDWORD pnUncompressedSize)
 read the raw (may be compressed file) More...
 
PE_CORE_DECL bool CloseFile (FileHandle &hFile)
 close file. More...
 
PE_CORE_DECL CSearchResultSearchFiles (const string &sRootPath, const string &sFilePattern, const string &sZipArchive, int nSubLevel=0, int nMaxFilesNum=50, int nFrom=0)
 search files at once. More...
 
PE_CORE_DECL bool DoesFileExist (const char *filename)
 Check whether a given file exists on disk. More...
 
- Public Member Functions inherited from ParaEngine::ISearchPathManager
bool AddDiskSearchPath (const std::string &sFile, bool nFront=false)
 this is low level, use with care. More...
 
PE_CORE_DECL bool AddSearchPath (const char *sFile, int nPriority=0)
 add a search path to the search path pool. More...
 
PE_CORE_DECL bool RemoveSearchPath (const char *sFile)
 remove a search path from the search path pool.
 
PE_CORE_DECL bool ClearAllSearchPath ()
 clear all search paths.
 
std::list< SearchPath > & GetSearchPaths ()
 this function is used mostly internally.
 
- Public Member Functions inherited from ParaEngine::IAttributeFields
virtual int GetAttributeClassID ()
 attribute class ID should be identical, unless one knows how overriding rules work. More...
 
virtual const char * GetAttributeClassName ()
 a static string, describing the attribute class object's name
 
virtual const char * GetAttributeClassDescription ()
 a static string, describing the attribute class object
 
virtual int GetChildAttributeColumnCount ()
 we support multi-dimensional child object. More...
 
 ATTRIBUTE_METHOD1 (IAttributeFields, GetName_s, const char **)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, SetName_s, const char *)
 
 ATTRIBUTE_METHOD (IAttributeFields, PrintObject_s)
 
 ATTRIBUTE_METHOD (IAttributeFields, AddRef_s)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, GetRefCount_s, int *)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, SetTime_s, int)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, GetTime_s, int *)
 
 ATTRIBUTE_METHOD (IAttributeFields, Release_s)
 
virtual const std::string & GetIdentifier ()
 
virtual void SetIdentifier (const std::string &sID)
 
virtual bool IsModified ()
 whether some of the fields are modified.It is up to the implementation class to provide this functionality if necessary. More...
 
virtual void SetModified (bool bModified)
 set whether any field has been modified. More...
 
virtual bool ValidateFields ()
 validate all fields and return true if validation passed. More...
 
virtual string GetValidationMessage ()
 get the recent validation message due to the most recent call to ValidateFields()
 
virtual bool ResetField (int nFieldID)
 Reset the field to its initial or default value. More...
 
virtual bool InvokeEditor (int nFieldID, const std::string &sParameters)
 Invoke an (external) editor for a given field. More...
 
virtual bool AddChildAttributeObject (IAttributeFields *pChild, int nRowIndex=-1, int nColumnIndex=0)
 add child object. More...
 
virtual void * QueryObjectByName (const std::string &sObjectType)
 convert to object of a given type. More...
 
virtual void * QueryObject (int nObjectType)
 convert to object of a given type. More...
 
virtual int GetTime ()
 get the current local time in case it is animated in milli seconds frames. More...
 
virtual void SetTime (int nTime)
 
virtual CDynamicAttributeFieldGetDynamicField (const std::string &sName)
 Get a dynamic field with a given name. More...
 
virtual CDynamicAttributeFieldGetDynamicField (int nIndex)
 Get a dynamic field with a given index. More...
 
virtual const char * GetDynamicFieldNameByIndex (int nIndex)
 get field name by index
 
virtual int GetDynamicFieldCount ()
 how many dynamic field this object currently have. More...
 
virtual int SetDynamicField (const std::string &sName, const CVariable &value)
 set a dynamic field with a given name. More...
 
virtual int AddDynamicField (const std::string &sName, ATTRIBUTE_FIELDTYPE dwType)
 add dynamic field and return field index
 
virtual void RemoveAllDynamicFields ()
 remove all dynamic fields
 
virtual int SaveDynamicFieldsToString (std::string &output)
 save only text dynamic fields to fieldname = value text strings. More...
 
virtual int LoadDynamicFieldsFromString (const std::string &input)
 load only text dynamic fields from string More...
 
CAttributeClassGetAttributeClass ()
 get the main attribute class object. More...
 
void PrintObject ()
 print the content of this object to a text file at temp/doc/[ClassName].txt. More...
 
- Public Member Functions inherited from ParaEngine::IObject
virtual void Clone (IObject *obj) const
 Clone the object's contains to a pointer. More...
 
virtual IObjectClone () const
 Clone the object's contains and return a pointer to the newly created object. More...
 
virtual bool Equals (const IObject *obj) const
 Compare the object with another object. More...
 
virtual const ITypeGetType () const
 
virtual std::string ToString () const
 
WeakPtr_typeGetWeakReference ()
 get weak reference object. More...
 
virtual int ProcessObjectEvent (const ObjectEvent &event)
 this function is only used to backward compatibility of ParaObject:AddEvent() function. More...
 
- Public Member Functions inherited from ParaEngine::CRefCounted
void addref () const
 add reference count of the object. More...
 
bool delref () const
 decrease reference count of the object. More...
 
int GetRefCount () const
 get the reference count
 
virtual int Release ()
 
CRefCountedAddToAutoReleasePool ()
 addref and releases the ownership sometime soon automatically (usually at the end of the current frame). More...
 

Static Public Member Functions

static PE_CORE_DECL CFileManagerGetInstance ()
 singleton instance
 
- Static Public Member Functions inherited from ParaEngine::IAttributeFields
static HRESULT GetAttributeClassID_s (IAttributeFields *cls, int *p1)
 
static HRESULT GetAttributeClassName_s (IAttributeFields *cls, const char **p1)
 
static bool OpenWithDefaultEditor (const char *sFilename, bool bWaitOnReturn=false)
 Open a given file with the default registered editor in the game engine. More...
 

Protected Attributes

list< CArchive * > m_archivers
 a list of all archives
 
int m_priority
 
BlockReadWriteLockm_pArchiveLock
 
- Protected Attributes inherited from ParaEngine::ISearchPathManager
std::list< SearchPathm_searchpaths
 a list of all search paths
 
- Protected Attributes inherited from ParaEngine::IObject
WeakPtr_type m_weak_reference
 
- Protected Attributes inherited from ParaEngine::CRefCounted
int m_refcount
 

Friends

class CParaFile
 

Additional Inherited Members

- Public Types inherited from ParaEngine::IAttributeFields
typedef ParaEngine::weak_ptr< IObject, IAttributeFieldsWeakPtr_type
 
- Public Types inherited from ParaEngine::IObject
typedef ParaEngine::weak_ptr< IObjectWeakPtr_type
 
- Protected Member Functions inherited from ParaEngine::IAttributeFields
virtual CAttributeClassCreateAttributeClass ()
 initialize fields
 
virtual CDynamicAttributesSetGetDynamicAttributes (bool bCreateIfNotExist=false)
 

Detailed Description

this is the main file interface exposed by ParaEngine.

it is mainly used as a singleton class.

Member Function Documentation

§ CloseArchive()

void CFileManager::CloseArchive ( const string &  path)

close an archive.

When done with an archive, one should always close it. Too many opened archives will compromise the IO performances.

§ CloseFile()

bool CFileManager::CloseFile ( FileHandle hFile)

close file.

§ DoesFileExist()

bool CFileManager::DoesFileExist ( const char *  filename)

Check whether a given file exists on disk.

Parameters
filenamefile name to check

§ GetChildAttributeObject()

IAttributeFields * ParaEngine::CFileManager::GetChildAttributeObject ( const std::string &  sName)
virtual

get attribute by child object.

used to iterate across the attribute field hierarchy.

Reimplemented from ParaEngine::IAttributeFields.

§ GetChildAttributeObjectCount()

int ParaEngine::CFileManager::GetChildAttributeObjectCount ( int  nColumnIndex = 0)
virtual

get the number of child objects (row count) in the given column.

please note different columns can have different row count.

Reimplemented from ParaEngine::IAttributeFields.

§ GetFileSize()

DWORD CFileManager::GetFileSize ( FileHandle handle)

get uncompressed file size.

§ InstallFields()

int ParaEngine::CFileManager::InstallFields ( CAttributeClass pClass,
bool  bOverride 
)
virtual

this class should be implemented if one wants to add new attribute.

This function is always called internally.

Reimplemented from ParaEngine::IAttributeFields.

§ LoadFile()

void CFileManager::LoadFile ( CParaFile pFile,
const char *  fileName 
)

load a file by name.

delete the pFile object when u does not need it. This is because, if the file is on disk, the file needs to release its handle.

Parameters
pFile[out] the returned file will be loaded in it.
fileNamefile name

§ OpenArchive()

bool CFileManager::OpenArchive ( const string &  path,
bool  bUseRelativePath = false 
)

add archive to manager

Parameters
pathpath of the zip or pkg file.
bUseRelativePathif this is true, files in the archive file will be relative to the parent directory of archive path.

§ OpenArchiveEx()

bool CFileManager::OpenArchiveEx ( const string &  path,
const string &  sRootDir 
)

add archive to manager

Parameters
pathpath of the zip or pkg file.
sRootDirfiles in the archive will be regarded as relative to this this root directory. If this is "", there is no root directory set. such as "model/", "script/", characters after the last slash is always stripped off.

we will not reopen it.

§ ReadFile()

bool CFileManager::ReadFile ( FileHandle handle,
LPVOID  lpBuffer,
DWORD  nNumberOfBytesToRead,
LPDWORD  lpNumberOfBytesRead 
)

read file.

§ ReadFileRaw()

bool CFileManager::ReadFileRaw ( FileHandle handle,
LPVOID *  lppBuffer,
LPDWORD  pnCompressedSize,
LPDWORD  pnUncompressedSize 
)

read the raw (may be compressed file)

Parameters
lppBufferthe buffer to hold the (compressed) output data. one need to use the SAFE_DELETE_ARRAY() to delete the output data.
pnCompressedSizeoutput the size of the compressed data
pnUncompressedSize:outputthe size of the uncompressed data. if 0, it means that the data is not compressed.
Returns
true if succeed.

§ SearchFiles()

CSearchResult * CFileManager::SearchFiles ( const string &  sRootPath,
const string &  sFilePattern,
const string &  sZipArchive,
int  nSubLevel = 0,
int  nMaxFilesNum = 50,
int  nFrom = 0 
)

search files at once.

See also
CSearchResult the current version of this function can support only one query at a time. The search result is invalid if called intermitantly
Parameters
sRootPaththe root path. for example: "", "xmodel/","xmodel/models/". Other format is not acceptable
sFilePatternfile pattern, e.g. "*.x" (all files with x extension), "*" (any files), "*."(directories only)
sZipArchiveit can be "" or a zip archive file name. if it is "", only disk files are saved. if it is not, only that archive files are saved.
nSubLevelhow many sub folders of sRootPath to look into. default value is 0, which only searches the sRootPath folder.
nMaxFilesNumone can limit the total number of files in the search result. Default value is 50. the search will stop at this value even there are more matching files.
nFromonly contains results from nFrom to (nFrom+nMaxFilesNum)
Returns
: one should manually release the search result.

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