diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-06-02 14:21:13 +0200 |
---|---|---|
committer | Ovahlord <dreadkiller@gmx.de> | 2024-06-20 01:15:34 +0200 |
commit | 970ca6093c590d390d6cfd649ce7f8a9febbd5f7 (patch) | |
tree | 94bcae1e0b71b09139343ab0efdc60f2309b4ead /src/tools | |
parent | b6714f5746dd2468488b51a6f2b9eb26a6c155e9 (diff) |
Core/Misc: Fixed windows _UNICODE incompatibilities
(cherry picked from commit fd4ffc81b2593dbf5554b553828a736ac6263e98)
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/extractor_common/CascHandles.cpp | 57 | ||||
-rw-r--r-- | src/tools/mmaps_generator/PathCommon.h | 6 |
2 files changed, 36 insertions, 27 deletions
diff --git a/src/tools/extractor_common/CascHandles.cpp b/src/tools/extractor_common/CascHandles.cpp index bb3692a1393..a08f1fb9a53 100644 --- a/src/tools/extractor_common/CascHandles.cpp +++ b/src/tools/extractor_common/CascHandles.cpp @@ -157,11 +157,16 @@ namespace } } -CASC::Storage::Storage(HANDLE handle) : _handle(handle) +namespace CASC +{ +using CASCCharType = std::remove_const_t<std::remove_pointer_t<decltype(CASC_OPEN_STORAGE_ARGS::szLocalPath)>>; +using CASCStringType = std::basic_string<CASCCharType>; + +Storage::Storage(HANDLE handle) : _handle(handle) { } -bool CASC::Storage::LoadOnlineTactKeys() +bool Storage::LoadOnlineTactKeys() { // attempt to download only once, not every storage opening static Optional<std::string> const tactKeys = DownloadFile("raw.githubusercontent.com", 443, "/wowdev/TACTKeys/master/WoW.txt"); @@ -169,21 +174,22 @@ bool CASC::Storage::LoadOnlineTactKeys() return tactKeys && CascImportKeysFromString(_handle, tactKeys->c_str()); } -CASC::Storage::~Storage() +Storage::~Storage() { ::CascCloseStorage(_handle); } -CASC::Storage* CASC::Storage::Open(boost::filesystem::path const& path, uint32 localeMask, char const* product) +Storage* Storage::Open(boost::filesystem::path const& path, uint32 localeMask, char const* product) { - std::string strPath = path.string(); + CASCStringType strPath = path.template string<CASCStringType>(); + CASCStringType strProduct(product, product + strlen(product)); // dumb conversion from char to wchar, always ascii CASC_OPEN_STORAGE_ARGS args = {}; args.Size = sizeof(CASC_OPEN_STORAGE_ARGS); args.szLocalPath = strPath.c_str(); - args.szCodeName = product; + args.szCodeName = strProduct.c_str(); args.dwLocaleMask = localeMask; HANDLE handle = nullptr; - if (!::CascOpenStorageEx(nullptr, &args, false, &handle)) + if (!CascOpenStorageEx(nullptr, &args, false, &handle)) { DWORD lastError = GetCascError(); // support checking error set by *Open* call, not the next *Close* printf("Error opening casc storage '%s': %s\n", path.string().c_str(), HumanReadableCASCError(lastError)); @@ -201,14 +207,16 @@ CASC::Storage* CASC::Storage::Open(boost::filesystem::path const& path, uint32 l return storage; } -CASC::Storage* CASC::Storage::OpenRemote(boost::filesystem::path const& path, uint32 localeMask, char const* product, char const* region) +Storage* Storage::OpenRemote(boost::filesystem::path const& path, uint32 localeMask, char const* product, char const* region) { - std::string strPath = path.string(); + CASCStringType strPath = path.template string<CASCStringType>(); + CASCStringType strProduct(product, product + strlen(product)); // dumb conversion from char to wchar, always ascii + CASCStringType strRegion(region, region + strlen(region)); // dumb conversion from char to wchar, always ascii CASC_OPEN_STORAGE_ARGS args = {}; args.Size = sizeof(CASC_OPEN_STORAGE_ARGS); args.szLocalPath = strPath.c_str(); - args.szCodeName = product; - args.szRegion = region; + args.szCodeName = strProduct.c_str(); + args.szRegion = strRegion.c_str(); args.dwLocaleMask = localeMask; HANDLE handle = nullptr; @@ -224,7 +232,7 @@ CASC::Storage* CASC::Storage::OpenRemote(boost::filesystem::path const& path, ui DWORD features = 0; if (!GetStorageInfo(handle, CascStorageFeatures, &features) || !(features & CASC_FEATURE_ONLINE)) { - printf("Local casc storage detected in cache path \"%s\" (or its parent directory). Remote storage not opened!\n", args.szLocalPath); + printf("Local casc storage detected in cache path \"%s\" (or its parent directory). Remote storage not opened!\n", path.string().c_str()); CascCloseStorage(handle); SetCascError(ERROR_FILE_OFFLINE); return nullptr; @@ -239,7 +247,7 @@ CASC::Storage* CASC::Storage::OpenRemote(boost::filesystem::path const& path, ui return storage; } -uint32 CASC::Storage::GetBuildNumber() const +uint32 Storage::GetBuildNumber() const { CASC_STORAGE_PRODUCT product; if (GetStorageInfo(_handle, CascStorageProduct, &product)) @@ -248,7 +256,7 @@ uint32 CASC::Storage::GetBuildNumber() const return 0; } -uint32 CASC::Storage::GetInstalledLocalesMask() const +uint32 Storage::GetInstalledLocalesMask() const { DWORD locales; if (GetStorageInfo(_handle, CascStorageInstalledLocales, &locales)) @@ -257,12 +265,12 @@ uint32 CASC::Storage::GetInstalledLocalesMask() const return 0; } -bool CASC::Storage::HasTactKey(uint64 keyLookup) const +bool Storage::HasTactKey(uint64 keyLookup) const { return CascFindEncryptionKey(_handle, keyLookup) != nullptr; } -CASC::File* CASC::Storage::OpenFile(char const* fileName, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/) const +File* Storage::OpenFile(char const* fileName, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/) const { DWORD openFlags = CASC_OPEN_BY_NAME; if (zerofillEncryptedParts) @@ -283,7 +291,7 @@ CASC::File* CASC::Storage::OpenFile(char const* fileName, uint32 localeMask, boo return new File(handle); } -CASC::File* CASC::Storage::OpenFile(uint32 fileDataId, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/) const +File* Storage::OpenFile(uint32 fileDataId, uint32 localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/) const { DWORD openFlags = CASC_OPEN_BY_FILEID; if (zerofillEncryptedParts) @@ -304,16 +312,16 @@ CASC::File* CASC::Storage::OpenFile(uint32 fileDataId, uint32 localeMask, bool p return new File(handle); } -CASC::File::File(HANDLE handle) : _handle(handle) +File::File(HANDLE handle) : _handle(handle) { } -CASC::File::~File() +File::~File() { ::CascCloseFile(_handle); } -uint32 CASC::File::GetId() const +uint32 File::GetId() const { CASC_FILE_FULL_INFO info; if (!::CascGetFileInfo(_handle, CascFileFullInfo, &info, sizeof(info), nullptr)) @@ -322,7 +330,7 @@ uint32 CASC::File::GetId() const return info.FileDataId; } -int64 CASC::File::GetSize() const +int64 File::GetSize() const { ULONGLONG size; if (!::CascGetFileSize64(_handle, &size)) @@ -331,7 +339,7 @@ int64 CASC::File::GetSize() const return int64(size); } -int64 CASC::File::GetPointer() const +int64 File::GetPointer() const { ULONGLONG position; if (!::CascSetFilePointer64(_handle, 0, &position, FILE_CURRENT)) @@ -340,14 +348,14 @@ int64 CASC::File::GetPointer() const return int64(position); } -bool CASC::File::SetPointer(int64 position) +bool File::SetPointer(int64 position) { LONG parts[2]; memcpy(parts, &position, sizeof(parts)); return ::CascSetFilePointer64(_handle, position, nullptr, FILE_BEGIN); } -bool CASC::File::ReadFile(void* buffer, uint32 bytes, uint32* bytesRead) +bool File::ReadFile(void* buffer, uint32 bytes, uint32* bytesRead) { DWORD bytesReadDWORD; if (!::CascReadFile(_handle, buffer, bytes, &bytesReadDWORD)) @@ -358,3 +366,4 @@ bool CASC::File::ReadFile(void* buffer, uint32 bytes, uint32* bytesRead) return true; } +} diff --git a/src/tools/mmaps_generator/PathCommon.h b/src/tools/mmaps_generator/PathCommon.h index c098ff02f4c..17d354a0997 100644 --- a/src/tools/mmaps_generator/PathCommon.h +++ b/src/tools/mmaps_generator/PathCommon.h @@ -85,12 +85,12 @@ namespace MMAP { #ifdef WIN32 HANDLE hFind; - WIN32_FIND_DATA findFileInfo; + WIN32_FIND_DATAA findFileInfo; std::string directory; directory = dirpath + "/" + filter; - hFind = FindFirstFile(directory.c_str(), &findFileInfo); + hFind = FindFirstFileA(directory.c_str(), &findFileInfo); if (hFind == INVALID_HANDLE_VALUE) return LISTFILE_DIRECTORY_NOT_FOUND; @@ -99,7 +99,7 @@ namespace MMAP if (strcmp(findFileInfo.cFileName, ".") != 0 && strcmp(findFileInfo.cFileName, "..") != 0) fileList.push_back(std::string(findFileInfo.cFileName)); } - while (FindNextFile(hFind, &findFileInfo)); + while (FindNextFileA(hFind, &findFileInfo)); FindClose(hFind); |