OSDN Git Service

PATCH: [ 1223754 ] Improve dircompare stats system
authorKimmo Varis <kimmov@gmail.com>
Tue, 21 Jun 2005 17:34:10 +0000 (17:34 +0000)
committerKimmo Varis <kimmov@gmail.com>
Tue, 21 Jun 2005 17:34:10 +0000 (17:34 +0000)
16 files changed:
Src/CompareStats.cpp [new file with mode: 0644]
Src/CompareStats.h [new file with mode: 0644]
Src/DiffContext.cpp
Src/DiffContext.h
Src/DiffThread.cpp
Src/DirCompStateBar.cpp
Src/DirCompStateBar.h
Src/DirDoc.cpp
Src/DirDoc.h
Src/DirFrame.cpp
Src/DirFrame.h
Src/DirScan.cpp
Src/DirScan.h
Src/DirView.cpp
Src/Merge.dsp
Src/readme.txt

diff --git a/Src/CompareStats.cpp b/Src/CompareStats.cpp
new file mode 100644 (file)
index 0000000..5361847
--- /dev/null
@@ -0,0 +1,187 @@
+/** 
+ * @file  CompareStats.cpp
+ *
+ * @brief Implementation of CompareStats class.
+ */
+// RCS ID line follows -- this is updated by CVS
+// $Id$
+
+#include "stdafx.h"
+#include "DiffItem.h"
+#include "CompareStats.h"
+
+/** 
+ * @brief Constructor, initializes critical section.
+ */
+CompareStats::CompareStats()
+: m_nTotalItems(0)
+{
+       InitializeCriticalSection(&m_csProtect);
+       ZeroMemory(&m_counts[0], sizeof(m_counts));
+}
+
+/** 
+ * @brief Destructor, deletes critical section.
+ */
+CompareStats::~CompareStats()
+{
+       DeleteCriticalSection(&m_csProtect);
+}
+
+/** 
+ * @brief Increase found items (dirs and files) count.
+ * @param [in] count Amount of items to add.
+ */
+void CompareStats::IncreaseTotalItems(int count /*= 1*/)
+{
+       m_nTotalItems += count;
+}
+
+/** 
+ * @brief Add compared item.
+ * @param [in] code Resultcode to add.
+ */
+void CompareStats::AddItem(int code)
+{
+       EnterCriticalSection(&m_csProtect);
+       RESULT res = GetResultFromCode(code);
+       int index = static_cast<int>(res);
+       m_counts[index] += 1;
+       LeaveCriticalSection(&m_csProtect);
+}
+
+/** 
+ * @brief Return count by resultcode.
+ * @param [in] result Resultcode to return.
+ * @return Count of items for given resultcode.
+ */
+int CompareStats::GetCount(CompareStats::RESULT result)
+{
+       int currentValue = 0;
+       EnterCriticalSection(&m_csProtect);
+       int resInd = static_cast<int>(result);
+       currentValue = m_counts[resInd];
+       LeaveCriticalSection(&m_csProtect);
+       return currentValue;
+}
+
+/** 
+ * @brief Return total count of items (so far) found.
+ */
+int CompareStats::GetTotalItems()
+{
+       return m_nTotalItems;
+}
+
+/** 
+ * @brief Reset comparestats.
+ * Use this function to reset stats before new compare.
+ */
+void CompareStats::Reset()
+{
+       ZeroMemory(&m_counts[0], sizeof(m_counts));
+       SetCompareState(STATE_IDLE);
+       m_nTotalItems = 0;
+}
+
+/** 
+ * @brief Change compare state.
+ * @param [in] state New compare state.
+ */
+void CompareStats::SetCompareState(CompareStats::CMP_STATE state)
+{
+       m_state = state;
+}
+
+/** 
+ * @brief Return current comparestate.
+ */
+CompareStats::CMP_STATE CompareStats::GetCompareState()
+{
+       return m_state;
+}
+
+/** 
+ * @brief Convert diffcode to compare-result.
+ * @param [in] diffcode DIFFITEM.diffcode to convert.
+ * @return Compare result.
+ */
+CompareStats::RESULT CompareStats::GetResultFromCode(UINT diffcode)
+{
+       DIFFCODE di = diffcode;
+       
+       // Test first for skipped so we pick all skipped items as such 
+       if (di.isResultFiltered())
+       {
+               // skipped
+               if (di.isDirectory())
+               {
+                       return RESULT_DIRSKIP;
+               }
+               else
+               {
+                       return RESULT_SKIP;
+               }
+       }
+       else if (di.isSideLeft())
+       {
+               // left-only
+               if (di.isDirectory())
+               {
+                       return RESULT_LDIRUNIQUE;
+               }
+               else
+               {
+                       return RESULT_LUNIQUE;
+               }
+       }
+       else if (di.isSideRight())
+       {
+               // right-only
+               if (di.isDirectory())
+               {
+                       return RESULT_RDIRUNIQUE;
+               }
+               else
+               {
+                       return RESULT_RUNIQUE;
+               }
+       }
+       else if (di.isResultError())
+       {
+               // could be directory error ?
+               return RESULT_ERROR;
+       }
+       // Now we know it was on both sides & compared!
+       else if (di.isResultSame())
+       {
+               // same
+               if (di.isBin())
+               {
+                       return RESULT_BINSAME;
+               }
+               else
+               {
+                       return RESULT_SAME;
+               }
+       }
+       else
+       {
+               // presumably it is diff
+               if (di.isDirectory())
+               {
+                       return RESULT_DIR;
+               }
+               else
+               {
+                       if (di.isBin())
+                       {
+                               return RESULT_BINDIFF;
+                       }
+                       else
+                       {
+                               return RESULT_DIFF;
+                       }
+               }
+       }
+}
diff --git a/Src/CompareStats.h b/Src/CompareStats.h
new file mode 100644 (file)
index 0000000..3248dc4
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+ *  @file CompareStats.h
+ *
+ *  @brief Declaration of class CompareStats
+ */ 
+//
+// RCS ID line follows -- this is updated by CVS
+// $Id$
+
+#ifndef _COMPARESTATS_H_
+#define _COMPARESTATS_H_
+
+/**
+ * @brief Class holding directory compare stats.
+ *
+ * This class is used for sharing compare stats between dir compare
+ * classes. DirScan.cpp functions and CDiffContext update statuses
+ * and compare statepane reads statuses and updates UI.
+ */
+class CompareStats
+{
+public:
+
+       /**
+       * @brief Different states for compare procedure.
+       */
+       enum CMP_STATE
+       {
+               STATE_IDLE,
+               STATE_COLLECT,
+               STATE_COMPARE,
+               STATE_READY,
+       };
+
+       /**
+       * @brief Resultcodes we store.
+       */
+       enum RESULT
+       {
+               RESULT_LUNIQUE = 0,
+               RESULT_RUNIQUE,
+               RESULT_DIFF,
+               RESULT_SAME,
+               RESULT_BINSAME,
+               RESULT_BINDIFF,
+               RESULT_LDIRUNIQUE,
+               RESULT_RDIRUNIQUE,
+               RESULT_SKIP,
+               RESULT_DIRSKIP,
+               RESULT_DIR,
+               RESULT_ERROR,
+               RESULT_COUNT  //THIS MUST BE THE LAST ITEM
+       };
+
+       CompareStats();
+       ~CompareStats();
+       void AddItem(int code);
+       void IncreaseTotalItems(int count = 1);
+       int GetCount(CompareStats::RESULT result);
+       int GetTotalItems();
+       void Reset();
+       void SetCompareState(CompareStats::CMP_STATE state);
+       CompareStats::CMP_STATE GetCompareState();
+       
+       static CompareStats::RESULT CompareStats::GetResultFromCode(UINT diffcode);
+
+private:
+       int m_counts[RESULT_COUNT]; /**< Table storing result counts */
+       CRITICAL_SECTION m_csProtect; /**< For synchronizing read/write of counts */
+       long m_nTotalItems; /**< Total items found to compare */
+       CMP_STATE m_state; /**< State for compare (collect, compare, ready..) */
+};
+
+#endif // _COMPARESTATS_H_
index 7fe8771..5113ad9 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "stdafx.h"
 #include "merge.h"
