ezEngine  Release 25.03
ezDataDirectoryType Class Referenceabstract

The base class for all data directory types. More...

#include <DataDirType.h>

Inheritance diagram for ezDataDirectoryType:

Public Member Functions

const ezString128GetDataDirectoryPath () const
 Returns the absolute path to the data directory.
 
virtual const ezString128GetRedirectedDataDirectoryPath () const
 By default this is the same as GetDataDirectoryPath(), but derived implementations may use a different location where they actually get the files from.
 
virtual void ReloadExternalConfigs ()
 Some data directory types may use external configuration files (e.g. asset lookup tables) that may get updated, while the directory is mounted. This function allows each directory type to implement reloading and reapplying of configurations, without dismounting and remounting the data directory.
 

Protected Member Functions

ezResult InitializeDataDirectory (ezStringView sDataDirPath)
 Tries to setup the data directory. Can fail, if the type is incorrect (e.g. a ZIP file data directory type cannot handle a simple folder and vice versa)
 
virtual ezDataDirectoryReaderOpenFileToRead (ezStringView sFile, ezFileShareMode::Enum FileShareMode, bool bSpecificallyThisDataDir)=0
 Must be implemented to create a ezDataDirectoryReader for accessing the given file. Returns nullptr if the file could not be opened. More...
 
virtual ezDataDirectoryWriterOpenFileToWrite (ezStringView sFile, ezFileShareMode::Enum FileShareMode)
 Must be implemented to create a ezDataDirectoryWriter for accessing the given file. Returns nullptr if the file could not be opened. More...
 
virtual void RemoveDataDirectory ()=0
 This function is called by the filesystem when a data directory is removed. More...
 
virtual void DeleteFile (ezStringView sFile)
 If a Data Directory Type supports it, this function will remove the given file from it.
 
virtual bool ExistsFile (ezStringView sFile, bool bOneSpecificDataDir)
 This function checks whether the given file exists in this data directory. More...
 
virtual ezResult GetFileStats (ezStringView sFileOrFolder, bool bOneSpecificDataDir, ezFileStats &out_Stats)=0
 Upon success returns the ezFileStats for a file in this data directory.
 
virtual bool ResolveAssetRedirection (ezStringView sPathOrAssetGuid, ezStringBuilder &out_sRedirection)
 If this data directory knows how to redirect the given path, it should do so and return true. Called by ezFileSystem::ResolveAssetRedirection.
 
virtual void OnReaderWriterClose (ezDataDirectoryReaderWriterBase *pClosed)
 This is automatically called whenever a ezDataDirectoryReaderWriterBase that was opened by this type is being closed. More...
 
virtual ezResult InternalInitializeDataDirectory (ezStringView sDirectory)=0
 This function should only be used by a Factory (which should be a static function in the respective ezDataDirectoryType). More...
 

Protected Attributes

ezString128 m_sDataDirectoryPath
 Derived classes can use 'GetDataDirectoryPath' to access this data.
 

Friends

class ezFileSystem
 
class ezDataDirectoryReaderWriterBase
 

Detailed Description

The base class for all data directory types.

There are different data directory types, such as a simple folder, a ZIP file or some kind of library (e.g. image files from procedural data). Even a HTTP server that actually transmits files over a network can provided by implementing it as a data directory type. Data directories are added through ezFileSystem, which uses factories to decide which ezDataDirectoryType to use for handling which data directory.

Member Function Documentation

◆ ExistsFile()

bool ezDataDirectoryType::ExistsFile ( ezStringView  sFile,
bool  bOneSpecificDataDir 
)
protectedvirtual

This function checks whether the given file exists in this data directory.

The default implementation simply calls ezOSFile::ExistsFile An optimized implementation might look this information up in some hash-map.

Reimplemented in ezDataDirectory::FolderType, ezDataDirectory::FileserveType, and ezDataDirectory::ArchiveType.

◆ InternalInitializeDataDirectory()

virtual ezResult ezDataDirectoryType::InternalInitializeDataDirectory ( ezStringView  sDirectory)
protectedpure virtual

This function should only be used by a Factory (which should be a static function in the respective ezDataDirectoryType).

It is used to initialize the data directory. If this ezDataDirectoryType cannot handle the given type, it must return EZ_FAILURE and the Factory needs to clean it up properly.

Implemented in ezDataDirectory::FolderType, ezDataDirectory::FileserveType, and ezDataDirectory::ArchiveType.

◆ OnReaderWriterClose()

virtual void ezDataDirectoryType::OnReaderWriterClose ( ezDataDirectoryReaderWriterBase pClosed)
inlineprotectedvirtual

This is automatically called whenever a ezDataDirectoryReaderWriterBase that was opened by this type is being closed.

It allows the ezDataDirectoryType to return the reader/writer to a pool of reusable objects, or to destroy it using the proper allocator.

Reimplemented in ezDataDirectory::FolderType, and ezDataDirectory::ArchiveType.

◆ OpenFileToRead()

virtual ezDataDirectoryReader* ezDataDirectoryType::OpenFileToRead ( ezStringView  sFile,
ezFileShareMode::Enum  FileShareMode,
bool  bSpecificallyThisDataDir 
)
protectedpure virtual

Must be implemented to create a ezDataDirectoryReader for accessing the given file. Returns nullptr if the file could not be opened.

Parameters
szFileis given as a path relative to the data directory's path. So unless the data directory path is empty, this will never be an absolute path. If a rooted path was given, the root name is also removed and only the relative part is passed along.
bSpecificallyThisDataDirThis is true when the original path specified to open the file through exactly this data directory, by using a rooted path. If an absolute path is used, which incidentally matches the prefix of this data directory, bSpecificallyThisDataDir is NOT set to true, as there might be other data directories that also match.

Implemented in ezDataDirectory::FolderType, ezDataDirectory::FileserveType, and ezDataDirectory::ArchiveType.

◆ OpenFileToWrite()

virtual ezDataDirectoryWriter* ezDataDirectoryType::OpenFileToWrite ( ezStringView  sFile,
ezFileShareMode::Enum  FileShareMode 
)
inlineprotectedvirtual

Must be implemented to create a ezDataDirectoryWriter for accessing the given file. Returns nullptr if the file could not be opened.

If it always returns nullptr (default) the data directory is read-only (at least through this type).

Reimplemented in ezDataDirectory::FolderType, and ezDataDirectory::FileserveType.

◆ RemoveDataDirectory()

virtual void ezDataDirectoryType::RemoveDataDirectory ( )
protectedpure virtual

This function is called by the filesystem when a data directory is removed.

It should delete itself using the proper allocator.

Implemented in ezDataDirectory::FolderType, ezDataDirectory::FileserveType, and ezDataDirectory::ArchiveType.


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