OSDN Git Service

paths.*: Add paths_ToWindowsPath() and paths_ToUnixPath() function
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 26 Nov 2016 13:35:52 +0000 (22:35 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 26 Nov 2016 13:35:52 +0000 (22:35 +0900)
Src/Common/coretools.cpp
Src/Common/coretools.h
Src/DiffWrapper.cpp
Src/DirActions.cpp
Src/DirDoc.cpp
Src/DirView.cpp
Src/PatchDlg.cpp
Src/PropRegistry.cpp
Src/SourceControl.cpp
Src/paths.cpp
Src/paths.h

index b3987ff..2f83b8c 100644 (file)
@@ -6,11 +6,6 @@
  */
 
 #include "coretools.h"
-#ifdef _WIN32
-#  include <mbctype.h> // MBCS (multibyte codepage stuff)
-#else
-#  define _tcsinc(x) ((x) + 1)
-#endif
 
 size_t linelen(const char *string, size_t maxlen)
 {
@@ -25,11 +20,3 @@ size_t linelen(const char *string, size_t maxlen)
        return stringlen;
 }
 
-void replace_char(TCHAR *s, int target, int repl)
-{
-       TCHAR *p;
-       for (p=s; *p != _T('\0'); p = _tcsinc(p))
-               if (*p == target)
-                       *p = (TCHAR)repl;
-}
-
index d29b193..db7f0f5 100644 (file)
@@ -7,8 +7,6 @@
 
 #include "UnicodeString.h"
 
-void replace_char(TCHAR *s, int target, int repl);
-
 size_t linelen(const char *string, size_t maxlen);
 
 #ifdef __cplusplus
index c736695..d972aaa 100644 (file)
@@ -687,7 +687,7 @@ bool CDiffWrapper::RunFileDiff()
        PathContext files = m_files;
        int file;
        for (file = 0; file < m_files.GetSize(); file++)
-               replace_char(&*files[file].begin(), '/', '\\');
+               files[file] = paths_ToWindowsPath(files[file]);
 
        bool bRet = true;
        String strFileTemp[3];
@@ -1533,8 +1533,8 @@ void CDiffWrapper::WritePatchFile(struct change * script, file_data * inf)
                path1 = m_files[0];
        if (path2.empty())
                path2 = m_files[1];
-       replace_char(&*path1.begin(), '\\', '/');
-       replace_char(&*path2.begin(), '\\', '/');
+       path1 = paths_ToUnixPath(path1);
+       path2 = paths_ToUnixPath(path2);
        inf_patch[0].name = strdup(ucr::toSystemCP(path1).c_str());
        inf_patch[1].name = strdup(ucr::toSystemCP(path2).c_str());
 
index abd01c8..db3055d 100644 (file)
@@ -22,7 +22,6 @@
 #include "FileActionScript.h"
 #include "locality.h"
 #include "FileFilterHelper.h"
-#include "coretools.h"
 #include "OptionsMgr.h"
 
 static void ThrowConfirmCopy(const CDiffContext& ctxt, int origin, int destination, int count,
@@ -304,8 +303,8 @@ uintptr_t FindItemFromPaths(const CDiffContext& ctxt, const String& pathLeft, co
 
        // Path can contain (because of difftools?) '/' and '\'
        // so for comparing purposes, convert whole path to use '\\'
-       replace_char(&*path1.begin(), '/', '\\');
-       replace_char(&*path2.begin(), '/', '\\');
+       path1 = paths_ToWindowsPath(path1);
+       path2 = paths_ToWindowsPath(path2);
 
        String base1 = ctxt.GetLeftPath(); // include trailing backslash
        if (path1.compare(0, base1.length(), base1.c_str()) != 0)
index 86a1c88..dafbf37 100644 (file)
@@ -38,7 +38,6 @@
 #include "DirView.h"
 #include "DirFrame.h"
 #include "MainFrm.h"
-#include "coretools.h"
 #include "paths.h"
 #include "7zCommon.h"
 #include "OptionsDef.h"
index bba04be..7bcf36b 100644 (file)
@@ -38,7 +38,6 @@
 #include "FileLocation.h"
 #include "MainFrm.h"
 #include "resource.h"
-#include "coretools.h"
 #include "FileTransform.h"
 #include "SelectUnpackerDlg.h"
 #include "paths.h"
index 0016969..3472d77 100644 (file)
@@ -24,7 +24,6 @@
 #include "PatchDlg.h"
 #include "PatchTool.h"
 #include "diff.h"
-#include "coretools.h"
 #include "paths.h"
 #include "CompareOptions.h"
 #include "PatchHTML.h"
index bc7780f..31960f0 100644 (file)
@@ -23,7 +23,6 @@
 #include "stdafx.h"
 #include "PropRegistry.h"
 #include "RegKey.h"
-#include "coretools.h"
 #include "FileOrFolderSelect.h"
 #include "OptionsDef.h"
 #include "OptionsMgr.h"
index 9d1059b..034c439 100644 (file)
@@ -247,7 +247,7 @@ bool SourceControl::SaveToVersionControl(const String& strSavePath)
                _tcslwr(buffer2);
 
                //make sure they both have \\ instead of /
-               replace_char(buffer1, '/', '\\');
+               _tcscpy_safe(buffer1, paths_ToWindowsPath(buffer1).c_str());
 
                m_vssHelper.SetProjectBase(buffer2);
                TCHAR * pbuf2 = &buffer2[2];//skip the $/
index 358f6a4..de4e4a5 100644 (file)
@@ -762,3 +762,25 @@ bool paths_IsDecendant(const String& path, const String& ancestor)
        return path.length() > ancestor.length() && 
                   string_compare_nocase(String(path.c_str(), path.c_str() + ancestor.length()), ancestor) == 0;
 }
+
+static void replace_char(TCHAR *s, int target, int repl)
+{
+       TCHAR *p;
+       for (p=s; *p != _T('\0'); p = _tcsinc(p))
+               if (*p == target)
+                       *p = (TCHAR)repl;
+}
+
+String paths_ToWindowsPath(const String& path)
+{
+       String winpath = path;
+       replace_char(&*winpath.begin(), '/', '\\');
+       return winpath;
+}
+
+String paths_ToUnixPath(const String& path)
+{
+       String unixpath = path;
+       replace_char(&*unixpath.begin(), '\\', '/');
+       return unixpath;
+}
index 4de1681..eda3c6a 100644 (file)
@@ -42,3 +42,5 @@ String paths_GetPathOnly(const String& fullpath);
 bool paths_IsURLorCLSID(const String& path);
 bool paths_IsDecendant(const String& path, const String& ancestor);
 inline String paths_AddTrailingSlash(const String& path) { return !paths_EndsWithSlash(path) ? path + _T("\\") : path; }
+String paths_ToWindowsPath(const String& path);
+String paths_ToUnixPath(const String& path);