WinMerge 2.11.1.1
Manual: Introduction update (#2011365)
Add ShellExtension menu for drive letters (root folders) (#2011602)
+ BugFix: Use system codepage for paths (#1979429, #2008581)
WinMerge 2.10.x (R2_10) branch created (r5561)
// ID line follows -- this is updated by SVN
// $Id$
-#include "stdafx.h"
+#include <windows.h>
+
+static LPCSTR convert(LPCTSTR str, UINT codepage);
/**
* @brief Convert from Unicode to Ansi using system codepage.
*/
LPCSTR ansiconvert_SystemCP(LPCTSTR str)
{
- // These lines replace USES_CONVERSION macro
- int _convert = 0;
- UINT _acp = GetACP();
- LPCWSTR _lpw = 0;
- LPCSTR _lpa = 0;
-
- return T2CA(str);
+ return convert(str, CP_ACP);
}
/**
*/
LPCSTR ansiconvert_ThreadCP(LPCTSTR str)
{
- USES_CONVERSION;
- return T2CA(str);
+ return convert(str, CP_THREAD_ACP);
}
-
+/**
+ * @brief Convert from Unicode to Ansi using given codepage.
+ * @param [in] str String to convert.
+ * @param [in] codepage Codepage to use in conversion.
+ * @return Ansi string.
+ */
+LPCSTR convert(LPCTSTR str, UINT codepage)
+{
+#ifndef UNICODE
+ return str;
+#else
+ int len = WideCharToMultiByte(codepage, 0, str, -1, 0, 0, 0, 0);
+ if (len)
+ {
+ char * ansi = (char *)malloc(len);
+ WideCharToMultiByte(codepage, 0, str, -1, ansi, len, NULL, NULL);
+ return ansi;
+ }
+ return NULL;
+#endif
+}
// Actual paths are m_FileLocation[i].filepath
// but these are often temporary files
// Displayable (original) paths are m_sDisplayFilepath[i]
- m_inf[i].name = strdup(ansiconvert_SystemCP(m_sDisplayFilepath[i]));
+ m_inf[i].name = ansiconvert_SystemCP(m_sDisplayFilepath[i]);
if (m_inf[i].name == NULL)
return false;
path2 = m_s2File;
replace_char(&*path1.begin(), '\\', '/');
replace_char(&*path2.begin(), '\\', '/');
- inf_patch[0].name = strdup(ansiconvert_SystemCP(path1.c_str()));
- inf_patch[1].name = strdup(ansiconvert_SystemCP(path2.c_str()));
+ inf_patch[0].name = ansiconvert_SystemCP(path1.c_str());
+ inf_patch[1].name = ansiconvert_SystemCP(path2.c_str());
outfile = NULL;
if (!m_sPatchFile.IsEmpty())