ICryPak

#include

Public Types

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)
}
Flags used in file path resolution rules. More...
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)
}
Used for widening FOpen functionality. They're ignored for the regular File System files. More...
enum ERecordFileOpenList { RFOM_Disabled, RFOM_EngineStartup, RFOM_Level, RFOM_NextLevel }
enum { g_nMaxPath = 0x800 }
The size of the buffer that receives the full path to the file.
enum EFileSearchLocation { eFileLocation_Any = 0, eFileLocation_OnDisk, eFileLocation_InPak }
File location enum used in isFileExist to control where the pak system looks for the file.
enum EInMemoryPakLocation { eInMemoryPakLocale_Unload = 0, eInMemoryPakLocale_CPU, eInMemoryPakLocale_GPU }
typedef uint64 FileTime
typedef int64 SignedFileSize
typedef std::function< void(const ArchiveEntryInfo &)> ArchiveEntrySinkFunction

Public Member Functions

virtual const char * AdjustFileName (const char *src, char dst[g_nMaxPath], unsigned nFlags)=0
virtual bool Init (const char *szBasePath)=0
virtual void Release ()=0
virtual bool IsInstalledToHDD (const char *acFilePath=0) const =0
virtual bool OpenPack (const char *pName, unsigned nFlags=FLAGS_PATH_REAL, IMemoryBlock *pData=0, CryFixedStringT< ICryPak::g_nMaxPath > *pFullPath=0)=0
virtual bool OpenPack (const char *pBindingRoot, const char *pName, unsigned nFlags=FLAGS_PATH_REAL, IMemoryBlock *pData=0, CryFixedStringT< ICryPak::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 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 OpenPacks (const char *pWildcard, unsigned nFlags=FLAGS_PATH_REAL, std::vector< CryFixedStringT< ICryPak::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< ICryPak::g_nMaxPath >> *pFullPaths=NULL)=0
Opens pack files by the path and wildcard.
virtual bool ClosePacks (const char *pWildcard, unsigned nFlags=FLAGS_PATH_REAL)=0
Closes pack files by the path and wildcard.
virtual bool FindPacks (const char *pWildcardIn)=0
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 bool SetPackAccessible (bool bAccessible, const char *pName, unsigned nFlags=FLAGS_PATH_REAL)=0
Set access status of a pack file.
virtual void SetPacksAccessibleForLevel (const char *sLevelName)=0
virtual bool LoadPakToMemory (const char *pName, EInMemoryPakLocation eLoadToMemory, IMemoryBlock *pMemoryBlock=NULL)=0
Load or unload pak file completely to memory.
virtual void LoadPaksToMemory (int nMaxPakSize, bool bLoadToMemory)=0
virtual void AddMod (const char *szMod)=0
Adds a mod to the list.
virtual void RemoveMod (const char *szMod)=0
Removes a mod from the list.
virtual const char * GetMod (int index)=0
virtual void ParseAliases (const char *szCommandLine)=0
Processes an alias command line containing multiple aliases.
virtual void SetAlias (const char *szName, const char *szAlias, bool bAdd)=0
Adds or removes an alias from the list.
virtual const char * GetAlias (const char *szName, bool bReturnSame=true)=0
virtual void Lock ()=0
Lock all the operations.
virtual void Unlock ()=0
virtual void LockReadIO (bool bValue)=0
Add a lock operation around the read operations to be sure they only happen from one thread.
virtual void SetGameFolder (const char *szFolder)=0
Set and Get "Game" folder (/Game, /Game04, ...).
virtual const char * GetGameFolder () const =0
virtual void SetLocalizationFolder (char const *const sLocalizationFolder)=0
Set and Get the localization folder name (Languages, Localization, ...).
virtual char const *const GetLocalizationFolder () const =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 ICryPak::PakInfo * GetPakInfo ()=0
virtual void FreePakInfo (PakInfo *)=0
virtual FILE * FOpen (const char *pName, const char *mode, unsigned nFlags=0)=0
virtual FILE * FOpen (const char *pName, const char *mode, char *szFileGamePath, int nLen)=0
virtual FILE * FOpenRaw (const char *pName, const char *mode)=0
Just a wrapper for fopen function. For loading sampler unification.
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
virtual void * FGetCachedFileData (FILE *handle, size_t &nFileSize)=0
virtual size_t FWrite (const void *data, size_t length, size_t elems, FILE *handle)=0
virtual int FPrintf (FILE *handle, const char *format,...) PRINTF_PARAMS(3
virtual int FScanf(FILE *, const char *, ...) SCANF_PARAMS(2, 3) =0;
virtual int virtual char * FGets (char *, int, FILE *)=0
virtual int Getc (FILE *)=0
virtual size_t FGetSize (FILE *f)=0
virtual size_t FGetSize (const char *pName, bool bAllowUseFileSystem=false)=0
virtual int Ungetc (int c, FILE *)=0
virtual bool IsInPak (FILE *handle)=0
virtual bool RemoveFile (const char *pName)=0
Remove file from FS (if supported).
virtual bool RemoveDir (const char *pName, bool bRecurse)=0
Remove directory from FS (if supported).
virtual bool IsAbsPath (const char *pPath)=0
Determines if pPath is an absolute or relative path.
virtual bool CopyFileOnDisk (const char *source, const char *dest, bool bFailIfExist)=0
virtual size_t FSeek (FILE *handle, long seek, int mode)=0
virtual long FTell (FILE *handle)=0
virtual int FClose (FILE *handle)=0
virtual int FEof (FILE *handle)=0
virtual int FError (FILE *handle)=0
virtual int FGetErrno ()=0
virtual int FFlush (FILE *handle)=0
virtual void * PoolMalloc (size_t size)=0
Return pointer to pool if available.
virtual void PoolFree (void *p)=0
Free pool.
virtual IMemoryBlock * PoolAllocMemoryBlock (size_t nSize, const char *sUsage, size_t nAlign=1)=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 int FindClose (intptr_t handle)=0
virtual ICryPak::FileTime GetModificationTime (FILE *f)=0
virtual bool IsFileExist (const char *sFilename, EFileSearchLocation=eFileLocation_Any)=0
virtual bool IsFolder (const char *sPath)=0
virtual ICryPak::SignedFileSize GetFileSizeOnDisk (const char *filename)=0
virtual bool IsFileCompressed (const char *filename)=0
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
virtual const char * GetFileArchivePath (FILE *f)=0
virtual int RawCompress (const void *pUncompressed, unsigned long *pDestSize, void *pCompressed, unsigned long nSrcSize, int nLevel=-1)=0
virtual int RawUncompress (void *pUncompressed, unsigned long *pDestSize, const void *pCompressed, unsigned long nSrcSize)=0
virtual void RecordFileOpen (const ERecordFileOpenList eList)=0
Turn on/off recording of filenames of opened files.
virtual void RecordFile (FILE *in, const char *szFilename)=0
virtual IResourceList * GetResourceList (const ERecordFileOpenList eList)=0
Get resource list of all recorded files, the next level, ...
virtual void SetResourceList (const ERecordFileOpenList eList, IResourceList *pResourceList)=0
virtual ICryPak::ERecordFileOpenList GetRecordFileOpenList ()=0
Get the current mode, can be set by RecordFileOpen().
virtual uint32 ComputeCRC (const char *szPath, uint32 nFileOpenFlags=0)=0
virtual bool ComputeMD5 (const char *szPath, unsigned char *md5, uint32 nFileOpenFlags=0)=0
virtual int ComputeCachedPakCDR_CRC (const char *filename, bool useCryFile=true, IMemoryBlock *pData=NULL)=0
virtual void RegisterFileAccessSink (ICryPakFileAcesssSink *pSink)=0
virtual void UnregisterFileAccessSink (ICryPakFileAcesssSink *pSink)=0
virtual bool GetLvlResStatus () const =0
virtual void DisableRuntimeFileAccess (bool status)=0
virtual bool DisableRuntimeFileAccess (bool status, threadID threadId)=0
virtual bool CheckFileAccessDisabled (const char *name, const char *mode)=0
virtual void SetRenderThreadId (threadID renderThreadId)=0
virtual int GetPakPriority ()=0
Gets the current pak priority.
virtual uint64 GetFileOffsetOnMedia (const char *szName)=0
virtual EStreamSourceMediaType GetFileMediaType (const char *szName)=0
Return media type for the file.
virtual void CreatePerfHUDWidget ()=0
PerfHUD widget for tracking pak file stats.
virtual bool ForEachArchiveFolderEntry (const char *szArchivePath, const char *szFolderPath, const ArchiveEntrySinkFunction &callback)=0
template
size_t FRead (T *data, size_t elems, FILE *handle, bool bSwapEndian=eLittleEndian)
Type-safe endian conversion read.
template
void FWrite (T *data, size_t elems, FILE *handle)
Type-independent Write.

Static Public Attributes

static const ICryPak::SignedFileSize FILE_NOT_PRESENT = -1

Detailed Description

Interface to the Pak file system.

See also
CryPak.

Member Enumeration Documentation

◆ EFOpenFlags

Used for widening FOpen functionality. They're ignored for the regular File System files.

Enumerator
FOPEN_HINT_DIRECT_OPERATION

If possible, will prevent the file from being read from memory.

FOPEN_HINT_QUIET

Will prevent a "missing file" warnings to be created.

FOPEN_ONDISK

File should be on disk.

FOPEN_FORSTREAMING

Open is done by the streaming thread.

FOPEN_LOCKED_OPEN

On supported platforms, file is open in 'locked' mode.

◆ EPathResolutionRules

Flags used in file path resolution rules.

Enumerator
FLAGS_PATH_REAL

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 Game).

FLAGS_COPY_DEST_ALWAYS

AdjustFileName will always copy the file path to the destination path: regardless of the returned value, szDestpath can be used.

FLAGS_ADD_TRAILING_SLASH

Adds trailing slash to the path.

FLAGS_NO_FULL_PATH

If this is set, AdjustFileName will not make relative paths into full paths.

FLAGS_REDIRECT_TO_DISC

If this is set, AdjustFileName will redirect path to disc.

FLAGS_FOR_WRITING

If this is set, AdjustFileName will not adjust path for writing files.

FLAGS_NO_LOWCASE

If this is set, AdjustFileName will not convert the path to low case.

FLAGS_PAK_IN_MEMORY

If this is set, the pak would be stored in memory (gpu).

FLAGS_FILENAMES_AS_CRC32

Store all file names as crc32 in a flat directory structure.

FLAGS_CHECK_MOD_PATHS

If this is set, AdjustFileName will try to find the file under any mod paths we know about.

FLAGS_NEVER_IN_PAK

If this is set, AdjustFileName will always check the filesystem/disk and not check inside open paks.

FLAGS_RESOLVE_TO_CACHE

Used by the resource compiler to pass the real file name.

Returns
Existing file name from the local data or existing cache file name.
FLAGS_PAK_IN_MEMORY_CPU

If this is set, the pak would be stored in memory (cpu).

◆ ERecordFileOpenList

Enumerator
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.

Member Function Documentation

◆ AdjustFileName()

virtual const char* ICryPak::AdjustFileName ( const char * src,
char dst[g_nMaxPath],
unsigned nFlags
)
pure virtual

Given the source relative path, constructs the full path to the file according to the flags.

Returns
Pointer to the constructed path (can be either szSourcePath, or szDestPath, or NULL in case of error.

◆ ComputeCRC()

virtual uint32 ICryPak::ComputeCRC ( const char * szPath,
uint32 nFileOpenFlags = 0
)
pure virtual

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).

Parameters
szPathMust not be 0.
Returns
Error code.

◆ ComputeMD5()

virtual bool ICryPak::ComputeMD5 ( const char * szPath,
unsigned char * md5,
uint32 nFileOpenFlags = 0
)
pure virtual

Computes MD5 checksum for a file. Good for big files - low memory overhead (1MB).

Parameters
szPath- must not be 0.
md5- destination array of unsigned char [16].
Returns
true on success, false on failure.

◆ FGetCachedFileData()

virtual void* ICryPak::FGetCachedFileData ( FILE * handle,
size_t & nFileSize
)
pure virtual

Get pointer to the internally cached, loaded data of the file.

Note
Requesting cached file data of the another file will invalidate previously retrieved pointer.

◆ FindFirst()

virtual intptr_t ICryPak::FindFirst ( const char * pDir,
_finddata_t * fd,
unsigned int nFlags = 0,
bool bAllOwUseFileSystem = false
)
pure virtual
Parameters
nFlagsA combination of EPathResolutionRules flags.

◆ FindPacks()

virtual bool ICryPak::FindPacks ( const char * pWildcardIn)
pure virtual
Returns
true if a pak exists matching the wildcard.

◆ FOpen()

virtual FILE* ICryPak::FOpen ( const char * pName,
const char * mode,
unsigned nFlags = 0
)
pure virtual

Open file handle, file can be on disk or in PAK file. Possible mode is r,b,x. Example: 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.

See also
ICryPak::EFOpenFlags.

◆ ForEachArchiveFolderEntry()

virtual bool ICryPak::ForEachArchiveFolderEntry ( const char * szArchivePath,
const char * szFolderPath,
const ArchiveEntrySinkFunction & callback
)
pure virtual

Calls a callback for all entries in an archive folder

Parameters
szFolderPathcontains search masks, if szFolderPath is just a filename or folderpath the callback will be called once for this entry.
Returns
Returns false if an error occurred.

◆ FReadRawAll()

virtual size_t ICryPak::FReadRawAll ( void * data,
size_t nFileSize,
FILE * handle
)
pure virtual

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.

◆ FWrite()

virtual size_t ICryPak::FWrite ( const void * data,
size_t length,
size_t elems,
FILE * handle
)
pure virtual

Write file data, cannot be used for writing into the PAK. Use ICryArchive interface for writing into the pak files.

◆ GetAlias()

virtual const char* ICryPak::GetAlias ( const char * szName,
bool bReturnSame = true
)
pure virtual

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.

◆ GetFileArchivePath()

virtual const char* ICryPak::GetFileArchivePath ( FILE * f)
pure virtual

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).

