Interface to the Pak file system
struct ICryPak { enum EPathResolutionRules { FLAGS_PATH_REAL = 1L<<16, FLAGS_COPY_DEST_ALWAYS = 1L<<17, FLAGS_ADD_TRAILING_SLASH = 1L<<18, FLAGS_NO_FULL_PATH = 1L<<21, FLAGS_REDIRECT_TO_DISC = 1L<<22, FLAGS_FOR_WRITING = 1L<<23, FLAGS_NO_LOWCASE = 1L<<24, FLAGS_PAK_IN_MEMORY = BIT(25), FLAGS_FILENAMES_AS_CRC32 = BIT(26), FLAGS_CHECK_MOD_PATHS = BIT(27), FLAGS_NEVER_IN_PAK = BIT(28), FLAGS_RESOLVE_TO_CACHE = BIT(29), FLAGS_PAK_IN_MEMORY_CPU = BIT(30) }; enum EFOpenFlags { FOPEN_HINT_DIRECT_OPERATION = BIT(0), FOPEN_HINT_QUIET = BIT(1), FOPEN_ONDISK = BIT(2), FOPEN_FORSTREAMING = BIT(3), FOPEN_LOCKED_OPEN = BIT(4) }; enum ERecordFileOpenList { RFOM_Disabled, RFOM_EngineStartup, RFOM_Level, RFOM_NextLevel }; enum { g_nMaxPath = 0x800 }; enum EFileSearchLocation { eFileLocation_Any = 0, eFileLocation_OnDisk, eFileLocation_InPak }; enum EInMemoryPakLocation { eInMemoryPakLocale_Unload = 0, eInMemoryPakLocale_CPU, eInMemoryPakLocale_GPU }; struct PakInfo { struct Pak { const char* szFilePath; const char* szBindRoot; size_t nUsedMem; }; unsigned numOpenPaks; Pak arrPaks[1]; }; const ICryPak::SignedFileSize FILE_NOT_PRESENT = -1; };
ICryPak.h
CryPak
enum EFileSearchLocation { eFileLocation_Any = 0, eFileLocation_OnDisk, eFileLocation_InPak };
ICryPak.h
file location enum used in isFileExist to control where the pak system looks for the file.
enum EFOpenFlags { FOPEN_HINT_DIRECT_OPERATION = BIT(0), FOPEN_HINT_QUIET = BIT(1), FOPEN_ONDISK = BIT(2), FOPEN_FORSTREAMING = BIT(3), FOPEN_LOCKED_OPEN = BIT(4) };
ICryPak.h
Members |
Description |
FOPEN_HINT_DIRECT_OPERATION = BIT(0) |
If possible, will prevent the file from being read from memory. |
FOPEN_HINT_QUIET = BIT(1) |
Will prevent a "missing file" warnings to be created. |
FOPEN_ONDISK = BIT(2) |
File should be on disk |
FOPEN_FORSTREAMING = BIT(3) |
Open is done by the streaming thread. |
FOPEN_LOCKED_OPEN = BIT(4) |
on supported platforms, file is open in 'locked' mode |
Used for widening FOpen functionality. They're ignored for the regular File System files.
enum EInMemoryPakLocation { eInMemoryPakLocale_Unload = 0, eInMemoryPakLocale_CPU, eInMemoryPakLocale_GPU };
ICryPak.h
enum EPathResolutionRules { FLAGS_PATH_REAL = 1L<<16, FLAGS_COPY_DEST_ALWAYS = 1L<<17, FLAGS_ADD_TRAILING_SLASH = 1L<<18, FLAGS_NO_FULL_PATH = 1L<<21, FLAGS_REDIRECT_TO_DISC = 1L<<22, FLAGS_FOR_WRITING = 1L<<23, FLAGS_NO_LOWCASE = 1L<<24, FLAGS_PAK_IN_MEMORY = BIT(25), FLAGS_FILENAMES_AS_CRC32 = BIT(26), FLAGS_CHECK_MOD_PATHS = BIT(27), FLAGS_NEVER_IN_PAK = BIT(28), FLAGS_RESOLVE_TO_CACHE = BIT(29), FLAGS_PAK_IN_MEMORY_CPU = BIT(30) };
ICryPak.h
Members |
Description |
FLAGS_PATH_REAL = 1L<<16 |
If used, the source path will be treated as the destination path and no transformations will be done. Pass this flag when the path is to be the actual path on the disk/in the packs and doesn't need adjustment (or after it has come through adjustments already) if this is set, AdjustFileName will not map the input path into the master folder (Ex: Shaders will not be converted to GameShaders) |
FLAGS_COPY_DEST_ALWAYS = 1L<<17 |
AdjustFileName will always copy the file path to the destination path: regardless of the returned value, szDestpath can be used |
FLAGS_ADD_TRAILING_SLASH = 1L<<18 |
Adds trailing slash to the path |
FLAGS_NO_FULL_PATH = 1L<<21 |
if this is set, AdjustFileName will not make relative paths into full paths |
FLAGS_REDIRECT_TO_DISC = 1L<<22 |
if this is set, AdjustFileName will redirect path to disc |
FLAGS_FOR_WRITING = 1L<<23 |
if this is set, AdjustFileName will not adjust path for writing files |
FLAGS_NO_LOWCASE = 1L<<24 |
if this is set, AdjustFileName will not convert the path to low case |
FLAGS_PAK_IN_MEMORY = BIT(25) |
if this is set, the pak would be stored in memory (gpu) |
FLAGS_FILENAMES_AS_CRC32 = BIT(26) |
Store all file names as crc32 in a flat directory structure. |
FLAGS_CHECK_MOD_PATHS = BIT(27) |
if this is set, AdjustFileName will try to find the file under any mod paths we know about |
FLAGS_NEVER_IN_PAK = BIT(28) |
if this is set, AdjustFileName will always check the filesystem/disk and not check inside open paks |
FLAGS_RESOLVE_TO_CACHE = BIT(29) |
returns existing file name from the local data or existing cache file name used by the resource compiler to pass the real file name |
FLAGS_PAK_IN_MEMORY_CPU = BIT(30) |
if this is set, the pak would be stored in memory (cpu) |
Flags used in file path resolution rules
enum ERecordFileOpenList { RFOM_Disabled, RFOM_EngineStartup, RFOM_Level, RFOM_NextLevel };
ICryPak.h
Members |
Description |
RFOM_Disabled |
file open are not recorded (fast, no extra memory) |
RFOM_EngineStartup |
before a level is loaded |
RFOM_Level |
during level loading till export2game -> resourcelist.txt, used to generate the list for level2level loading |
RFOM_NextLevel |
used for level2level loading |
struct PakInfo { struct Pak { const char* szFilePath; const char* szBindRoot; size_t nUsedMem; }; unsigned numOpenPaks; Pak arrPaks[1]; };
ICryPak.h
Members |
Description |
unsigned numOpenPaks; |
the number of packs in the arrPacks array |
Pak arrPaks[1]; |
the packs |
struct Pak { const char* szFilePath; const char* szBindRoot; size_t nUsedMem; };
ICryPak.h
const ICryPak::SignedFileSize FILE_NOT_PRESENT = -1;
virtual ~ICryPak();
virtual void AddMod(const char* szMod) = 0;
adds a mod to the list
virtual const char* AdjustFileName(const char * src, char dst[g_nMaxPath], unsigned nFlags) = 0;
given the source relative path, constructs the full path to the file according to the flags returns the pointer to the constructed path (can be either szSourcePath, or szDestPath, or NULL in case of error
virtual bool CheckFileAccessDisabled(const char * name, const char * mode) = 0;
virtual bool ClosePack(const char* pName, unsigned nFlags = FLAGS_PATH_REAL) = 0;
after this call, the file will be unlocked and closed, and its contents won't be used to search for files
virtual bool ClosePacks(const char* pWildcard, unsigned nFlags = FLAGS_PATH_REAL) = 0;
closes pack files by the path and wildcard
virtual int ComputeCachedPakCDR_CRC(const char* filename, bool useCryFile = true, IMemoryBlock* pData = NULL) = 0;
virtual uint32 ComputeCRC(const char* szPath, uint32 nFileOpenFlags = 0) = 0;
Parameters |
Description |
const char* szPath |
must not be 0 |
error code
computes CRC (zip compatible) for a file useful if a huge uncompressed file is generation in non continuous way good for big files - low memory overhead (1MB)
virtual bool ComputeMD5(const char* szPath, unsigned char* md5, uint32 nFileOpenFlags = 0) = 0;
Parameters |
Description |
const char* szPath |
must not be 0 |
unsigned char* md5 |
destination array of unsigned char [16] |
true if success, false on failure
computes MD5 checksum for a file good for big files - low memory overhead (1MB)
virtual bool CopyFileOnDisk(const char * source, const char * dest, bool bFailIfExist) = 0;
virtual void CreatePerfHUDWidget() = 0;
PerfHUD widget for tracking pak file stats
virtual void DisableRuntimeFileAccess(bool status) = 0;
When enabled, files accessed at runtime will be tracked
virtual bool DisableRuntimeFileAccess(bool status, threadID threadId) = 0;
virtual int FClose(FILE * handle) = 0;
virtual int FEof(FILE * handle) = 0;
virtual int FError(FILE * handle) = 0;
virtual int FFlush(FILE * handle) = 0;
virtual void* FGetCachedFileData(FILE * handle, size_t & nFileSize) = 0;
Get pointer to the internally cached, loaded data of the file. WARNING! requesting cached file data of the another file will invalidate previously retrieved pointer.
virtual int FGetErrno() = 0;
virtual char * FGets(char *, int, FILE *) = 0;
virtual size_t FGetSize(FILE* f) = 0;
virtual size_t FGetSize(const char* pName, bool bAllowUseFileSystem = false) = 0;
virtual int FindClose(intptr_t handle) = 0;
virtual intptr_t FindFirst(const char * pDir, _finddata_t * fd, unsigned int nFlags = 0, bool bAllOwUseFileSystem = false) = 0;
virtual int FindNext(intptr_t handle, _finddata_t * fd) = 0;
virtual bool FindPacks(const char * pWildcardIn) = 0;
returns if a pak exists matching the wildcard
virtual FILE * FOpen(const char * pName, const char * mode, char * szFileGamePath, int nLen) = 0;
virtual FILE * FOpen(const char * pName, const char * mode, unsigned nFlags = 0) = 0;
Open file handle, file can be on disk or in PAK file. Possible mode is r,b,x ex: FILE *f = FOpen( "test.txt","rbx" ); mode x is a direct access mode, when used file reads will go directly into the low level file system without any internal data caching. Text mode is not supported for files in PAKs. for nFlags @see ICryPak::EFOpenFlags
virtual FILE * FOpenRaw(const char * pName, const char * mode) = 0;
Just wrapper for fopen function. For loading sampler unification
virtual int FPrintf(FILE * handle, const char * format, ...);
virtual int FScanf(FILE *, const char *, ...) SCANF_PARAMS(2, 3) =0;
template <class T> size_t FRead(T * data, size_t elems, FILE * handle, bool bSwapEndian = eLittleEndian);
Type-safe endian conversion read.
virtual size_t FReadRaw(void * data, size_t length, size_t elems, FILE * handle) = 0;
Read raw data from file, no endian conversion.
virtual size_t FReadRawAll(void * data, size_t nFileSize, FILE * handle) = 0;
Read all file contents into the provided memory, nSizeOfFile must be the same as returned by GetFileSize(handle) Current seek pointer is ignored and reseted to 0. no endian conversion.
virtual void FreePakInfo(PakInfo*) = 0;
virtual size_t FSeek(FILE * handle, long seek, int mode) = 0;
virtual long FTell(FILE * handle) = 0;
template <class T> void FWrite(T * data, size_t elems, FILE * handle);
Type-independent Write.
virtual size_t FWrite(const void * data, size_t length, size_t elems, FILE * handle) = 0;
Write file data, cannot be used for writing into the PAK. Use ICryArchive interface for writing into the pak files.
virtual const char * GetAlias(const char* szName, bool bReturnSame = true) = 0;
gets an alias from the list, if any exist. if bReturnSame==true, it will return the input name if an alias doesn't exist. Otherwise returns NULL
virtual int Getc(FILE *) = 0;
virtual void GetCachedPakCDROffsetSize(const char* szName, uint32 & offset, uint32 & size) = 0;
Only returns useful results on a dedicated server at present - and only if the pak is already opened
virtual const char* GetFileArchivePath(FILE* f) = 0;
returns the path to the archive in which the file was opened returns NULL if the file is a physical file, and "" if the path to archive is unknown (shouldn't ever happen)
Return media type for the file
virtual EStreamSourceMediaType GetFileMediaType(const char* szName) = 0;
Return offset in pak file (ideally has to return offset on DVD) for streaming requests sorting
virtual uint64 GetFileOffsetOnMedia(const char* szName) = 0;
virtual ICryPak::SignedFileSize GetFileSizeOnDisk(const char * filename) = 0;
virtual const char* GetGameFolder() const = 0;
virtual char const* const GetLocalizationFolder() const = 0;
virtual bool GetLvlResStatus() const = 0;
true=on, false=off
LvlRes can be enabled by command line - then asset resource recording is enabled and some modules can do more asset tracking work based on that
virtual const char* GetMod(int index) = 0;
returns indexed mod path, or NULL if out of range
virtual ICryPak::FileTime GetModificationTime(FILE* f) = 0;
virtual bool IsOutOfDate(const char * szCompiledName, const char * szMasterFile)=0; returns file modification time
virtual ICryPak::PakInfo* GetPakInfo() = 0;
returns an array of PackInfo structures inside OpenPacks structure you MUST call FreeOpenPackInfo
virtual int GetPakPriority() = 0;
gets the current pak priority
virtual ICryPak::ERecordFileOpenList GetRecordFileOpenList() = 0;
get the current mode, can be set by RecordFileOpen()
Get resource list of all recorded files, the next level, ...
virtual IResourceList* GetResourceList(const ERecordFileOpenList eList) = 0;
virtual bool Init(const char * szBasePath) = 0;
virtual bool IsAbsPath(const char* pPath) = 0;
determines if pPath is an absolute or relative path
virtual bool IsFileCompressed(const char* filename) = 0;
checks if file is compressed inside a pak
virtual bool IsFileExist(const char * sFilename, EFileSearchLocation = eFileLocation_Any) = 0;
Checks if specified file exist in filesystem.
virtual bool IsFolder(const char * sPath) = 0;
Checks if path is a folder
virtual bool IsInPak(FILE * handle) = 0;
Returns true if given pak path is installed to HDD If no file path is given it will return true if whole application is installed to HDD
virtual bool IsInstalledToHDD(const char* acFilePath = 0) const = 0;
virtual void LoadPaksToMemory(int nMaxPakSize, bool bLoadToMemory) = 0;
virtual bool LoadPakToMemory(const char * pName, EInMemoryPakLocation eLoadToMemory, IMemoryBlock * pMemoryBlock = NULL) = 0;
Load or unload pak file completely to memory.
virtual void Lock() = 0;
lock all the operations
virtual void LockReadIO(bool bValue) = 0;
add a lock operation around the read operations to be sure they only happen from one thread
virtual bool MakeDir(const char* szPath, bool bGamePathMapping = false) = 0;
creates a directory
virtual ICryArchive* OpenArchive(const char* szPath, unsigned int nFlags = 0, IMemoryBlock* pData = 0) = 0;
open the physical archive file - creates if it doesn't exist returns NULL if it's invalid or can't open the file nFlags is a combination of flags from EPakFlags enum.
virtual bool OpenPack(const char * pName, unsigned nFlags = FLAGS_PATH_REAL, IMemoryBlock* pData = 0, CryFixedStringT<:g_nmaxpath> * pFullPath = 0) = 0;
Parameters |
Description |
const char * pName |
must not be 0 |
after this call, the pak file will be searched for files when they aren't on the OS file system
virtual bool OpenPack(const char* pBindingRoot, const char * pName, unsigned nFlags = FLAGS_PATH_REAL, IMemoryBlock* pData = 0, CryFixedStringT<:g_nmaxpath> * pFullPath = 0) = 0;
after this call, the pak file will be searched for files when they aren't on the OS file system
virtual bool OpenPacks(const char * pWildcard, unsigned nFlags = FLAGS_PATH_REAL, std::vector< CryFixedStringT<:g_nmaxpath> > * pFullPaths = NULL) = 0;
opens pack files by the path and wildcard
virtual bool OpenPacks(const char* pBindingRoot, const char * pWildcard, unsigned nFlags = FLAGS_PATH_REAL, std::vector< CryFixedStringT<:g_nmaxpath> > * pFullPaths = NULL) = 0;
opens pack files by the path and wildcard
virtual void ParseAliases(const char* szCommandLine) = 0;
Processes an alias command line containing multiple aliases.
virtual IMemoryBlock* PoolAllocMemoryBlock(size_t nSize, const char * sUsage, size_t nAlign = 1) = 0;
Return an interface to the Memory Block allocated on the File Pool memory. sUsage indicates for what usage this memory was requested.
virtual void PoolFree(void * p) = 0;
! Free pool
virtual void * PoolMalloc(size_t size) = 0;
! Return pointer to pool if available
virtual int RawCompress(const void* pUncompressed, unsigned long* pDestSize, void* pCompressed, unsigned long nSrcSize, int nLevel = -1) = 0;
compresses the raw data into raw data. The buffer for compressed data itself with the heap passed. Uses method 8 (deflate) returns one of the Z_* errors (Z_OK upon success) MT-safe
virtual int RawUncompress(void* pUncompressed, unsigned long* pDestSize, const void* pCompressed, unsigned long nSrcSize) = 0;
Uncompresses raw (without wrapping) data that is compressed with method 8 (deflated) in the Zip file returns one of the Z_* errors (Z_OK upon success) This function just mimics the standard uncompress (with modification taken from unzReadCurrentFile) with 2 differences: there are no 16-bit checks, and it initializes the inflation to start without waiting for compression method byte, as this is the way it's stored into zip file
virtual void RecordFile(FILE * in, const char * szFilename) = 0;
Parameters |
Description |
FILE * in |
0 if asyncronous read |
Record this file if recording is enabled.
virtual void RecordFileOpen(const ERecordFileOpenList eList) = 0;
Turn on/off recording of filenames of opened files.
virtual void RegisterFileAccessSink(ICryPakFileAcesssSink * pSink) = 0;
Parameters |
Description |
ICryPakFileAcesssSink * pSink |
must not be 0 |
useful for gathering file access statistics, assert if it was inserted already but then it does not become insersted
virtual void Release() = 0;
virtual bool RemoveDir(const char* pName, bool bRecurse) = 0;
remove directory from FS (if supported)
virtual bool RemoveFile(const char* pName) = 0;
remove file from FS (if supported)
virtual void RemoveMod(const char* szMod) = 0;
removes a mod from the list
virtual void SetAlias(const char* szName, const char* szAlias, bool bAdd) = 0;
adds or removes an alias from the list
virtual void SetGameFolder(const char* szFolder) = 0;
Set and Get "Game" folder (/Game, /Game04, ...)
virtual void SetLocalizationFolder(char const* const sLocalizationFolder) = 0;
Set and Get the localization folder name (Languages, Localization, ...)
virtual bool SetPackAccessible(bool bAccessible, const char* pName, unsigned nFlags = FLAGS_PATH_REAL) = 0;
Set access status of a pack file
virtual bool SetPacksAccessible(bool bAccessible, const char* pWildcard, unsigned nFlags = FLAGS_PATH_REAL) = 0;
Set access status of a pak files with a wildcard
virtual void SetPacksAccessibleForLevel(const char* sLevelName) = 0;
this marks as Accessible all paks required for specific level and vice versa for all other paks - useful in case game have per level split assets
virtual void SetRenderThreadId(threadID renderThreadId) = 0;
virtual void SetResourceList(const ERecordFileOpenList eList, IResourceList* pResourceList) = 0;
virtual int Ungetc(int c, FILE *) = 0;
virtual void Unlock() = 0;
virtual void UnregisterFileAccessSink(ICryPakFileAcesssSink * pSink) = 0;
Parameters |
Description |
ICryPakFileAcesssSink * pSink |
must not be 0 |
assert if it was not registered already
typedef uint64 FileTime;
typedef int64 SignedFileSize;