MCPcopy Create free account
hub / github.com/diasurgical/devilution / CreatePseudoFileName

Function CreatePseudoFileName

3rdParty/StormLib/src/SFileGetFileInfo.cpp:923–964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

921};
922
923static int CreatePseudoFileName(HANDLE hFile, TFileEntry * pFileEntry, char * szFileName)
924{
925 TMPQFile * hf = (TMPQFile *)hFile; // MPQ File handle
926 DWORD FirstBytes[2] = {0, 0}; // The first 4 bytes of the file
927 DWORD dwBytesRead = 0;
928 DWORD dwFilePos; // Saved file position
929
930 // Read the first 2 DWORDs bytes from the file
931 dwFilePos = SFileSetFilePointer(hFile, 0, NULL, FILE_CURRENT);
932 SFileReadFile(hFile, FirstBytes, sizeof(FirstBytes), &dwBytesRead, NULL);
933 SFileSetFilePointer(hFile, dwFilePos, NULL, FILE_BEGIN);
934
935 // If we read at least 8 bytes
936 if(dwBytesRead == sizeof(FirstBytes))
937 {
938 // Make sure that the array is properly BSWAP-ed
939 BSWAP_ARRAY32_UNSIGNED(FirstBytes, sizeof(FirstBytes));
940
941 // Try to guess file extension from those 2 DWORDs
942 for(size_t i = 0; data2ext[i].szExt != NULL; i++)
943 {
944 if((FirstBytes[0] & data2ext[i].dwOffset00Mask) == data2ext[i].dwOffset00Data &&
945 (FirstBytes[1] & data2ext[i].dwOffset04Mask) == data2ext[i].dwOffset04Data)
946 {
947 char szPseudoName[20] = "";
948
949 // Format the pseudo-name
950 sprintf(szPseudoName, "File%08u.%s", (unsigned int)(pFileEntry - hf->ha->pFileTable), data2ext[i].szExt);
951
952 // Save the pseudo-name in the file entry as well
953 AllocateFileName(hf->ha, pFileEntry, szPseudoName);
954
955 // If the caller wants to copy the file name, do it
956 if(szFileName != NULL)
957 strcpy(szFileName, szPseudoName);
958 return ERROR_SUCCESS;
959 }
960 }
961 }
962
963 return ERROR_CAN_NOT_COMPLETE;
964}
965
966bool STORMAPI SFileGetFileName(HANDLE hFile, char * szFileName)
967{

Callers 1

SFileGetFileNameFunction · 0.85

Calls 3

SFileSetFilePointerFunction · 0.85
SFileReadFileFunction · 0.85
AllocateFileNameFunction · 0.85

Tested by

no test coverage detected