◆ GetFileOffsetOnMedia()

virtual uint64 ICryPak::GetFileOffsetOnMedia ( const char * szName)
pure virtual
Returns
Offset in pak file (ideally has to return offset on DVD) for streaming requests sorting.

◆ GetLvlResStatus()

virtual bool ICryPak::GetLvlResStatus ( ) const
pure virtual

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.

Returns
true=on, false=off

◆ GetMod()

virtual const char* ICryPak::GetMod ( int index)
pure virtual
Returns
Indexed mod path, or NULL if out of range.

◆ GetModificationTime()

virtual ICryPak::FileTime ICryPak::GetModificationTime ( FILE * f)
pure virtual
Returns
File modification time.

◆ GetPakInfo()

virtual ICryPak::PakInfo* ICryPak::GetPakInfo ( )
pure virtual
Returns
Array of PackInfo structures inside OpenPacks structure. You MUST call FreeOpenPackInfo.

◆ IsFileCompressed()

virtual bool ICryPak::IsFileCompressed ( const char * filename)
pure virtual
Returns
true if file is compressed inside a pak.

◆ IsFileExist()

virtual bool ICryPak::IsFileExist ( const char * sFilename,
EFileSearchLocation = eFileLocation_Any
)
pure virtual
Returns
true if specified file exists in filesystem.

