From a184dd7d8fbf836cb3102be1b2be9f26b909c4a7 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 10 Dec 2016 13:01:27 +0100 Subject: [PATCH] Changed: Convert std::string <> TCHAR --- .../3d/object_viewer/particle_tree_ctrl.cpp | 3 ++- .../3d/plugin_max/nel_export/progress.cpp | 3 ++- .../georges_dll/edit_list_ctrl.cpp | 2 +- .../world_editor/file_dialog_ex.cpp | 25 ++++++++++++++++--- .../DialogFlags.cpp | 12 ++++++--- .../world_editor_sound_plugin/DialogFlags.cpp | 18 +++++++------ 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/code/nel/tools/3d/object_viewer/particle_tree_ctrl.cpp b/code/nel/tools/3d/object_viewer/particle_tree_ctrl.cpp index 49eede1c9..332a5163e 100644 --- a/code/nel/tools/3d/object_viewer/particle_tree_ctrl.cpp +++ b/code/nel/tools/3d/object_viewer/particle_tree_ctrl.cpp @@ -1528,7 +1528,8 @@ void CParticleTreeCtrl::insertNewPS(CParticleWorkspace &pws) CFileDialog fd(TRUE, _T(".ps"), _T("*.ps"), OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST, szFilter, this); const uint MAX_NUM_CHAR = 65536; TCHAR filenamesBuf[MAX_NUM_CHAR]; - _tcscpy(filenamesBuf, _T("*.ps")); + _tcscpy_s(filenamesBuf, MAX_NUM_CHAR, _T("*.ps")); + fd.m_ofn.lpstrFile = filenamesBuf; fd.m_ofn.nMaxFile = MAX_NUM_CHAR - 1; if (fd.DoModal() == IDOK) diff --git a/code/nel/tools/3d/plugin_max/nel_export/progress.cpp b/code/nel/tools/3d/plugin_max/nel_export/progress.cpp index 8a8973154..17b3fab2a 100644 --- a/code/nel/tools/3d/plugin_max/nel_export/progress.cpp +++ b/code/nel/tools/3d/plugin_max/nel_export/progress.cpp @@ -62,7 +62,8 @@ INT_PTR CALLBACK CalculatingDialogCallback ( (((uint32)TimeLeft)/60)%60, (((uint32)TimeLeft))%60 ); if (pClass->bCancelCalculation) - _tcscpy (temp, _T("INTERRUPTED - Finishing current object...")); + _tcscpy_s (temp, 256, _T("INTERRUPTED - Finishing current object...")); + SendMessage (GetDlgItem (hwndDlg, IDC_STATICTIMELEFT), WM_SETTEXT, 0, (LPARAM)temp); SendMessage (GetDlgItem (hwndDlg, IDC_BUTTONCANCEL), WM_PAINT, 0, 0); } diff --git a/code/ryzom/tools/leveldesign/georges_dll/edit_list_ctrl.cpp b/code/ryzom/tools/leveldesign/georges_dll/edit_list_ctrl.cpp index 4efdf0c16..0b16abd4f 100644 --- a/code/ryzom/tools/leveldesign/georges_dll/edit_list_ctrl.cpp +++ b/code/ryzom/tools/leveldesign/georges_dll/edit_list_ctrl.cpp @@ -312,7 +312,7 @@ LRESULT CMyListCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) Ctrl->getBrowseInfo (Ctrl->Item, Ctrl->SubItem, defExt, defFilename, defDir, filter); TCHAR buffer[MAX_PATH]; - _tcscpy(buffer, utf8ToTStr(defDir)); + _tcscpy_s(buffer, MAX_PATH, utf8ToTStr(defDir)); CFileDialog dlgFile (TRUE, utf8ToTStr(defExt), utf8ToTStr(defFilename), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, utf8ToTStr(filter), theApp.m_pMainWnd); dlgFile.m_ofn.lpstrInitialDir = buffer; diff --git a/code/ryzom/tools/leveldesign/world_editor/world_editor/file_dialog_ex.cpp b/code/ryzom/tools/leveldesign/world_editor/world_editor/file_dialog_ex.cpp index 706c4053e..aa23e4013 100644 --- a/code/ryzom/tools/leveldesign/world_editor/world_editor/file_dialog_ex.cpp +++ b/code/ryzom/tools/leveldesign/world_editor/world_editor/file_dialog_ex.cpp @@ -73,9 +73,19 @@ INT_PTR CFileDialogEx::DoModal () if ((result = CFileDialog::DoModal ()) == IDOK) { // Update the path - std::string newPath = tStrToUtf8(GetPathName ()); - newPath = NLMISC::CFile::getPath (newPath); - RegSetValueEx (hKey, utf8ToTStr(_FileType), 0, REG_SZ, (LPBYTE)newPath.c_str (), newPath.size ()+1); + std::string newPath = NLMISC::CFile::getPath (tStrToUtf8(GetPathName())); + +#ifdef _UNICODE + ucstring tmp; + tmp.fromUtf8(newPath); + const uint cs = 2; +#else + std::stringg tmp = newPath; + const uint cs = 1; +#endif + uint length = (tmp.length() + 1) * cs; + + RegSetValueEx (hKey, utf8ToTStr(_FileType), 0, REG_SZ, (LPBYTE)tmp.c_str(), length); // Update the path list set oldPath; @@ -91,7 +101,14 @@ INT_PTR CFileDialogEx::DoModal () uint index = 0; while (ite != oldPath.end ()) { - RegSetValueEx (hKey, utf8ToTStr(toString(index)), 0, REG_SZ, (LPBYTE)ite->c_str (), ite->size ()+1); +#ifdef _UNICODE + tmp.fromUtf8(*ite); +#else + tmp = *ite; +#endif + length = (tmp.length() + 1) * cs; + + RegSetValueEx (hKey, utf8ToTStr(toString(index)), 0, REG_SZ, (LPBYTE)tmp.c_str (), length); ite++; index++; } diff --git a/code/ryzom/tools/leveldesign/world_editor/world_editor_shard_monitor_plugin/DialogFlags.cpp b/code/ryzom/tools/leveldesign/world_editor/world_editor_shard_monitor_plugin/DialogFlags.cpp index 54184c45a..12c3d9b88 100644 --- a/code/ryzom/tools/leveldesign/world_editor/world_editor_shard_monitor_plugin/DialogFlags.cpp +++ b/code/ryzom/tools/leveldesign/world_editor/world_editor_shard_monitor_plugin/DialogFlags.cpp @@ -318,7 +318,7 @@ void CDialogFlags::loadEntityDisplayInfoToRegistry(TEntityDisplayInfoVect &infos if (infos[k].Value == value) { int r, g, b, visible; - if (sscanf((const char *) dataStr, "%d, %d, %d, visible = %d", &r, &g, &b, &visible) == 4) + if (_stscanf((const TCHAR *) dataStr, _T("%d, %d, %d, visible = %d"), &r, &g, &b, &visible) == 4) { infos[k].Color = CRGBA(r, g, b); infos[k].Visible = visible != 0; @@ -342,10 +342,14 @@ void CDialogFlags::saveEntityDisplayInfoToRegistry(const TEntityDisplayInfoVect { for(uint k = 0; k < infos.size(); ++k) { - char colorStr[128]; CRGBA color = infos[k].Color; - sprintf(colorStr, "%d, %d, %d, visible = %d", (int) color.R, (int) color.G, (int) color.B, (int) (infos[k].Visible ? 1 : 0)); - LONG result = RegSetValueEx(hKey, utf8ToTStr(toString(infos[k].Value)), 0, REG_SZ, (const BYTE *) colorStr, strlen(colorStr)); + + TCHAR colorStr[32]; + _stprintf_s(colorStr, 32, _T("%d, %d, %d, visible = %d"), (int) color.R, (int) color.G, (int) color.B, (int) (infos[k].Visible ? 1 : 0)); + + TCHAR id[16]; + + LONG result = RegSetValueEx(hKey, _itot(infos[k].Value, id, 10), 0, REG_SZ, (const BYTE *)colorStr, (_tcslen(colorStr) + 1)*sizeof(TCHAR)); if (result != ERROR_SUCCESS) { nlwarning("Couldn't write registry key for entity % color", infos[k].Name); diff --git a/code/ryzom/tools/leveldesign/world_editor/world_editor_sound_plugin/DialogFlags.cpp b/code/ryzom/tools/leveldesign/world_editor/world_editor_sound_plugin/DialogFlags.cpp index a83578c9f..55cbbd25c 100644 --- a/code/ryzom/tools/leveldesign/world_editor/world_editor_sound_plugin/DialogFlags.cpp +++ b/code/ryzom/tools/leveldesign/world_editor/world_editor_sound_plugin/DialogFlags.cpp @@ -225,7 +225,11 @@ void CDialogFlags::OnTimer(UINT_PTR nIDEvent) c = _SbList.GetItemCount(); for (i=0; i