+#include "CompareStats.h"
 #include "version.h"
 #include "DiffContext.h"
 #include "paths.h"
@@ -109,9 +110,7 @@ static CString GetFixedFileVersion(const CString & path)
 void CDiffContext::AddDiff(const DIFFITEM & di)
 {
        DiffItemList::AddDiff(di);
-
-       // ignore return value
-       SendMessage(m_hDirFrame, m_msgUpdateStatus, di.diffcode, NULL);
+       m_pCompareStats->AddItem(di.diffcode);
 }
 
 /**
index 7b6b71a..0e98ee7 100644 (file)
@@ -26,6 +26,7 @@ class PackingInfo;
 class PrediffingInfo;
 class IDiffFilter;
 struct DIFFITEM;
+class CompareStats;
 
 // Interface for reporting current file, as diff traverses file tree
 class IDiffStatus
@@ -89,6 +90,7 @@ public:
        BOOL m_bGuessEncoding;
        int m_nCompMethod; /**< Compare method */
        BOOL m_bIgnoreSmallTimeDiff; /**< Ignore small timedifferences when comparing by date */
+       CompareStats *m_pCompareStats;
 
 private:
        CList<DIFFITEM,DIFFITEM&> *m_pList; /**< Pointer to list, used to access list */
index b9562de..af77e65 100644 (file)
@@ -207,7 +207,7 @@ UINT DiffThread(LPVOID lpParam)
        }
        else
        {
-               DirScan_GetItems(paths, subdir, &itemList, casesensitive, depth, myStruct->m_pAbortgate);
+               DirScan_GetItems(paths, subdir, &itemList, casesensitive, depth,  myStruct->context, myStruct->m_pAbortgate);
                DirScan_CompareItems(itemList, myStruct->context, myStruct->m_pAbortgate);
        }
 
index fbed525..0e9b015 100644 (file)
 static char THIS_FILE[] = __FILE__;
 #endif
 