◆ IsFolder()

virtual bool ICryPak::IsFolder ( const char * sPath)
pure virtual
Returns
true if path is a folder.

◆ IsInstalledToHDD()

virtual bool ICryPak::IsInstalledToHDD ( const char * acFilePath = 0) const
pure virtual
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.

◆ OpenArchive()

virtual ICryArchive* ICryPak::OpenArchive ( const char * szPath,
unsigned int nFlags = 0,
IMemoryBlock * pData = 0
)
pure virtual

Open the physical archive file - creates if it doesn't exist. nFlags is a combination of flags from EPakFlags enum.

Returns
NULL if it's invalid or can't open the file.
See also
EPakFlags

◆ OpenPack()

virtual bool ICryPak::OpenPack ( const char * pName,
unsigned nFlags = FLAGS_PATH_REAL,
IMemoryBlock * pData = 0,
CryFixedStringT< ICryPak::g_nMaxPath > * pFullPath = 0
)
pure virtual

After this call, the pak file will be searched for files when they aren't on the OS file system.

Parameters
pNameMust not be 0.

◆ PoolAllocMemoryBlock()

virtual IMemoryBlock* ICryPak::PoolAllocMemoryBlock ( size_t nSize,
const char * sUsage,
size_t nAlign = 1
)
pure virtual
Parameters
sUsageindicates for what usage this memory was requested.
Returns
Interface to the Memory Block allocated on the File Pool memory.

