4 * @brief Declarations of CDiffContext and diff structures
8 #define POCO_NO_UNWINDOWS 1
9 #include <Poco/Mutex.h>
11 #include "PathContext.h"
12 #include "DiffItemList.h"
13 #include "FilterList.h"
14 #include "SubstitutionList.h"
25 /** Interface to a provider of plugin info */
29 virtual void FetchPluginInfos(const String& filteredFilenames,
30 PackingInfo ** infoUnpacker,
31 PrediffingInfo ** infoPrediffer) = 0;
35 * The folder compare context.
36 * This class holds data of the current folder compare. There are paths
37 * to compare, filters used, compare options etc. And compare results list
38 * is also contained in this class. Many compare classes and functions have
39 * a pointer to instance of this class.
41 * @note If you add new member variables, remember to copy values in
42 * CDiffContext::CDiffContext(..,CDiffContext) constructor!
44 class CDiffContext : public DiffItemList
47 /** @brief Special values for difference counts. */
50 DIFFS_UNKNOWN = -1, /**< Difference count unknown (generally). */
51 DIFFS_UNKNOWN_QUICKCOMPARE = -9, /**< Unknown because of quick-compare method. */
54 CDiffContext(const PathContext & paths, int compareMethod);
57 void UpdateVersion(DIFFITEM &di, int nIndex) const;
60 * Get the main compare method used in this compare.
61 * @return Compare method used.
63 int GetCompareMethod(void) const { return m_nCompMethod; }
67 * @name Path accessor functions.
69 * These functions return left/right path associated to DiffContext.
70 * There is no setter fuctions and path can be set only via constructor.
71 * Normalized paths are preferred to use - short paths are expanded
72 * and trailing slashes removed (except from root path).
75 * Get left-side compare path.
76 * @return full path in left-side.
78 String GetLeftPath() const { return m_paths.GetLeft(false); }
79 String GetMiddlePath() const { return m_paths.GetMiddle(false); }
81 * Get right-side compare path.
82 * @return full path in right-side.
84 String GetRightPath() const { return m_paths.GetRight(false); }
85 String GetPath(int nIndex) const { return m_paths.GetPath(nIndex, false); }
87 * Get left-side compare path in normalized form.
88 * @return full path in left-side.
90 String GetNormalizedLeft() const { return m_paths.GetLeft(); }
91 String GetNormalizedMiddle() const { return m_paths.GetMiddle(); }
93 * Get right-side compare path in normalized form.
94 * @return full path in left-side.
96 String GetNormalizedRight() const { return m_paths.GetRight(); }
97 String GetNormalizedPath(int nIndex) const { return m_paths.GetPath(nIndex, true); }
98 PathContext GetNormalizedPaths() const
101 for (int nIndex = 0; nIndex < m_paths.GetSize(); nIndex++)
102 paths.SetPath(nIndex, m_paths.GetPath(nIndex, true));
107 // change an existing difference
108 bool UpdateInfoFromDiskHalf(DIFFITEM &di, int nIndex);
109 void UpdateStatusFromDisk(DIFFITEM *diffpos, int nIndex);
111 bool CreateCompareOptions(int compareMethod, const DIFFOPTIONS & options);
112 CompareOptions * GetCompareOptions(int compareMethod);
114 // retrieve or manufacture plugin info for specified file comparison
115 void FetchPluginInfos(const String& filteredFilenames,
116 PackingInfo ** infoUnpacker, PrediffingInfo ** infoPrediffer);
120 * @name Compare aborting interface.
121 * These functions handle compare aborting using IAbortable interface.
123 bool ShouldAbort() const;
126 * Set pointer to IAbortable interface.
127 * This function sets pointer to interface used to abort the compare when
129 * @param [in] piAbortable Pointer to interface.
131 void SetAbortable(IAbortable * piAbortable) { m_piAbortable = piAbortable; }
134 * Returns a pointer to current IAbortable interface.
135 * This function returns a pointer to interface used to abort the compare.
136 * @return Pointer to current IAbortable interface.
138 const IAbortable * GetAbortable() const { return m_piAbortable; }
141 int GetCompareDirs() const { return m_paths.GetSize(); }
143 void Swap(int idx1, int idx2)
146 tmp = m_paths.GetPath(idx1);
147 m_paths.SetPath(idx1, m_paths.GetPath(idx2));
148 m_paths.SetPath(idx2, tmp);
149 DiffItemList::Swap(idx1, idx2);
152 const DIFFOPTIONS *GetOptions() const { return m_pOptions.get(); }
154 IDiffFilter * m_piFilterGlobal; /**< Interface for file filtering. */
155 IDiffFilter * m_pImgfileFilter; /**< Interface for image file filtering */
156 IPluginInfos * m_piPluginInfos;
157 int m_iGuessEncodingType;
159 bool m_bIgnoreSmallTimeDiff; /**< Ignore small timedifferences when comparing by date */
160 CompareStats *m_pCompareStats; /**< Pointer to compare statistics */
163 * Optimize compare by stopping after first difference.
164 * In some compare methods (currently quick compare) we can stop the
165 * compare right after finding the first difference. This speeds up the
166 * compare, but also causes compare statistics to be inaccurate.
168 bool m_bStopAfterFirstDiff;
171 * Threshold size for switching to quick compare.
172 * When diffutils compare is selected, files bigger (in bytes) than this
173 * value are compared using Quick compare. This is because diffutils simply
174 * cannot compare large files. And large files are usually binary files.
176 int m_nQuickCompareLimit;
178 int m_nBinaryCompareLimit;
181 * Walk into unique folders and add contents.
182 * This enables/disables walking into unique folders. If we don't walk into
183 * unique folders, they are shown as such in folder compare results. If we
184 * walk into unique folders, we'll show all files in the unique folder and
185 * in possible subfolders.
187 * This value is true by default.
190 bool m_bIgnoreReparsePoints;
191 bool m_bIgnoreCodepage;
192 bool m_bEnableImageCompare;
193 double m_dColorDistanceThreshold;
195 bool m_bRecursive; /**< Do we include subfolders to compare? */
196 bool m_bPluginsEnabled; /**< Are plugins enabled? */
197 std::unique_ptr<FilterList> m_pFilterList; /**< Filter list for line filters */
198 std::shared_ptr<SubstitutionList> m_pSubstitutionList; /// list for Substitution Filters
202 * The main compare method used.
203 * This is the main compare method set when compare is started. There
204 * can be temporary switches to other method (e.g. for large file) but
205 * this main method must be set back for next file.
209 std::unique_ptr<DIFFOPTIONS> m_pOptions; /**< Generalized compare options. */
210 std::unique_ptr<CompareOptions> m_pContentCompareOptions; /**< Per compare method compare options. */
211 std::unique_ptr<CompareOptions> m_pQuickCompareOptions; /**< Per compare method compare options. */
212 PathContext m_paths; /**< (root) paths for this context */
213 IAbortable *m_piAbortable; /**< Interface for aborting the compare. */
214 Poco::FastMutex m_mutex;