, __int64 lmtime, __int64 rmtime
, __int64 lctime, __int64 rctime
, __int64 lsize, __int64 rsize
- , BYTE code
+ , int diffcode
)
{
DIFFITEM di;
di.right.mtime = rmtime;
di.left.ctime = lctime;
di.right.ctime = rctime;
- di.code = code;
+ di.diffcode = diffcode;
di.left.size = lsize;
di.right.size = rsize;
UpdateFieldsNeededForNewItems(di, di.left);
m_pList->AddTail(di);
// ignore return value
- SendMessage(m_hMainFrame, m_msgUpdateStatus, di.code, NULL);
+ SendMessage(m_hMainFrame, m_msgUpdateStatus, di.diffcode, NULL);
}
void CDiffContext::RemoveDiff(POSITION diffpos)
return m_pList->GetNext(diffpos);
}
-DIFFITEM CDiffContext::GetDiffAt(POSITION diffpos)
+const DIFFITEM & CDiffContext::GetDiffAt(POSITION diffpos) const
{
return m_pList->GetAt(diffpos);
}
-const DIFFITEM CDiffContext::GetDiffAt(POSITION diffpos) const
-{
- return m_pList->GetAt(diffpos);
-}
-
-BYTE CDiffContext::GetDiffStatus(POSITION diffpos)
-{
- return m_pList->GetAt(diffpos).code;
-}
-
int CDiffContext::GetDiffCount()
{
return m_pList->GetCount();
}
-void CDiffContext::UpdateStatusCode(POSITION diffpos, BYTE status)
+void CDiffContext::SetDiffStatusCode(POSITION diffpos, UINT diffcode, UINT mask)
{
+ ASSERT(diffpos);
DIFFITEM & di = m_pList->GetAt(diffpos);
- di.code = status;
+ ASSERT(! ((~mask) && diffcode) ); // make sure they only set flags in their mask
+ di.diffcode = di.diffcode & (~mask); // remove current data
+ di.diffcode = di.diffcode | diffcode; // add new data
}
/**
}
/**
- * @brief Update information from disk
+ * @brief Update the diffitem passed from disk
*/
void CDiffContext::UpdateInfoFromDisk(DIFFITEM & di)
{
}
/**
+ * @brief Update info in list (specified by position) from disk
+ */
+void CDiffContext::UpdateStatusFromDisk(POSITION diffpos)
+{
+ UpdateInfoFromDisk(m_pList->GetAt(diffpos));
+}
+
+/**
* @brief Convert a FILETIME to a long (standard time)
*/
static __int64 FileTimeToInt64(FILETIME & ft)
};
// values for DIFFITEM.code
+namespace DIFFCODE {
+ enum {
+ // We use extra bits so that no valid values are 0
+ // and each set of flags is in a different hex digit
+ // to make debugging easier
+ // These can always be packed down in the future
+ TEXTFLAG=0x3, TEXT=0x1, BIN=0x2,
+ DIRFLAG=0x30, FILE=0x10, DIR=0x20,
+ SIDEFLAG=0x300, LEFT=0x100, RIGHT=0x200, BOTH=0x300,
+ COMPAREFLAGS=0x7000, SAME=0x1000, DIFF=0x2000, SKIPPED=0x3000, CMPERR=0x4000
+ };
+};
+// old codes
+/* TODO: delete
#define FILE_LUNIQUE 0
#define FILE_RUNIQUE 1
#define FILE_DIFF 2
#define FILE_RDIRUNIQUE 8
#define FILE_SKIP 9
#define FILE_DIRSKIP 10
+*/
struct FileFlags
{
CString sfilename;
CString sSubdir; //*< Common subdirectory from root of comparison */
CString sext;
- BYTE code;
+ int diffcode;
+
+ DIFFITEM() : diffcode(0) { }
+
CString getLeftFilepath() const;
CString getRightFilepath() const;
- DIFFITEM() : code(0) { }
+
+ // file/directory
+ bool isDirectory() const { return ((diffcode & DIFFCODE::DIRFLAG) == DIFFCODE::DIR); }
+ // left/right
+ bool isSideLeft() const { return ((diffcode & DIFFCODE::SIDEFLAG) == DIFFCODE::LEFT); }
+ bool isSideRight() const { return ((diffcode & DIFFCODE::SIDEFLAG) == DIFFCODE::RIGHT); }
+ // result filters
+ bool isResultError() const { return ((diffcode & DIFFCODE::COMPAREFLAGS) == DIFFCODE::CMPERR); }
+ bool isResultSame() const { return ((diffcode & DIFFCODE::COMPAREFLAGS) == DIFFCODE::SAME); }
+ bool isResultSkipped() const { return ((diffcode & DIFFCODE::COMPAREFLAGS) == DIFFCODE::SKIPPED); }
+ // type
+ bool isBin() const { return ((diffcode & DIFFCODE::TEXTFLAG) == DIFFCODE::BIN); }
};
// Interface for reporting current file, as diff traverses file tree
// add & remove differences
void AddDiff(LPCTSTR pszFilename, LPCTSTR szSubdir, LPCTSTR pszLeftDir, LPCTSTR pszRightDir
, __int64 lmtime, __int64 rmtime, __int64 lctime, __int64 rctime
- , __int64 lsize, __int64 rsize, BYTE code);
+ , __int64 lsize, __int64 rsize, int diffcode);
void AddDiff(DIFFITEM di);
void RemoveDiff(POSITION diffpos);
void RemoveAll();
// to iterate over all differences on list
POSITION GetFirstDiffPosition();
DIFFITEM GetNextDiffPosition(POSITION & diffpos);
- DIFFITEM GetDiffAt(POSITION diffpos);
- const DIFFITEM GetDiffAt(POSITION diffpos) const;
- BYTE GetDiffStatus(POSITION diffpos);
+// DIFFITEM GetDiffAt(POSITION diffpos);
+ const DIFFITEM & GetDiffAt(POSITION diffpos) const;
+// int GetDiffStatus(POSITION diffpos);
int GetDiffCount();
// change an existing difference
- void UpdateStatusCode(POSITION diffpos, BYTE status);
+ void SetDiffStatusCode(POSITION diffpos, UINT diffcode, UINT mask);
void UpdateInfoFromDisk(DIFFITEM & di);
void UpdateInfoFromDiskHalf(DIFFITEM & di, DiffFileInfo & dfi);
+ void UpdateStatusFromDisk(POSITION diffpos);
BOOL m_bRecurse;
CString m_strLeft;
return (rtn==IDYES);
}
-static BOOL
-IsItemCodeDir(int code)
-{
- return code==FILE_LDIRUNIQUE || code==FILE_RDIRUNIQUE;
-}
-
// Prompt & copy item from right to left, if legal
void CDirView::DoCopyFileToLeft()
{
while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemCopyableToLeft(di.code))
+ if (IsItemCopyableToLeft(di))
{
GetItemFileNames(sel, slFile, srFile);
action act;
act.src = srFile;
act.dest = slFile;
act.idx = sel;
- act.code = di.code;
- act.dirflag = IsItemCodeDir(di.code);
+ act.code = di.diffcode;
+ act.dirflag = di.isDirectory();
actionList.actions.AddTail(act);
}
++actionList.selcount;
while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemCopyableToRight(di.code))
+ if (IsItemCopyableToRight(di))
{
GetItemFileNames(sel, slFile, srFile);
action act;
act.src = slFile;
act.dest = srFile;
- act.dirflag = IsItemCodeDir(di.code);
+ act.dirflag = di.isDirectory();
act.idx = sel;
- act.code = di.code;
+ act.code = di.diffcode;
actionList.actions.AddTail(act);
}
++actionList.selcount;
while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemDeletableOnLeft(di.code))
+ if (IsItemDeletableOnLeft(di))
{
GetItemFileNames(sel, slFile, srFile);
action act;
act.src = slFile;
- act.dirflag = IsItemCodeDir(di.code);
+ act.dirflag = di.isDirectory();
act.idx = sel;
- act.code = di.code;
+ act.code = di.diffcode;
actionList.actions.AddTail(act);
}
++actionList.selcount;
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemDeletableOnRight(di.code))
+ if (IsItemDeletableOnRight(di))
{
GetItemFileNames(sel, slFile, srFile);
action act;
act.src = srFile;
- act.dirflag = IsItemCodeDir(di.code);
+ act.dirflag = di.isDirectory();
act.idx = sel;
- act.code = di.code;
+ act.code = di.diffcode;
actionList.actions.AddTail(act);
}
++actionList.selcount;
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemDeletableOnBoth(di.code))
+ if (IsItemDeletableOnBoth(di))
{
GetItemFileNames(sel, slFile, srFile);
action act;
act.src = srFile;
act.dest = slFile;
- act.dirflag = IsItemCodeDir(di.code);
+ act.dirflag = di.isDirectory();
act.idx = sel;
- act.code = di.code;
+ act.code = di.diffcode;
actionList.actions.AddTail(act);
}
++actionList.selcount;
// copy single file, and update status immediately
if (mf->SyncFiles(act.src, act.dest, &s))
{
- if (act.code == FILE_BINDIFF)
- mf->UpdateCurrentFileStatus(GetDocument(), FILE_BINSAME, act.idx);
- else
- mf->UpdateCurrentFileStatus(GetDocument(), FILE_SAME, act.idx);
+ GetDocument()->SetDiffStatus(DIFFCODE::SAME, DIFFCODE::COMPAREFLAGS, act.idx);
}
else
{
{
// figure out if copy on right
POSITION diffpos = GetItemKey(act.idx);
- BYTE code = GetDiffContext()->GetDiffStatus(diffpos);
- if (IsItemLeftOnly(code))
+ const DIFFITEM & di = GetDiffContext()->GetDiffAt(diffpos);
+ if (di.isSideLeft())
actionList.deletedItems.AddTail(act.idx);
else
- mf->UpdateCurrentFileStatus(GetDocument(), FILE_RUNIQUE, act.idx);
+ GetDocument()->SetDiffStatus(DIFFCODE::RIGHT, DIFFCODE::SIDEFLAG, act.idx);
}
else
{
{
// figure out if copy on right
POSITION diffpos = GetItemKey(act.idx);
- BYTE code = GetDiffContext()->GetDiffStatus(diffpos);
- if (IsItemRightOnly(code))
+ const DIFFITEM & di = GetDiffContext()->GetDiffAt(diffpos);
+ if (di.isSideRight())
actionList.deletedItems.AddTail(act.idx);
else
- mf->UpdateCurrentFileStatus(GetDocument(), FILE_LUNIQUE, act.idx);
+ GetDocument()->SetDiffStatus(DIFFCODE::LEFT, DIFFCODE::SIDEFLAG, act.idx);
}
else
{
return bResult;
}
-// Does item exist only on the left ?
-BOOL CDirView::IsItemLeftOnly(int code)
-{
- return code==FILE_LUNIQUE || code==FILE_LDIRUNIQUE;
-}
-// Does item exist only on the right ?
-BOOL CDirView::IsItemRightOnly(int code)
-{
- return code==FILE_RUNIQUE || code==FILE_RDIRUNIQUE;
-}
-
// is it possible to copy item to left ?
-BOOL CDirView::IsItemCopyableToLeft(int code)
-{
- switch(code)
- {
- case FILE_RUNIQUE:
- case FILE_DIFF:
- case FILE_BINDIFF:
- return TRUE;
- // no point in allowing FILE_SAME
- // TODO: FILE_RDIRUNIQUE: add code for directory copy
- }
- return FALSE;
+BOOL CDirView::IsItemCopyableToLeft(const DIFFITEM & di)
+{
+ // don't let them mess with error items
+ if (di.isResultError()) return FALSE;
+ // no directory copying right now
+ if (di.isDirectory()) return FALSE;
+ // can't copy same items
+ if (di.isResultSame()) return FALSE;
+ // impossible if only on left
+ if (di.isSideLeft()) return FALSE;
+
+ // everything else can be copied to left
+ return TRUE;
}
// is it possible to copy item to right ?
-BOOL CDirView::IsItemCopyableToRight(int code)
-{
- switch(code)
- {
- case FILE_LUNIQUE:
- case FILE_DIFF:
- case FILE_BINDIFF:
- return TRUE;
- // no point in allowing FILE_SAME
- // TODO: FILE_LDIRUNIQUE: add code for directory copy
- }
- return FALSE;
+BOOL CDirView::IsItemCopyableToRight(const DIFFITEM & di)
+{
+ // don't let them mess with error items
+ if (di.isResultError()) return FALSE;
+ // no directory copying right now
+ if (di.isDirectory()) return FALSE;
+ // can't copy same items
+ if (di.isResultSame()) return FALSE;
+ // impossible if only on right
+ if (di.isSideRight()) return FALSE;
+
+ // everything else can be copied to right
+ return TRUE;
}
// is it possible to delete left item ?
-BOOL CDirView::IsItemDeletableOnLeft(int code)
+BOOL CDirView::IsItemDeletableOnLeft(const DIFFITEM & di)
{
- switch(code)
- {
- case FILE_LUNIQUE:
- case FILE_DIFF:
- case FILE_BINSAME:
- case FILE_BINDIFF:
- case FILE_SAME:
- case FILE_LDIRUNIQUE:
- return TRUE;
- }
- return FALSE;
+ // don't let them mess with error items
+ if (di.isResultError()) return FALSE;
+ // impossible if only on right
+ if (di.isSideRight()) return FALSE;
+ // everything else can be deleted on left
+ return TRUE;
}
// is it possible to delete right item ?
-BOOL CDirView::IsItemDeletableOnRight(int code)
+BOOL CDirView::IsItemDeletableOnRight(const DIFFITEM & di)
{
- switch(code)
- {
- case FILE_RUNIQUE:
- case FILE_DIFF:
- case FILE_BINSAME:
- case FILE_BINDIFF:
- case FILE_SAME:
- case FILE_RDIRUNIQUE:
- return TRUE;
- }
- return FALSE;
+ // don't let them mess with error items
+ if (di.isResultError()) return FALSE;
+ // impossible if only on right
+ if (di.isSideLeft()) return FALSE;
+
+ // everything else can be deleted on right
+ return TRUE;
}
// is it possible to delete both items ?
-BOOL CDirView::IsItemDeletableOnBoth(int code)
+BOOL CDirView::IsItemDeletableOnBoth(const DIFFITEM & di)
{
- switch(code)
- {
- case FILE_DIFF:
- case FILE_BINSAME:
- case FILE_BINDIFF:
- case FILE_SAME:
- return TRUE;
- }
- return FALSE;
+ // don't let them mess with error items
+ if (di.isResultError()) return FALSE;
+ // impossible if only on right or left
+ if (di.isSideLeft() || di.isSideRight()) return FALSE;
+
+ // everything else can be deleted on both
+ return TRUE;
}
// is it possible to open left item ?
-BOOL CDirView::IsItemOpenableOnLeft(int code)
+BOOL CDirView::IsItemOpenableOnLeft(const DIFFITEM & di)
{
- switch(code)
- {
- case FILE_LUNIQUE:
- case FILE_LDIRUNIQUE:
- case FILE_DIFF:
- case FILE_BINSAME:
- case FILE_BINDIFF:
- case FILE_SAME:
- return TRUE;
- }
- return FALSE;
+ // impossible if only on right
+ if (di.isSideRight()) return FALSE;
+
+ // everything else can be opened on right
+ return TRUE;
}
// is it possible to open right item ?
-BOOL CDirView::IsItemOpenableOnRight(int code)
+BOOL CDirView::IsItemOpenableOnRight(const DIFFITEM & di)
{
- switch(code)
- {
- case FILE_RUNIQUE:
- case FILE_RDIRUNIQUE:
- case FILE_DIFF:
- case FILE_BINSAME:
- case FILE_BINDIFF:
- case FILE_SAME:
- return TRUE;
- }
- return FALSE;
+ // impossible if only on left
+ if (di.isSideLeft()) return FALSE;
+
+ // everything else can be opened on left
+ return TRUE;
}
// is it possible to open left ... item ?
-BOOL CDirView::IsItemOpenableOnLeftWith(int code)
+BOOL CDirView::IsItemOpenableOnLeftWith(const DIFFITEM & di)
{
- switch(code)
- {
- case FILE_LUNIQUE:
- case FILE_DIFF:
- case FILE_BINSAME:
- case FILE_BINDIFF:
- case FILE_SAME:
- return TRUE;
- }
- return FALSE;
+ return (!di.isDirectory() && IsItemOpenableOnLeft(di));
}
// is it possible to open with ... right item ?
-BOOL CDirView::IsItemOpenableOnRightWith(int code)
+BOOL CDirView::IsItemOpenableOnRightWith(const DIFFITEM & di)
{
- switch(code)
- {
- case FILE_RUNIQUE:
- case FILE_DIFF:
- case FILE_BINSAME:
- case FILE_BINDIFF:
- case FILE_SAME:
- return TRUE;
- }
- return FALSE;
+ return (!di.isDirectory() && IsItemOpenableOnRight(di));
}
// get the file names on both sides for first selected item
if (IsItemHiddenBackup(di))
return NULL;
- LPCTSTR p = NULL;
+ // file type filters
+ if (di.isBin() && !mf->m_bShowBinaries)
+ return 0;
- BOOL leftside = (di.code==FILE_LUNIQUE || di.code==FILE_LDIRUNIQUE);
- BOOL rightside = (di.code==FILE_RUNIQUE || di.code==FILE_RDIRUNIQUE);
+ // result filters
+ if (di.isResultSame() && !mf->m_bShowIdent)
+ return 0;
+ if (di.isResultError() && !mf->m_bShowErrors)
+ return 0;
+ if (di.isResultSkipped() && !mf->m_bShowSkipped)
+ return 0;
- switch (di.code)
- {
- case FILE_DIFF:
- if (mf->m_bShowDiff)
- {
- p = _tcsninc(di.getLeftFilepath(), llen);
- }
- break;
- case FILE_BINSAME:
- if (mf->m_bShowIdent && mf->m_bShowBinaries)
- {
- p = _tcsninc(di.getLeftFilepath(), llen);
- }
- break;
- case FILE_BINDIFF:
- if (mf->m_bShowDiff && mf->m_bShowBinaries)
- {
- p = _tcsninc(di.getLeftFilepath(), llen);
- }
- break;
- case FILE_LUNIQUE:
- case FILE_RUNIQUE:
- case FILE_LDIRUNIQUE:
- case FILE_RDIRUNIQUE:
- if ((mf->m_bShowUniqueLeft && leftside)
- || (mf->m_bShowUniqueRight && rightside))
- {
- if (di.code==FILE_LUNIQUE || di.code==FILE_LDIRUNIQUE)
- {
- p = _tcsninc(di.getLeftFilepath(), llen);
- }
- else
- {
- p = _tcsninc(di.getRightFilepath(), rlen);
- }
- }
- break;
- case FILE_SAME:
- if (mf->m_bShowIdent)
- {
- p = _tcsninc(di.getLeftFilepath(), llen);
- }
- break;
- default: // error
+ // left/right filters
+ if (di.isSideLeft() && !mf->m_bShowUniqueLeft)
+ return 0;
+ if (di.isSideRight() && !mf->m_bShowUniqueRight)
+ return 0;
+
+
+ LPCTSTR p = NULL;
+ if (di.isSideRight())
+ p = _tcsninc(di.getRightFilepath(), rlen);
+ else
p = _tcsninc(di.getLeftFilepath(), llen);
- break;
- }
+
return p;
}
// Get index at view, update filetimes to context
// and tell view to update found item
- DIFFITEM current = m_pCtxt->GetDiffAt(pos);
- m_pCtxt->UpdateInfoFromDisk(current);
+ m_pCtxt->UpdateStatusFromDisk(pos);
// Figure out new status code
- current.code = (unified ? FILE_SAME : FILE_DIFF);
-
+ UINT diffcode = (unified ? DIFFCODE::SAME : DIFFCODE::DIFF);
// Save new status code to diff context memory
- m_pCtxt->UpdateStatusCode(pos, current.code);
+ m_pCtxt->SetDiffStatusCode(pos, diffcode, DIFFCODE::COMPAREFLAGS);
// Update view
- UpdateScreenItemStatus(ind, current);
+ const DIFFITEM & updated = m_pCtxt->GetDiffAt(pos);
+ UpdateScreenItemStatus(ind, updated);
}
/**
{
m_bRecursive = bRecursive;
}
+
+void CDirDoc::SetDiffSide(UINT diffcode, int idx)
+{
+ SetDiffStatus(diffcode, DIFFCODE::SIDEFLAG, idx);
+}
+
+void CDirDoc::SetDiffCompare(UINT diffcode, int idx)
+{
+ SetDiffStatus(diffcode, DIFFCODE::COMPAREFLAGS, idx);
+}
+
+void CDirDoc::SetDiffStatus(UINT diffcode, UINT mask, int idx)
+{
+ CDirView *pv = GetMainView();
+ ASSERT(pv);
+ // first change it in the dirlist
+ POSITION diffpos = pv->GetItemKey(idx);
+
+ // TODO: Why is the update broken into these pieces ?
+ // Someone could figure out these pieces and probably simplify this.
+
+ // update DIFFITEM code
+ m_pCtxt->SetDiffStatusCode(diffpos, diffcode, mask);
+ // update DIFFITEM time, and also tell views
+ ReloadItemStatus(idx);
+}
+
void CompareReady();
void UpdateChangedItem(LPCTSTR pathLeft, LPCTSTR pathRight, bool unified);
POSITION FindItemFromPaths(LPCTSTR pathLeft, LPCTSTR pathRight);
- void SetDiffContext(CDiffContext *pCtxt);
+ void SetDiffSide(UINT diffcode, int idx);
+ void SetDiffCompare(UINT diffcode, int idx);
void UpdateResources();
void InitStatusStrings();
void ReloadItemStatus(UINT nIdx);
void AddMergeDoc(CMergeDoc * pMergeDoc);
void MergeDocClosing(CMergeDoc * pMergeDoc);
CDiffThread m_diffThread;
+ void SetDiffStatus(UINT diffcode, UINT mask, int idx);
+ void SetDiffContext(CDiffContext *pCtxt);
#ifdef _DEBUG
virtual void AssertValid() const;
if (i<leftDirs.GetSize() && (j==rightDirs.GetSize() || collstr(leftDirs[i].name, rightDirs[j].name, casesensitive)<0))
{
// Advance left pointer over left-only entry, and then retest with new pointers
- FilterAdd(subdir, &leftDirs[i], 0, FILE_LDIRUNIQUE, pCtxt);
+ FilterAdd(subdir, &leftDirs[i], 0, DIFFCODE::LEFT+DIFFCODE::DIR, pCtxt);
++i;
continue;
}
if (j<rightDirs.GetSize() && (i==leftDirs.GetSize() || collstr(leftDirs[i].name, rightDirs[j].name, casesensitive)>0))
{
// Advance right pointer over right-only entry, and then retest with new pointers
- FilterAdd(subdir, 0, &rightDirs[j], FILE_RDIRUNIQUE, pCtxt);
+ FilterAdd(subdir, 0, &rightDirs[j], DIFFCODE::RIGHT+DIFFCODE::DIR, pCtxt);
++j;
continue;
}
CString newsub = subprefix + leftDirs[i].name;
if (!depth || !pCtxt->m_piFilter->includeDir(newsub))
{
- FilterAdd(subdir, &leftDirs[i], &rightDirs[j], FILE_DIRSKIP, pCtxt);
+ FilterAdd(subdir, &leftDirs[i], &rightDirs[j], DIFFCODE::SKIPPED+DIFFCODE::DIR, pCtxt);
}
else
{
if (i<leftFiles.GetSize() && (j==rightFiles.GetSize() || collstr(leftFiles[i].name, rightFiles[j].name, casesensitive)<0))
{
// Advance left pointer over left-only entry, and then retest with new pointers
- FilterAdd(subdir, &leftFiles[i], 0, FILE_LUNIQUE, pCtxt);
+ FilterAdd(subdir, &leftFiles[i], 0, DIFFCODE::LEFT+DIFFCODE::FILE, pCtxt);
++i;
continue;
}
if (j<rightFiles.GetSize() && (i==leftFiles.GetSize() || collstr(leftFiles[i].name, rightFiles[j].name, casesensitive)>0))
{
// Advance right pointer over right-only entry, and then retest with new pointers
- FilterAdd(subdir, 0, &rightFiles[j], FILE_RUNIQUE, pCtxt);
+ FilterAdd(subdir, 0, &rightFiles[j], DIFFCODE::RIGHT+DIFFCODE::FILE, pCtxt);
++j;
continue;
}
CString newsubfile = subprefix + leftFiles[i].name;
if (!pCtxt->m_piFilter->includeFile(newsubfile))
{
- FilterAdd(subdir, &leftFiles[i], &rightFiles[j], FILE_SKIP, pCtxt);
+ FilterAdd(subdir, &leftFiles[i], &rightFiles[j], DIFFCODE::SKIPPED+DIFFCODE::FILE, pCtxt);
}
else
{
if (res == 0)
{
// same
- FilterAdd(subdir, &leftFiles[i], &rightFiles[j], FILE_SAME, pCtxt);
+ FilterAdd(subdir, &leftFiles[i], &rightFiles[j], DIFFCODE::SAME+DIFFCODE::FILE, pCtxt);
}
else if (res == 1)
{
// different
- FilterAdd(subdir, &leftFiles[i], &rightFiles[j], FILE_DIFF, pCtxt);
+ FilterAdd(subdir, &leftFiles[i], &rightFiles[j], DIFFCODE::DIFF+DIFFCODE::FILE, pCtxt);
}
else
{
ASSERT(0);
}
// error
- FilterAdd(subdir, &leftFiles[i], &rightFiles[j], FILE_ERROR, pCtxt);
+ FilterAdd(subdir, &leftFiles[i], &rightFiles[j], DIFFCODE::CMPERR+DIFFCODE::FILE, pCtxt);
}
}
++i;
SetFullRowSel(FALSE);
}
+// These are the offsets into the image list created in OnInitDialog
+#define DIFFIMG_LUNIQUE 0
+#define DIFFIMG_RUNIQUE 1
+#define DIFFIMG_DIFF 2
+#define DIFFIMG_SAME 3
+#define DIFFIMG_ERROR 4
+#define DIFFIMG_BINSAME 5
+#define DIFFIMG_BINDIFF 6
+#define DIFFIMG_LDIRUNIQUE 7
+#define DIFFIMG_RDIRUNIQUE 8
+#define DIFFIMG_SKIP 9
+#define DIFFIMG_DIRSKIP 10
+
+/**
+ * @brief Return image index appropriate for this row
+ */
+int CDirView::GetColImage(const DIFFITEM & di) const
+{
+ // Must return an image index into image list created above in OnInitDialog
+ if (di.isResultError()) return DIFFIMG_ERROR;
+ if (di.isResultSkipped())
+ return (di.isDirectory() ? DIFFIMG_DIRSKIP : DIFFIMG_SKIP);
+ if (di.isSideLeft())
+ return (di.isDirectory() ? DIFFIMG_LDIRUNIQUE : DIFFIMG_LUNIQUE);
+ if (di.isSideRight())
+ return (di.isDirectory() ? DIFFIMG_RDIRUNIQUE : DIFFIMG_RUNIQUE);
+ if (di.isResultSame())
+ return (di.isBin() ? DIFFIMG_BINSAME : DIFFIMG_SAME);
+ // diff
+ return (di.isBin() ? DIFFIMG_BINDIFF : DIFFIMG_DIFF);
+}
+int CDirView::GetDefaultColImage() const
+{
+ return DIFFIMG_ERROR;
+}
+
+
void CDirView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
WaitStatusCursor waitstatus(LoadResString(IDS_STATUS_OPENING_SELECTION));
while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemCopyableToLeft(di.code))
+ if (IsItemCopyableToLeft(di))
++legalcount;
++selcount;
}
while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemCopyableToRight(di.code))
+ if (IsItemCopyableToRight(di))
++legalcount;
++selcount;
}
{
POSITION diffpos = GetItemKey(sel);
DIFFITEM di = GetDiffContext()->GetDiffAt(diffpos);
- switch(di.code)
+ if (di.isDirectory())
+ AfxMessageBox(IDS_FILEISDIR, MB_ICONINFORMATION);
+ else if (di.isSideLeft() || di.isSideRight())
+ AfxMessageBox(IDS_FILEUNIQUE, MB_ICONINFORMATION);
+ else if (di.isBin())
+ AfxMessageBox(IDS_FILEBINARY, MB_ICONSTOP);
+ else
{
- // Open identical and different files
- case FILE_DIFF:
- case FILE_SAME:
- {
- CString left, right;
- GetItemFileNames(sel, left, right);
- mf->ShowMergeDoc(GetDocument(), left, right,
- GetDocument()->GetReadOnly(TRUE),
- GetDocument()->GetReadOnly(FALSE));
- }
- break;
- case FILE_LDIRUNIQUE:
- case FILE_RDIRUNIQUE:
- {
- AfxMessageBox(IDS_FILEISDIR, MB_ICONINFORMATION);
- }
- break;
- case FILE_LUNIQUE:
- case FILE_RUNIQUE:
- {
- AfxMessageBox(IDS_FILEUNIQUE, MB_ICONINFORMATION);
- }
- break;
- case FILE_BINDIFF:
- case FILE_BINSAME:
- {
- AfxMessageBox(IDS_FILEBINARY, MB_ICONSTOP);
- }
- break;
- default:
- {
- AfxMessageBox(IDS_FILEERROR, MB_ICONSTOP);
- }
- break;
+ // Open identical and different files
+ CString left, right;
+ GetItemFileNames(sel, left, right);
+ mf->ShowMergeDoc(GetDocument(), left, right,
+ GetDocument()->GetReadOnly(TRUE),
+ GetDocument()->GetReadOnly(FALSE));
}
}
}
while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemDeletableOnLeft(di.code))
+ if (IsItemDeletableOnLeft(di))
++count;
++total;
}
while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemDeletableOnRight(di.code))
+ if (IsItemDeletableOnRight(di))
++count;
++total;
}
while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (IsItemDeletableOnBoth(di.code))
+ if (IsItemDeletableOnBoth(di))
++count;
++total;
}
if (sel != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (!IsItemOpenableOnLeft(di.code))
+ if (!IsItemOpenableOnLeft(di))
sel = -1;
}
if (sel != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (!IsItemOpenableOnRight(di.code))
+ if (!IsItemOpenableOnRight(di))
sel = -1;
}
if (sel != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (!IsItemOpenableOnLeftWith(di.code))
+ if (!IsItemOpenableOnLeftWith(di))
sel = -1;
}
if (sel != -1)
{
const DIFFITEM& di = GetDiffItem(sel);
- if (!IsItemOpenableOnRightWith(di.code))
+ if (!IsItemOpenableOnRightWith(di))
sel = -1;
}
// When navigating differences, do we stop at this one ?
bool CDirView::IsItemNavigableDiff(const DIFFITEM & di) const
{
- switch(di.code)
- {
- case FILE_DIFF: return true;
- case FILE_BINDIFF: return true;
- case FILE_LUNIQUE: return true;
- case FILE_RUNIQUE: return true;
- }
- return false;
+ if (di.isResultSkipped() || di.isResultError())
+ return false;
+ if (di.isDirectory())
+ return false;
+ return true;
}
// move focus (& selection if only one selected) from currentInd to i
void GetItemFileNames(int sel, CString& strLeft, CString& strRight) const;
BOOL IsItemLeftOnly(int code);
BOOL IsItemRightOnly(int code);
- BOOL IsItemCopyableToLeft(int code);
- BOOL IsItemCopyableToRight(int code);
- BOOL IsItemDeletableOnLeft(int code);
- BOOL IsItemDeletableOnRight(int code);
- BOOL IsItemDeletableOnBoth(int code);
- BOOL IsItemOpenableOnLeft(int code);
- BOOL IsItemOpenableOnRight(int code);
- BOOL IsItemOpenableOnLeftWith(int code);
- BOOL IsItemOpenableOnRightWith(int code);
+ BOOL IsItemCopyableToLeft(const DIFFITEM & di);
+ BOOL IsItemCopyableToRight(const DIFFITEM & di);
+ BOOL IsItemDeletableOnLeft(const DIFFITEM & di);
+ BOOL IsItemDeletableOnRight(const DIFFITEM & di);
+ BOOL IsItemDeletableOnBoth(const DIFFITEM & di);
+ BOOL IsItemOpenableOnLeft(const DIFFITEM & di);
+ BOOL IsItemOpenableOnRight(const DIFFITEM & di);
+ BOOL IsItemOpenableOnLeftWith(const DIFFITEM & di);
+ BOOL IsItemOpenableOnRightWith(const DIFFITEM & di);
void DoCopyFileToRight();
void DoCopyFileToLeft();
void DoDelLeft();
int GetFocusedItem();
int GetFirstDifferentItem();
int GetLastDifferentItem();
+ int GetColImage(const DIFFITEM & di) const;
+ int GetDefaultColImage() const;
// Implementation data
protected:
{
int i = AddNewItem(index);
SetItemKey(i, curdiffpos);
- SetImage(i, FILE_ERROR);
+ SetImage(i, GetDefaultColImage());
return i;
}
-/**
- * @brief Return image index appropriate for this row
- */
-static int GetColImage(const DIFFITEM & di)
-{
- switch (di.code)
- {
- case FILE_DIFF: return FILE_DIFF;
- case FILE_BINDIFF: return FILE_BINDIFF;
- case FILE_BINSAME: return FILE_BINSAME;
- case FILE_LUNIQUE:
- case FILE_LDIRUNIQUE:
- return di.code;
- case FILE_RUNIQUE:
- case FILE_RDIRUNIQUE:
- return di.code;
- break;
- case FILE_SAME: return FILE_SAME;
- default: return FILE_ERROR;
- }
-}
// Update listview display of details for specified row
void CDirView::UpdateDiffItemStatus(UINT nIdx, const DIFFITEM & di)
if (i1==i2) return 0;
return i1>i2 ? 1 : -1;
}
+/**
+ * @brief Function to compare two diffcodes
+ */
+static int cmpdiffcode(int diffcode1, int diffcode2)
+{
+ // TODO: How shall we order these ?
+ return diffcode1-diffcode2;
+}
/**
* @{ Functions to display each type of column info
static CString ColStatusGet(const DIFFITEM & di)
{
CString s;
- switch (di.code)
+ if (di.isResultError())
+ {
+ VERIFY(s.LoadString(IDS_CANT_COMPARE_FILES));
+ }
+ else if (di.isSideLeft())
{
- case FILE_DIFF:
- VERIFY(s.LoadString(IDS_FILES_ARE_DIFFERENT));
- break;
- case FILE_BINDIFF:
- VERIFY(s.LoadString(IDS_BIN_FILES_DIFF));
- break;
- case FILE_BINSAME:
- VERIFY(s.LoadString(IDS_BIN_FILES_SAME));
- break;
- case FILE_LUNIQUE:
- case FILE_LDIRUNIQUE:
AfxFormatString1(s, IDS_ONLY_IN_FMT, di.getLeftFilepath());
- break;
- case FILE_RUNIQUE:
- case FILE_RDIRUNIQUE:
+ }
+ else if (di.isSideRight())
+ {
AfxFormatString1(s, IDS_ONLY_IN_FMT, di.getRightFilepath());
- break;
- case FILE_SAME:
- VERIFY(s.LoadString(IDS_IDENTICAL));
- break;
- case FILE_SKIP:
- VERIFY(s.LoadString(IDS_FILE_SKIPPED));
- break;
- case FILE_DIRSKIP:
- VERIFY(s.LoadString(IDS_DIR_SKIPPED));
- break;
- default: // error
- VERIFY(s.LoadString(IDS_CANT_COMPARE_FILES));
- break;
+ }
+ else if (di.isResultSkipped())
+ {
+ if (di.isDirectory())
+ VERIFY(s.LoadString(IDS_DIR_SKIPPED));
+ else
+ VERIFY(s.LoadString(IDS_FILE_SKIPPED));
+ }
+ else if (di.isResultSame())
+ {
+ if (di.isBin())
+ VERIFY(s.LoadString(IDS_BIN_FILES_SAME));
+ else
+ VERIFY(s.LoadString(IDS_IDENTICAL));
+ }
+ else // diff
+ {
+ if (di.isBin())
+ VERIFY(s.LoadString(IDS_BIN_FILES_DIFF));
+ else
+ VERIFY(s.LoadString(IDS_FILES_ARE_DIFFERENT));
}
return s;
}
static CString ColStatusAbbrGet(const DIFFITEM & di)
{
int id;
- switch (di.code)
+
+ if (di.isResultError())
+ {
+ id = IDS_CANT_COMPARE_FILES;
+ }
+ else if (di.isSideLeft())
+ {
+ id = IDS_LEFTONLY;
+ }
+ else if (di.isSideRight())
{
- case FILE_DIFF: id = IDS_FILES_ARE_DIFFERENT; break;
- case FILE_BINDIFF: id = IDS_BIN_FILES_DIFF; break;
- case FILE_BINSAME: id = IDS_BIN_FILES_SAME; break;
- case FILE_LUNIQUE:
- case FILE_LDIRUNIQUE:
- id = IDS_LEFTONLY; break;
- case FILE_RUNIQUE:
- case FILE_RDIRUNIQUE:
- id = IDS_RIGHTONLY; break;
- case FILE_SAME: id = IDS_IDENTICAL; break;
- case FILE_SKIP: id = IDS_FILE_SKIPPED; break;
- case FILE_DIRSKIP: id = IDS_DIR_SKIPPED; break;
- default: id = IDS_CANT_COMPARE_FILES;
+ id = IDS_RIGHTONLY;
}
+ else if (di.isResultSkipped())
+ {
+ if (di.isDirectory())
+ id = IDS_DIR_SKIPPED;
+ else
+ id = IDS_FILE_SKIPPED;
+ }
+ else if (di.isResultSame())
+ {
+ if (di.isBin())
+ id = IDS_BIN_FILES_SAME;
+ else
+ id = IDS_IDENTICAL;
+ }
+ else // diff
+ {
+ if (di.isBin())
+ id = IDS_BIN_FILES_DIFF;
+ else
+ id = IDS_FILES_ARE_DIFFERENT;
+ }
+
CString s;
VERIFY(s.LoadString(id));
return s;
}
static int ColStatusSort(const DIFFITEM & ldi, const DIFFITEM &rdi)
{
- return rdi.code-ldi.code;
+ return cmpdiffcode(rdi.diffcode, ldi.diffcode);
}
static int ColLmtimeSort(const DIFFITEM & ldi, const DIFFITEM &rdi)
{
m_bShowDiff = theApp.GetProfileInt(_T("Settings"), _T("ShowDifferent"), TRUE)!=0;
m_bShowIdent = theApp.GetProfileInt(_T("Settings"), _T("ShowIdentical"), TRUE)!=0;
m_bShowBinaries = theApp.GetProfileInt(_T("Settings"), _T("ShowBinaries"), TRUE)!=0;
+ m_bShowErrors = TRUE;
+ m_bShowSkipped = TRUE;
m_bBackup = theApp.GetProfileInt(_T("Settings"), _T("BackupFile"), TRUE)!=0;
m_bViewWhitespace = theApp.GetProfileInt(_T("Settings"), _T("ViewWhitespace"), FALSE)!=0;
m_bScrollToFirst = theApp.GetProfileInt(_T("Settings"), _T("ScrollToFirst"), FALSE)!=0;
}
// diff completed another file
-void CMainFrame::rptStatus(BYTE code)
+void CMainFrame::rptStatus(UINT diffcode)
{
- switch(code)
+ // TODO: This is a mess
+ // How do we fix this ?
+ DIFFITEM di;
+ di.diffcode = diffcode;
+ if (di.isSideLeft())
{
- case FILE_SAME:
- ++m_nStatusFileSame;
- break;
- case FILE_BINSAME:
- ++m_nStatusFileBinSame;
- break;
- case FILE_DIFF:
- ++m_nStatusFileDiff;
- break;
- case FILE_BINDIFF:
- ++m_nStatusFileBinDiff;
- break;
- case FILE_ERROR:
- ++m_nStatusFileError;
- break;
- case FILE_LUNIQUE:
- ++m_nStatusLeftFileOnly;
- break;
- case FILE_LDIRUNIQUE:
- ++m_nStatusLeftDirOnly;
- break;
- case FILE_RUNIQUE:
- ++m_nStatusRightFileOnly;
- break;
- case FILE_RDIRUNIQUE:
- ++m_nStatusRightDirOnly;
- break;
+ if (di.isDirectory())
+ {
+ ++m_nStatusLeftDirOnly;
+ }
+ else
+ {
+ ++m_nStatusLeftFileOnly;
+ }
}
+ else if (di.isSideRight())
+ {
+ if (di.isDirectory())
+ {
+ ++m_nStatusRightDirOnly;
+ }
+ else
+ {
+ ++m_nStatusRightFileOnly;
+ }
+ }
+ else
+ {
+ if (di.isResultSkipped())
+ {
+ // what about skipped items ?
+ }
+ else if (di.isResultError())
+ {
+ // could be directory error ?
+ ++m_nStatusFileError;
+ }
+ // Now we know it was on both sides & compared!
+ else if (di.isResultSame())
+ {
+ if (di.isBin())
+ {
+ ++m_nStatusFileBinSame;
+ }
+ else
+ {
+ ++m_nStatusFileSame;
+ }
+ }
+ else
+ {
+ // presumably it is diff
+ if (di.isDirectory())
+ {
+ // this doesn't happen right now, but it will
+ // TODO
+ }
+ else
+ {
+ if (di.isBin())
+ {
+ ++m_nStatusFileBinDiff;
+ }
+ else
+ {
+ ++m_nStatusFileDiff;
+ }
+ }
+ }
+ }
+
CString s;
// TODO: Load the format string from resource
s.Format(_T("s:%d bs:%d d:%d bd:%d lf:%d ld:%d rf:%d rd:%d e:%d")
return TRUE;
}
-void CMainFrame::UpdateCurrentFileStatus(CDirDoc * pDirDoc, UINT nStatus, int idx)
-{
- ASSERT(pDirDoc);
- CDirView *pv = pDirDoc->GetMainView();
- ASSERT(pv);
- // first change it in the dirlist
- POSITION diffpos = pv->GetItemKey(idx);
-
- // TODO: Why is the update broken into these pieces ?
- // Someone could figure out these pieces and probably simplify this.
-
- // update DIFFITEM code
- pDirDoc->m_pCtxt->UpdateStatusCode(diffpos, (BYTE)nStatus);
- // update DIFFITEM time, and also tell views
- pDirDoc->ReloadItemStatus(idx);
-}
void CMainFrame::OnViewSelectfont()
{
BOOL m_bShowDiff;
BOOL m_bShowIdent;
BOOL m_bShowBinaries;
+ BOOL m_bShowErrors;
+ BOOL m_bShowSkipped;
BOOL m_bBackup;
BOOL m_bAllowMixedEol;
LOGFONT m_lfDiff;
// Operations
public:
BOOL DeleteFileOrError(LPCTSTR szFile);
- void rptStatus(BYTE code);
+ void rptStatus(UINT diffcode);
void clearStatus();
BOOL SyncFiles(LPCTSTR pszSrc, LPCTSTR pszDest, CString * psError);
BOOL DoSyncFiles(LPCTSTR pszSrc, LPCTSTR pszDest, CString * psError);
- void UpdateCurrentFileStatus(CDirDoc * pDirDoc, UINT nStatus, int idx);
BOOL DoFileOpen(LPCTSTR pszLeft = NULL, LPCTSTR pszRight = NULL,
DWORD dwLeftFlags = 0, DWORD dwRightFlags = 0, BOOL bRecurse = FALSE);
void ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft = FALSE, BOOL bRORight = FALSE);
+2003-09-14 Perry
+ PATCH: [ 805875 ] Switch to diffcode flags
+ WinMerge: DiffContext.cpp DiffContext.h DirActions.cpp DirDoc.cpp DirDoc.h
+ DirScan.cpp DirView.cpp DirView.h DirViewColHandler.cpp DirViewColItems.cpp
+ MainFrm.cpp MainFrm.h
+
2003-09-13 Perry
Widen label IDC_PRIVATEBUILD on about box.
WinMerge: Merge.rc