The CASC_FILE_TREE class provides a common implementation for representing and navigating file trees within various ROOt file formats. It manages a collection of CASC_FILE_NODE objects, allowing for insertion, searching, and path retrieval.
Lifecycle
- Initialization: Call
Create(DWORD Flags) to initialize the tree. You can pass flags to enable storage of extra metadata. - Destruction: Call
Free() to destroy the tree and release resources.
Key Operations
- Insertion: Add nodes using
InsertByName, InsertByHash, or InsertById. - Searching: Locate nodes using
Find (by path, ID, or CKey), FindById, or Find (by hash). - Path Retrieval: Use
PathAt to get the full string path of a node. - Metadata: Use
GetExtras and SetExtras to manage additional data like FileDataId, LocaleFlags, or ContentFlags if the tree was created with the appropriate flags.
// Example usage pattern
PCASC_FILE_TREE pTree = (PCASC_FILE_TREE)new CASC_FILE_TREE();
// Create tree with support for FileDataId, LocaleFlags, and ContentFlags
DWORD flags = FTREE_FLAG_USE_DATA_ID | FTREE_FLAG_USE_LOCALE_FLAGS | FTREE_FLAG_USE_CONTENT_FLAGS;
pTree->Create(flags);
// Insert a node
PCASC_FILE_NODE pNode = pTree->InsertByName(pCKeyEntry, "example/path/file.txt", fileDataId);
// Find a node by path
PCASC_FILE_NODE pFound = pTree->Find("example/path/file.txt", CASC_INVALID_ID, nullptr);
// Get the path string
char szPath[MAX_PATH];
pTree->PathAt(szPath, MAX_PATH, pFound);
pTree->Free();
delete pTree;