-/////////////////////////////////////////////////////////////////////////////
-// CDirCompStateBar construction destruction
+/**
+ * @brief ID for timer updating UI.
+ */
+static const UINT IDT_UPDATE = 1;
+
+/**
+ * @brief Interval (in milliseconds) for UI updates.
+ */
+static const UINT UPDATE_INTERVAL = 500;
 
 /**
- * @brief Set all stats to zero
+ * @brief Reset all UI fields to zero.
  */
 void CDirCompStateBar::ClearStat()
 {
-       //{{AFX_DATA_INIT(CDirCompStateBar)
-       m_nBinaryDiff = 0;
-       m_nBinarySame = 0;
-       m_nEqual = 0;
-       m_nFileSkip = 0;
-       m_nFolderSkip = 0;
-       m_nLFile = 0;
-       m_nLFolder = 0;
-       m_nNotEqual = 0;
-       m_nRFile = 0;
-       m_nRFolder = 0;
-       m_nError = 0;
-       m_nFolder = 0;
-       //}}AFX_DATA_INIT
+       SetDlgItemInt(IDC_COUNT_LFILE, 0);
+       SetDlgItemInt(IDC_COUNT_RFILE, 0);
+       SetDlgItemInt(IDC_COUNT_NOTEQUAL, 0);
+       SetDlgItemInt(IDC_COUNT_EQUAL, 0);
+       SetDlgItemInt(IDC_COUNT_BINARYSAME, 0);
+       SetDlgItemInt(IDC_COUNT_BINARYDIFF, 0);
+       SetDlgItemInt(IDC_COUNT_LFOLDER, 0);
+       SetDlgItemInt(IDC_COUNT_RFOLDER, 0);
+       SetDlgItemInt(IDC_COUNT_FILESKIP, 0);
+       SetDlgItemInt(IDC_COUNT_FOLDERSKIP, 0);
+       SetDlgItemInt(IDC_COUNT_FOLDER, 0);
+       SetDlgItemInt(IDC_COUNT_ERROR, 0);
 }
 
 /**
  * @brief Constructor.
- *
- * Resets stats and loads strings from resource.
  */
 CDirCompStateBar::CDirCompStateBar(CWnd* pParent /*=NULL*/)
+: m_bStopText(TRUE)
 {
-       ClearStat();
 }
 
+/**
+ * @brief Loads strings from resource.
+ */
 BOOL CDirCompStateBar::Create(CWnd* pParentWnd)
 {
        VERIFY(strAbort.LoadString(IDC_COMPARISON_STOP));
@@ -63,6 +69,7 @@ BOOL CDirCompStateBar::Create(CWnd* pParentWnd)
                        CDirCompStateBar::IDD))
                return FALSE;
 
+       ClearStat();
        return TRUE;
 };
 
@@ -70,28 +77,16 @@ void CDirCompStateBar::DoDataExchange(CDataExchange* pDX)
 {
        CDialogBar::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CDirCompStateBar)
-       DDX_Text(pDX, IDC_COUNT_BINARYDIFF, m_nBinaryDiff);
-       DDX_Text(pDX, IDC_COUNT_BINARYSAME, m_nBinarySame);
-       DDX_Text(pDX, IDC_COUNT_EQUAL, m_nEqual);
-       DDX_Text(pDX, IDC_COUNT_FILESKIP, m_nFileSkip);
-       DDX_Text(pDX, IDC_COUNT_FOLDERSKIP, m_nFolderSkip);
-       DDX_Text(pDX, IDC_COUNT_LFILE, m_nLFile);
-       DDX_Text(pDX, IDC_COUNT_LFOLDER, m_nLFolder);
-       DDX_Text(pDX, IDC_COUNT_NOTEQUAL, m_nNotEqual);
-       DDX_Text(pDX, IDC_COUNT_RFILE, m_nRFile);
-       DDX_Text(pDX, IDC_COUNT_RFOLDER, m_nRFolder);
-       DDX_Text(pDX, IDC_COUNT_ERROR, m_nError);
-       DDX_Text(pDX, IDC_COUNT_FOLDER, m_nFolder);
        DDX_Control(pDX, IDC_COMPARISON_STOP, m_ctlStop);
        //}}AFX_DATA_MAP
 }
 
-
 BEGIN_MESSAGE_MAP(CDirCompStateBar, CDialogBar)
        //{{AFX_MSG_MAP(CDirCompStateBar)
        ON_COMMAND(IDC_COMPARISON_STOP, OnStop)
        ON_UPDATE_COMMAND_UI(IDC_COMPARISON_STOP, OnUpdateStop)
        ON_WM_WINDOWPOSCHANGING()
+       ON_WM_TIMER()
        //}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
@@ -120,6 +115,7 @@ BOOL CDirCompStateBar::GetDefaultRect( LPRECT lpRect ) const
  * @brief User selects to stop compare.
  *
  * Aborts compare and hides status panel.
+ * @todo Couldn't we close this bar without using frame code?
  */
 void CDirCompStateBar::OnStop()
 {
@@ -138,7 +134,7 @@ void CDirCompStateBar::OnStop()
 }
 
 /**
- * @brief Update button text.
+ * @brief Update button text (Stop/Close).
  *
  * Changes button text after compare is ready.
  */
