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*
#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

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))
#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); }

View file

@ -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();

View file

@ -526,6 +526,15 @@ template<> struct hash<uint64>
*/
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

View file

@ -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");

View file

@ -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
);

View file

@ -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;
}
}

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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

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;
}
}

View file

@ -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,&regkey)==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,&regkey)==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);

View file

@ -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;
}
}

View file

@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#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

View file

@ -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;
}

View file

@ -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; i<PluginsNames.size (); i++)
{
// Load the dll
HINSTANCE hModule = AfxLoadLibrary (utf8ToTStr(PluginsNames[i]));
HINSTANCE hModule = AfxLoadLibrary(nlUtf8ToTStr(PluginsNames[i]));
if (hModule)
{
// Get the proc adrdess
@ -829,10 +829,10 @@ NLGEORGES::IEditDocument *CGeorgesEditApp::createDocument (const char *dfnName,
// Set the filename
if (strcmp (pathName, "") != 0)
{
doc->SetPathName (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()

View file

@ -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<StaticStrings.size(); i++)
{
_ComboBox.InsertString (count, utf8ToTStr(StaticStrings[i]));
_ComboBox.InsertString(count, nlUtf8ToTStr(StaticStrings[i]));
count++;
}
@ -453,7 +453,7 @@ void CMemoryComboBox::refreshStrings ()
std::string ret;
if (getMemory (i, ret))
{
_ComboBox.InsertString (count, utf8ToTStr(ret));
_ComboBox.InsertString(count, nlUtf8ToTStr(ret));
count++;
}
}
@ -492,7 +492,7 @@ void CMemoryComboBox::clearCommand ()
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))
{
str += _T(".");
str += utf8ToTStr(_Extension);
str += nlUtf8ToTStr(_Extension);
_ComboBox.SetWindowText (str);
}
}

View file

