From 842deeaa698ceb98795c2aa7d68e6750a204a004 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 1 May 2019 05:59:03 +0800 Subject: [PATCH] Cleaning up unicode conversion --- code/nel/include/nel/misc/common.h | 12 +- code/nel/include/nel/misc/string_common.h | 4 +- code/nel/include/nel/misc/system_utils.h | 4 +- code/nel/include/nel/misc/types_nl.h | 9 ++ code/nel/src/misc/common.cpp | 8 +- code/nel/src/misc/debug.cpp | 4 +- code/nel/src/misc/displayer.cpp | 12 +- code/nel/src/misc/dynloadlib.cpp | 2 +- code/nel/src/misc/path.cpp | 24 ++-- code/nel/src/misc/system_info.cpp | 2 +- code/nel/src/misc/system_utils.cpp | 27 ++--- code/nel/src/misc/win_displayer.cpp | 2 +- code/nel/tools/3d/tile_edit/Browse.cpp | 14 ++- .../tools/misc/data_mirror/data_mirror.cpp | 24 ++-- .../multi_cd_setup_fix/multi_cd_setup_fix.cpp | 61 ++++++----- .../common/src/game_share/login_registry.cpp | 7 +- .../leveldesign/georges_dll/georges_edit.cpp | 16 +-- .../georges_dll/memory_combo_box.cpp | 16 +-- .../leveldesign/georges_dll/reg_shell_ext.cpp | 103 ++++++++++-------- .../world_editor/file_dialog_ex.cpp | 18 +-- .../DialogFlags.cpp | 4 +- .../memory_combo_box.cpp | 26 ++--- 22 files changed, 207 insertions(+), 192 deletions(-) diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 48468d6fd..c385af463 100644 --- a/code/nel/include/nel/misc/common.h +++ b/code/nel/include/nel/misc/common.h @@ -310,15 +310,15 @@ inline sint nlstricmp(const char *lhs, const std::string &rhs) { return stricmp( // Macros helper to convert UTF-8 std::string and TCHAR* #ifdef _UNICODE -#define tStrToUtf8(str) (ucstring((ucchar*)(LPCWSTR)str).toUtf8()) -#define utf8ToTStr(str) ((const wchar_t *)ucstring::makeFromUtf8(str).c_str()) +// #define tStrToUtf8(str) (ucstring((ucchar*)(LPCWSTR)str).toUtf8()) +// #define utf8ToTStr(str) ((const wchar_t *)ucstring::makeFromUtf8(str).c_str()) // #define tstring wstring #else // FIXME: This is not accurate, it should be a conversion between local charset and utf8 -#define tStrToUtf8(str) (std::string((LPCSTR)str)) -inline const char *nlutf8ToTStr(const char *str) { return str; } -inline const char *nlutf8ToTStr(const std::string &str) { return str.c_str(); } -#define utf8ToTStr(str) NLMISC::nlutf8ToTStr(str) +// #define tStrToUtf8(str) (std::string((LPCSTR)str)) +// inline const char *nlutf8ToTStr(const char *str) { return str; } +// inline const char *nlutf8ToTStr(const std::string &str) { return str.c_str(); } +// #define utf8ToTStr(str) NLMISC::nlutf8ToTStr(str) // #define tstring string #endif diff --git a/code/nel/include/nel/misc/string_common.h b/code/nel/include/nel/misc/string_common.h index 4b757b989..d21b75d43 100644 --- a/code/nel/include/nel/misc/string_common.h +++ b/code/nel/include/nel/misc/string_common.h @@ -298,7 +298,7 @@ inline const wchar_t* asCStr(const std::wstring &str) { return str.c_str(); } #define nlMbcsToUtf8(str) (NLMISC::asCStr(str)) #endif #define nlWideToUtf8(str) (NLMISC::wideToUtf8(str).c_str()) -#define nlUtf8ToWide(str) (NLMISC::utf8ToWide(str).c_str() +#define nlUtf8ToWide(str) (NLMISC::utf8ToWide(str).c_str()) #define nlWideToMbcs(str) (NLMISC::wideToMbcs(str).c_str()) #define nlMbcsToWide(str) (NLMISC::mbcsToWide(str).c_str()) @@ -308,7 +308,6 @@ inline const wchar_t* asCStr(const std::wstring &str) { return str.c_str(); } #if defined(NL_OS_WINDOWS) && (defined(UNICODE) || defined(_UNICODE)) typedef std::wstring tstring; typedef wchar_t tchar; -#define nltmain wmain inline std::string tStrToUtf8(const tchar *str) { return wideToUtf8((const wchar_t *)str); } inline std::string tStrToUtf8(const tstring &str) { return wideToUtf8((const std::wstring &)str); } inline std::wstring tStrToWide(const tchar *str) { return (const wchar_t *)str; } @@ -330,7 +329,6 @@ inline tstring mbcsToTStr(const std::string &str) { return (const tstring &)mbcs #else typedef std::string tstring; typedef char tchar; -#define nltmain main inline std::string tStrToUtf8(const tchar *str) { return mbcsToUtf8((const char *)str); } inline std::string tStrToUtf8(const tstring &str) { return mbcsToUtf8((const std::string &)str); } inline std::wstring tStrToWide(const tchar *str) { return mbcsToWide((const char *)str); } diff --git a/code/nel/include/nel/misc/system_utils.h b/code/nel/include/nel/misc/system_utils.h index b6f121d94..c51a5ab99 100644 --- a/code/nel/include/nel/misc/system_utils.h +++ b/code/nel/include/nel/misc/system_utils.h @@ -70,10 +70,10 @@ public: static void setRootKey(const std::string &root); /// Read a value from registry. - static std::string getRegKey(const std::string &Entry); + static std::string getRegKey(const std::string &entry); /// Write a value to registry. - static bool setRegKey(const std::string &ValueName, const std::string &Value); + static bool setRegKey(const std::string &valueName, const std::string &value); /// Get desktop current color depth without using UDriver. static uint getCurrentColorDepth(); diff --git a/code/nel/include/nel/misc/types_nl.h b/code/nel/include/nel/misc/types_nl.h index 27d147ffd..353f50490 100644 --- a/code/nel/include/nel/misc/types_nl.h +++ b/code/nel/include/nel/misc/types_nl.h @@ -526,6 +526,15 @@ template<> struct hash */ typedef uint16 ucchar; +#if defined(NL_OS_WINDOWS) && (defined(UNICODE) || defined(_UNICODE)) +#define nltmain wmain +#define nltWinMain wWinMain +#else +#define nltmain main +#if defined(NL_OS_WINDOWS) +#define nltWinMain WinMain +#endif +#endif // To define a 64bits constant; ie: UINT64_CONSTANT(0x123456781234) #ifdef NL_COMP_VC diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 72f29eb82..bb7cf0bcd 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -911,7 +911,7 @@ static bool createProcess(const std::string &programName, const std::string &arg } // or 0 for a window - BOOL res = CreateProcessW(sProgramName, utf8ToWide(args), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL /* current dir */, &si, &pi); + BOOL res = CreateProcessW(sProgramName, (LPWSTR)nlUtf8ToWide(args), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL /* current dir */, &si, &pi); if (sProgramName) { @@ -1453,7 +1453,7 @@ void displayDwordBits( uint32 b, uint nbits, sint beginpos, bool displayBegin, N FILE* nlfopen(const std::string &filename, const std::string &mode) { #ifdef NL_OS_WINDOWS - return _wfopen(utf8ToWide(filename), utf8ToWide(mode)); + return _wfopen(nlUtf8ToWide(filename), nlUtf8ToWide(mode)); #else return fopen(filename.c_str(), mode.c_str()); #endif @@ -1632,7 +1632,7 @@ static bool openDocWithExtension (const std::string &document, const std::string { #ifdef NL_OS_WINDOWS // First try ShellExecute() - HINSTANCE result = ShellExecuteW(NULL, L"open", utf8ToWide(document), NULL, NULL, SW_SHOWDEFAULT); + HINSTANCE result = ShellExecuteW(NULL, L"open", nlUtf8ToWide(document), NULL, NULL, SW_SHOWDEFAULT); // If it failed, get the .htm regkey and lookup the program if ((uintptr_t)result <= HINSTANCE_ERROR) @@ -1640,7 +1640,7 @@ static bool openDocWithExtension (const std::string &document, const std::string wchar_t key[MAX_PATH + MAX_PATH]; // get the type of the extension - if (GetRegKey(HKEY_CLASSES_ROOT, utf8ToWide("." + ext), key) == ERROR_SUCCESS) + if (GetRegKey(HKEY_CLASSES_ROOT, nlUtf8ToWide("." + ext), key) == ERROR_SUCCESS) { lstrcatW(key, L"\\shell\\open\\command"); diff --git a/code/nel/src/misc/debug.cpp b/code/nel/src/misc/debug.cpp index c6d10b700..260834200 100644 --- a/code/nel/src/misc/debug.cpp +++ b/code/nel/src/misc/debug.cpp @@ -1431,7 +1431,7 @@ int getLastError() std::string formatErrorMessage(int errorCode) { #ifdef NL_OS_WINDOWS - LPVOID lpMsgBuf = NULL; + LPWSTR lpMsgBuf = NULL; DWORD len = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | @@ -1439,7 +1439,7 @@ std::string formatErrorMessage(int errorCode) NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPWSTR) &lpMsgBuf, + (LPWSTR)(&lpMsgBuf), 0, NULL ); diff --git a/code/nel/src/misc/displayer.cpp b/code/nel/src/misc/displayer.cpp index 8feaa9358..ba5cc85d0 100644 --- a/code/nel/src/misc/displayer.cpp +++ b/code/nel/src/misc/displayer.cpp @@ -286,14 +286,14 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess // WARNING: READ THIS !!!!!!!!!!!!!!!! /////////////////////////// // If at the release time, it freezes here, it's a microsoft bug: // http://support.microsoft.com/support/kb/articles/q173/2/60.asp - OutputDebugStringW(utf8ToWide(str2)); + OutputDebugStringW(nlUtf8ToWide(str2)); } else { sint count = 0; uint n = (uint)strlen(message); std::string s(&str2.c_str()[0], (str2.size() - n)); - OutputDebugStringW(utf8ToWide(s)); + OutputDebugStringW(nlUtf8ToWide(s)); for(;;) { @@ -301,14 +301,14 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess if((n - count) < maxOutString ) { s = std::string(&message[count], (n - count)); - OutputDebugStringW(utf8ToWide(s)); + OutputDebugStringW(nlUtf8ToWide(s)); OutputDebugStringW(L"\n"); break; } else { s = std::string(&message[count] , count + maxOutString); - OutputDebugStringW(utf8ToWide(s)); + OutputDebugStringW(nlUtf8ToWide(s)); OutputDebugStringW(L"\n\t\t\t"); count += maxOutString; } @@ -323,13 +323,13 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess if (pos+1000 < args.CallstackAndLog.size ()) { splited = args.CallstackAndLog.substr (pos, 1000); - OutputDebugStringW(utf8ToWide(splited)); + OutputDebugStringW(nlUtf8ToWide(splited)); pos += 1000; } else { splited = args.CallstackAndLog.substr (pos); - OutputDebugStringW(utf8ToWide(splited)); + OutputDebugStringW(nlUtf8ToWide(splited)); break; } } diff --git a/code/nel/src/misc/dynloadlib.cpp b/code/nel/src/misc/dynloadlib.cpp index 66f774fa2..a36c02f17 100644 --- a/code/nel/src/misc/dynloadlib.cpp +++ b/code/nel/src/misc/dynloadlib.cpp @@ -32,7 +32,7 @@ NL_LIB_HANDLE nlLoadLibrary(const std::string &libName) { NL_LIB_HANDLE res = 0; #ifdef NL_OS_WINDOWS - res = LoadLibraryW(utf8ToWide(libName)); + res = LoadLibraryW(nlUtf8ToWide(libName)); #elif defined(NL_OS_UNIX) res = dlopen(libName.c_str(), RTLD_NOW); #else diff --git a/code/nel/src/misc/path.cpp b/code/nel/src/misc/path.cpp index c6f9786f4..0c650918f 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -700,7 +700,7 @@ bool CFileContainer::setCurrentPath (const std::string &path) int res; //nldebug("Change current path to '%s' (current path is '%s')", path.c_str(), getCurrentPath().c_str()); #ifdef NL_OS_WINDOWS - res = _wchdir(utf8ToWide(path)); + res = _wchdir(nlUtf8ToWide(path)); #else res = chdir(path.c_str()); #endif @@ -792,7 +792,7 @@ dirent *readdir (DIR *dir) // first visit in this directory : FindFirstFile() if (hFind == NULL) { - hFind = FindFirstFileW (utf8ToWide(CPath::standardizePath(sDir) + "*"), &findData); + hFind = FindFirstFileW(nlUtf8ToWide(CPath::standardizePath(sDir) + "*"), &findData); } // directory already visited : FindNextFile() else @@ -1914,7 +1914,7 @@ string CFile::getPath (const string &filename) bool CFile::isDirectory (const string &filename) { #ifdef NL_OS_WINDOWS - DWORD res = GetFileAttributesW(utf8ToWide(filename)); + DWORD res = GetFileAttributesW(nlUtf8ToWide(filename)); if (res == INVALID_FILE_ATTRIBUTES) { // nlwarning ("PATH: '%s' is not a valid file or directory name", filename.c_str ()); @@ -1937,7 +1937,7 @@ bool CFile::isDirectory (const string &filename) bool CFile::isExists (const string &filename) { #ifdef NL_OS_WINDOWS - return GetFileAttributesW(utf8ToWide(filename)) != INVALID_FILE_ATTRIBUTES; + return GetFileAttributesW(nlUtf8ToWide(filename)) != INVALID_FILE_ATTRIBUTES; #else // NL_OS_WINDOWS struct stat buf; return stat (filename.c_str (), &buf) == 0; @@ -2017,7 +2017,7 @@ uint32 CFile::getFileSize (const std::string &filename) { #if defined (NL_OS_WINDOWS) struct _stat buf; - int result = _wstat (utf8ToWide(filename), &buf); + int result = _wstat(nlUtf8ToWide(filename), &buf); #elif defined (NL_OS_UNIX) struct stat buf; int result = stat (filename.c_str (), &buf); @@ -2068,7 +2068,7 @@ uint32 CFile::getFileModificationDate(const std::string &filename) // Use the WIN32 API to read the file times in UTC // create a file handle (this does not open the file) - HANDLE h = CreateFileW(utf8ToWide(fn), 0, 0, NULL, OPEN_EXISTING, 0, 0); + HANDLE h = CreateFileW(nlUtf8ToWide(fn), 0, 0, NULL, OPEN_EXISTING, 0, 0); if (h == INVALID_HANDLE_VALUE) { nlwarning("Can't get modification date on file '%s' : %s", fn.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str()); @@ -2138,7 +2138,7 @@ bool CFile::setFileModificationDate(const std::string &filename, uint32 modTime) // Use the WIN32 API to set the file times in UTC // create a file handle (this does not open the file) - HANDLE h = CreateFileW(utf8ToWide(fn), GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); + HANDLE h = CreateFileW(nlUtf8ToWide(fn), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); if (h == INVALID_HANDLE_VALUE) { nlwarning("Can't set modification date on file '%s' (error accessing file) : %s", fn.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str()); @@ -2223,7 +2223,7 @@ uint32 CFile::getFileCreationDate(const std::string &filename) #if defined (NL_OS_WINDOWS) struct _stat buf; - int result = _wstat(utf8ToWide(fn), &buf); + int result = _wstat(nlUtf8ToWide(fn), &buf); #elif defined (NL_OS_UNIX) struct stat buf; int result = stat(fn.c_str (), &buf); @@ -2357,7 +2357,7 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c else { #ifdef NL_OS_WINDOWS - if (MoveFileW(utf8ToWide(ssrc), utf8ToWide(sdest)) == 0) + if (MoveFileW(nlUtf8ToWide(ssrc), nlUtf8ToWide(sdest)) == 0) { sint lastError = NLMISC::getLastError(); nlwarning ("PATH: CopyMoveFile error: can't link/move '%s' into '%s', error %u (%s)", @@ -2482,7 +2482,7 @@ bool CFile::moveFile(const std::string &dest, const std::string &src) bool CFile::createDirectory(const std::string &filename) { #ifdef NL_OS_WINDOWS - return _wmkdir(utf8ToWide(filename))==0; + return _wmkdir(nlUtf8ToWide(filename)) == 0; #else // Set full permissions.... return mkdir(filename.c_str(), 0xFFFF)==0; @@ -2751,7 +2751,7 @@ bool CFile::deleteFile(const std::string &filename) { setRWAccess(filename); #ifdef NL_OS_WINDOWS - sint res = _wunlink(utf8ToWide(filename)); + sint res = _wunlink(nlUtf8ToWide(filename)); #else sint res = unlink(filename.c_str()); #endif @@ -2770,7 +2770,7 @@ bool CFile::deleteDirectory(const std::string &filename) { setRWAccess(filename); #ifdef NL_OS_WINDOWS - sint res = _wrmdir(utf8ToWide(filename)); + sint res = _wrmdir(nlUtf8ToWide(filename)); #else sint res = rmdir(filename.c_str()); #endif diff --git a/code/nel/src/misc/system_info.cpp b/code/nel/src/misc/system_info.cpp index 75d9707b3..3e8c296d3 100644 --- a/code/nel/src/misc/system_info.cpp +++ b/code/nel/src/misc/system_info.cpp @@ -1460,7 +1460,7 @@ uint64 CSystemInfo::availableHDSpace (const string &filename) return (uint64)stfs.f_bavail * (uint64)stfs.f_bsize; #else ULARGE_INTEGER freeSpace = {0}; - BOOL bRes = ::GetDiskFreeSpaceExW(utf8ToWide(path), &freeSpace, NULL, NULL); + BOOL bRes = ::GetDiskFreeSpaceExW(nlUtf8ToWide(path), &freeSpace, NULL, NULL); if (!bRes) return 0; return (uint64)freeSpace.QuadPart; diff --git a/code/nel/src/misc/system_utils.cpp b/code/nel/src/misc/system_utils.cpp index 480e1c9a1..3655bc70c 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -323,58 +323,55 @@ void CSystemUtils::setRootKey(const std::string &root) RootKey = root; } -string CSystemUtils::getRegKey(const string &Entry) +string CSystemUtils::getRegKey(const string &entry) { string ret; #ifdef NL_OS_WINDOWS HKEY hkey; - if (RegOpenKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, KEY_READ, &hkey) == ERROR_SUCCESS) + if (RegOpenKeyExW(HKEY_CURRENT_USER, nlUtf8ToWide(RootKey), 0, KEY_READ, &hkey) == ERROR_SUCCESS) { DWORD dwType = 0L; DWORD dwSize = KeyMaxLength; - wchar_t Buffer[KeyMaxLength]; + wchar_t buffer[KeyMaxLength]; - if (RegQueryValueExW(hkey, utf8ToWide(Entry), NULL, &dwType, (LPBYTE)Buffer, &dwSize) != ERROR_SUCCESS) + if (RegQueryValueExW(hkey, nlUtf8ToWide(entry), NULL, &dwType, (LPBYTE)buffer, &dwSize) != ERROR_SUCCESS) { - nlwarning("Can't get the reg key '%s'", Entry.c_str()); + nlwarning("Can't get the reg key '%s'", entry.c_str()); } else { - ret = wideToUtf8(Buffer); + ret = wideToUtf8(buffer); } RegCloseKey(hkey); } else { - nlwarning("Can't get the reg key '%s'", Entry.c_str()); + nlwarning("Can't get the reg key '%s'", entry.c_str()); } #endif return ret; } -bool CSystemUtils::setRegKey(const string &ValueName, const string &Value) +bool CSystemUtils::setRegKey(const string &valueName, const string &value) { bool res = false; #ifdef NL_OS_WINDOWS HKEY hkey; DWORD dwDisp; - if (RegCreateKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS) + if (RegCreateKeyExW(HKEY_CURRENT_USER, nlUtf8ToWide(RootKey), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS) { - ucstring utf16Value = ucstring::makeFromUtf8(Value); - // we must use the real Unicode string size in bytes - DWORD size = (utf16Value.length() + 1) * 2; - - if (RegSetValueExW(hkey, utf8ToWide(ValueName), 0L, REG_SZ, (const BYTE *)utf16Value.c_str(), size) == ERROR_SUCCESS) + std::wstring wvalue = nlUtf8ToWide(value); + if (RegSetValueExW(hkey, nlUtf8ToWide(valueName), 0, REG_SZ, (const BYTE *)wvalue.c_str(), (wvalue.size() + 1) * sizeof(WCHAR)) == ERROR_SUCCESS) res = true; RegCloseKey(hkey); } else { - nlwarning("Can't set the reg key '%s' '%s'", ValueName.c_str(), Value.c_str()); + nlwarning("Can't set the reg key '%s' '%s'", valueName.c_str(), value.c_str()); } #endif diff --git a/code/nel/src/misc/win_displayer.cpp b/code/nel/src/misc/win_displayer.cpp index d350f25f3..03e1265b9 100644 --- a/code/nel/src/misc/win_displayer.cpp +++ b/code/nel/src/misc/win_displayer.cpp @@ -298,7 +298,7 @@ void CWinDisplayer::updateLabels () } } - SendMessageW ((HWND)access.value()[i].Hwnd, WM_SETTEXT, 0, (LPARAM) utf8ToWide(n)); + SendMessageW((HWND)access.value()[i].Hwnd, WM_SETTEXT, 0, (LPARAM)nlUtf8ToWide(n)); access.value()[i].NeedUpdate = false; } } diff --git a/code/nel/tools/3d/tile_edit/Browse.cpp b/code/nel/tools/3d/tile_edit/Browse.cpp index 89e45c62d..a0064456d 100644 --- a/code/nel/tools/3d/tile_edit/Browse.cpp +++ b/code/nel/tools/3d/tile_edit/Browse.cpp @@ -612,7 +612,7 @@ void Browse::Init() unsigned long value; unsigned long type; int cx=-1,cy=-1,x=-1,y=-1; - char sWindowpl[256]; + TCHAR sWindowpl[256]; if (RegOpenKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,®key)==ERROR_SUCCESS) { @@ -621,7 +621,7 @@ void Browse::Init() if (RegQueryValueEx(regkey,REGKEY_WNDPL,0,&type,(unsigned char *)&sWindowpl,&value)==ERROR_SUCCESS) { WINDOWPLACEMENT wndpl; - sscanf(sWindowpl,"%d %d %d %d %d %d %d %d %d %d", + _stscanf(sWindowpl,_T("%d %d %d %d %d %d %d %d %d %d"), &wndpl.flags, &wndpl.ptMaxPosition.x,&wndpl.ptMaxPosition.y, &wndpl.ptMinPosition.x,&wndpl.ptMinPosition.y, @@ -632,10 +632,10 @@ void Browse::Init() } value=256; type=REG_SZ; - if (RegQueryValueEx(regkey,REGKEY_LASTPATH,0,&type,(unsigned char *)&sWindowpl,&value)!=ERROR_SUCCESS) + if (RegQueryValueEx(regkey, REGKEY_LASTPATH, 0, &type, (unsigned char *)&sWindowpl, &value) != ERROR_SUCCESS) m_ctrl.LastPath.clear(); else - m_ctrl.LastPath=(const char*)sWindowpl; + m_ctrl.LastPath = tStrToUtf8(sWindowpl); value=4; type=REG_DWORD; if (RegQueryValueEx(regkey,REGKEY_BUTTONZOOM,0,&type,(unsigned char *)&m_ctrl.Zoom,&value)!=ERROR_SUCCESS) @@ -808,8 +808,10 @@ void Browse::OnDestroy() if (RegCreateKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,®key)==ERROR_SUCCESS) { //int sel = ((CComboBox*)GetDlgItem(IDC_LISTTYPE))->GetCurSel(); - RegSetValueEx(regkey,REGKEY_WNDPL,0,REG_SZ,(const unsigned char*)sWindowpl,(DWORD)strlen(sWindowpl)); - RegSetValueEx(regkey,REGKEY_LASTPATH,0,REG_SZ,(const unsigned char*)m_ctrl.LastPath.c_str(),(DWORD)strlen(m_ctrl.LastPath.c_str())); + tstring tWindowpl = utf8ToTStr(sWindowpl); + tstring tLastPath = utf8ToTStr(m_ctrl.LastPath); + RegSetValueEx(regkey, REGKEY_WNDPL, 0, REG_SZ, (const BYTE *)tWindowpl.c_str(), (tWindowpl.size() + 1) * sizeof(TCHAR)); + RegSetValueEx(regkey, REGKEY_LASTPATH, 0, REG_SZ, (const BYTE *)tLastPath.c_str(), (tLastPath.size() + 1) * sizeof(TCHAR)); RegSetValueEx(regkey,REGKEY_BUTTONZOOM,0,REG_DWORD,(const unsigned char*)&m_ctrl.Zoom,4); RegSetValueEx(regkey,REGKEY_BUTTONVARIETY,0,REG_DWORD,(const unsigned char*)&m_128x128,4); RegSetValueEx(regkey,REGKEY_BUTTONTEXTURE,0,REG_DWORD,(const unsigned char*)&m_ctrl.Texture,4); diff --git a/code/nel/tools/misc/data_mirror/data_mirror.cpp b/code/nel/tools/misc/data_mirror/data_mirror.cpp index 99a87f547..344ecc1ad 100644 --- a/code/nel/tools/misc/data_mirror/data_mirror.cpp +++ b/code/nel/tools/misc/data_mirror/data_mirror.cpp @@ -73,7 +73,7 @@ BOOL CData_mirrorApp::InitInstance() { // Get the module CConfigFile cf; - string exePath = GetCommandLine (); + string exePath = nlTStrToUtf8(GetCommandLineW()); if (exePath.size()>0) { if (exePath[0] == '\"') @@ -124,7 +124,7 @@ BOOL CData_mirrorApp::InitInstance() if ((sBinaryCompare == "true") || (sBinaryCompare=="1")) BinaryCompare = true; - CurrentDir = m_lpCmdLine; + CurrentDir = nlTStrToUtf8(m_lpCmdLine); // Remove if (CurrentDir.size ()>=2) { @@ -151,7 +151,7 @@ BOOL CData_mirrorApp::InitInstance() } else { - MessageBox (NULL, (CurrentDir+" is not a directory nor a file.").c_str (), "NeL Data Mirror", MB_OK|MB_ICONEXCLAMATION); + MessageBox (NULL, nlUtf8ToTStr(CurrentDir+" is not a directory nor a file."), _T("NeL Data Mirror"), MB_OK|MB_ICONEXCLAMATION); return FALSE; } @@ -168,8 +168,8 @@ BOOL CData_mirrorApp::InitInstance() } else { - MessageBox (NULL, (CurrentDir+" is not a sub directory of "+MainDirectory+" or "+MirrorDirectory).c_str (), - "NeL Data Mirror", MB_OK|MB_ICONEXCLAMATION); + MessageBox(NULL, nlUtf8ToTStr(CurrentDir + " is not a sub directory of " + MainDirectory + " or " + MirrorDirectory), + _T("NeL Data Mirror"), MB_OK|MB_ICONEXCLAMATION); return FALSE; } } @@ -200,7 +200,7 @@ BOOL CData_mirrorApp::InitInstance() } catch (const Exception &e) { - MessageBox (NULL, e.what (), "NeL Data Mirror", MB_OK|MB_ICONEXCLAMATION); + MessageBox(NULL, nlUtf8ToTStr(e.what()), _T("NeL Data Mirror"), MB_OK | MB_ICONEXCLAMATION); } CData_mirrorDlg dlg; @@ -227,19 +227,21 @@ bool RegisterDirectoryAppCommand (const char *appName, const char *command, cons { // Create the app key HKEY hKey; - if (RegCreateKey (HKEY_CLASSES_ROOT, "Directory", &hKey) == ERROR_SUCCESS) + if (RegCreateKey (HKEY_CLASSES_ROOT, _T("Directory"), &hKey) == ERROR_SUCCESS) { // Create the icon char tmp[512]; smprintf (tmp, 512, "shell\\%s", appName); - if (RegCreateKey (hKey, tmp, &hKey) == ERROR_SUCCESS) + if (RegCreateKey(hKey, nlUtf8ToTStr(tmp), &hKey) == ERROR_SUCCESS) { // Set the description - RegSetValue (hKey, "", REG_SZ, command, (DWORD)strlen (command)); - if (RegCreateKey (hKey, "command", &hKey) == ERROR_SUCCESS) + tstring tcommand = utf8ToTStr(command); + RegSetValue(hKey, _T(""), REG_SZ, tcommand.c_str(), (tcommand.size() + 1) * sizeof(TCHAR)); + if (RegCreateKey (hKey, _T("command"), &hKey) == ERROR_SUCCESS) { // Set the description - RegSetValue (hKey, "", REG_SZ, app, (DWORD)strlen (app)); + tstring tapp = utf8ToTStr(app); + RegSetValue(hKey, _T(""), REG_SZ, tapp.c_str(), (tapp.size() + 1) * sizeof(TCHAR)); return true; } } diff --git a/code/nel/tools/misc/multi_cd_setup_fix/multi_cd_setup_fix.cpp b/code/nel/tools/misc/multi_cd_setup_fix/multi_cd_setup_fix.cpp index f7ef1a9fc..9e20c09a0 100644 --- a/code/nel/tools/misc/multi_cd_setup_fix/multi_cd_setup_fix.cpp +++ b/code/nel/tools/misc/multi_cd_setup_fix/multi_cd_setup_fix.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see . #include +#include #include #include "resource.h" @@ -40,7 +41,7 @@ void pump () } } -int APIENTRY WinMain(HINSTANCE hInstance, +int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) @@ -57,68 +58,68 @@ int APIENTRY WinMain(HINSTANCE hInstance, pump (); // Get the temp directory - char tempPath[1024]; + TCHAR tempPath[1024]; if (GetTempPath(1024, tempPath)) { - char pathToDelete[1024]; - strcpy (pathToDelete, tempPath); - strcat (pathToDelete, "Ryzom"); + TCHAR pathToDelete[1024]; + _tcscpy (pathToDelete, tempPath); + _tcscat (pathToDelete, _T("Ryzom")); CreateDirectory(tempPath, NULL); - strcat (tempPath, "Ryzom\\"); + _tcscat (tempPath, _T("Ryzom\\")); CreateDirectory(tempPath, NULL); // Copy the files pump (); // Setup.dat - char setupFile[1024]; - strcpy (setupFile, tempPath); - strcat (setupFile, "setup.exe"); + TCHAR setupFile[1024]; + _tcscpy (setupFile, tempPath); + _tcscat(setupFile, _T("setup.exe")); SetFileAttributes(setupFile, GetFileAttributes(setupFile)&~FILE_ATTRIBUTE_READONLY); BOOL deleted = DeleteFile (setupFile); - if (!CopyFile ("setup.dat", setupFile, FALSE) && deleted) - MessageBox (NULL, "Not enough disk space", "Setup", MB_OK|MB_ICONERROR); + if (!CopyFile (_T("setup.dat"), setupFile, FALSE) && deleted) + MessageBox (NULL, _T("Not enough disk space"), _T("Setup"), MB_OK|MB_ICONERROR); SetFileAttributes(setupFile, GetFileAttributes(setupFile)&~FILE_ATTRIBUTE_READONLY); pump (); // Ryzom.msi - char msiFile[1024]; - strcpy (msiFile, tempPath); - strcat (msiFile, "Ryzom.msi"); + TCHAR msiFile[1024]; + _tcscpy(msiFile, tempPath); + _tcscat(msiFile, _T("Ryzom.msi")); SetFileAttributes(msiFile, GetFileAttributes(msiFile)&~FILE_ATTRIBUTE_READONLY); deleted = DeleteFile (msiFile); - if (!CopyFile ("Ryzom.msi", msiFile, FALSE) && deleted) - MessageBox (NULL, "Not enough disk space", "Setup", MB_OK|MB_ICONERROR); + if (!CopyFile (_T("Ryzom.msi"), msiFile, FALSE) && deleted) + MessageBox (NULL, _T("Not enough disk space"), _T("Setup"), MB_OK|MB_ICONERROR); SetFileAttributes(msiFile, GetFileAttributes(msiFile)&~FILE_ATTRIBUTE_READONLY); pump (); // Generate the remove bat file - char batFile[1024]; - strcpy (batFile, tempPath); - strcat (batFile, "remove.bat"); - FILE *file = fopen (batFile, "w"); - fprintf (file, "@echo off\nrmdir /S /Q \"%s\" > NUL\ndeltree /Y \"%s\" > NUL\n", pathToDelete, pathToDelete); + TCHAR batFile[1024]; + _tcscpy (batFile, tempPath); + _tcscat(batFile, _T("remove.bat")); + FILE *file = _tfopen (batFile, _T("w")); + _ftprintf (file, _T("@echo off\nrmdir /S /Q \"%s\" > NUL\ndeltree /Y \"%s\" > NUL\n"), pathToDelete, pathToDelete); fclose (file); // Register the remove bat file HKEY hKey; - RegCreateKey (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Runonce", &hKey); - char batFileReg[1024]; - sprintf (batFileReg, "\"%s\"", batFile); - RegSetValueEx(hKey, "RyzomSetupClean", 0, REG_SZ, (const unsigned char*)batFileReg, (DWORD)strlen (batFileReg)+1); + RegCreateKey (HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Runonce"), &hKey); + TCHAR batFileReg[1024]; + _stprintf (batFileReg, _T("\"%s\""), batFile); + RegSetValueEx(hKey, _T("RyzomSetupClean"), 0, REG_SZ, (const unsigned char *)batFileReg, (DWORD)(_tcslen(batFileReg) + 1) * sizeof(TCHAR)); pump (); // Get the current path - char currentPath[1024]; + TCHAR currentPath[1024]; GetCurrentDirectory (1024, currentPath); - if (currentPath[strlen(currentPath)-1] == '\\') - currentPath[strlen(currentPath)-1] = 0; + if (currentPath[_tcslen(currentPath) - 1] == '\\') + currentPath[_tcslen(currentPath) - 1] = 0; pump (); // Build the command line : /z"f:\" - char option[1024]; - sprintf (option, "\"%s\" /z\"%s\"", setupFile, currentPath); + TCHAR option[1024]; + _stprintf(option, _T("\"%s\" /z\"%s\""), setupFile, currentPath); pump (); // Execute the setup diff --git a/code/ryzom/common/src/game_share/login_registry.cpp b/code/ryzom/common/src/game_share/login_registry.cpp index 7e0c68234..e30949400 100644 --- a/code/ryzom/common/src/game_share/login_registry.cpp +++ b/code/ryzom/common/src/game_share/login_registry.cpp @@ -39,7 +39,7 @@ std::string CLoginRegistry::getProductInstallId() if (RegQueryValueExW(hKey, InstallIdKeyHandle, NULL, &dwType, (BYTE *) buffer, &dwSize) == ERROR_SUCCESS && dwType == REG_SZ) { RegCloseKey(hKey); - return wideToUtf8(buffer); + return NLMISC::wideToUtf8(buffer); } RegCloseKey(hKey); } @@ -58,10 +58,9 @@ std::string CLoginRegistry::getProductInstallId() // copy wide string to a buffer const uint keyMaxLength = 16; - wchar_t buffer[keyMaxLength]; - wcscpy(buffer, utf8ToWide(id)); + std::wstring wid = NLMISC::utf8ToWide(id); - if (RegSetValueExW(hKey, InstallIdKeyHandle, 0L, REG_SZ, (const BYTE *) buffer, (DWORD)(wcslen(buffer)*2+2)) == ERROR_SUCCESS) + if (RegSetValueExW(hKey, InstallIdKeyHandle, 0L, REG_SZ, (const BYTE *)wid.c_str(), (DWORD)((wid.size() + 1) * sizeof(WCHAR))) == ERROR_SUCCESS) { return id; } diff --git a/code/ryzom/tools/leveldesign/georges_dll/georges_edit.cpp b/code/ryzom/tools/leveldesign/georges_dll/georges_edit.cpp index 9b62e3a1a..480fdfbe0 100644 --- a/code/ryzom/tools/leveldesign/georges_dll/georges_edit.cpp +++ b/code/ryzom/tools/leveldesign/georges_dll/georges_edit.cpp @@ -477,9 +477,9 @@ void CGeorgesEditApp::OnAppAbout() void CGeorgesEditApp::outputError (const char* message) { if (m_pMainWnd) - m_pMainWnd->MessageBox (utf8ToTStr(message), _T("Georges Edit"), MB_OK|MB_ICONEXCLAMATION); + m_pMainWnd->MessageBox(nlUtf8ToTStr(message), _T("Georges Edit"), MB_OK | MB_ICONEXCLAMATION); else - MessageBox (NULL, utf8ToTStr(message), _T("Georges Edit"), MB_OK|MB_ICONEXCLAMATION); + MessageBox(NULL, nlUtf8ToTStr(message), _T("Georges Edit"), MB_OK | MB_ICONEXCLAMATION); } void CGeorgesEditApp::getConfigFilePath (std::string &output) @@ -711,9 +711,9 @@ bool CGeorgesEditApp::getColor (NLMISC::CRGBA &color) bool CGeorgesEditApp::yesNo (const char* message) { if (m_pMainWnd) - return m_pMainWnd->MessageBox (utf8ToTStr(message), _T("Georges Edit"), MB_YESNO|MB_ICONQUESTION) != IDNO; + return m_pMainWnd->MessageBox(nlUtf8ToTStr(message), _T("Georges Edit"), MB_YESNO | MB_ICONQUESTION) != IDNO; else - return MessageBox (NULL, utf8ToTStr(message), _T("Georges Edit"), MB_YESNO|MB_ICONQUESTION) != IDNO; + return MessageBox(NULL, nlUtf8ToTStr(message), _T("Georges Edit"), MB_YESNO | MB_ICONQUESTION) != IDNO; } void CGeorgesEditApp::loadPlugins () @@ -722,7 +722,7 @@ void CGeorgesEditApp::loadPlugins () for (i=0; iSetPathName (utf8ToTStr(pathName), FALSE ); + doc->SetPathName (nlUtf8ToTStr(pathName), FALSE ); // Create the file - doc->OnSaveDocument(utf8ToTStr(pathName) ); + doc->OnSaveDocument(nlUtf8ToTStr(pathName)); } // Init the frame @@ -925,7 +925,7 @@ void CGeorgesEditApp::gotoURL (LPCTSTR url) void CGeorgesEditApp::WinHelp(DWORD dwData, UINT nCmd) { - gotoURL(utf8ToTStr(NLMISC::CFile::getPath(ExePath) + "georges_edit.html")); + gotoURL(nlUtf8ToTStr(NLMISC::CFile::getPath(ExePath) + "georges_edit.html")); } void CGeorgesEditApp::OnViewRefresh() diff --git a/code/ryzom/tools/leveldesign/georges_dll/memory_combo_box.cpp b/code/ryzom/tools/leveldesign/georges_dll/memory_combo_box.cpp index 86204d8f7..989afa15b 100644 --- a/code/ryzom/tools/leveldesign/georges_dll/memory_combo_box.cpp +++ b/code/ryzom/tools/leveldesign/georges_dll/memory_combo_box.cpp @@ -102,7 +102,7 @@ bool CMemoryComboBox::getMemory (int slot, std::string &ret) smprintf (strSrc, 512, "%d", slot); TCHAR str[512]; LONG size = 512 * sizeof(TCHAR); - if (RegQueryValue(hKey, utf8ToTStr(strSrc), str, &size) == ERROR_SUCCESS) + if (RegQueryValue(hKey, nlUtf8ToTStr(strSrc), str, &size) == ERROR_SUCCESS) { ret = tStrToUtf8(str); @@ -134,12 +134,12 @@ void CMemoryComboBox::scrollDown (int start, int end) smprintf (strSrc, 512, "%d", i-1); TCHAR str[512]; LONG size = 512 * sizeof(TCHAR); - if (RegQueryValue (hKey, utf8ToTStr(strSrc), str, &size) == ERROR_SUCCESS) + if (RegQueryValue (hKey, nlUtf8ToTStr(strSrc), str, &size) == ERROR_SUCCESS) { // Set the value char strDst[512]; smprintf (strDst, 512, "%d", i); - RegSetValue (hKey, utf8ToTStr(strSrc), REG_SZ, str, size); + RegSetValue (hKey, nlUtf8ToTStr(strDst), REG_SZ, str, size); } } @@ -158,7 +158,7 @@ void CMemoryComboBox::pushString (const std::string &str) { // Set the value tstring tstr = utf8ToTStr(str); - RegSetValue (hKey, _T("0"), REG_SZ, tstr.c_str (), tstr.size ()); + RegSetValue (hKey, _T("0"), REG_SZ, tstr.c_str(), (tstr.size() + 1) * sizeof(TCHAR)); // Close RegCloseKey (hKey); @@ -444,7 +444,7 @@ void CMemoryComboBox::refreshStrings () int count = Commands.size(); for (i=0; i oldPath; @@ -86,7 +86,7 @@ INT_PTR CFileDialogEx::DoModal () for (i=0; istart; i--) @@ -134,12 +134,12 @@ void CMemoryComboBox::scrollDown (int start, int end) smprintf (strSrc, 512, "%d", i-1); TCHAR str[512]; long size = 512 * sizeof(TCHAR); - if (RegQueryValue (hKey, utf8ToTStr(strSrc), str, &size) == ERROR_SUCCESS) + if (RegQueryValue(hKey, nlUtf8ToTStr(strSrc), str, &size) == ERROR_SUCCESS) { // Set the value char strDst[512]; smprintf (strDst, 512, "%d", i); - RegSetValue (hKey, utf8ToTStr(strDst), REG_SZ, str, size); + RegSetValue(hKey, nlUtf8ToTStr(strDst), REG_SZ, str, size); } } @@ -154,10 +154,10 @@ void CMemoryComboBox::writeStringInRegistry (const std::string &str) { // Open the key HKEY hKey; - if (RegCreateKey (HKEY_CURRENT_USER, utf8ToTStr(RegisterAdress), &hKey) == ERROR_SUCCESS) + if (RegCreateKey(HKEY_CURRENT_USER, nlUtf8ToTStr(RegisterAdress), &hKey) == ERROR_SUCCESS) { // Set the value - RegSetValue (hKey, _T("0"), REG_SZ, utf8ToTStr(str), str.size ()); + RegSetValue(hKey, _T("0"), REG_SZ, nlUtf8ToTStr(str), str.size()); // Close RegCloseKey (hKey); @@ -428,7 +428,7 @@ void CMemoryComboBox::pushString (const std::string &str) if (i == (int)(itemCount+Commands.size()+ StaticStrings.size())) { // Insert the sting - _ComboBox.InsertString (Commands.size()+ StaticStrings.size(), utf8ToTStr(str)); + _ComboBox.InsertString(Commands.size() + StaticStrings.size(), nlUtf8ToTStr(str)); } } } @@ -449,7 +449,7 @@ void CMemoryComboBox::refreshStrings () int count = Commands.size(); for (i=0; i