| 921 | }; |
| 922 | |
| 923 | static 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 | |
| 966 | bool STORMAPI SFileGetFileName(HANDLE hFile, char * szFileName) |
| 967 | { |
no test coverage detected