Cleaning up unicode conversion

This commit is contained in:
kaetemi 2019-05-01 05:59:03 +08:00
parent 8efe1d91c4
commit 842deeaa69
22 changed files with 207 additions and 192 deletions

View file

@ -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* // Macros helper to convert UTF-8 std::string and TCHAR*
#ifdef _UNICODE #ifdef _UNICODE
#define tStrToUtf8(str) (ucstring((ucchar*)(LPCWSTR)str).toUtf8()) // #define tStrToUtf8(str) (ucstring((ucchar*)(LPCWSTR)str).toUtf8())
#define utf8ToTStr(str) ((const wchar_t *)ucstring::makeFromUtf8(str).c_str()) // #define utf8ToTStr(str) ((const wchar_t *)ucstring::makeFromUtf8(str).c_str())
// #define tstring wstring // #define tstring wstring
#else #else
// FIXME: This is not accurate, it should be a conversion between local charset and utf8 // FIXME: This is not accurate, it should be a conversion between local charset and utf8
#define tStrToUtf8(str) (std::string((LPCSTR)str)) // #define tStrToUtf8(str) (std::string((LPCSTR)str))
inline const char *nlutf8ToTStr(const char *str) { return str; } // inline const char *nlutf8ToTStr(const char *str) { return str; }
inline const char *nlutf8ToTStr(const std::string &str) { return str.c_str(); } // inline const char *nlutf8ToTStr(const std::string &str) { return str.c_str(); }
#define utf8ToTStr(str) NLMISC::nlutf8ToTStr(str) // #define utf8ToTStr(str) NLMISC::nlutf8ToTStr(str)
// #define tstring string // #define tstring string
#endif #endif

View file

@ -298,7 +298,7 @@ inline const wchar_t* asCStr(const std::wstring &str) { return str.c_str(); }
#define nlMbcsToUtf8(str) (NLMISC::asCStr(str)) #define nlMbcsToUtf8(str) (NLMISC::asCStr(str))
#endif #endif
#define nlWideToUtf8(str) (NLMISC::wideToUtf8(str).c_str()) #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 nlWideToMbcs(str) (NLMISC::wideToMbcs(str).c_str())
#define nlMbcsToWide(str) (NLMISC::mbcsToWide(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)) #if defined(NL_OS_WINDOWS) && (defined(UNICODE) || defined(_UNICODE))
typedef std::wstring tstring; typedef std::wstring tstring;
typedef wchar_t tchar; 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 tchar *str) { return wideToUtf8((const wchar_t *)str); }
inline std::string tStrToUtf8(const tstring &str) { return wideToUtf8((const std::wstring &)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; } 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 #else
typedef std::string tstring; typedef std::string tstring;
typedef char tchar; typedef char tchar;
#define nltmain main
inline std::string tStrToUtf8(const tchar *str) { return mbcsToUtf8((const char *)str); } 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::string tStrToUtf8(const tstring &str) { return mbcsToUtf8((const std::string &)str); }
inline std::wstring tStrToWide(const tchar *str) { return mbcsToWide((const char *)str); } inline std::wstring tStrToWide(const tchar *str) { return mbcsToWide((const char *)str); }

View file

@ -70,10 +70,10 @@ public:
static void setRootKey(const std::string &root); static void setRootKey(const std::string &root);
/// Read a value from registry. /// 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. /// 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. /// Get desktop current color depth without using UDriver.
static uint getCurrentColorDepth(); static uint getCurrentColorDepth();

View file

@ -526,6 +526,15 @@ template<> struct hash<uint64>
*/ */
typedef uint16 ucchar; 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) // To define a 64bits constant; ie: UINT64_CONSTANT(0x123456781234)
#ifdef NL_COMP_VC #ifdef NL_COMP_VC

View file

@ -911,7 +911,7 @@ static bool createProcess(const std::string &programName, const std::string &arg
} }
// or 0 for a window // 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) 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) FILE* nlfopen(const std::string &filename, const std::string &mode)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
return _wfopen(utf8ToWide(filename), utf8ToWide(mode)); return _wfopen(nlUtf8ToWide(filename), nlUtf8ToWide(mode));
#else #else
return fopen(filename.c_str(), mode.c_str()); return fopen(filename.c_str(), mode.c_str());
#endif #endif
@ -1632,7 +1632,7 @@ static bool openDocWithExtension (const std::string &document, const std::string
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
// First try ShellExecute() // 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 it failed, get the .htm regkey and lookup the program
if ((uintptr_t)result <= HINSTANCE_ERROR) 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]; wchar_t key[MAX_PATH + MAX_PATH];
// get the type of the extension // 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"); lstrcatW(key, L"\\shell\\open\\command");

View file

@ -1431,7 +1431,7 @@ int getLastError()
std::string formatErrorMessage(int errorCode) std::string formatErrorMessage(int errorCode)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
LPVOID lpMsgBuf = NULL; LPWSTR lpMsgBuf = NULL;
DWORD len = FormatMessageW( DWORD len = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_SYSTEM |
@ -1439,7 +1439,7 @@ std::string formatErrorMessage(int errorCode)
NULL, NULL,
errorCode, errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPWSTR) &lpMsgBuf, (LPWSTR)(&lpMsgBuf),
0, 0,
NULL NULL
); );

View file