@@ -150,17 +146,17 @@ void CDirCompStateBar::OnUpdateStop(CCmdUI* pCmdUI)
        CDirDoc * pDirDoc = dynamic_cast<CDirDoc*>(pFrameWnd->GetActiveDocument());
        ASSERT(pDirDoc != NULL);
 
-       // adapt the text of button 
+       // Change button text if scan is finished and it hasn't been yet changed. 
        if (m_ctlStop.GetSafeHwnd())
        {
                if (!pDirDoc->IsCurrentScanAbortable())
                {
-                       CString text;
-                       m_ctlStop.GetWindowText(text);
-                       if (text != strClose)
+                       if (m_bStopText)
                        {
                                m_ctlStop.SetWindowText(strClose);
+                               m_bStopText = FALSE;
                                m_lElapsed += ::GetTickCount();
+                               CString text;
                                text.Format(IDS_ELAPSED_TIME, m_lElapsed);
                                pFrameWnd->SetMessageText(text);
                        }
@@ -170,125 +166,66 @@ void CDirCompStateBar::OnUpdateStop(CCmdUI* pCmdUI)
 }
  
 /**
- * @brief Increase given category count by one and update panel
- *
- * Diff code calls this function every time it has compeleted comparing
- * one item.
- * @todo This could be optimised by letting timer call UI update
- * couple of times per second.
+ * @brief Return control ID for result code.
  */
-void CDirCompStateBar::AddElement(UINT diffcode)
+UINT CDirCompStateBar::GetIDFromResult(CompareStats::RESULT res)
 {
-       DIFFCODE di = diffcode;
-       
-       // Test first for skipped so we pick all skipped items as such 
-       if (di.isResultFiltered())
-       {
-               // skipped
-               if (di.isDirectory())
-               {
-                       ++m_nFolderSkip;
-                       SetDlgItemInt(IDC_COUNT_FOLDERSKIP, m_nFolderSkip);
-               }
-               else
-               {
-                       ++m_nFileSkip;
-                       SetDlgItemInt(IDC_COUNT_FILESKIP, m_nFileSkip);
-               }
-       }
-       else if (di.isSideLeft())
-       {
-               // left-only
-               if (di.isDirectory())
-               {
-                       ++m_nLFolder;
-                       SetDlgItemInt(IDC_COUNT_LFOLDER, m_nLFolder);
-               }
-               else
-               {
-                       ++m_nLFile;
-                       SetDlgItemInt(IDC_COUNT_LFILE, m_nLFile);
-               }
-       }
-       else if (di.isSideRight())
-       {
-               // right-only
-               if (di.isDirectory())
-               {
-                       ++m_nRFolder;
-                       SetDlgItemInt(IDC_COUNT_RFOLDER, m_nRFolder);
-               }
-               else
-               {
-                       ++m_nRFile;
-                       SetDlgItemInt(IDC_COUNT_RFILE, m_nRFile);
-               }
-       }
-       else if (di.isResultError())
-       {
-               // could be directory error ?
-               ++m_nError;
-               SetDlgItemInt(IDC_COUNT_ERROR, m_nError);
-       }
-       // Now we know it was on both sides & compared!
-       else if (di.isResultSame())
-       {
-               // same
-               if (di.isBin())
-               {
-                       ++m_nBinarySame;
-                       SetDlgItemInt(IDC_COUNT_BINARYSAME, m_nBinarySame);
-               }
-               else
-               {
-                       ++m_nEqual;
-                       SetDlgItemInt(IDC_COUNT_EQUAL, m_nEqual);
-               }
-       }
-       else
+       UINT resID = 0;
+
+       switch ((int)res)
        {
-               // presumably it is diff
-               if (di.isDirectory())
-               {
-                       ++m_nFolder;
-                       SetDlgItemInt(IDC_COUNT_FOLDER, m_nFolder);
-               }
-               else
-               {
-                       if (di.isBin())
-                       {
-                               ++m_nBinaryDiff;
-                               SetDlgItemInt(IDC_COUNT_BINARYDIFF, m_nBinaryDiff);
-                       }
-                       else
-                       {
-                               ++m_nNotEqual;
-                               SetDlgItemInt(IDC_COUNT_NOTEQUAL, m_nNotEqual);
-                       }
-               }
+       case CompareStats::RESULT_LUNIQUE:
+               resID = IDC_COUNT_LFILE;
+               break;
+       case CompareStats::RESULT_RUNIQUE:
+               resID = IDC_COUNT_RFILE;
+               break;
+       case CompareStats::RESULT_DIFF:
+               resID = IDC_COUNT_NOTEQUAL;
+               break;
+       case CompareStats::RESULT_SAME:
+               resID = IDC_COUNT_EQUAL;
+               break;
+       case CompareStats::RESULT_BINSAME:
+               resID = IDC_COUNT_BINARYSAME;
+               break;
+       case CompareStats::RESULT_BINDIFF:
+               resID = IDC_COUNT_BINARYDIFF;
+               break;
+       case CompareStats::RESULT_LDIRUNIQUE:
+               resID = IDC_COUNT_LFOLDER;
+               break;
+       case CompareStats::RESULT_RDIRUNIQUE:
+               resID = IDC_COUNT_RFOLDER;
+               break;
+       case CompareStats::RESULT_SKIP:
+               resID = IDC_COUNT_FILESKIP;
+               break;
+       case CompareStats::RESULT_DIRSKIP:
+               resID = IDC_COUNT_FOLDERSKIP;
+               break;
+       case CompareStats::RESULT_DIR:
+               resID = IDC_COUNT_FOLDER;
+               break;
+       case CompareStats::RESULT_ERROR:
+               resID = IDC_COUNT_ERROR;
+               break;
        }
+       return resID;
 }
 
 /**
- * @brief Reflow all status counts at current values
- *
- * Used when this bar is reloaded for a language change
- * This duplicates the SetDlgItem calls in AddElement.
+ * @brief Update all status counts at current values.
  */
 void CDirCompStateBar::UpdateElements()
 {
-       SetDlgItemInt(IDC_COUNT_LFOLDER, m_nLFolder);
-       SetDlgItemInt(IDC_COUNT_LFILE, m_nLFile);
-       SetDlgItemInt(IDC_COUNT_RFOLDER, m_nRFolder);
-       SetDlgItemInt(IDC_COUNT_RFILE, m_nRFile);
-       SetDlgItemInt(IDC_COUNT_FOLDERSKIP, m_nFolderSkip);
-       SetDlgItemInt(IDC_COUNT_FILESKIP, m_nFileSkip);
-       SetDlgItemInt(IDC_COUNT_ERROR, m_nError);
-       SetDlgItemInt(IDC_COUNT_BINARYSAME, m_nBinarySame);
-       SetDlgItemInt(IDC_COUNT_EQUAL, m_nEqual);
-       SetDlgItemInt(IDC_COUNT_FOLDER, m_nFolder);
-       SetDlgItemInt(IDC_COUNT_BINARYDIFF, m_nBinaryDiff);
-       SetDlgItemInt(IDC_COUNT_NOTEQUAL, m_nNotEqual);
+       for (int i = 0; i < CompareStats::RESULT_COUNT; i++)
+       {
+               CompareStats::RESULT resnum = static_cast<CompareStats::RESULT>(i);
+               UINT resID = GetIDFromResult(resnum);
+               int count = m_pCompareStats->GetCount(resnum);
+               SetDlgItemInt(resID, count);
+       }
 }
 
 /**
@@ -307,9 +244,7 @@ BOOL CDirCompStateBar::PreTranslateMessage(MSG* pMsg)
                }
 
                // When the scan is finished, any key will hide the bar
-               CFrameWnd * pFrameWnd = static_cast<CFrameWnd*> (GetOwner());
-               CDirDoc * pDirDoc = dynamic_cast<CDirDoc*>(pFrameWnd->GetActiveDocument());
-               if (!pDirDoc->IsCurrentScanAbortable())
+               if (m_pCompareStats->GetCompareState() == CompareStats::STATE_READY)
                {
                        OnStop();
                        return TRUE;
@@ -346,6 +281,50 @@ void CDirCompStateBar::Reset()
        m_lElapsed -= ::GetTickCount();
        UpdateData(FALSE);
        m_ctlStop.SetWindowText(strAbort);
+       m_bStopText = TRUE;
        // also give the focus to the button (PreTranslateMessage needs it)
        m_ctlStop.SetFocus();
 }
+
+/**
+ * @brief Set pointer to compare stats.
+ */
+void CDirCompStateBar::SetCompareStat(CompareStats * pCompareStats)
+{
+       m_pCompareStats = pCompareStats;
+}
+
+/**
+ * @brief Timer message received.
+ */
+void CDirCompStateBar::OnTimer(UINT nIDEvent)
+{
+       if (nIDEvent == IDT_UPDATE)
+       {
+               UpdateElements();
+
+               // If compare is finished, stop timer
+               if (m_pCompareStats->GetCompareState() == CompareStats::STATE_READY)
+                       EndUpdating();
+       }
+       else
+               CDialogBar::OnTimer(nIDEvent);
+
+}
+
+/**
+ * @brief Start timer for UI updating.
+ */
+void CDirCompStateBar::StartUpdating()
+{
+       UpdateElements();
+       SetTimer(IDT_UPDATE, UPDATE_INTERVAL, NULL);
+}
+
+/**
+ * @brief Stop timer updating UI.
+ */
+void CDirCompStateBar::EndUpdating()
+{
+       KillTimer(IDT_UPDATE);
+}
index 92abddd..02f201e 100644 (file)
@@ -9,8 +9,12 @@
 #if !defined(AFX_DIRCOMPSTATEDLG_H__8F66C090_C232_429F_A4A2_18D43CCC6C38__INCLUDED_)
 #define AFX_DIRCOMPSTATEDLG_H__8F66C090_C232_429F_A4A2_18D43CCC6C38__INCLUDED_
 
+#ifndef _COMPARESTATS_H_
+#include "CompareStats.h"
+#endif
 
 class CDirFrame;
+class CompareStats;
 
 /////////////////////////////////////////////////////////////////////////////
 // CDirCompStateBar dialog
@@ -27,35 +31,21 @@ class CDirCompStateBar : public CDialogBar
 public:
        CDirCompStateBar(CWnd* pParent = NULL);   // standard constructor
        BOOL Create(CWnd* pParentWnd);
-       void AddElement(UINT diffcode);
        BOOL GetDefaultRect( LPRECT lpRect ) const;
        void UpdateText(CStatic * ctrl, int num) const;
        void Reset();
        void UpdateElements();
+       void SetCompareStat(CompareStats * pCompareStats);
+       void StartUpdating();
+       void EndUpdating();
+       UINT GetIDFromResult(CompareStats::RESULT res);
 
 // Dialog Data
        //{{AFX_DATA(CDirCompStateBar)
        enum { IDD = IDD_DIRCOMPSTATE };
-       int             m_nBinaryDiff;
-       int             m_nBinarySame;
-       int             m_nEqual;
-       int             m_nFileSkip;
-       int             m_nFolderSkip;
-       int             m_nLFile;
-       int             m_nLFolder;
-       int             m_nNotEqual;
-       int             m_nRFile;
-       int             m_nRFolder;
-       int             m_nError;
-       int             m_nFolder;
        CButton m_ctlStop;
        //}}AFX_DATA
 
-       CString strAbort;
-       CString strClose;
-
-       long m_lElapsed;
-
 // Overrides
        virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
 
@@ -75,8 +65,16 @@ protected:
        afx_msg void OnStop();
        afx_msg void OnUpdateStop(CCmdUI* pCmdUI);
        afx_msg void OnWindowPosChanging( WINDOWPOS* lpwndpos );
+       afx_msg void OnTimer(UINT nIDEvent);
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
+
+private:
+       CString strAbort; /**< 'Stop' text for button */
+       CString strClose; /**< 'Close' text for button */
+       long m_lElapsed; /**< Elapsed time for compare */
+       CompareStats *m_pCompareStats; /**< Pointer to comparestats */
+       BOOL m_bStopText; /**< Button has 'Stop' text? */
 };
 
 //{{AFX_INSERT_LOCATION}}
