OSDN Git Service

PATCH: [ 1264721 ] Change AllowUpwardDirectory() policy
authorJochen Tucht <jtuc@users.sourceforge.net>
Mon, 22 Aug 2005 06:02:17 +0000 (06:02 +0000)
committerJochen Tucht <jtuc@users.sourceforge.net>
Mon, 22 Aug 2005 06:02:17 +0000 (06:02 +0000)
Src/DirDoc.cpp
Src/DirDoc.h
Src/DirView.cpp
Src/Merge.rc
Src/readme.txt
Src/resource.h

index 5292403..8a53277 100644 (file)
@@ -29,7 +29,7 @@
 //
 
 #include "stdafx.h"
-#include <Shlwapi.h>           // PathCompactPathEx()
+#include <Shlwapi.h>           // PathFindFileName()
 #include "Merge.h"
 #include "CompareStats.h"
 #include "DirDoc.h"
@@ -73,7 +73,6 @@ CDirDoc::CDirDoc()
 , m_bReuseCloses(FALSE)
 , m_bMarkedRescan(FALSE)
 , m_pTempPathContext(NULL)
-, m_cchLeftRoot(0)
 {
        DIFFOPTIONS options = {0};
 
@@ -179,7 +178,7 @@ void CDirDoc::Serialize(CArchive& ar)
  * @param [in] paths Paths to compare
  * @param [in] bRecursive If TRUE subdirectories are included to compare.
  */
-void CDirDoc::InitCompare(const PathContext & paths, BOOL bRecursive, BOOL bInitRootLength, CTempPathContext *pTempPathContext)
+void CDirDoc::InitCompare(const PathContext & paths, BOOL bRecursive, CTempPathContext *pTempPathContext)
 {
        // Anything that can go wrong here will yield an exception.
        // Default implementation of operator new() never returns NULL.
@@ -199,11 +198,6 @@ void CDirDoc::InitCompare(const PathContext & paths, BOOL bRecursive, BOOL bInit
                m_pTempPathContext->m_strLeftRoot = m_pCtxt->GetLeftPath();
                m_pTempPathContext->m_strRightRoot = m_pCtxt->GetRightPath();
        }
-
-       if (bInitRootLength)
-       {
-               m_cchLeftRoot = m_pCtxt->GetLeftPath().GetLength();
-       }
        
        m_bRecursive = bRecursive;
        // All plugin management is done by our plugin manager
@@ -217,19 +211,56 @@ void CDirDoc::InitCompare(const PathContext & paths, BOOL bRecursive, BOOL bInit
  * ParentIsRegularPath : upward ENABLED
  * ParentIsTempPath : upward ENABLED
  */
-CDirDoc::AllowUpwardDirectory::ReturnCode CDirDoc::AllowUpwardDirectory()
+CDirDoc::AllowUpwardDirectory::ReturnCode CDirDoc::AllowUpwardDirectory(CString &leftParent, CString &rightParent)
 {
-       return
-       (
-        GetLeftBasePath().GetLength() > m_cchLeftRoot
-    ||  m_pTempPathContext == NULL
-       &&  lstrcmpi(PathFindFileName(GetLeftBasePath()), 
-               PathFindFileName(GetRightBasePath())) == 0
-    ?   AllowUpwardDirectory::ParentIsRegularPath
-       :       m_pTempPathContext && m_pTempPathContext->m_pParent
-       ?       AllowUpwardDirectory::ParentIsTempPath
-       :       AllowUpwardDirectory::No
-       );
+       const CString & left = GetLeftBasePath();
+       const CString & right = GetRightBasePath();
+       LPCTSTR lname = PathFindFileName(left);
+       LPCTSTR rname = PathFindFileName(right);
+       if (m_pTempPathContext)
+       {
+               int cchLeftRoot = m_pTempPathContext->m_strLeftRoot.GetLength();
+               if (left.GetLength() <= cchLeftRoot)
+               {
+                       if (m_pTempPathContext->m_pParent)
+                       {
+                               leftParent = m_pTempPathContext->m_pParent->m_strLeftRoot;
+                               rightParent = m_pTempPathContext->m_pParent->m_strRightRoot;
+                               if (GetPairComparability(leftParent, rightParent) != IS_EXISTING_DIR)
+                                       return AllowUpwardDirectory::Never;
+                               return AllowUpwardDirectory::ParentIsTempPath;
+                       }
+                       leftParent = m_pTempPathContext->m_strLeftDisplayRoot;
+                       rightParent = m_pTempPathContext->m_strRightDisplayRoot;
+                       if (!m_pCtxt->m_piFilterGlobal->includeFile(leftParent, rightParent))
+                               return AllowUpwardDirectory::Never;
+                       if (lstrcmpi(lname, _T("ORIGINAL")) == 0 && lstrcmpi(rname, _T("ALTERED")) == 0)
+                       {
+                               leftParent = paths_GetParentPath(leftParent);
+                               rightParent = paths_GetParentPath(rightParent);
+                               rname = lname;
+                       }
+                       if (lstrcmpi(lname, rname) == 0)
+                       {
+                               leftParent = paths_GetParentPath(leftParent);
+                               rightParent = paths_GetParentPath(rightParent);
+                               if (GetPairComparability(leftParent, rightParent) != IS_EXISTING_DIR)
+                                       return AllowUpwardDirectory::Never;
+                               return AllowUpwardDirectory::ParentIsTempPath;
+                       }
+                       return AllowUpwardDirectory::No;
+               }
+               rname = lname;
+       }
+       if (lstrcmpi(lname, rname) == 0)
+       {
+               leftParent = paths_GetParentPath(left);
+               rightParent = paths_GetParentPath(right);
+               if (GetPairComparability(leftParent, rightParent) != IS_EXISTING_DIR)
+                       return AllowUpwardDirectory::Never;
+               return AllowUpwardDirectory::ParentIsRegularPath;
+       }
+       return AllowUpwardDirectory::No;
 }
 
 /**
@@ -891,9 +922,9 @@ void CDirDoc::SetTitle(LPCTSTR lpszTitle)
                CString strTitle;
                const TCHAR strSeparator[] = _T(" - ");
 
-               strTitle = paths_GetLastSubdir(m_pCtxt->GetLeftPath());
+               strTitle = PathFindFileName(m_pCtxt->GetLeftPath());
                strTitle += strSeparator;
-               strTitle += paths_GetLastSubdir(m_pCtxt->GetRightPath());
+               strTitle += PathFindFileName(m_pCtxt->GetRightPath());
                CDocument::SetTitle(strTitle);
        }       
 }
index 0730db4..f2f6ddd 100644 (file)
@@ -84,7 +84,7 @@ public:
 
 // Implementation
 public:
-       void InitCompare(const PathContext & paths, BOOL bRecursive, BOOL bSetRootLength, CTempPathContext *);
+       void InitCompare(const PathContext & paths, BOOL bRecursive, CTempPathContext *);
        void Rescan();
        BOOL GetRecursive() { return m_bRecursive; }
        BOOL GetReadOnly(BOOL bLeft) const;
@@ -132,12 +132,13 @@ public:
        {
                enum ReturnCode
                {
+                       Never,
                        No,
                        ParentIsRegularPath,
                        ParentIsTempPath
                };
        };
-       AllowUpwardDirectory::ReturnCode AllowUpwardDirectory();
+       AllowUpwardDirectory::ReturnCode AllowUpwardDirectory(CString &leftParent, CString &rightParent);
        void SetItemViewFlag(POSITION key, UINT flag, UINT mask);
        void SetItemViewFlag(UINT flag, UINT mask);
 
@@ -165,7 +166,6 @@ private:
        PluginManager m_pluginman;
        BOOL m_bReuseCloses; /**< Are we closing because of reuse? */
        BOOL m_bMarkedRescan; /**< If TRUE next rescan scans only marked items */
-       int m_cchLeftRoot; /**< Don't go upward any further */
 };
 
 //{{AFX_INSERT_LOCATION}}
index fc88e46..5a73bb0 100644 (file)
@@ -39,7 +39,7 @@
 #include "locality.h"
 #include "FileTransform.h"
 #include "SelectUnpackerDlg.h"
-#include "paths.h"     // paths_GetParentPath()
+#include "paths.h"     // GetPairComparability()
 #include "7zCommon.h"
 #include "OptionsDef.h"
 #include "BCMenu.h"
@@ -858,27 +858,19 @@ void CDirView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
 void CDirView::OpenParentDirectory()
 {
        CDirDoc *pDoc = GetDocument();
-       const CString & left = pDoc->GetLeftBasePath();
-       const CString & right = pDoc->GetRightBasePath();
-       CString leftParent = paths_GetParentPath(left);
-       CString rightParent = paths_GetParentPath(right);
-
-       if (paths_DoesPathExist(leftParent) == IS_EXISTING_DIR &&
-                       paths_DoesPathExist(rightParent) == IS_EXISTING_DIR) // &&
-                       //(pDoc->AllowUpwardDirectory() || pDoc->m_pTempPathContext && pDoc->m_pTempPathContext->m_pParent))
-       {
-               switch (pDoc->AllowUpwardDirectory())
-               {
-               case CDirDoc::AllowUpwardDirectory::ParentIsRegularPath:
-                       mf->DoFileOpen(leftParent, rightParent,
-                               FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
-                       break;
-               case CDirDoc::AllowUpwardDirectory::ParentIsTempPath:
-                       pDoc->m_pTempPathContext = pDoc->m_pTempPathContext->DeleteHead();
-                       mf->DoFileOpen(pDoc->m_pTempPathContext->m_strLeftRoot, pDoc->m_pTempPathContext->m_strRightRoot,
-                               FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
-                       break;
-               }
+       CString leftParent, rightParent;
+       switch (pDoc->AllowUpwardDirectory(leftParent, rightParent))
+       {
+       case CDirDoc::AllowUpwardDirectory::ParentIsTempPath:
+               pDoc->m_pTempPathContext = pDoc->m_pTempPathContext->DeleteHead();
+               // fall through (no break!)
+       case CDirDoc::AllowUpwardDirectory::ParentIsRegularPath:
+               mf->DoFileOpen(leftParent, rightParent,
+                       FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
+               break;
+       default:
+               AfxMessageBox(IDS_INVALID_DIRECTORY, MB_ICONSTOP);
+               break;
        }
 }
 
@@ -921,7 +913,10 @@ void CDirView::OpenSelection(PackingInfo * infoUnpacker /*= NULL*/)
                        {
                                // Open subfolders if non-recursive compare
                                // Don't add folders to MRU
-                               mf->DoFileOpen(paths.GetLeft(), paths.GetRight(), FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
+                               if (GetPairComparability(paths.GetLeft(), paths.GetRight()) == IS_EXISTING_DIR)
+                                       mf->DoFileOpen(paths.GetLeft(), paths.GetRight(), FFILEOPEN_NOMRU, FFILEOPEN_NOMRU, pDoc->GetRecursive(), pDoc);
+                               else
+                                       AfxMessageBox(IDS_INVALID_DIRECTORY, MB_ICONSTOP);
                        }
                        break;
                }
@@ -2142,17 +2137,19 @@ int CDirView::AddSpecialItems()
 {
        CDirDoc *pDoc = GetDocument();
        int retVal = 0;
-       const CString & leftPath = pDoc->GetLeftBasePath();
-       const CString & rightPath = pDoc->GetRightBasePath();
-       CString leftParent = paths_GetParentPath(leftPath);
-       CString rightParent = paths_GetParentPath(rightPath);
-
-       if (paths_DoesPathExist(leftParent) == IS_EXISTING_DIR &&
-               paths_DoesPathExist(rightParent) == IS_EXISTING_DIR)
-       {
-               BOOL bEnable = pDoc->AllowUpwardDirectory() != CDirDoc::AllowUpwardDirectory::No; //|| pDoc->m_pTempPathContext && pDoc->m_pTempPathContext->m_pParent;
+       BOOL bEnable = TRUE;
+       CString leftParent, rightParent;
+       switch (pDoc->AllowUpwardDirectory(leftParent, rightParent))
+       {
+       case CDirDoc::AllowUpwardDirectory::No:
+               bEnable = FALSE;
+               // fall through
+       default:
                AddParentFolderItem(bEnable);
                retVal = 1;
+               // fall through
+       case CDirDoc::AllowUpwardDirectory::Never:
+               break;
        }
        return retVal;
 }
index 611d473..cc072aa 100644 (file)
@@ -2074,6 +2074,7 @@ BEGIN
     IDS_SUGGEST_PRESERVEEOL "The EOL are of different types (DOS/UNIX/MAC) in the file '%1'.\n With the current options, they will be unified to the main type.\n Do you want to change the options and preserve the different EOL ?"
     IDS_PREDIFFER_ERROR      "An error occurred while prediffing the file '%1' with the plugin '%2'. The prediffing is not applied any more."
     IDS_SUGGEST_IGNORECODEPAGE "Different codepages found in left (cp%d) and right (cp%d) files. \nDisplaying each file in its codepage will give a better display but merging/copying will be dangerous.\nWould you like to treat both files as being in the default windows codepage (recommended)?"
+    IDS_INVALID_DIRECTORY   "The selected folder is invalid."
 END
 
 // EDITOR : SHOW LINE DIFF
index 27a4c5d..9ffecd7 100644 (file)
@@ -3,6 +3,8 @@
  - sscanf() was used in an unsafe way
  - GuessCodepageEncoding() did not work
   Src: codepage_detect.cpp
+ PATCH: [ 1264721 ] Change AllowUpwardDirectory() policy
+  Src: DirDoc.cpp DirDoc.h DirView.cpp Merge.rc resource.h
 
 2005-08-21 Kimmo
  PATCH: [ 1264957 ] fix Bug:[ 1246957 ] 2.3.4 regular expression replace borked
index 22b035e..f797601 100644 (file)
 #define IDS_SUGGEST_PRESERVEEOL         18008
 #define IDS_PREDIFFER_ERROR             18009
 #define IDS_SUGGEST_IGNORECODEPAGE      18010
+#define IDS_INVALID_DIRECTORY           18011
 #define IDS_LINEDIFF_NODIFF             18016
 #define IDS_LINEDIFF_NODIFF_CAPTION     18017
 #define IDS_NUM_REPLACED                18032