◆ RawCompress()

virtual int ICryPak::RawCompress ( const void * pUncompressed,
unsigned long * pDestSize,
void * pCompressed,
unsigned long nSrcSize,
int nLevel = -1
)
pure virtual

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).
Note
Multithreaded-safe.

◆ RawUncompress()

virtual int ICryPak::RawUncompress ( void * pUncompressed,
unsigned long * pDestSize,
const void * pCompressed,
unsigned long nSrcSize
)
pure virtual

Uncompresses raw (without wrapping) data that is compressed with method 8 (deflated) in the Zip file. 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.

Returns
One of the Z_* errors (Z_OK upon success).

◆ RecordFile()

virtual void ICryPak::RecordFile ( FILE * in,
const char * szFilename
)
pure virtual

Record this file if recording is enabled.

Parameters
in- 0 if asyncronous read.

◆ RegisterFileAccessSink()

virtual void ICryPak::RegisterFileAccessSink ( ICryPakFileAcesssSink * pSink)
pure virtual

Useful for gathering file access statistics, assert if it was inserted already but then it does not become insersted.

Parameters
pSinkMust not be 0.

◆ SetPacksAccessibleForLevel()

virtual void ICryPak::SetPacksAccessibleForLevel ( const char * sLevelName)
pure virtual

This marks as Accessible all paks required for specific level and vice versa for all other paks. This is useful in case the game has per level split assets.

◆ UnregisterFileAccessSink()

virtual void ICryPak::UnregisterFileAccessSink ( ICryPakFileAcesssSink * pSink)
pure virtual

Assert if it was not registered already.

Parameters
pSinkMust not be 0.