//
#include "stdafx.h"
-#include <Shlwapi.h> // PathCompactPathEx()
+#include <Shlwapi.h> // PathFindFileName()
#include "Merge.h"
#include "CompareStats.h"
#include "DirDoc.h"
, m_bReuseCloses(FALSE)
, m_bMarkedRescan(FALSE)
, m_pTempPathContext(NULL)
-, m_cchLeftRoot(0)
{
DIFFOPTIONS options = {0};
* @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.
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
* 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;
}
/**
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);
}
}
// 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;
{
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);
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}}
#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"
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;
}
}
{
// 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;
}
{
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;
}
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
- 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
#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