ezEngine  Milestone 9
ezDataDirectory::FolderType Class Reference

A data directory type to handle access to ordinary files. More...

#include <DataDirTypeFolder.h>

Inheritance diagram for ezDataDirectory::FolderType:

Public Member Functions

virtual void ReloadExternalConfigs () override
 When s_sRedirectionFile and s_sRedirectionPrefix are used to enable file redirection, this will reload those config files.
 
virtual const ezString128GetRedirectedDataDirectoryPath () const override
 By default this is the same as GetDataDirectoryPath(), but derived implementations may use a different location where they actually get the files from.
 
- Public Member Functions inherited from ezDataDirectoryType
const ezString128GetDataDirectoryPath () const
 Returns the absolute path to the data directory.
 

Static Public Member Functions

static ezDataDirectoryTypeFactory (const char *szDataDirectory, const char *szGroup, const char *szRootName, ezFileSystem::DataDirUsage Usage)
 The factory that can be registered at ezFileSystem to create data directories of this type.
 

Static Public Attributes

static ezString s_sRedirectionFile
 
static ezString s_sRedirectionPrefix
 If a redirection file is used AND the redirection lookup was successful, s_sRedirectionPrefix is prepended to the redirected file access.
 

Protected Member Functions

virtual ezDataDirectoryReaderOpenFileToRead (const char *szFile, bool bSpecificallyThisDataDir) override
 Must be implemented to create a ezDataDirectoryReader for accessing the given file. Returns nullptr if the file could not be opened. More...
 
virtual bool ResolveAssetRedirection (const char *szPathOrAssetGuid, ezStringBuilder &out_sRedirection) override
 If this data directory knows how to redirect the given path, it should do so and return true. Called by ezFileSystem::ResolveAssetRedirection.
 
virtual ezDataDirectoryWriterOpenFileToWrite (const char *szFile) override
 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 () override
 This function is called by the filesystem when a data directory is removed. More...
 
virtual void DeleteFile (const char *szFile) override
 If a Data Directory Type supports it, this function will remove the given file from it.
 
virtual bool ExistsFile (const char *szFile, bool bOneSpecificDataDir) override
 This function checks whether the given file exists in this data directory. More...
 
virtual ezResult GetFileStats (const char *szFileOrFolder, bool bOneSpecificDataDir, ezFileStats &out_Stats) override
 Upon success returns the ezFileStats for a file in this data directory.
 
virtual FolderReaderCreateFolderReader () const
 
virtual FolderWriterCreateFolderWriter () const
 
virtual ezResult InternalInitializeDataDirectory (const char *szDirectory) override
 Called by 'ezDataDirectoryType_Folder::Factory'.
 
virtual void OnReaderWriterClose (ezDataDirectoryReaderWriterBase *pClosed) override
 Marks the given reader/writer as reusable.
 
void LoadRedirectionFile ()
 
- Protected Member Functions inherited from ezDataDirectoryType
ezResult InitializeDataDirectory (const char *szDataDirPath)
 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)
 

Protected Attributes

ezMutex m_ReaderWriterMutex
 Locks m_Readers / m_Writers as well as the m_bIsInUse flag of each reader / writer.
 
ezHybridArray< ezDataDirectory::FolderReader *, 4 > m_Readers
 
ezHybridArray< ezDataDirectory::FolderWriter *, 4 > m_Writers
 
ezMutex m_RedirectionMutex
 
ezMap< ezString, ezStringm_FileRedirection
 
ezString128 m_sRedirectedDataDirPath
 
- Protected Attributes inherited from ezDataDirectoryType
ezString128 m_sDataDirectoryPath
 Derived classes can use 'GetDataDirectoryPath' to access this data.
 

Detailed Description

A data directory type to handle access to ordinary files.

Register the 'Factory' function at ezFileSystem to allow it to mount local directories.

Member Function Documentation

◆ ExistsFile()

bool ezDataDirectory::FolderType::ExistsFile ( const char *  szFile,
bool  bOneSpecificDataDir 
)
overrideprotectedvirtual

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

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

Reimplemented from ezDataDirectoryType.

Reimplemented in ezDataDirectory::FileserveType.

◆ OpenFileToRead()

ezDataDirectoryReader * ezDataDirectory::FolderType::OpenFileToRead ( const char *  szFile,
bool  bSpecificallyThisDataDir 
)
overrideprotectedvirtual

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.

Implements ezDataDirectoryType.

Reimplemented in ezDataDirectory::FileserveType.

◆ OpenFileToWrite()

ezDataDirectoryWriter * ezDataDirectory::FolderType::OpenFileToWrite ( const char *  szFile)
overrideprotectedvirtual

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 from ezDataDirectoryType.

Reimplemented in ezDataDirectory::FileserveType.

◆ RemoveDataDirectory()

void ezDataDirectory::FolderType::RemoveDataDirectory ( )
overrideprotectedvirtual

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

It should delete itself using the proper allocator.

Implements ezDataDirectoryType.

Reimplemented in ezDataDirectory::FileserveType.

Member Data Documentation

◆ s_sRedirectionFile

ezString ezDataDirectory::FolderType::s_sRedirectionFile
static

A 'redirection file' is an optional file located inside a data directory that lists which file access is redirected to which other file lookup. Each redirection is one line in the file (terminated by a
). Each line consists of the 'key' string, a semicolon and a 'value' string. No unnecessary whitespace is allowed. When a file that matches 'key' is accessed through a mounted data directory, the file access will be replaced by 'value' (plus s_sRedirectionPrefix) 'key' may be anything (e.g. a GUID string), 'value' should be a valid relative path into the SAME data directory. The redirection file can be used to implement an asset lookup, where assets are identified by GUIDs and need to be mapped to the actual asset file.


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