| 147 | // phMpq - Pointer to store open archive handle |
| 148 | |
| 149 | bool STORMAPI SFileOpenArchive( |
| 150 | const TCHAR * szMpqName, |
| 151 | DWORD dwPriority, |
| 152 | DWORD dwFlags, |
| 153 | HANDLE * phMpq) |
| 154 | { |
| 155 | TMPQUserData * pUserData; |
| 156 | TFileStream * pStream = NULL; // Open file stream |
| 157 | TMPQArchive * ha = NULL; // Archive handle |
| 158 | TFileEntry * pFileEntry; |
| 159 | ULONGLONG FileSize = 0; // Size of the file |
| 160 | LPBYTE pbHeaderBuffer = NULL; // Buffer for searching MPQ header |
| 161 | DWORD dwStreamFlags = (dwFlags & STREAM_FLAGS_MASK); |
| 162 | bool bIsWarcraft3Map = false; |
| 163 | int nError = ERROR_SUCCESS; |
| 164 | |
| 165 | // Verify the parameters |
| 166 | if(szMpqName == NULL || *szMpqName == 0 || phMpq == NULL) |
| 167 | { |
| 168 | SetLastError(ERROR_INVALID_PARAMETER); |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | // One time initialization of MPQ cryptography |
| 173 | InitializeMpqCryptography(); |
| 174 | dwPriority = dwPriority; |
| 175 | |
| 176 | // If not forcing MPQ v 1.0, also use file bitmap |
| 177 | dwStreamFlags |= (dwFlags & MPQ_OPEN_FORCE_MPQ_V1) ? 0 : STREAM_FLAG_USE_BITMAP; |
| 178 | |
| 179 | #ifndef FULL |
| 180 | char translatedName[260]; |
| 181 | TranslateFileName(translatedName, sizeof(translatedName), szMpqName); |
| 182 | #endif |
| 183 | |
| 184 | // Open the MPQ archive file |
| 185 | pStream = FileStream_OpenFile(translatedName, dwStreamFlags); |
| 186 | if(pStream == NULL) |
| 187 | return false; |
| 188 | |
| 189 | // Check the file size. There must be at least 0x20 bytes |
| 190 | if(nError == ERROR_SUCCESS) |
| 191 | { |
| 192 | FileStream_GetSize(pStream, &FileSize); |
| 193 | if(FileSize < MPQ_HEADER_SIZE_V1) |
| 194 | nError = ERROR_BAD_FORMAT; |
| 195 | } |
| 196 | |
| 197 | // Allocate the MPQhandle |
| 198 | if(nError == ERROR_SUCCESS) |
| 199 | { |
| 200 | if((ha = STORM_ALLOC(TMPQArchive, 1)) == NULL) |
| 201 | nError = ERROR_NOT_ENOUGH_MEMORY; |
| 202 | } |
| 203 | |
| 204 | // Allocate buffer for searching MPQ header |
| 205 | if(nError == ERROR_SUCCESS) |
| 206 | { |
no test coverage detected