@ -21,50 +21,53 @@
using namespace std;
using namespace NLMISC;
void deleteKey (HKEY hKey, const TCHAR *name)
void deleteKey(HKEY hKey, const TCHAR *name)
{
HKEY subKey;
if (RegOpenKey (hKey, name, &subKey) == ERROR_SUCCESS)
if (RegOpenKey(hKey, name, &subKey) == ERROR_SUCCESS)
{
TCHAR subName[512];
while (RegEnumKey (subKey, 0, subName, 512) == ERROR_SUCCESS)
while (RegEnumKey(subKey, 0, subName, 512) == ERROR_SUCCESS)
{
deleteKey (subKey, subName);
deleteKey(subKey, subName);
}
nlverify (RegDeleteKey (hKey, name) == ERROR_SUCCESS);
nlverify(RegDeleteKey(hKey, name) == ERROR_SUCCESS);
}
}
// Register an application
bool RegisterApp (const char *appName, const char *appDescription, const char *icon, int iconIndex)
bool RegisterApp(const char *appName, const char *appDescription, const char *icon, int iconIndex)
{
// Create the app key
HKEY hKey;
if (RegCreateKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS)
if (RegCreateKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{
// 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
HKEY hKey2;
if (RegCreateKey (hKey, "DefaultIcon", &hKey2) == ERROR_SUCCESS)
if (RegCreateKey(hKey, _T("DefaultIcon"), &hKey2) == ERROR_SUCCESS)
{
// Set the description
char tmp[512];
smprintf (tmp, 512, "%s,%d", icon, iconIndex);
RegSetValue (hKey2, "", REG_SZ, tmp, strlen (tmp));
smprintf(tmp, 512, "%s,%d", icon, iconIndex);
tstring ttmp = utf8ToTStr(tmp);
RegSetValue(hKey2, _T(""), REG_SZ, ttmp.c_str(), (ttmp.size() + 1) * sizeof(TCHAR));
}
// 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
string tmp = string(icon)+" \"%1\"";
RegSetValue (hKey, "", REG_SZ, tmp.c_str(), tmp.size());
string tmp = string(icon) + " \"%1\"";
tstring ttmp = utf8ToTStr(tmp);
RegSetValue(hKey, _T(""), REG_SZ, ttmp.c_str(), (ttmp.size() + 1) * sizeof(TCHAR));
}
}
}
@ -75,43 +78,44 @@ bool RegisterApp (const char *appName, const char *appDescription, const char *i
}
// Unregister an application
bool UnregisterApp (const char *appName)
bool UnregisterApp(const char *appName)
{
// Delete the app key
deleteKey (HKEY_CLASSES_ROOT, appName);
deleteKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName));
return true;
}
// Unregister an application command
bool UnregisterAppCommand (const char *appName, const char *command)
bool UnregisterAppCommand(const char *appName, const char *command)
{
// Create the app key
HKEY hKey;
if (RegOpenKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS)
if (RegOpenKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{
// Create the icon
char tmp[512];
smprintf (tmp, 512, "shell\\%s", command);
deleteKey (hKey, tmp);
smprintf(tmp, 512, "shell\\%s", command);
deleteKey(hKey, nlUtf8ToTStr(tmp));
return true;
}
return false;
}
// Register an application command
bool RegisterAppCommand (const char *appName, const char *command, const char *app)
bool RegisterAppCommand(const char *appName, const char *command, const char *app)
{
// Create the app key
HKEY hKey;
if (RegCreateKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS)
if (RegCreateKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{
// Create the icon
char tmp[512];
smprintf (tmp, 512, "shell\\%s\\command", command);
if (RegCreateKey (hKey, tmp, &hKey) == ERROR_SUCCESS)
smprintf(tmp, 512, "shell\\%s\\command", command);
if (RegCreateKey(hKey, nlUtf8ToTStr(tmp), &hKey) == ERROR_SUCCESS)
{
// 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;
}
@ -119,41 +123,43 @@ bool RegisterAppCommand (const char *appName, const char *command, const char *a
}
// Unregister an application DDE command
bool UnregisterDDECommand (const char *appName, const char *command)
bool UnregisterDDECommand(const char *appName, const char *command)
{
// Create the app key
HKEY hKey;
if (RegOpenKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS)
if (RegOpenKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{
// Create the icon
char tmp[512];
smprintf (tmp, 512, "shell\\%s\\ddeexec", command);
deleteKey (hKey, tmp);
smprintf(tmp, 512, "shell\\%s\\ddeexec", command);
deleteKey(hKey, nlUtf8ToTStr(tmp));
}
return false;
}
// Register an application DDE command
bool RegisterDDECommand (const char *appName, const char *command, const char *ddeCommand, const char *application)
bool RegisterDDECommand(const char *appName, const char *command, const char *ddeCommand, const char *application)
{
// Create the app key
HKEY hKey;
if (RegCreateKey (HKEY_CLASSES_ROOT, appName, &hKey) == ERROR_SUCCESS)
if (RegCreateKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(appName), &hKey) == ERROR_SUCCESS)
{
// Create the icon
char tmp[512];
smprintf (tmp, 512, "shell\\%s\\ddeexec", command);
if (RegCreateKey (hKey, tmp, &hKey) == ERROR_SUCCESS)
smprintf(tmp, 512, "shell\\%s\\ddeexec", command);
if (RegCreateKey(hKey, nlUtf8ToTStr(tmp), &hKey) == ERROR_SUCCESS)
{
// 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;
if (RegCreateKey (hKey, "application", &hKey2) == ERROR_SUCCESS)
if (RegCreateKey(hKey, _T("application"), &hKey2) == ERROR_SUCCESS)
{
RegSetValue (hKey2, "", REG_SZ, application, strlen (application));
if (RegCreateKey (hKey, "topic", &hKey2) == ERROR_SUCCESS)
tstring tapplication = utf8ToTStr(application);
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;
}
}
@ -163,28 +169,29 @@ bool RegisterDDECommand (const char *appName, const char *command, const char *d
}
// Register a file extension
bool RegisterShellFileExt (const char *ext, const char *appName)
bool RegisterShellFileExt(const char *ext, const char *appName)
{
// Remove key in explorer registry if exist
HKEY hKey;
string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\"+string (ext);
deleteKey (HKEY_CURRENT_USER, key.c_str ());
string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + string(ext);
deleteKey(HKEY_CURRENT_USER, nlUtf8ToTStr(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
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 false;
}
// Register a file extension
bool UnregisterShellFileExt (const char *ext)
bool UnregisterShellFileExt(const char *ext)
{
// Delete the app key
if (RegDeleteKey (HKEY_CLASSES_ROOT, ext) == ERROR_SUCCESS)
if (RegDeleteKey(HKEY_CLASSES_ROOT, nlUtf8ToTStr(ext)) == ERROR_SUCCESS)
{
return true;
}

View file

@ -59,9 +59,9 @@ INT_PTR CFileDialogEx::DoModal ()
HKEY hKey;
DWORD type = REG_SZ;
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;
}
@ -76,9 +76,9 @@ INT_PTR CFileDialogEx::DoModal ()
std::string newPath = NLMISC::CFile::getPath (tStrToUtf8(GetPathName()));
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
set<string> oldPath;
@ -86,7 +86,7 @@ INT_PTR CFileDialogEx::DoModal ()
for (i=0; i<PATH_REMEBERED_SIZE; i++)
{
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 (newPath);
@ -94,9 +94,9 @@ INT_PTR CFileDialogEx::DoModal ()
uint index = 0;
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++;
index++;
}
@ -158,13 +158,13 @@ BOOL CFileDialogEx::OnInitDialog()
HKEY hKey;
DWORD type = REG_SZ;
DWORD size;
if (RegCreateKey (HKEY_CURRENT_USER, utf8ToTStr(_RegistryPath), &hKey) == ERROR_SUCCESS)
if (RegCreateKey(HKEY_CURRENT_USER, nlUtf8ToTStr(_RegistryPath), &hKey) == ERROR_SUCCESS)
{
uint i;
for (i=0; i<PATH_REMEBERED_SIZE; i++)
{
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);
}
if (m_ofn.lpstrInitialDir)

View file

@ -301,7 +301,7 @@ void CDialogFlags::setCurrentEntityDisplayMode(TEntityDisplayMode edm)
void CDialogFlags::loadEntityDisplayInfoToRegistry(TEntityDisplayInfoVect &infos, const std::string &regId)
{
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;
for(;;)
@ -338,7 +338,7 @@ void CDialogFlags::loadEntityDisplayInfoToRegistry(TEntityDisplayInfoVect &infos
void CDialogFlags::saveEntityDisplayInfoToRegistry(const TEntityDisplayInfoVect &infos, const std::string &regId)
{
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)
{

View file

@ -95,14 +95,14 @@ bool CMemoryComboBox::getMemory (int slot, std::string &ret)
{
// Open the key
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
char strSrc[512];
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);
@ -124,7 +124,7 @@ void CMemoryComboBox::scrollDown (int start, int end)
{
// 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)
{
// Scroll down the list
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);
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<StaticStrings.size(); i++)
{
_ComboBox.InsertString (count, utf8ToTStr(StaticStrings[i]));
_ComboBox.InsertString(count, nlUtf8ToTStr(StaticStrings[i]));
count++;
}
@ -458,7 +458,7 @@ void CMemoryComboBox::refreshStrings ()
std::string ret;
if (getMemory (i, ret))
{
_ComboBox.InsertString (count, utf8ToTStr(ret));
_ComboBox.InsertString(count, nlUtf8ToTStr(ret));
count++;
}
}
@ -497,7 +497,7 @@ void CMemoryComboBox::clearCommand ()
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))
{
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)
{
int index = _ComboBox.FindStringExact(0, utf8ToTStr(value));
int index = _ComboBox.FindStringExact(0, nlUtf8ToTStr(value));
if (index != CB_ERR)
{
_ComboBox.SetCurSel(index);