index ef6b22f..3cb13c7 100644 (file)
@@ -31,6 +31,7 @@
 #include "stdafx.h"
 #include <Shlwapi.h>           // PathCompactPathEx()
 #include "Merge.h"
+#include "CompareStats.h"
 #include "DirDoc.h"
 #include "DirFrame.h"
 #include "diff.h"
@@ -64,6 +65,7 @@ IMPLEMENT_DYNCREATE(CDirDoc, CDocument)
 CDirDoc::CDirDoc()
 : m_pCtxt(NULL)
 , m_pDirView(NULL)
+, m_pCompareStats(NULL)
 , m_bROLeft(FALSE)
 , m_bRORight(FALSE)
 , m_bRecursive(FALSE)
@@ -90,6 +92,8 @@ CDirDoc::CDirDoc()
 CDirDoc::~CDirDoc()
 {
        delete m_pCtxt;
+       delete m_pCompareStats;
+
        // Inform all of our merge docs that we're closing
        for (POSITION pos = m_MergeDocs.GetHeadPosition(); pos; )
        {
@@ -179,9 +183,12 @@ BOOL CDirDoc::InitCompare(const PathContext & paths, BOOL bRecursive)
        if (m_pCtxt != NULL)
                delete m_pCtxt;
        
+       if (m_pCompareStats == NULL)
+               m_pCompareStats = new CompareStats();
+
        m_pCtxt = new CDiffContext(paths.GetLeft(), paths.GetRight());
        
-       if (m_pCtxt != NULL)
+       if (m_pCtxt != NULL && m_pCompareStats != NULL)
        {
                m_bRecursive = bRecursive;
                // All plugin management is done by our plugin manager
@@ -209,6 +216,8 @@ void CDirDoc::Rescan()
 
        gLog.Write(LOGLEVEL::LNOTICE, _T("Starting directory scan:\n\tLeft: %s\n\tRight: %s\n"),
                        m_pCtxt->GetLeftPath(), m_pCtxt->GetRightPath());
+       m_pCompareStats->Reset();
+       pf->SetCompareStats(m_pCompareStats);
        pf->clearStatus();
        pf->ShowProcessingBar(TRUE);
 
@@ -221,6 +230,7 @@ void CDirDoc::Rescan()
        m_pCtxt->m_bGuessEncoding = mf->m_options.GetBool(OPT_CP_DETECT);
        m_pCtxt->m_nCompMethod = mf->m_options.GetInt(OPT_CMP_METHOD);
        m_pCtxt->m_bIgnoreSmallTimeDiff = mf->m_options.GetBool(OPT_IGNORE_SMALL_FILETIME);
+       m_pCtxt->m_pCompareStats = m_pCompareStats;
        UpdateHeaderPath(TRUE);
        UpdateHeaderPath(FALSE);
        // draw the headers as active ones
@@ -766,6 +776,7 @@ void CDirDoc::AbortCurrentScan()
 {
        gLog.Write(LOGLEVEL::LNOTICE, _T("Dircompare aborted!"));
        m_diffThread.Abort();
+       m_pCompareStats->SetCompareState(CompareStats::STATE_READY);
 }
 
 /**
index 4b76d39..9f06731 100644 (file)
@@ -137,6 +137,7 @@ protected:
 private:
        CDiffContext *m_pCtxt; /**< Pointer to diff-data */
        CDirView *m_pDirView;
+       CompareStats *m_pCompareStats;
        MergeDocPtrList m_MergeDocs;
        BOOL m_bROLeft; /**< Is left side read-only */
        BOOL m_bRORight; /**< Is right side read-only */
index 3998b47..01622b5 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "stdafx.h"
 #include "Merge.h"
+#include "CompareStats.h"
 #include "DirFrame.h"
 #include "FilepathEdit.h"
 #include "DirDoc.h"
@@ -92,7 +93,6 @@ BEGIN_MESSAGE_MAP(CDirFrame, CMDIChildWnd)
        ON_UPDATE_COMMAND_UI(ID_STATUS_DIFFNUM, OnUpdateStatusNum)
        ON_WM_CLOSE()
        ON_WM_SIZE()
-       ON_MESSAGE(MSG_STAT_UPDATE, OnUpdateStatusMessage)
        ON_WM_MDIACTIVATE()
        //}}AFX_MSG_MAP
 END_MESSAGE_MAP()
@@ -252,6 +252,9 @@ void CDirFrame::SetStateBarLoc()
        FloatControlBar(&m_wndCompStateBar, origin);
 }
 
+/**
+ * @brief Empty diff-number pane from statusbar when dirview active
+ */
 void CDirFrame::OnUpdateStatusNum(CCmdUI* pCmdUI) 
 {
        pCmdUI->SetText(_T(""));
@@ -308,21 +311,6 @@ void CDirFrame::clearStatus()
        m_wndCompStateBar.Reset();
 }
 
-/// diff completed another file
-void CDirFrame::rptStatus(UINT diffcode)
-{
-       m_wndCompStateBar.AddElement(diffcode);
-}
-
-LRESULT CDirFrame::OnUpdateStatusMessage(WPARAM wParam, LPARAM lParam)
-{
-       if (wParam == 0xFF)
-               clearStatus();
-       else
-               rptStatus(wParam);
-       return 0; // return value not meaningful
-}
-
 /** 
  * @brief Interface to show/hide the floating state bar
  */
@@ -333,9 +321,13 @@ void CDirFrame::ShowProcessingBar(BOOL bShow)
                ShowControlBar(&m_wndCompStateBar, TRUE, FALSE);
                // disable the list view as long as the state bar is shown
                GetActiveView()->EnableWindow(FALSE);
+               m_wndCompStateBar.StartUpdating();
        }
-       else if (!bShow) 
+       else if (!bShow)
+       {
+               m_wndCompStateBar.EndUpdating();
                ShowControlBar(&m_wndCompStateBar, FALSE, FALSE);
+       }
 
        m_bStateBarIsActive = bShow;
 }
