aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-06-02 14:21:13 +0200
committerShauren <shauren.trinity@gmail.com>2025-08-30 22:55:25 +0200
commitbad2936918e060c25bf008b94627c0835ed4314f (patch)
tree4de31da5de7ca5b75b4346634beefefb17249a23 /src
parent7e193e15dbaf6429b93ec9f0bea099f1fb90ff05 (diff)
Core/Misc: Fixed windows _UNICODE incompatibilities
(cherry picked from commit fd4ffc81b2593dbf5554b553828a736ac6263e98)
Diffstat (limited to 'src')
-rw-r--r--src/common/Debugging/WheatyExceptionReport.cpp18
-rw-r--r--src/common/Platform/ServiceWin32.cpp36
-rw-r--r--src/server/authserver/Main.cpp7
-rw-r--r--src/server/worldserver/Main.cpp7
-rw-r--r--src/tools/mmaps_generator/PathCommon.h6
5 files changed, 48 insertions, 26 deletions
diff --git a/src/common/Debugging/WheatyExceptionReport.cpp b/src/common/Debugging/WheatyExceptionReport.cpp
index 00d168efd71..69ade2deab3 100644
--- a/src/common/Debugging/WheatyExceptionReport.cpp
+++ b/src/common/Debugging/WheatyExceptionReport.cpp
@@ -42,7 +42,7 @@ inline LPTSTR ErrorMessage(DWORD dw)
else
{
LPTSTR msgBuf = (LPTSTR)LocalAlloc(LPTR, 30);
- snprintf(msgBuf, 30, "Unknown error: %u", dw);
+ _sntprintf(msgBuf, 30, _T("Unknown error: %d"), (int)dw);
return msgBuf;
}
@@ -122,19 +122,25 @@ PEXCEPTION_POINTERS pExceptionInfo)
++pos;
TCHAR crash_folder_path[MAX_PATH];
- _stprintf_s(crash_folder_path, "%s\\%s", module_folder_name, CrashFolder);
+ _stprintf_s(crash_folder_path, _T("%s\\%s"), module_folder_name, CrashFolder);
if (!CreateDirectory(crash_folder_path, nullptr))
{
if (GetLastError() != ERROR_ALREADY_EXISTS)
return 0;
}
+#ifdef _UNICODE
+#define PRSTRc "S"
+#else
+#define PRSTRc "s"
+#endif
+
SYSTEMTIME systime;
GetLocalTime(&systime);
- _stprintf_s(m_szDumpFileName, "%s\\%s_%s_[%u-%u_%u-%u-%u].dmp",
+ _stprintf_s(m_szDumpFileName, _T("%s\\%" PRSTRc "_%s_[%u-%u_%u-%u-%u].dmp"),
crash_folder_path, GitRevision::GetHash(), pos, systime.wDay, systime.wMonth, systime.wHour, systime.wMinute, systime.wSecond);
- _stprintf_s(m_szLogFileName, _T("%s\\%s_%s_[%u-%u_%u-%u-%u].txt"),
+ _stprintf_s(m_szLogFileName, _T("%s\\%" PRSTRc "_%s_[%u-%u_%u-%u-%u].txt"),
crash_folder_path, GitRevision::GetHash(), pos, systime.wDay, systime.wMonth, systime.wHour, systime.wMinute, systime.wSecond);
m_hDumpFile = CreateFile(m_szDumpFileName,
@@ -223,7 +229,7 @@ template<size_t size>
void ToTchar(wchar_t const* src, TCHAR (&dst)[size])
{
if constexpr (std::is_same_v<TCHAR, char>)
- ::wcstombs_s(nullptr, dst, src, size);
+ ::wcstombs_s(nullptr, dst, src, _TRUNCATE);
else
::wcscpy_s(dst, size, src);
}
@@ -548,7 +554,7 @@ BOOL WheatyExceptionReport::_GetWindowsVersionFromWMI(TCHAR* szVersion, DWORD cn
_tcsncat(szVersion, _T(" "), cntMax);
memset(buf, 0, sizeof(buf));
ToTchar(field.bstrVal, buf);
- if (strlen(buf))
+ if (_tcslen(buf))
_tcsncat(szVersion, buf, cntMax);
}
VariantClear(&field);
diff --git a/src/common/Platform/ServiceWin32.cpp b/src/common/Platform/ServiceWin32.cpp
index 87381090dbc..8cb213e501a 100644
--- a/src/common/Platform/ServiceWin32.cpp
+++ b/src/common/Platform/ServiceWin32.cpp
@@ -20,6 +20,7 @@
#include "Common.h"
#include "Log.h"
#include <cstring>
+#include <tchar.h>
#include <windows.h>
#include <winsvc.h>
@@ -32,9 +33,9 @@
#endif
extern int main(int argc, char ** argv);
-extern char serviceLongName[];
-extern char serviceName[];
-extern char serviceDescription[];
+extern TCHAR serviceLongName[];
+extern TCHAR serviceName[];
+extern TCHAR serviceDescription[];
extern int m_ServiceStatus;
@@ -50,11 +51,11 @@ bool WinServiceInstall()
if (serviceControlManager)
{
- char path[_MAX_PATH + 10];
+ TCHAR path[_MAX_PATH + 10];
if (GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0)
{
SC_HANDLE service;
- std::strcat(path, " --service run");
+ _tcscat(path, _T(" --service run"));
service = CreateService(serviceControlManager,
serviceName, // name of service
serviceLongName, // service name to display
@@ -71,7 +72,7 @@ bool WinServiceInstall()
0); // no password
if (service)
{
- HMODULE advapi32 = GetModuleHandle("ADVAPI32.DLL");
+ HMODULE advapi32 = GetModuleHandle(_T("ADVAPI32.DLL"));
if (!advapi32)
{
CloseServiceHandle(service);
@@ -183,7 +184,16 @@ void WINAPI ServiceControlHandler(DWORD controlCode)
SetServiceStatus(serviceStatusHandle, &serviceStatus);
}
-void WINAPI ServiceMain(DWORD argc, char *argv[])
+template<size_t size>
+void TCharToChar(TCHAR const* src, char(&dst)[size])
+{
+ if constexpr (std::is_same_v<TCHAR, char>)
+ ::strcpy_s(dst, src, size);
+ else
+ ::wcstombs_s(nullptr, dst, src, _TRUNCATE);
+}
+
+void WINAPI ServiceMain(DWORD /*argc*/, TCHAR *argv[])
{
// initialise service status
serviceStatus.dwServiceType = SERVICE_WIN32;
@@ -198,12 +208,12 @@ void WINAPI ServiceMain(DWORD argc, char *argv[])
if ( serviceStatusHandle )
{
- char path[_MAX_PATH + 1];
+ TCHAR path[_MAX_PATH + 1];
unsigned int i, last_slash = 0;
GetModuleFileName(0, path, sizeof(path)/sizeof(path[0]));
- size_t pathLen = std::strlen(path);
+ size_t pathLen = _tcslen(path);
for (i = 0; i < pathLen; i++)
{
if (path[i] == '\\') last_slash = i;
@@ -228,8 +238,12 @@ void WINAPI ServiceMain(DWORD argc, char *argv[])
////////////////////////
m_ServiceStatus = 1;
- argc = 1;
- main(argc, argv);
+
+ char cArg[_MAX_PATH + 1];
+ TCharToChar(argv[0], cArg);
+ char* cArgv[] = { cArg };
+
+ main(1, cArgv);
// service was stopped
serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp
index b254e9c28fe..079f804fe30 100644
--- a/src/server/authserver/Main.cpp
+++ b/src/server/authserver/Main.cpp
@@ -63,9 +63,10 @@ namespace fs = boost::filesystem;
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
#include "ServiceWin32.h"
-char serviceName[] = "authserver";
-char serviceLongName[] = "TrinityCore auth service";
-char serviceDescription[] = "TrinityCore World of Warcraft emulator auth service";
+#include <tchar.h>
+TCHAR serviceName[] = _T("authserver");
+TCHAR serviceLongName[] = _T("TrinityCore auth service");
+TCHAR serviceDescription[] = _T("TrinityCore World of Warcraft emulator auth service");
/*
* -1 - not in service mode
* 0 - stopped
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp
index 63145380745..87b4363be53 100644
--- a/src/server/worldserver/Main.cpp
+++ b/src/server/worldserver/Main.cpp
@@ -76,9 +76,10 @@ namespace fs = boost::filesystem;
#ifdef _WIN32
#include "ServiceWin32.h"
-char serviceName[] = "worldserver";
-char serviceLongName[] = "TrinityCore world service";
-char serviceDescription[] = "TrinityCore World of Warcraft emulator world service";
+#include <tchar.h>
+TCHAR serviceName[] = _T("worldserver");
+TCHAR serviceLongName[] = _T("TrinityCore world service");
+TCHAR serviceDescription[] = _T("TrinityCore World of Warcraft emulator world service");
/*
* -1 - not in service mode
* 0 - stopped
diff --git a/src/tools/mmaps_generator/PathCommon.h b/src/tools/mmaps_generator/PathCommon.h
index 4f29a034d92..ba57228c269 100644
--- a/src/tools/mmaps_generator/PathCommon.h
+++ b/src/tools/mmaps_generator/PathCommon.h
@@ -79,12 +79,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;
@@ -93,7 +93,7 @@ namespace MMAP
if ((findFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
fileList.push_back(std::string(findFileInfo.cFileName));
}
- while (FindNextFile(hFind, &findFileInfo));
+ while (FindNextFileA(hFind, &findFileInfo));
FindClose(hFind);