OSDN Git Service

PATCH: [ 2008581 ] Convert paths using system codepage
authorKimmo Varis <kimmov@gmail.com>
Thu, 3 Jul 2008 19:39:57 +0000 (19:39 +0000)
committerKimmo Varis <kimmov@gmail.com>
Thu, 3 Jul 2008 19:39:57 +0000 (19:39 +0000)
 Patch idea from rarevisitor

Docs/Users/ChangeLog.txt
Src/AnsiConvert.cpp [new file with mode: 0644]
Src/AnsiConvert.h [new file with mode: 0644]
Src/DiffFileData.cpp
Src/DiffWrapper.cpp
Src/DirCmpReport.cpp
Src/Merge.vcproj

index 17833e7..97f0221 100644 (file)
@@ -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 (file)
index 0000000..e967638
--- /dev/null
@@ -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 (file)
index 0000000..8faf64c
--- /dev/null
@@ -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_
index ec448d4..cf4eba3 100644 (file)
@@ -19,6 +19,7 @@
 #include "common/unicoder.h"
 #include "codepage_detect.h"
 #include <shlwapi.h>
+#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;
 
index b3b7e4e..7149830 100644 (file)
@@ -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())
index d9dcfc1..ce8c17d 100644 (file)
@@ -16,6 +16,7 @@
 #include "coretools.h"
 #include "WaitStatusCursor.h"
 #include "paths.h"
+#include "AnsiConvert.h"
 #include <afxadv.h>
 
 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))
        {
index 71a46a7..f6fd287 100644 (file)
                                </FileConfiguration>
                        </File>
                        <File
+                               RelativePath=".\AnsiConvert.cpp">
+                               <FileConfiguration
+                                       Name="UnicodeRelease|Win32">
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                               Optimization="1"
+                                               AdditionalIncludeDirectories=""
+                                               PreprocessorDefinitions="WIN32;_WINDOWS;_AFXDLL;EDITPADC_CLASS=;COMPILE_MULTIMON_STUBS;UNICODE;_UNICODE;$(NoInherit)"/>
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="UnicodeDebug|Win32">
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                               Optimization="0"
+                                               AdditionalIncludeDirectories=""
+                                               PreprocessorDefinitions=""
+                                               BrowseInformation="1"/>
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Debug|Win32">
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                               Optimization="0"
+                                               AdditionalIncludeDirectories=""
+                                               PreprocessorDefinitions=""
+                                               BrowseInformation="1"/>
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release|Win32">
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                               Optimization="1"
+                                               AdditionalIncludeDirectories=""
+                                               PreprocessorDefinitions="WIN32;_WINDOWS;_MBCS;_AFXDLL;EDITPADC_CLASS=;COMPILE_MULTIMON_STUBS;$(NoInherit)"/>
+                               </FileConfiguration>                    </File>
+                       <File
                                RelativePath="BCMenu.cpp">
                                <FileConfiguration
                                        Name="UnicodeRelease|Win32">
                                RelativePath="AboutDlg.h">
                        </File>
                        <File
+                               RelativePath=".\AnsiConvert.h">
+                       </File>
+                       <File
                                RelativePath="BCMenu.h">
                        </File>
                        <File