Browse Source

Define UNICODE/_UNICODE for StormLib and use SFileOpenArchive with wchar_t (TCHAR) on Windows

pull/1925/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
58becefada
  1. 5
      CMakeLists.txt
  2. 4
      Source/storm/storm.h
  3. 9
      Source/utils/file_util.cpp

5
CMakeLists.txt

@ -270,6 +270,11 @@ add_library(StormLib STATIC
3rdParty/StormLib/src/SFileOpenFileEx.cpp
3rdParty/StormLib/src/SFileReadFile.cpp)
if(WIN32)
# Enable Unicode for StormLib wchar_t* file APIs
target_compile_definitions(StormLib PRIVATE -DUNICODE -D_UNICODE)
endif()
add_library(PKWare STATIC
3rdParty/PKWare/explode.cpp
3rdParty/PKWare/implode.cpp)

4
Source/storm/storm.h

@ -244,7 +244,11 @@ bool SNetSendTurn(char *data, unsigned int databytes);
bool SFileOpenFile(const char *filename, HANDLE *phFile);
// Functions implemented in StormLib
#if defined(_WIN64) || defined(_WIN32)
bool WINAPI SFileOpenArchive(const wchar_t *szMpqName, DWORD dwPriority, DWORD dwFlags, HANDLE *phMpq);
#else
bool WINAPI SFileOpenArchive(const char *szMpqName, DWORD dwPriority, DWORD dwFlags, HANDLE *phMpq);
#endif
bool WINAPI SFileCloseArchive(HANDLE hArchive);
bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char *szFileName, DWORD dwSearchScope, HANDLE *phFile);
bool WINAPI SFileReadFile(HANDLE hFile, void *buffer, DWORD nNumberOfBytesToRead, DWORD *read, int *lpDistanceToMoveHigh);

9
Source/utils/file_util.cpp

@ -174,7 +174,16 @@ std::unique_ptr<std::fstream> CreateFileStream(const char *path, std::ios::openm
bool SFileOpenArchiveDiablo(const char *szMpqName, DWORD dwPriority, DWORD dwFlags, HANDLE *phMpq)
{
#if defined(_WIN64) || defined(_WIN32)
const auto szMpqNameUtf16 = ToWideChar(szMpqName);
if (szMpqNameUtf16 == nullptr) {
LogError("UTF-8 -> UTF-16 conversion error code {}", ::GetLastError());
return false;
}
return SFileOpenArchive(szMpqNameUtf16.get(), dwPriority, dwFlags, phMpq);
#else
return SFileOpenArchive(szMpqName, dwPriority, dwFlags, phMpq);
#endif
}
} // namespace devilution

Loading…
Cancel
Save