@@ -448,4 +440,12 @@ void CDirFrame::ShowControlBar( CControlBar* pBar, BOOL bShow, BOOL bDelay )
        }
 }
 
+void CDirFrame::SetCompareStats(CompareStats *pCompareStats)
+{
+       m_wndCompStateBar.SetCompareStat(pCompareStats);
+}
 
+void CDirFrame::UpdateStats()
+{
+       m_wndCompStateBar.UpdateElements();
+}
index 16106c7..9dcf400 100644 (file)
@@ -32,6 +32,8 @@
 #include "EditorFilepathBar.h"
 #include "DirCompStateBar.h"
 
+class CompareStats;
+
 /////////////////////////////////////////////////////////////////////////////
 // CDirFrame frame
 
@@ -54,11 +56,12 @@ public:
        CStatusBar  m_wndStatusBar;
        void SetClosableCallback(bool (*canclose)(void *), void * param);
        IHeaderBar * GetHeaderInterface();
-       void rptStatus(UINT diffcode);
        void clearStatus();
        void ShowProcessingBar(BOOL bShow);
        void NotifyHideStateBar();
        void UpdateResources();
+       void SetCompareStats(CompareStats *pCompareStats);
+       void UpdateStats();
 
 // Overrides
        // ClassWizard generated virtual function overrides
