From: Kimmo Varis Date: Thu, 3 Jul 2008 19:39:57 +0000 (+0000) Subject: PATCH: [ 2008581 ] Convert paths using system codepage X-Git-Tag: 2.16.5~3213 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=adec568d07c747e4962177e36180fbf3cfea3e33;p=winmerge-jp%2Fwinmerge-jp.git PATCH: [ 2008581 ] Convert paths using system codepage Patch idea from rarevisitor --- diff --git a/Docs/Users/ChangeLog.txt b/Docs/Users/ChangeLog.txt index 17833e758..97f02215e 100644 --- a/Docs/Users/ChangeLog.txt +++ b/Docs/Users/ChangeLog.txt @@ -10,6 +10,7 @@ WinMerge 2.9.1.5 Release Notes update (#2007673) BugFix: Possible crash when enabling line filter (#2004160) BugFix: Location Pane flickers when scrolling (#1938177, #2005031) + BugFix: Use system codepage for paths (#1979429, #2008581) Translation updates: - Chinese Traditional (#2007426) diff --git a/Src/AnsiConvert.cpp b/Src/AnsiConvert.cpp new file mode 100644 index 000000000..e967638f5 --- /dev/null +++ b/Src/AnsiConvert.cpp @@ -0,0 +1,44 @@ +/** + * @file AnsiConvert.cpp + * + * @brief Implementation file for Unicode to ANSI conversion routines. + * + */ +// ID line follows -- this is updated by SVN +// $Id$ + +#include "stdafx.h" + +/** + * @brief Convert from Unicode to Ansi using system codepage. + * This function converts Unicode string to ansi string using system codepage. + * This conversion function should be used when converting strings containing + * paths. As paths are handled by the system and are not file content. + * @param [in] str String to convert. + * @return Ansi string. + */ +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); +} + +/** + * @brief Convert from Unicode to Ansi using thread codepage. + * This function converts Unicode string to ansi string using thread codepage. + * Thread codepage is practically the codepage WinMerge is using internally. + * @param [in] str String to convert. + * @return Ansi string. + */ +LPCSTR ansiconvert_ThreadCP(LPCTSTR str) +{ + USES_CONVERSION; + return T2CA(str); +} + + diff --git a/Src/AnsiConvert.h b/Src/AnsiConvert.h new file mode 100644 index 000000000..8faf64ce1 --- /dev/null +++ b/Src/AnsiConvert.h @@ -0,0 +1,16 @@ +/** + * @file AnsiConvert.h + * + * @brief Declaration file for routines to convert from Unicode to ANSI. + * + */ +// ID line follows -- this is updated by SVN +// $Id$ + +#ifndef _ANSI_CONVERST_H_ +#define _ANSI_CONVERT_H_ + +LPCSTR ansiconvert_SystemCP(LPCTSTR str); +LPCSTR ansiconvert_ThreadCP(LPCTSTR str); + +#endif // _ANSI_CONVERT_H_ diff --git a/Src/DiffFileData.cpp b/Src/DiffFileData.cpp index ec448d459..cf4eba383 100644 --- a/Src/DiffFileData.cpp +++ b/Src/DiffFileData.cpp @@ -19,6 +19,7 @@ #include "common/unicoder.h" #include "codepage_detect.h" #include +#include "AnsiConvert.h" #include "DiffFileData.h" @@ -83,11 +84,10 @@ bool DiffFileData::DoOpenFiles() for (int i=0; i<2; ++i) { // Fill in 8-bit versions of names for diffutils (WinMerge doesn't use these) - USES_CONVERSION; // 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(T2CA(m_sDisplayFilepath[i])); + m_inf[i].name = strdup(ansiconvert_SystemCP(m_sDisplayFilepath[i])); if (m_inf[i].name == NULL) return false; diff --git a/Src/DiffWrapper.cpp b/Src/DiffWrapper.cpp index b3b7e4ece..71498305f 100644 --- a/Src/DiffWrapper.cpp +++ b/Src/DiffWrapper.cpp @@ -44,6 +44,7 @@ #include "FolderCmp.h" #include "FilterCommentsManager.h" #include "Environment.h" +#include "AnsiConvert.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -662,12 +663,10 @@ BOOL CDiffWrapper::RunFileDiff() replace_char(&*filepath2.begin(), '/', '\\'); BOOL bRet = TRUE; - USES_CONVERSION; String strFile1Temp = filepath1; String strFile2Temp = filepath2; m_options.SetToDiffUtils(); - //SwapToInternalSettings(); if (m_bUseDiffList) m_nDiffs = m_pDiffList->GetSize(); @@ -1190,7 +1189,6 @@ CDiffWrapper::LoadWinMergeDiffsFromDiffUtilsScript(struct change * script, const */ void CDiffWrapper::WritePatchFile(struct change * script, file_data * inf) { - USES_CONVERSION; file_data inf_patch[2] = {0}; CopyMemory(&inf_patch, inf, sizeof(file_data) * 2); @@ -1204,8 +1202,8 @@ void CDiffWrapper::WritePatchFile(struct change * script, file_data * inf) path2 = m_s2File; replace_char(&*path1.begin(), '\\', '/'); replace_char(&*path2.begin(), '\\', '/'); - inf_patch[0].name = strdup(T2CA(path1.c_str())); - inf_patch[1].name = strdup(T2CA(path2.c_str())); + inf_patch[0].name = strdup(ansiconvert_SystemCP(path1.c_str())); + inf_patch[1].name = strdup(ansiconvert_SystemCP(path2.c_str())); outfile = NULL; if (!m_sPatchFile.IsEmpty()) diff --git a/Src/DirCmpReport.cpp b/Src/DirCmpReport.cpp index d9dcfc1fa..ce8c17da7 100644 --- a/Src/DirCmpReport.cpp +++ b/Src/DirCmpReport.cpp @@ -16,6 +16,7 @@ #include "coretools.h" #include "WaitStatusCursor.h" #include "paths.h" +#include "AnsiConvert.h" #include UINT CF_HTML = RegisterClipboardFormat(_T("HTML Format")); @@ -222,8 +223,7 @@ void DirCmpReport::GenerateReport(REPORT_TYPE nReportType) */ void DirCmpReport::WriteString(LPCTSTR pszText) { - USES_CONVERSION; - LPCSTR pchOctets = T2A((LPTSTR)pszText); + LPCSTR pchOctets = ansiconvert_ThreadCP((LPTSTR)pszText); size_t cchAhead = strlen(pchOctets); while (LPCSTR pchAhead = (LPCSTR)memchr(pchOctets, '\n', cchAhead)) { diff --git a/Src/Merge.vcproj b/Src/Merge.vcproj index 71a46a7de..f6fd287b5 100644 --- a/Src/Merge.vcproj +++ b/Src/Merge.vcproj @@ -388,6 +388,42 @@ + + + + + + + + + + + + + @@ -5934,6 +5970,9 @@ RelativePath="AboutDlg.h"> + +