@ -286,14 +286,14 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
// WARNING: READ THIS !!!!!!!!!!!!!!!! /////////////////////////// // WARNING: READ THIS !!!!!!!!!!!!!!!! ///////////////////////////
// If at the release time, it freezes here, it's a microsoft bug: // If at the release time, it freezes here, it's a microsoft bug:
// http://support.microsoft.com/support/kb/articles/q173/2/60.asp // http://support.microsoft.com/support/kb/articles/q173/2/60.asp
OutputDebugStringW(utf8ToWide(str2)); OutputDebugStringW(nlUtf8ToWide(str2));
} }
else else
{ {
sint count = 0; sint count = 0;
uint n = (uint)strlen(message); uint n = (uint)strlen(message);
std::string s(&str2.c_str()[0], (str2.size() - n)); std::string s(&str2.c_str()[0], (str2.size() - n));
OutputDebugStringW(utf8ToWide(s)); OutputDebugStringW(nlUtf8ToWide(s));
for(;;) for(;;)
{ {
@ -301,14 +301,14 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
if((n - count) < maxOutString ) if((n - count) < maxOutString )
{ {
s = std::string(&message[count], (n - count)); s = std::string(&message[count], (n - count));
OutputDebugStringW(utf8ToWide(s)); OutputDebugStringW(nlUtf8ToWide(s));
OutputDebugStringW(L"\n"); OutputDebugStringW(L"\n");
break; break;
} }
else else
{ {
s = std::string(&message[count] , count + maxOutString); s = std::string(&message[count] , count + maxOutString);
OutputDebugStringW(utf8ToWide(s)); OutputDebugStringW(nlUtf8ToWide(s));
OutputDebugStringW(L"\n\t\t\t"); OutputDebugStringW(L"\n\t\t\t");
count += maxOutString; count += maxOutString;
} }
@ -323,13 +323,13 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
if (pos+1000 < args.CallstackAndLog.size ()) if (pos+1000 < args.CallstackAndLog.size ())
{ {
splited = args.CallstackAndLog.substr (pos, 1000); splited = args.CallstackAndLog.substr (pos, 1000);
OutputDebugStringW(utf8ToWide(splited)); OutputDebugStringW(nlUtf8ToWide(splited));
pos += 1000; pos += 1000;
} }
else else
{ {
splited = args.CallstackAndLog.substr (pos); splited = args.CallstackAndLog.substr (pos);
OutputDebugStringW(utf8ToWide(splited)); OutputDebugStringW(nlUtf8ToWide(splited));
break; break;
} }
} }

View file

@ -32,7 +32,7 @@ NL_LIB_HANDLE nlLoadLibrary(const std::string &libName)
{ {
NL_LIB_HANDLE res = 0; NL_LIB_HANDLE res = 0;
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
res = LoadLibraryW(utf8ToWide(libName)); res = LoadLibraryW(nlUtf8ToWide(libName));
#elif defined(NL_OS_UNIX) #elif defined(NL_OS_UNIX)
res = dlopen(libName.c_str(), RTLD_NOW); res = dlopen(libName.c_str(), RTLD_NOW);
#else #else

View file

@ -700,7 +700,7 @@ bool CFileContainer::setCurrentPath (const std::string &path)
int res; int res;
//nldebug("Change current path to '%s' (current path is '%s')", path.c_str(), getCurrentPath().c_str()); //nldebug("Change current path to '%s' (current path is '%s')", path.c_str(), getCurrentPath().c_str());
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
res = _wchdir(utf8ToWide(path)); res = _wchdir(nlUtf8ToWide(path));
#else #else
res = chdir(path.c_str()); res = chdir(path.c_str());
#endif #endif
@ -792,7 +792,7 @@ dirent *readdir (DIR *dir)
// first visit in this directory : FindFirstFile() // first visit in this directory : FindFirstFile()
if (hFind == NULL) if (hFind == NULL)
{ {
hFind = FindFirstFileW (utf8ToWide(CPath::standardizePath(sDir) + "*"), &findData); hFind = FindFirstFileW(nlUtf8ToWide(CPath::standardizePath(sDir) + "*"), &findData);
} }
// directory already visited : FindNextFile() // directory already visited : FindNextFile()
else else
@ -1914,7 +1914,7 @@ string CFile::getPath (const string &filename)
bool CFile::isDirectory (const string &filename) bool CFile::isDirectory (const string &filename)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
DWORD res = GetFileAttributesW(utf8ToWide(filename)); DWORD res = GetFileAttributesW(nlUtf8ToWide(filename));
if (res == INVALID_FILE_ATTRIBUTES) if (res == INVALID_FILE_ATTRIBUTES)
{ {
// nlwarning ("PATH: '%s' is not a valid file or directory name", filename.c_str ()); // 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) bool CFile::isExists (const string &filename)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
return GetFileAttributesW(utf8ToWide(filename)) != INVALID_FILE_ATTRIBUTES; return GetFileAttributesW(nlUtf8ToWide(filename)) != INVALID_FILE_ATTRIBUTES;
#else // NL_OS_WINDOWS #else // NL_OS_WINDOWS
struct stat buf; struct stat buf;
return stat (filename.c_str (), &buf) == 0; return stat (filename.c_str (), &buf) == 0;
@ -2017,7 +2017,7 @@ uint32 CFile::getFileSize (const std::string &filename)
{ {
#if defined (NL_OS_WINDOWS) #if defined (NL_OS_WINDOWS)
struct _stat buf; struct _stat buf;
int result = _wstat (utf8ToWide(filename), &buf); int result = _wstat(nlUtf8ToWide(filename), &buf);
#elif defined (NL_OS_UNIX) #elif defined (NL_OS_UNIX)
struct stat buf; struct stat buf;
int result = stat (filename.c_str (), &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 // Use the WIN32 API to read the file times in UTC
// create a file handle (this does not open the file) // 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) if (h == INVALID_HANDLE_VALUE)
{ {
nlwarning("Can't get modification date on file '%s' : %s", fn.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str()); 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 // Use the WIN32 API to set the file times in UTC
// create a file handle (this does not open the file) // 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) 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()); 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) #if defined (NL_OS_WINDOWS)
struct _stat buf; struct _stat buf;
int result = _wstat(utf8ToWide(fn), &buf); int result = _wstat(nlUtf8ToWide(fn), &buf);
#elif defined (NL_OS_UNIX) #elif defined (NL_OS_UNIX)
struct stat buf; struct stat buf;
int result = stat(fn.c_str (), &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 else
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
if (MoveFileW(utf8ToWide(ssrc), utf8ToWide(sdest)) == 0) if (MoveFileW(nlUtf8ToWide(ssrc), nlUtf8ToWide(sdest)) == 0)
{ {
sint lastError = NLMISC::getLastError(); sint lastError = NLMISC::getLastError();
nlwarning ("PATH: CopyMoveFile error: can't link/move '%s' into '%s', error %u (%s)", 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) bool CFile::createDirectory(const std::string &filename)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
return _wmkdir(utf8ToWide(filename))==0; return _wmkdir(nlUtf8ToWide(filename)) == 0;
#else #else
// Set full permissions.... // Set full permissions....
return mkdir(filename.c_str(), 0xFFFF)==0; return mkdir(filename.c_str(), 0xFFFF)==0;
@ -2751,7 +2751,7 @@ bool CFile::deleteFile(const std::string &filename)
{ {
setRWAccess(filename); setRWAccess(filename);
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
sint res = _wunlink(utf8ToWide(filename)); sint res = _wunlink(nlUtf8ToWide(filename));
#else #else
sint res = unlink(filename.c_str()); sint res = unlink(filename.c_str());
#endif #endif
@ -2770,7 +2770,7 @@ bool CFile::deleteDirectory(const std::string &filename)
{ {
setRWAccess(filename); setRWAccess(filename);
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
sint res = _wrmdir(utf8ToWide(filename)); sint res = _wrmdir(nlUtf8ToWide(filename));
#else #else
sint res = rmdir(filename.c_str()); sint res = rmdir(filename.c_str());
#endif #endif

View file

@ -1460,7 +1460,7 @@ uint64 CSystemInfo::availableHDSpace (const string &filename)
return (uint64)stfs.f_bavail * (uint64)stfs.f_bsize; return (uint64)stfs.f_bavail * (uint64)stfs.f_bsize;
#else #else
ULARGE_INTEGER freeSpace = {0}; ULARGE_INTEGER freeSpace = {0};
BOOL bRes = ::GetDiskFreeSpaceExW(utf8ToWide(path), &freeSpace, NULL, NULL); BOOL bRes = ::GetDiskFreeSpaceExW(nlUtf8ToWide(path), &freeSpace, NULL, NULL);
if (!bRes) return 0; if (!bRes) return 0;
return (uint64)freeSpace.QuadPart; return (uint64)freeSpace.QuadPart;

View file

@ -323,58 +323,55 @@ void CSystemUtils::setRootKey(const std::string &root)
RootKey = root; RootKey = root;
} }
string CSystemUtils::getRegKey(const string &Entry) string CSystemUtils::getRegKey(const string &entry)
{ {
string ret; string ret;
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
HKEY hkey; 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 dwType = 0L;
DWORD dwSize = KeyMaxLength; 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 else
{ {
ret = wideToUtf8(Buffer); ret = wideToUtf8(buffer);
} }
RegCloseKey(hkey); RegCloseKey(hkey);
} }
else else
{ {
nlwarning("Can't get the reg key '%s'", Entry.c_str()); nlwarning("Can't get the reg key '%s'", entry.c_str());
} }
#endif #endif
return ret; return ret;
} }
bool CSystemUtils::setRegKey(const string &ValueName, const string &Value) bool CSystemUtils::setRegKey(const string &valueName, const string &value)
{ {
bool res = false; bool res = false;
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
HKEY hkey; HKEY hkey;
DWORD dwDisp; 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 // we must use the real Unicode string size in bytes
DWORD size = (utf16Value.length() + 1) * 2; 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)
if (RegSetValueExW(hkey, utf8ToWide(ValueName), 0L, REG_SZ, (const BYTE *)utf16Value.c_str(), size) == ERROR_SUCCESS)
res = true; res = true;
RegCloseKey(hkey); RegCloseKey(hkey);
} }
else 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 #endif

View file

@ -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; access.value()[i].NeedUpdate = false;
} }
} }

View file

@ -612,7 +612,7 @@ void Browse::Init()
unsigned long value; unsigned long value;
unsigned long type; unsigned long type;
int cx=-1,cy=-1,x=-1,y=-1; int cx=-1,cy=-1,x=-1,y=-1;
char sWindowpl[256]; TCHAR sWindowpl[256];
if (RegOpenKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,&regkey)==ERROR_SUCCESS) if (RegOpenKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,&regkey)==ERROR_SUCCESS)
{ {
@ -621,7 +621,7 @@ void Browse::Init()
if (RegQueryValueEx(regkey,REGKEY_WNDPL,0,&type,(unsigned char *)&sWindowpl,&value)==ERROR_SUCCESS) if (RegQueryValueEx(regkey,REGKEY_WNDPL,0,&type,(unsigned char *)&sWindowpl,&value)==ERROR_SUCCESS)
{ {
WINDOWPLACEMENT wndpl; 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.flags,
&wndpl.ptMaxPosition.x,&wndpl.ptMaxPosition.y, &wndpl.ptMaxPosition.x,&wndpl.ptMaxPosition.y,
&wndpl.ptMinPosition.x,&wndpl.ptMinPosition.y, &wndpl.ptMinPosition.x,&wndpl.ptMinPosition.y,
@ -635,7 +635,7 @@ void Browse::Init()
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(); m_ctrl.LastPath.clear();
else else
m_ctrl.LastPath=(const char*)sWindowpl; m_ctrl.LastPath = tStrToUtf8(sWindowpl);
value=4; value=4;
type=REG_DWORD; type=REG_DWORD;
if (RegQueryValueEx(regkey,REGKEY_BUTTONZOOM,0,&type,(unsigned char *)&m_ctrl.Zoom,&value)!=ERROR_SUCCESS) 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,&regkey)==ERROR_SUCCESS) if (RegCreateKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,&regkey)==ERROR_SUCCESS)
{ {
//int sel = ((CComboBox*)GetDlgItem(IDC_LISTTYPE))->GetCurSel(); //int sel = ((CComboBox*)GetDlgItem(IDC_LISTTYPE))->GetCurSel();
RegSetValueEx(regkey,REGKEY_WNDPL,0,REG_SZ,(const unsigned char*)sWindowpl,(DWORD)strlen(sWindowpl)); tstring tWindowpl = utf8ToTStr(sWindowpl);
RegSetValueEx(regkey,REGKEY_LASTPATH,0,REG_SZ,(const unsigned char*)m_ctrl.LastPath.c_str(),(DWORD)strlen(m_ctrl.LastPath.c_str())); 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_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_BUTTONVARIETY,0,REG_DWORD,(const unsigned char*)&m_128x128,4);
RegSetValueEx(regkey,REGKEY_BUTTONTEXTURE,0,REG_DWORD,(const unsigned char*)&m_ctrl.Texture,4); RegSetValueEx(regkey,REGKEY_BUTTONTEXTURE,0,REG_DWORD,(const unsigned char*)&m_ctrl.Texture,4);

View file

@ -73,7 +73,7 @@ BOOL CData_mirrorApp::InitInstance()
{ {
// Get the module // Get the module
CConfigFile cf; CConfigFile cf;
string exePath = GetCommandLine (); string exePath = nlTStrToUtf8(GetCommandLineW());
if (exePath.size()>0) if (exePath.size()>0)
{ {
if (exePath[0] == '\"') if (exePath[0] == '\"')
@ -124,7 +124,7 @@ BOOL CData_mirrorApp::InitInstance()
if ((sBinaryCompare == "true") || (sBinaryCompare=="1")) if ((sBinaryCompare == "true") || (sBinaryCompare=="1"))
BinaryCompare = true; BinaryCompare = true;
CurrentDir = m_lpCmdLine; CurrentDir = nlTStrToUtf8(m_lpCmdLine);
// Remove // Remove
if (CurrentDir.size ()>=2) if (CurrentDir.size ()>=2)
{ {
@ -151,7 +151,7 @@ BOOL CData_mirrorApp::InitInstance()
} }
else 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; return FALSE;
} }
@ -168,8 +168,8 @@ BOOL CData_mirrorApp::InitInstance()
} }
else else
{ {
MessageBox (NULL, (CurrentDir+" is not a sub directory of "+MainDirectory+" or "+MirrorDirectory).c_str (), MessageBox(NULL, nlUtf8ToTStr(CurrentDir + " is not a sub directory of " + MainDirectory + " or " + MirrorDirectory),
"NeL Data Mirror", MB_OK|MB_ICONEXCLAMATION); _T("NeL Data Mirror"), MB_OK|MB_ICONEXCLAMATION);
return FALSE; return FALSE;
} }
} }
@ -200,7 +200,7 @@ BOOL CData_mirrorApp::InitInstance()
} }
catch (const Exception &e) 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; CData_mirrorDlg dlg;
@ -227,19 +227,21 @@ bool RegisterDirectoryAppCommand (const char *appName, const char *command, cons
{ {
// Create the app key // Create the app key
HKEY hKey; HKEY hKey;
if (RegCreateKey (HKEY_CLASSES_ROOT, "Directory", &hKey) == ERROR_SUCCESS) if (RegCreateKey (HKEY_CLASSES_ROOT, _T("Directory"), &hKey) == ERROR_SUCCESS)
{ {
// Create the icon // Create the icon
char tmp[512]; char tmp[512];
smprintf (tmp, 512, "shell\\%s", appName); smprintf (tmp, 512, "shell\\%s", appName);
if (RegCreateKey (hKey, tmp, &hKey) == ERROR_SUCCESS) if (RegCreateKey(hKey, nlUtf8ToTStr(tmp), &hKey) == ERROR_SUCCESS)
{ {
// Set the description // Set the description
RegSetValue (hKey, "", REG_SZ, command, (DWORD)strlen (command)); tstring tcommand = utf8ToTStr(command);
if (RegCreateKey (hKey, "command", &hKey) == ERROR_SUCCESS) RegSetValue(hKey, _T(""), REG_SZ, tcommand.c_str(), (tcommand.size() + 1) * sizeof(TCHAR));
if (RegCreateKey (hKey, _T("command"), &hKey) == ERROR_SUCCESS)
{ {
// Set the description // 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; return true;
} }
} }

View file

@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <windows.h> #include <windows.h>
#include <tchar.h>
#include <stdio.h> #include <stdio.h>
#include "resource.h" #include "resource.h"
@ -40,7 +41,7 @@ void pump ()
} }
} }
int APIENTRY WinMain(HINSTANCE hInstance, int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, LPSTR lpCmdLine,
int nCmdShow) int nCmdShow)
@ -57,68 +58,68 @@ int APIENTRY WinMain(HINSTANCE hInstance,
pump (); pump ();
// Get the temp directory // Get the temp directory
char tempPath[1024]; TCHAR tempPath[1024];
if (GetTempPath(1024, tempPath)) if (GetTempPath(1024, tempPath))
{ {
char pathToDelete[1024]; TCHAR pathToDelete[1024];
strcpy (pathToDelete, tempPath); _tcscpy (pathToDelete, tempPath);
strcat (pathToDelete, "Ryzom"); _tcscat (pathToDelete, _T("Ryzom"));
CreateDirectory(tempPath, NULL); CreateDirectory(tempPath, NULL);
strcat (tempPath, "Ryzom\\"); _tcscat (tempPath, _T("Ryzom\\"));
CreateDirectory(tempPath, NULL); CreateDirectory(tempPath, NULL);
// Copy the files // Copy the files
pump (); pump ();
// Setup.dat // Setup.dat
char setupFile[1024]; TCHAR setupFile[1024];
strcpy (setupFile, tempPath); _tcscpy (setupFile, tempPath);
strcat (setupFile, "setup.exe"); _tcscat(setupFile, _T("setup.exe"));
SetFileAttributes(setupFile, GetFileAttributes(setupFile)&~FILE_ATTRIBUTE_READONLY); SetFileAttributes(setupFile, GetFileAttributes(setupFile)&~FILE_ATTRIBUTE_READONLY);
BOOL deleted = DeleteFile (setupFile); BOOL deleted = DeleteFile (setupFile);
if (!CopyFile ("setup.dat", setupFile, FALSE) && deleted) if (!CopyFile (_T("setup.dat"), setupFile, FALSE) && deleted)
MessageBox (NULL, "Not enough disk space", "Setup", MB_OK|MB_ICONERROR); MessageBox (NULL, _T("Not enough disk space"), _T("Setup"), MB_OK|MB_ICONERROR);
SetFileAttributes(setupFile, GetFileAttributes(setupFile)&~FILE_ATTRIBUTE_READONLY); SetFileAttributes(setupFile, GetFileAttributes(setupFile)&~FILE_ATTRIBUTE_READONLY);
pump (); pump ();
// Ryzom.msi // Ryzom.msi
char msiFile[1024]; TCHAR msiFile[1024];
strcpy (msiFile, tempPath); _tcscpy(msiFile, tempPath);
strcat (msiFile, "Ryzom.msi"); _tcscat(msiFile, _T("Ryzom.msi"));
SetFileAttributes(msiFile, GetFileAttributes(msiFile)&~FILE_ATTRIBUTE_READONLY); SetFileAttributes(msiFile, GetFileAttributes(msiFile)&~FILE_ATTRIBUTE_READONLY);
deleted = DeleteFile (msiFile); deleted = DeleteFile (msiFile);
if (!CopyFile ("Ryzom.msi", msiFile, FALSE) && deleted) if (!CopyFile (_T("Ryzom.msi"), msiFile, FALSE) && deleted)
MessageBox (NULL, "Not enough disk space", "Setup", MB_OK|MB_ICONERROR); MessageBox (NULL, _T("Not enough disk space"), _T("Setup"), MB_OK|MB_ICONERROR);
SetFileAttributes(msiFile, GetFileAttributes(msiFile)&~FILE_ATTRIBUTE_READONLY); SetFileAttributes(msiFile, GetFileAttributes(msiFile)&~FILE_ATTRIBUTE_READONLY);
pump (); pump ();
// Generate the remove bat file // Generate the remove bat file
char batFile[1024]; TCHAR batFile[1024];
strcpy (batFile, tempPath); _tcscpy (batFile, tempPath);
strcat (batFile, "remove.bat"); _tcscat(batFile, _T("remove.bat"));
FILE *file = fopen (batFile, "w"); FILE *file = _tfopen (batFile, _T("w"));
fprintf (file, "@echo off\nrmdir /S /Q \"%s\" > NUL\ndeltree /Y \"%s\" > NUL\n", pathToDelete, pathToDelete); _ftprintf (file, _T("@echo off\nrmdir /S /Q \"%s\" > NUL\ndeltree /Y \"%s\" > NUL\n"), pathToDelete, pathToDelete);
fclose (file); fclose (file);
// Register the remove bat file // Register the remove bat file
HKEY hKey; HKEY hKey;
RegCreateKey (HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Runonce", &hKey); RegCreateKey (HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Runonce"), &hKey);
char batFileReg[1024]; TCHAR batFileReg[1024];
sprintf (batFileReg, "\"%s\"", batFile); _stprintf (batFileReg, _T("\"%s\""), batFile);
RegSetValueEx(hKey, "RyzomSetupClean", 0, REG_SZ, (const unsigned char*)batFileReg, (DWORD)strlen (batFileReg)+1); RegSetValueEx(hKey, _T("RyzomSetupClean"), 0, REG_SZ, (const unsigned char *)batFileReg, (DWORD)(_tcslen(batFileReg) + 1) * sizeof(TCHAR));
pump (); pump ();
// Get the current path // Get the current path
char currentPath[1024]; TCHAR currentPath[1024];
GetCurrentDirectory (1024, currentPath); GetCurrentDirectory (1024, currentPath);
if (currentPath[strlen(currentPath)-1] == '\\') if (currentPath[_tcslen(currentPath) - 1] == '\\')
currentPath[strlen(currentPath)-1] = 0; currentPath[_tcslen(currentPath) - 1] = 0;
pump (); pump ();
// Build the command line : /z"f:\" // Build the command line : /z"f:\"
char option[1024]; TCHAR option[1024];
sprintf (option, "\"%s\" /z\"%s\"", setupFile, currentPath); _stprintf(option, _T("\"%s\" /z\"%s\""), setupFile, currentPath);
pump (); pump ();
// Execute the setup // Execute the setup

View file

@ -39,7 +39,7 @@ std::string CLoginRegistry::getProductInstallId()
if (RegQueryValueExW(hKey, InstallIdKeyHandle, NULL, &dwType, (BYTE *) buffer, &dwSize) == ERROR_SUCCESS && dwType == REG_SZ) if (RegQueryValueExW(hKey, InstallIdKeyHandle, NULL, &dwType, (BYTE *) buffer, &dwSize) == ERROR_SUCCESS && dwType == REG_SZ)
{ {
RegCloseKey(hKey); RegCloseKey(hKey);
return wideToUtf8(buffer); return NLMISC::wideToUtf8(buffer);
} }
RegCloseKey(hKey); RegCloseKey(hKey);
} }
@ -58,10 +58,9 @@ std::string CLoginRegistry::getProductInstallId()
// copy wide string to a buffer // copy wide string to a buffer
const uint keyMaxLength = 16; const uint keyMaxLength = 16;
wchar_t buffer[keyMaxLength]; std::wstring wid = NLMISC::utf8ToWide(id);
wcscpy(buffer, 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; return id;
} }

View file

@ -477,9 +477,9 @@ void CGeorgesEditApp::OnAppAbout()
void CGeorgesEditApp::outputError (const char* message) void CGeorgesEditApp::outputError (const char* message)
{ {
if (m_pMainWnd) 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 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) void CGeorgesEditApp::getConfigFilePath (std::string &output)
@ -711,9 +711,9 @@ bool CGeorgesEditApp::getColor (NLMISC::CRGBA &color)
bool CGeorgesEditApp::yesNo (const char* message) bool CGeorgesEditApp::yesNo (const char* message)
{ {
if (m_pMainWnd) 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 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 () void CGeorgesEditApp::loadPlugins ()
@ -722,7 +722,7 @@ void CGeorgesEditApp::loadPlugins ()
for (i=0; i<PluginsNames.size (); i++) for (i=0; i<PluginsNames.size (); i++)
{ {
// Load the dll // Load the dll
HINSTANCE hModule = AfxLoadLibrary (utf8ToTStr(PluginsNames[i])); HINSTANCE hModule = AfxLoadLibrary(nlUtf8ToTStr(PluginsNames[i]));
if (hModule) if (hModule)
{ {
// Get the proc adrdess // Get the proc adrdess
@ -829,10 +829,10 @@ NLGEORGES::IEditDocument *CGeorgesEditApp::createDocument (const char *dfnName,
// Set the filename // Set the filename
if (strcmp (pathName, "") != 0) if (strcmp (pathName, "") != 0)
{ {
doc->SetPathName (utf8ToTStr(pathName), FALSE ); doc->SetPathName (nlUtf8ToTStr(pathName), FALSE );
// Create the file // Create the file
doc->OnSaveDocument(utf8ToTStr(pathName) ); doc->OnSaveDocument(nlUtf8ToTStr(pathName));
} }
// Init the frame // Init the frame
@ -925,7 +925,7 @@ void CGeorgesEditApp::gotoURL (LPCTSTR url)
void CGeorgesEditApp::WinHelp(DWORD dwData, UINT nCmd) 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() void CGeorgesEditApp::OnViewRefresh()

View file

@ -102,7 +102,7 @@ bool CMemoryComboBox::getMemory (int slot, std::string &ret)
smprintf (strSrc, 512, "%d", slot); smprintf (strSrc, 512, "%d", slot);
TCHAR str[512]; TCHAR str[512];
LONG size = 512 * sizeof(TCHAR); 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); ret = tStrToUtf8(str);
@ -134,12 +134,12 @@ void CMemoryComboBox::scrollDown (int start, int end)
smprintf (strSrc, 512, "%d", i-1); smprintf (strSrc, 512, "%d", i-1);
TCHAR str[512]; TCHAR str[512];
LONG size = 512 * sizeof(TCHAR); 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 // Set the value
char strDst[512]; char strDst[512];
smprintf (strDst, 512, "%d", i); 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 // Set the value
tstring tstr = utf8ToTStr(str); 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 // Close
RegCloseKey (hKey); RegCloseKey (hKey);
@ -444,7 +444,7 @@ void CMemoryComboBox::refreshStrings ()
int count = Commands.size(); int count = Commands.size();
for (i=0; i<StaticStrings.size(); i++) for (i=0; i<StaticStrings.size(); i++)
{ {
_ComboBox.InsertString (count, utf8ToTStr(StaticStrings[i])); _ComboBox.InsertString(count, nlUtf8ToTStr(StaticStrings[i]));
count++; count++;
} }
@ -453,7 +453,7 @@ void CMemoryComboBox::refreshStrings ()
std::string ret; std::string ret;
if (getMemory (i, ret)) if (getMemory (i, ret))
{ {
_ComboBox.InsertString (count, utf8ToTStr(ret)); _ComboBox.InsertString(count, nlUtf8ToTStr(ret));
count++; count++;
} }
} }
@ -492,7 +492,7 @@ void CMemoryComboBox::clearCommand ()
void CMemoryComboBox::addLabelCommands (uint i) void CMemoryComboBox::addLabelCommands (uint i)
{ {
_ComboBox.InsertString (i, utf8ToTStr(Commands[i].Label)); _ComboBox.InsertString(i, nlUtf8ToTStr(Commands[i].Label));
} }
// *************************************************************************** // ***************************************************************************
@ -683,7 +683,7 @@ BOOL CMemoryComboBox::PreTranslateMessage(MSG* pMsg)
if ((!str.IsEmpty()) && (str.Find('.') == -1)) if ((!str.IsEmpty()) && (str.Find('.') == -1))
{ {
str += _T("."); str += _T(".");
str += utf8ToTStr(_Extension); str += nlUtf8ToTStr(_Extension);
_ComboBox.SetWindowText (str); _ComboBox.SetWindowText (str);
} }
} }

View file

@ -40,31 +40,34 @@ bool RegisterApp (const char *appName, const char *appDescription, const char *i
{ {
// Create the app key // Create the app key
HKEY hKey; HKEY hKey;
if (RegCreateKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS) if (RegCreateKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{ {
// Set the description // Set the description
RegSetValue (hKey, "", REG_SZ, appDescription, strlen (appDescription)); tstring tAppDescription = utf8ToTStr(appDescription);
RegSetValue(hKey, _T(""), REG_SZ, tAppDescription.c_str(), (tAppDescription.size() + 1) * sizeof(TCHAR));
// Create the icon // Create the icon
HKEY hKey2; HKEY hKey2;
if (RegCreateKey (hKey, "DefaultIcon", &hKey2) == ERROR_SUCCESS) if (RegCreateKey(hKey, _T("DefaultIcon"), &hKey2) == ERROR_SUCCESS)
{ {
// Set the description // Set the description
char tmp[512]; char tmp[512];
smprintf(tmp, 512, "%s,%d", icon, iconIndex); smprintf(tmp, 512, "%s,%d", icon, iconIndex);
RegSetValue (hKey2, "", REG_SZ, tmp, strlen (tmp)); tstring ttmp = utf8ToTStr(tmp);
RegSetValue(hKey2, _T(""), REG_SZ, ttmp.c_str(), (ttmp.size() + 1) * sizeof(TCHAR));
} }
// Create the shell/open/command // Create the shell/open/command
if (RegCreateKey (hKey, "shell", &hKey) == ERROR_SUCCESS) if (RegCreateKey(hKey, _T("shell"), &hKey) == ERROR_SUCCESS)
{ {
if (RegCreateKey (hKey, "open", &hKey) == ERROR_SUCCESS) if (RegCreateKey(hKey, _T("open"), &hKey) == ERROR_SUCCESS)
{ {
if (RegCreateKey (hKey, "command", &hKey) == ERROR_SUCCESS) if (RegCreateKey(hKey, _T("command"), &hKey) == ERROR_SUCCESS)
{ {
// Set the description // Set the description
string tmp = string(icon) + " \"%1\""; string tmp = string(icon) + " \"%1\"";
RegSetValue (hKey, "", REG_SZ, tmp.c_str(), tmp.size()); tstring ttmp = utf8ToTStr(tmp);
RegSetValue(hKey, _T(""), REG_SZ, ttmp.c_str(), (ttmp.size() + 1) * sizeof(TCHAR));
} }
} }
} }
@ -78,7 +81,7 @@ bool RegisterApp (const char *appName, const char *appDescription, const char *i
bool UnregisterApp(const char *appName) bool UnregisterApp(const char *appName)
{ {
// Delete the app key // Delete the app key
deleteKey (HKEY_CLASSES_ROOT, appName); deleteKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName));
return true; return true;
} }
@ -87,12 +90,12 @@ bool UnregisterAppCommand (const char *appName, const char *command)
{ {
// Create the app key // Create the app key
HKEY hKey; HKEY hKey;
if (RegOpenKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS) if (RegOpenKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{ {
// Create the icon // Create the icon
char tmp[512]; char tmp[512];
smprintf(tmp, 512, "shell\\%s", command); smprintf(tmp, 512, "shell\\%s", command);
deleteKey (hKey, tmp); deleteKey(hKey, nlUtf8ToTStr(tmp));
return true; return true;
} }
return false; return false;
@ -103,15 +106,16 @@ bool RegisterAppCommand (const char *appName, const char *command, const char *a
{ {
// Create the app key // Create the app key
HKEY hKey; HKEY hKey;
if (RegCreateKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS) if (RegCreateKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{ {
// Create the icon // Create the icon
char tmp[512]; char tmp[512];
smprintf(tmp, 512, "shell\\%s\\command", command); smprintf(tmp, 512, "shell\\%s\\command", command);
if (RegCreateKey (hKey, tmp, &hKey) == ERROR_SUCCESS) if (RegCreateKey(hKey, nlUtf8ToTStr(tmp), &hKey) == ERROR_SUCCESS)
{ {
// Set the description // Set the description
RegSetValue (hKey, "", REG_SZ, app, strlen (app)); tstring tapp = utf8ToTStr(app);
RegSetValue(hKey, _T(""), REG_SZ, tapp.c_str(), (tapp.size() + 1) * sizeof(TCHAR));
} }
return true; return true;
} }
@ -123,12 +127,12 @@ bool UnregisterDDECommand (const char *appName, const char *command)
{ {
// Create the app key // Create the app key
HKEY hKey; HKEY hKey;
if (RegOpenKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS) if (RegOpenKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{ {
// Create the icon // Create the icon
char tmp[512]; char tmp[512];
smprintf(tmp, 512, "shell\\%s\\ddeexec", command); smprintf(tmp, 512, "shell\\%s\\ddeexec", command);
deleteKey (hKey, tmp); deleteKey(hKey, nlUtf8ToTStr(tmp));
} }
return false; return false;
} }
@ -138,22 +142,24 @@ bool RegisterDDECommand (const char *appName, const char *command, const char *d
{ {
// Create the app key // Create the app key
HKEY hKey; HKEY hKey;
if (RegCreateKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS) if (RegCreateKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{ {
// Create the icon // Create the icon
char tmp[512]; char tmp[512];
smprintf(tmp, 512, "shell\\%s\\ddeexec", command); smprintf(tmp, 512, "shell\\%s\\ddeexec", command);
if (RegCreateKey (hKey, tmp, &hKey) == ERROR_SUCCESS) if (RegCreateKey(hKey, nlUtf8ToTStr(tmp), &hKey) == ERROR_SUCCESS)
{ {
// Set the description // Set the description
RegSetValue (hKey, "", REG_SZ, ddeCommand, strlen (ddeCommand)); tstring tddeCommand = utf8ToTStr(ddeCommand);
RegSetValue(hKey, _T(""), REG_SZ, tddeCommand.c_str(), (tddeCommand.size() + 1) * sizeof(TCHAR));
HKEY hKey2; HKEY hKey2;
if (RegCreateKey (hKey, "application", &hKey2) == ERROR_SUCCESS) if (RegCreateKey(hKey, _T("application"), &hKey2) == ERROR_SUCCESS)
{ {
RegSetValue (hKey2, "", REG_SZ, application, strlen (application)); tstring tapplication = utf8ToTStr(application);
if (RegCreateKey (hKey, "topic", &hKey2) == ERROR_SUCCESS) RegSetValue(hKey2, _T(""), REG_SZ, tapplication.c_str(), (tapplication.size() + 1) * sizeof(TCHAR));
if (RegCreateKey(hKey, _T("topic"), &hKey2) == ERROR_SUCCESS)
{ {
RegSetValue (hKey2, "", REG_SZ, "system", strlen ("system")); RegSetValue(hKey2, _T(""), REG_SZ, _T("system"), (strlen("system") + 1) * sizeof(TCHAR));
return true; return true;
} }
} }
@ -168,13 +174,14 @@ bool RegisterShellFileExt (const char *ext, const char *appName)
// Remove key in explorer registry if exist // Remove key in explorer registry if exist
HKEY hKey; HKEY hKey;
string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + string(ext); string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + string(ext);
deleteKey (HKEY_CURRENT_USER, key.c_str ()); deleteKey(HKEY_CURRENT_USER, nlUtf8ToTStr(key));
// Create the app key // Create the app key
if (RegCreateKey (HKEY_CLASSES_ROOT, ext, &hKey) == ERROR_SUCCESS) if (RegCreateKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(ext), &hKey) == ERROR_SUCCESS)
{ {
// Set the description // Set the description
RegSetValue (hKey, "", REG_SZ, appName, strlen (appName)); tstring tAppName = utf8ToTStr(appName);
RegSetValue(hKey, _T(""), REG_SZ, tAppName.c_str(), (tAppName.size() + 1) * sizeof(TCHAR));
return true; return true;
} }
return false; return false;
@ -184,7 +191,7 @@ bool RegisterShellFileExt (const char *ext, const char *appName)
bool UnregisterShellFileExt(const char *ext) bool UnregisterShellFileExt(const char *ext)
{ {
// Delete the app key // Delete the app key
if (RegDeleteKey (HKEY_CLASSES_ROOT, ext) == ERROR_SUCCESS) if (RegDeleteKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(ext)) == ERROR_SUCCESS)
{ {
return true; return true;
} }

View file

@ -59,9 +59,9 @@ INT_PTR CFileDialogEx::DoModal ()
HKEY hKey; HKEY hKey;
DWORD type = REG_SZ; DWORD type = REG_SZ;
DWORD size = 512 * sizeof(TCHAR); DWORD size = 512 * sizeof(TCHAR);
if (RegCreateKey (HKEY_CURRENT_USER, utf8ToTStr(_RegistryPath), &hKey) == ERROR_SUCCESS) if (RegCreateKey(HKEY_CURRENT_USER, nlUtf8ToTStr(_RegistryPath), &hKey) == ERROR_SUCCESS)
{ {
if (RegQueryValueEx (hKey, utf8ToTStr(_FileType), 0, &type, (LPBYTE)path, &size) == ERROR_SUCCESS) if (RegQueryValueEx(hKey, nlUtf8ToTStr(_FileType), 0, &type, (LPBYTE)path, &size) == ERROR_SUCCESS)
m_ofn.lpstrInitialDir = path; m_ofn.lpstrInitialDir = path;
} }
@ -76,9 +76,9 @@ INT_PTR CFileDialogEx::DoModal ()
std::string newPath = NLMISC::CFile::getPath (tStrToUtf8(GetPathName())); std::string newPath = NLMISC::CFile::getPath (tStrToUtf8(GetPathName()));
TCHAR buffer[MAX_PATH]; TCHAR buffer[MAX_PATH];
_tcscpy_s(buffer, MAX_PATH, utf8ToTStr(newPath)); _tcscpy_s(buffer, MAX_PATH, nlUtf8ToTStr(newPath));
RegSetValueEx (hKey, utf8ToTStr(_FileType), 0, REG_SZ, (LPBYTE)buffer, (_tcslen(buffer) + 1) * sizeof(TCHAR)); RegSetValueEx(hKey, nlUtf8ToTStr(_FileType), 0, REG_SZ, (LPBYTE)buffer, (_tcslen(buffer) + 1) * sizeof(TCHAR));
// Update the path list // Update the path list
set<string> oldPath; set<string> oldPath;
@ -86,7 +86,7 @@ INT_PTR CFileDialogEx::DoModal ()
for (i=0; i<PATH_REMEBERED_SIZE; i++) for (i=0; i<PATH_REMEBERED_SIZE; i++)
{ {
size = 512; size = 512;
if (RegQueryValueEx (hKey, utf8ToTStr(toString(i)), 0, &type, (LPBYTE)path, &size) == ERROR_SUCCESS) if (RegQueryValueEx(hKey, nlUtf8ToTStr(toString(i)), 0, &type, (LPBYTE)path, &size) == ERROR_SUCCESS)
oldPath.insert (tStrToUtf8(path)); oldPath.insert (tStrToUtf8(path));
} }
oldPath.insert (newPath); oldPath.insert (newPath);
@ -94,9 +94,9 @@ INT_PTR CFileDialogEx::DoModal ()
uint index = 0; uint index = 0;
while (ite != oldPath.end ()) while (ite != oldPath.end ())
{ {
_tcscpy_s(buffer, MAX_PATH, utf8ToTStr(*ite)); _tcscpy_s(buffer, MAX_PATH, nlUtf8ToTStr(*ite));
RegSetValueEx (hKey, utf8ToTStr(toString(index)), 0, REG_SZ, (LPBYTE)buffer, (_tcslen(buffer) + 1) * sizeof(TCHAR)); RegSetValueEx(hKey, nlUtf8ToTStr(toString(index)), 0, REG_SZ, (LPBYTE)buffer, (_tcslen(buffer) + 1) * sizeof(TCHAR));
ite++; ite++;
index++; index++;
} }
@ -158,13 +158,13 @@ BOOL CFileDialogEx::OnInitDialog()
HKEY hKey; HKEY hKey;
DWORD type = REG_SZ; DWORD type = REG_SZ;
DWORD size; DWORD size;
if (RegCreateKey (HKEY_CURRENT_USER, utf8ToTStr(_RegistryPath), &hKey) == ERROR_SUCCESS) if (RegCreateKey(HKEY_CURRENT_USER, nlUtf8ToTStr(_RegistryPath), &hKey) == ERROR_SUCCESS)
{ {
uint i; uint i;
for (i=0; i<PATH_REMEBERED_SIZE; i++) for (i=0; i<PATH_REMEBERED_SIZE; i++)
{ {
size = 512 * sizeof(TCHAR); size = 512 * sizeof(TCHAR);
if (RegQueryValueEx (hKey, utf8ToTStr(toString(i)), 0, &type, (LPBYTE)text, &size) == ERROR_SUCCESS) if (RegQueryValueEx(hKey, nlUtf8ToTStr(toString(i)), 0, &type, (LPBYTE)text, &size) == ERROR_SUCCESS)
combo.InsertString (-1, text); combo.InsertString (-1, text);
} }
if (m_ofn.lpstrInitialDir) if (m_ofn.lpstrInitialDir)

View file

@ -301,7 +301,7 @@ void CDialogFlags::setCurrentEntityDisplayMode(TEntityDisplayMode edm)
void CDialogFlags::loadEntityDisplayInfoToRegistry(TEntityDisplayInfoVect &infos, const std::string &regId) void CDialogFlags::loadEntityDisplayInfoToRegistry(TEntityDisplayInfoVect &infos, const std::string &regId)
{ {
HKEY hKey; HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER, utf8ToTStr(tStrToUtf8(REGKEY_ENTITY_DISPLAY_INFO) + regId), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) if (RegOpenKeyEx(HKEY_CURRENT_USER, nlUtf8ToTStr(tStrToUtf8(REGKEY_ENTITY_DISPLAY_INFO) + regId), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
{ {
DWORD index = 0; DWORD index = 0;
for(;;) for(;;)
@ -338,7 +338,7 @@ void CDialogFlags::loadEntityDisplayInfoToRegistry(TEntityDisplayInfoVect &infos
void CDialogFlags::saveEntityDisplayInfoToRegistry(const TEntityDisplayInfoVect &infos, const std::string &regId) void CDialogFlags::saveEntityDisplayInfoToRegistry(const TEntityDisplayInfoVect &infos, const std::string &regId)
{ {
HKEY hKey; HKEY hKey;
if (RegCreateKeyEx(HKEY_CURRENT_USER, utf8ToTStr(tStrToUtf8(REGKEY_ENTITY_DISPLAY_INFO) + regId), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) if (RegCreateKeyEx(HKEY_CURRENT_USER, nlUtf8ToTStr(tStrToUtf8(REGKEY_ENTITY_DISPLAY_INFO) + regId), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
{ {
for(uint k = 0; k < infos.size(); ++k) for(uint k = 0; k < infos.size(); ++k)
{ {

View file

@ -95,14 +95,14 @@ bool CMemoryComboBox::getMemory (int slot, std::string &ret)
{ {
// Open the key // Open the key
HKEY hKey; HKEY hKey;
if (RegOpenKey (HKEY_CURRENT_USER, utf8ToTStr(RegisterAdress), &hKey) == ERROR_SUCCESS) if (RegOpenKey(HKEY_CURRENT_USER, nlUtf8ToTStr(RegisterAdress), &hKey) == ERROR_SUCCESS)
{ {
// Get the value // Get the value
char strSrc[512]; char strSrc[512];
smprintf (strSrc, 512, "%d", slot); smprintf (strSrc, 512, "%d", slot);
TCHAR str[512]; TCHAR str[512];
long size = 512*sizeof(TCHAR); 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); ret = tStrToUtf8(str);
@ -124,7 +124,7 @@ void CMemoryComboBox::scrollDown (int start, int end)
{ {
// Open the key // Open the key
HKEY hKey; HKEY hKey;
if (RegCreateKey (HKEY_CURRENT_USER, utf8ToTStr(RegisterAdress), &hKey) == ERROR_SUCCESS) if (RegCreateKey (HKEY_CURRENT_USER, nlUtf8ToTStr(RegisterAdress), &hKey) == ERROR_SUCCESS)
{ {
// Scroll down the list // Scroll down the list
for (int i=end-1; i>start; i--) for (int i=end-1; i>start; i--)
@ -134,12 +134,12 @@ void CMemoryComboBox::scrollDown (int start, int end)
smprintf (strSrc, 512, "%d", i-1); smprintf (strSrc, 512, "%d", i-1);
TCHAR str[512]; TCHAR str[512];
long size = 512 * sizeof(TCHAR); 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 // Set the value
char strDst[512]; char strDst[512];
smprintf (strDst, 512, "%d", i); 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 // Open the key
HKEY hKey; 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 // Set the value
RegSetValue (hKey, _T("0"), REG_SZ, utf8ToTStr(str), str.size ()); RegSetValue(hKey, _T("0"), REG_SZ, nlUtf8ToTStr(str), str.size());
// Close // Close
RegCloseKey (hKey); RegCloseKey (hKey);
@ -428,7 +428,7 @@ void CMemoryComboBox::pushString (const std::string &str)
if (i == (int)(itemCount+Commands.size()+ StaticStrings.size())) if (i == (int)(itemCount+Commands.size()+ StaticStrings.size()))
{ {
// Insert the sting // 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(); int count = Commands.size();
for (i=0; i<StaticStrings.size(); i++) for (i=0; i<StaticStrings.size(); i++)
{ {
_ComboBox.InsertString (count, utf8ToTStr(StaticStrings[i])); _ComboBox.InsertString(count, nlUtf8ToTStr(StaticStrings[i]));
count++; count++;
} }
@ -458,7 +458,7 @@ void CMemoryComboBox::refreshStrings ()
std::string ret; std::string ret;
if (getMemory (i, ret)) if (getMemory (i, ret))
{ {
_ComboBox.InsertString (count, utf8ToTStr(ret)); _ComboBox.InsertString(count, nlUtf8ToTStr(ret));
count++; count++;
} }
} }
@ -497,7 +497,7 @@ void CMemoryComboBox::clearCommand ()
void CMemoryComboBox::addLabelCommands (uint i) void CMemoryComboBox::addLabelCommands (uint i)
{ {
_ComboBox.InsertString (i, utf8ToTStr(Commands[i].Label)); _ComboBox.InsertString(i, nlUtf8ToTStr(Commands[i].Label));
} }
// *************************************************************************** // ***************************************************************************
@ -688,7 +688,7 @@ BOOL CMemoryComboBox::PreTranslateMessage(MSG* pMsg)
if ((!str2.empty ()) && (str2.find ('.') == string::npos)) if ((!str2.empty ()) && (str2.find ('.') == string::npos))
{ {
str2 += "." + _Extension; str2 += "." + _Extension;
_ComboBox.SetWindowText (utf8ToTStr(str2)); _ComboBox.SetWindowText(nlUtf8ToTStr(str2));
} }
} }
@ -739,7 +739,7 @@ CString CMemoryComboBox::getCurrString() const
// *************************************************************************** // ***************************************************************************
void CMemoryComboBox::setCurSel(const std::string &value) void CMemoryComboBox::setCurSel(const std::string &value)
{ {
int index = _ComboBox.FindStringExact(0, utf8ToTStr(value)); int index = _ComboBox.FindStringExact(0, nlUtf8ToTStr(value));
if (index != CB_ERR) if (index != CB_ERR)
{ {
_ComboBox.SetCurSel(index); _ComboBox.SetCurSel(index);