@@ -95,7 +98,6 @@ protected:
        afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
        afx_msg void OnClose();
        afx_msg void OnSize(UINT nType, int cx, int cy);
-       afx_msg LRESULT OnUpdateStatusMessage(WPARAM wParam, LPARAM lParam);
        afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd);
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
index 388926d..75e3515 100644 (file)
@@ -10,6 +10,7 @@
 #include <shlwapi.h>
 #include <sys/stat.h>
 #include "DirScan.h"
+#include "CompareStats.h"
 #include "common/unicoder.h"
 #include "DiffContext.h"
 #include "DiffWrapper.h"
@@ -74,9 +75,12 @@ typedef int (CString::*cmpmth)(LPCTSTR sz) const;
  * @return 1 normally, -1 if compare was aborted
  */
 int DirScan_GetItems(const PathContext &paths, const CString & subdir, DiffItemList *pList,
-               bool casesensitive, int depth, IAbortable * piAbortable)
+               bool casesensitive, int depth, CDiffContext * pCtxt, IAbortable * piAbortable)
 {
        static const TCHAR backslash[] = _T("\\");
+
+       pCtxt->m_pCompareStats->SetCompareState(CompareStats::STATE_COLLECT);
+
        CString sLeftDir = paths.GetLeft();
        CString sRightDir = paths.GetRight();
        CString subprefix;
@@ -144,7 +148,7 @@ int DirScan_GetItems(const PathContext &paths, const CString & subdir, DiffItemL
                                        // Recursive compare
                                        // Scan recursively all subdirectories too, we are not adding folders
                                        if (DirScan_GetItems(paths, newsub, pList, casesensitive,
-                                                       depth - 1, piAbortable) == -1)
+                                                       depth - 1, pCtxt, piAbortable) == -1)
                                        {
                                                return -1;
                                        }
