diff options
| author | Haaxor1689 <betkomaros@gmail.com> | 2025-08-25 19:31:53 +0200 | 
|---|---|---|
| committer | Haaxor1689 <betkomaros@gmail.com> | 2025-08-25 19:31:53 +0200 | 
| commit | e6e9ad2bc81868d93038b5e5198e31b19cdec265 (patch) | |
| tree | b643c0a85f51dac862f08902771d043355313c50 | |
| parent | 519927d280f75b80223986c615f4383a36255b7c (diff) | |
Get nearest power of 2 for max file count before checking against current count
| -rw-r--r-- | src/SFileCompactArchive.cpp | 9 | 
1 files changed, 4 insertions, 5 deletions
diff --git a/src/SFileCompactArchive.cpp b/src/SFileCompactArchive.cpp index 8ad1b4b..63a6de2 100644 --- a/src/SFileCompactArchive.cpp +++ b/src/SFileCompactArchive.cpp @@ -463,15 +463,17 @@ DWORD WINAPI SFileGetMaxFileCount(HANDLE hMpq)  bool WINAPI SFileSetMaxFileCount(HANDLE hMpq, DWORD dwMaxFileCount)
  {
      TMPQArchive * ha = (TMPQArchive *)hMpq;
 -    DWORD dwNewHashTableSize = 0;
      DWORD dwErrCode = ERROR_SUCCESS;
 +    // Calculate the hash table size for the new file limit
 +    DWORD dwNewHashTableSize = GetNearestPowerOfTwo(dwMaxFileCount);
 +
      // Test the valid parameters
      if(!IsValidMpqHandle(hMpq))
          dwErrCode = ERROR_INVALID_HANDLE;
      if(ha->dwFlags & MPQ_FLAG_READ_ONLY)
          dwErrCode = ERROR_ACCESS_DENIED;
 -    if(dwMaxFileCount < ha->dwFileTableSize)
 +    if(dwNewHashTableSize < ha->dwFileTableSize)
          dwErrCode = ERROR_DISK_FULL;
      // ALL file names must be known in order to be able to rebuild hash table
 @@ -480,9 +482,6 @@ bool WINAPI SFileSetMaxFileCount(HANDLE hMpq, DWORD dwMaxFileCount)          dwErrCode = CheckIfAllFilesKnown(ha);
          if(dwErrCode == ERROR_SUCCESS)
          {
 -            // Calculate the hash table size for the new file limit
 -            dwNewHashTableSize = GetNearestPowerOfTwo(dwMaxFileCount);
 -
              // Rebuild both file tables
              dwErrCode = RebuildFileTable(ha, dwNewHashTableSize);
          }
  | 
