MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / CascOpenFile

Function CascOpenFile

src/External/CascLib/src/CascOpenFile.cpp:305–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303// Public functions
304
305bool WINAPI CascOpenFile(HANDLE hStorage, const void * pvFileName, DWORD dwLocaleFlags, DWORD dwOpenFlags, HANDLE * PtrFileHandle)
306{
307 PCASC_CKEY_ENTRY pCKeyEntry = NULL;
308 TCascStorage * hs;
309 const char * szFileName;
310 DWORD FileDataId = CASC_INVALID_ID;
311 BYTE CKeyEKeyBuffer[MD5_HASH_SIZE];
312 DWORD dwErrCode = ERROR_SUCCESS;
313
314 // This parameter is not used
315 CASCLIB_UNUSED(dwLocaleFlags);
316
317 // Validate the storage handle
318 hs = TCascStorage::IsValid(hStorage);
319 if(hs == NULL)
320 {
321 SetCascError(ERROR_INVALID_HANDLE);
322 return false;
323 }
324
325 // Validate the other parameters
326 if(PtrFileHandle == NULL)
327 {
328 SetCascError(ERROR_INVALID_PARAMETER);
329 return false;
330 }
331
332 // Retrieve the CKey/EKey from the file name in different modes
333 switch(dwOpenFlags & CASC_OPEN_TYPE_MASK)
334 {
335 case CASC_OPEN_BY_NAME:
336
337 // The 'pvFileName' must be zero terminated ANSI file name
338 szFileName = (const char *)pvFileName;
339 if(szFileName == NULL || szFileName[0] == 0)
340 {
341 SetCascError(ERROR_INVALID_PARAMETER);
342 return false;
343 }
344
345 // The first chance: Try to find the file by name (using the root handler)
346 pCKeyEntry = hs->pRootHandler->GetFile(hs, szFileName);
347 if(pCKeyEntry != NULL)
348 break;
349
350 // Second chance: If the file name is actually a file data id, we convert it to file data ID
351 if(IsFileDataIdName(szFileName, FileDataId))
352 {
353 pCKeyEntry = hs->pRootHandler->GetFile(hs, FileDataId);
354 if(pCKeyEntry != NULL)
355 break;
356 }
357
358 // Third chance: If the file name is a string representation of CKey/EKey, we try to query for CKey
359 if(IsFileCKeyEKeyName(szFileName, CKeyEKeyBuffer))
360 {
361 pCKeyEntry = FindCKeyEntry_CKey(hs, CKeyEKeyBuffer);
362 if(pCKeyEntry != NULL)

Callers 5

ExtractFileFunction · 0.85
Storage_SeekFilesFunction · 0.85
OnlineStorage_TestFunction · 0.85
mainFunction · 0.85
OpenFileMethod · 0.85

Calls 7

SetCascErrorFunction · 0.85
IsFileDataIdNameFunction · 0.85
IsFileCKeyEKeyNameFunction · 0.85
FindCKeyEntry_CKeyFunction · 0.85
FindCKeyEntry_EKeyFunction · 0.85
OpenFileByCKeyEntryFunction · 0.85
GetFileMethod · 0.45

Tested by 4

ExtractFileFunction · 0.68
Storage_SeekFilesFunction · 0.68
OnlineStorage_TestFunction · 0.68
mainFunction · 0.68