@@ -225,17 +229,25 @@ int DirScan_GetItems(const PathContext &paths, const CString & subdir, DiffItemL
  */
 int DirScan_CompareItems(DiffItemList & list, CDiffContext * pCtxt, IAbortable * piAbortable)
 {
+       int res = 1;
+
+       pCtxt->m_pCompareStats->SetCompareState(CompareStats::STATE_COMPARE);
+
        POSITION pos = list.GetFirstDiffPosition();
        
        while (pos != NULL)
        {
                if (piAbortable && piAbortable->ShouldAbort())
-                       return -1;
+               {
+                       res = -1;
+                       break;
+               }
 
                DIFFITEM di = list.GetNextDiffPosition(pos);
                CompareDiffItem(di, pCtxt);
        }
-       return 1;
+       pCtxt->m_pCompareStats->SetCompareState(CompareStats::STATE_READY);
+       return res;
 }
 
 /**
@@ -247,12 +259,19 @@ int DirScan_CompareItems(DiffItemList & list, CDiffContext * pCtxt, IAbortable *
  */
 int DirScan_CompareItems(CDiffContext * pCtxt, IAbortable * piAbortable)
 {
+       int res = 1;
+
+       pCtxt->m_pCompareStats->SetCompareState(CompareStats::STATE_COMPARE);
+
        POSITION pos = pCtxt->GetFirstDiffPosition();
        
        while (pos != NULL)
        {
                if (piAbortable && piAbortable->ShouldAbort())
-                       return -1;
+               {
+                       res = -1;
+                       break;
+               }
 
                POSITION oldPos = pos;
                DIFFITEM di = pCtxt->GetNextDiffPosition(pos);
@@ -265,7 +284,8 @@ int DirScan_CompareItems(CDiffContext * pCtxt, IAbortable * piAbortable)
                                CompareDiffItem(di, pCtxt);
                }
        }
-       return 1;
+       pCtxt->m_pCompareStats->SetCompareState(CompareStats::STATE_READY);
+       return res;
 }
 
 /**
index 4e9f736..15d1430 100644 (file)
@@ -21,7 +21,7 @@ public:
 };
 
 int DirScan_GetItems(const PathContext &paths, const CString & subdir, DiffItemList * pLst,
-               bool casesensitive, int depth, IAbortable * piAbortable);
+               bool casesensitive, int depth, CDiffContext * pCtxt, IAbortable * piAbortable);
 
 int DirScan_CompareItems(DiffItemList & list, CDiffContext * pCtxt, IAbortable * piAbortable);
 int DirScan_CompareItems(CDiffContext * pCtxt, IAbortable * piAbortable);
index a74b82d..0812630 100644 (file)
@@ -2058,15 +2058,7 @@ void CDirView::OnDirStatePane()
 
        // Clear and recount item numbers
        pf->clearStatus();
-       DIFFITEM di;
-       POSITION pos = ctxt.GetFirstDiffPosition();
-       while (pos)
-       {
-               di = ctxt.GetDiffAt(pos);
-               pf->rptStatus(di.diffcode);
-               ctxt.GetNextDiffPosition(pos);
-       }
-
+       pf->UpdateStats();
        pf->ShowProcessingBar(TRUE);
 }
 
index d9d3972..7fabf26 100644 (file)
@@ -221,6 +221,10 @@ SOURCE=.\ColorButton.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\CompareStats.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\ConfigLog.cpp
 # End Source File
 # Begin Source File
@@ -897,6 +901,10 @@ SOURCE=.\ColorButton.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\CompareStats.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\ConfigLog.h
 # End Source File
 # Begin Source File
index a87a8da..d9dc282 100644 (file)
@@ -1,3 +1,10 @@
+2005-06-21 Kimmo
+ PATCH: [ 1223754 ] Improve dircompare stats system
+  Src: DiffContext.cpp DiffContext.h DiffThread.cpp DirCompareStateBar.cpp
+   DirCompareStateBar.h DirDoc.cpp DirDoc.h DirFrame.cpp DirFrame.h DirScan.cpp
+   DirScan.h DirView.cpp Merge.dsp
+  Src new files: CompareStats.cpp CompareStats.h
+
 2005-06-21 WinMerge experimental release 2.3.3.6 (cvs)
 
 2005-06-21 Kimmo