aboutsummaryrefslogtreecommitdiff
path: root/dep/CascLib/src/common/RootHandler.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2019-06-06 16:48:21 +0200
committerShauren <shauren.trinity@gmail.com>2019-06-08 17:09:24 +0200
commitfc330fd8ff0115804d9c4b53a1f810c00dd63de9 (patch)
treecfa10998fed66779834bf0b7a9b8b799d33d91d4 /dep/CascLib/src/common/RootHandler.cpp
parent82c7b6c5688495d90c4ee5995a4ff74039348296 (diff)
Dep/CascLib: Update to ladislav-zezula/CascLib@a1197edf0b3bd4d52c3f39be7fa7b44bb0b98012
Diffstat (limited to 'dep/CascLib/src/common/RootHandler.cpp')
-rw-r--r--dep/CascLib/src/common/RootHandler.cpp115
1 files changed, 72 insertions, 43 deletions
diff --git a/dep/CascLib/src/common/RootHandler.cpp b/dep/CascLib/src/common/RootHandler.cpp
index 4baeb41a421..89b693f55cb 100644
--- a/dep/CascLib/src/common/RootHandler.cpp
+++ b/dep/CascLib/src/common/RootHandler.cpp
@@ -13,76 +13,105 @@
#include "../CascCommon.h"
//-----------------------------------------------------------------------------
-// Common support
+// Constructor and destructor - TFileTreeRoot
-int RootHandler_Insert(TRootHandler * pRootHandler, const char * szFileName, LPBYTE pbEncodingKey)
+TFileTreeRoot::TFileTreeRoot(DWORD FileTreeFlags) : TRootHandler()
{
- if(pRootHandler == NULL || pRootHandler->Insert == NULL || pbEncodingKey == NULL)
- return ERROR_NOT_SUPPORTED;
+ // Initialize the file tree
+ FileTree.Create(FileTreeFlags);
+}
- return pRootHandler->Insert(pRootHandler, szFileName, pbEncodingKey);
+TFileTreeRoot::~TFileTreeRoot()
+{
+ // Free the file tree
+ FileTree.Free();
+ dwFeatures = 0;
}
-LPBYTE RootHandler_Search(TRootHandler * pRootHandler, struct _TCascSearch * pSearch, PDWORD PtrFileSize, PDWORD PtrLocaleFlags, PDWORD PtrFileDataId)
+//-----------------------------------------------------------------------------
+// Virtual functions - TFileTreeRoot
+
+int TFileTreeRoot::Insert(
+ const char * szFileName,
+ PCASC_CKEY_ENTRY pCKeyEntry)
{
- // Check if the root structure is valid at all
- if(pRootHandler == NULL)
- return NULL;
+ PCASC_FILE_NODE pFileNode;
- return pRootHandler->Search(pRootHandler, pSearch, PtrFileSize, PtrLocaleFlags, PtrFileDataId);
+ pFileNode = FileTree.InsertByName(pCKeyEntry, szFileName, FileTree.GetNextFileDataId());
+ return (pFileNode != NULL) ? ERROR_SUCCESS : ERROR_CAN_NOT_COMPLETE;
}
-void RootHandler_EndSearch(TRootHandler * pRootHandler, struct _TCascSearch * pSearch)
+PCASC_CKEY_ENTRY TFileTreeRoot::GetFile(TCascStorage * /* hs */, const char * szFileName)
{
- // Check if the root structure is valid at all
- if(pRootHandler != NULL)
- {
- pRootHandler->EndSearch(pRootHandler, pSearch);
- }
+ PCASC_FILE_NODE pFileNode;
+ ULONGLONG FileNameHash = CalcFileNameHash(szFileName);
+
+ pFileNode = FileTree.Find(FileNameHash);
+ return (pFileNode != NULL) ? pFileNode->pCKeyEntry : NULL;
}
-LPBYTE RootHandler_GetKey(TRootHandler * pRootHandler, const char * szFileName)
+PCASC_CKEY_ENTRY TFileTreeRoot::GetFile(TCascStorage * /* hs */, DWORD FileDataId)
{
- // Check if the root structure is valid at all
- if(pRootHandler == NULL)
- return NULL;
+ PCASC_FILE_NODE pFileNode;
- return pRootHandler->GetKey(pRootHandler, szFileName);
+ pFileNode = FileTree.FindById(FileDataId);
+ return (pFileNode != NULL) ? pFileNode->pCKeyEntry : NULL;
}
-void RootHandler_Dump(TCascStorage * hs, LPBYTE pbRootHandler, DWORD cbRootHandler, const TCHAR * szNameFormat, const TCHAR * szListFile, int nDumpLevel)
+PCASC_CKEY_ENTRY TFileTreeRoot::Search(TCascSearch * pSearch, PCASC_FIND_DATA pFindData)
{
- TDumpContext * dc;
+ PCASC_FILE_NODE pFileNode;
+ size_t nMaxFileIndex = FileTree.GetMaxFileIndex();
- // Only if the ROOT provider suports the dump option
- if(hs->pRootHandler != NULL && hs->pRootHandler->Dump != NULL)
+ // Are we still inside the root directory range?
+ while(pSearch->nFileIndex < nMaxFileIndex)
{
- // Create the dump file
- dc = CreateDumpContext(hs, szNameFormat);
- if(dc != NULL)
+ //BREAKIF(pSearch->nFileIndex >= 2823765);
+
+ // Retrieve the file item
+ pFileNode = FileTree.PathAt(pFindData->szFileName, MAX_PATH, pSearch->nFileIndex++);
+ if(pFileNode != NULL)
{
- // Dump the content and close the file
- hs->pRootHandler->Dump(hs, dc, pbRootHandler, cbRootHandler, szListFile, nDumpLevel);
- dump_close(dc);
+ // Ignore folders and mount points
+ if(!(pFileNode->Flags & CFN_FLAG_FOLDER))
+ {
+ // Check the wildcard
+ if (CascCheckWildCard(pFindData->szFileName, pSearch->szMask))
+ {
+ // Retrieve the extra values (FileDataId, file size and locale flags)
+ FileTree.GetExtras(pFileNode, &pFindData->dwFileDataId, &pFindData->dwLocaleFlags, &pFindData->dwContentFlags);
+
+ // Supply the bCanOpenByDataId variable
+ pFindData->bCanOpenByName = (pFileNode->FileNameHash != 0);
+ pFindData->bCanOpenByDataId = (pFindData->dwFileDataId != CASC_INVALID_ID);
+
+ // Return the found CKey entry
+ return pFileNode->pCKeyEntry;
+ }
+ }
}
}
+
+ // No more entries
+ return NULL;
}
-void RootHandler_Close(TRootHandler * pRootHandler)
+bool TFileTreeRoot::GetInfo(PCASC_CKEY_ENTRY pCKeyEntry, PCASC_FILE_FULL_INFO pFileInfo)
{
- // Check if the root structure is allocated at all
- if(pRootHandler != NULL)
+ PCASC_FILE_NODE pFileNode;
+
+ // Can't do much if the root key is NULL
+ if(pCKeyEntry != NULL)
{
- pRootHandler->Close(pRootHandler);
+ pFileNode = FileTree.Find(pCKeyEntry);
+ if(pFileNode != NULL)
+ {
+ FileTree.GetExtras(pFileNode, &pFileInfo->FileDataId, &pFileInfo->LocaleFlags, &pFileInfo->ContentFlags);
+ pFileInfo->FileNameHash = pFileNode->FileNameHash;
+ return true;
+ }
}
-}
-
-DWORD RootHandler_GetFileId(TRootHandler * pRootHandler, const char * szFileName)
-{
- // Check if the root structure is valid at all
- if(pRootHandler == NULL)
- return 0;
- return pRootHandler->GetFileId(pRootHandler, szFileName);
+ return false;
}