1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
5 // SPDX-License-Identifier: GPL-2.0-or-later
6 /////////////////////////////////////////////////////////////////////////////
10 * @brief Implementation file for CDirDoc
16 #include <Poco/StringTokenizer.h>
17 #include <boost/range/mfc.hpp>
19 #include "IMergeDoc.h"
20 #include "CompareOptions.h"
21 #include "UnicodeString.h"
22 #include "CompareStats.h"
23 #include "FilterList.h"
24 #include "SubstitutionList.h"
30 #include "OptionsDef.h"
31 #include "OptionsMgr.h"
32 #include "OptionsDiffOptions.h"
33 #include "LineFiltersList.h"
34 #include "SubstitutionFiltersList.h"
35 #include "FileFilterHelper.h"
37 #include "DirActions.h"
39 #include "MessageBoxDialog.h"
40 #include "DirCmpReport.h"
41 #include "DiffWrapper.h"
42 #include "FolderCmp.h"
43 #include "DirViewColItems.h"
44 #include <Poco/Semaphore.h>
50 using Poco::StringTokenizer;
54 int CDirDoc::m_nDirsTemp = 2;
56 /////////////////////////////////////////////////////////////////////////////
59 IMPLEMENT_DYNCREATE(CDirDoc, CDocument)
67 , m_pCompareStats(nullptr)
68 , m_bMarkedRescan(false)
69 , m_pTempPathContext(nullptr)
70 , m_bGeneratingReport(false)
73 m_nDirs = m_nDirsTemp;
83 * Clears document list and deleted possible archive-temp files.
87 // Inform all of our merge docs that we're closing
88 for (auto pMergeDoc : m_MergeDocs)
89 pMergeDoc->DirDocClosing(this);
90 // Delete all temporary folders belonging to this document
91 while (m_pTempPathContext != nullptr)
93 m_pTempPathContext = m_pTempPathContext->DeleteHead();
98 * @brief Called when new dirdoc is created.
100 BOOL CDirDoc::OnNewDocument()
102 if (!CDocument::OnNewDocument())
109 BEGIN_MESSAGE_MAP(CDirDoc, CDocument)
110 //{{AFX_MSG_MAP(CDirDoc)
111 // NOTE - the ClassWizard will add and remove mapping macros here.
116 /////////////////////////////////////////////////////////////////////////////
117 // CDirDoc serialization
119 void CDirDoc::Serialize(CArchive& ar)
123 // TODO: add storing code here
127 // TODO: add loading code here
131 /////////////////////////////////////////////////////////////////////////////
135 * @brief Initialise directory compare for given paths.
137 * Initialises directory compare with paths given and recursive choice.
138 * Previous compare context is first free'd.
139 * @param [in] paths Paths to compare
140 * @param [in] bRecursive If `true` subdirectories are included to compare.
142 void CDirDoc::InitCompare(const PathContext & paths, bool bRecursive, CTempPathContext *pTempPathContext)
144 // Abort previous comparing
145 while (m_diffThread.GetThreadState() == CDiffThread::THREAD_COMPARING)
147 m_diffThread.Abort();
151 m_pDirView->DeleteAllDisplayItems();
152 // Anything that can go wrong here will yield an exception.
153 // Default implementation of operator new() never returns `nullptr`.
155 if (m_pCompareStats == nullptr)
156 m_pCompareStats.reset(new CompareStats(m_nDirs));
158 m_pCtxt.reset(new CDiffContext(paths,
159 GetOptionsMgr()->GetInt(OPT_CMP_METHOD)));
160 m_pCtxt->m_bRecursive = bRecursive;
162 if (pTempPathContext != nullptr)
165 for (nIndex = 0; nIndex < m_nDirs; nIndex++)
166 ApplyDisplayRoot(nIndex, pTempPathContext->m_strDisplayRoot[nIndex]);
167 pTempPathContext->m_pParent = m_pTempPathContext;
168 m_pTempPathContext = pTempPathContext;
169 for (nIndex = 0; nIndex < m_nDirs; nIndex++)
170 m_pTempPathContext->m_strRoot[nIndex] = m_pCtxt->GetNormalizedPath(nIndex);
176 * @brief Load line filters to the compare context.
177 * Loads linefilters, converts them to UTF-8 and sets them for compare context.
179 void CDirDoc::LoadLineFilterList(CDiffContext *pCtxt)
181 ASSERT(pCtxt != nullptr);
183 bool bFilters = GetOptionsMgr()->GetBool(OPT_LINEFILTER_ENABLED);
184 String filters = theApp.m_pLineFilters->GetAsString();
185 if (!bFilters || filters.empty())
187 pCtxt->m_pFilterList.reset();
191 if (pCtxt->m_pFilterList)
192 pCtxt->m_pFilterList->RemoveAllFilters();
194 pCtxt->m_pFilterList.reset(new FilterList());
196 std::string regexp_str = ucr::toUTF8(filters);
198 // Add every "line" of regexps to regexp list
199 StringTokenizer tokens(regexp_str, "\r\n");
200 for (StringTokenizer::Iterator it = tokens.begin(); it != tokens.end(); ++it)
201 pCtxt->m_pFilterList->AddRegExp(*it);
204 void CDirDoc::LoadSubstitutionFiltersList(CDiffContext* pCtxt)
206 ASSERT(pCtxt != nullptr);
208 bool SubstitutionFiltersEnabled = theApp.m_pSubstitutionFiltersList->GetEnabled();
209 if (!SubstitutionFiltersEnabled || theApp.m_pSubstitutionFiltersList->GetCount() == 0)
211 pCtxt->m_pSubstitutionList.reset();
215 pCtxt->m_pSubstitutionList = theApp.m_pSubstitutionFiltersList->MakeSubstitutionList();
218 void CDirDoc::DiffThreadCallback(int& state)
220 PostMessage(m_pDirView->GetSafeHwnd(), MSG_UI_UPDATE, state, false);
223 void CDirDoc::InitDiffContext(CDiffContext *pCtxt)
225 LoadLineFilterList(pCtxt);
226 LoadSubstitutionFiltersList(pCtxt);
228 DIFFOPTIONS options = {0};
229 Options::DiffOptions::Load(GetOptionsMgr(), options);
231 pCtxt->CreateCompareOptions(GetOptionsMgr()->GetInt(OPT_CMP_METHOD), options);
233 pCtxt->m_iGuessEncodingType = GetOptionsMgr()->GetInt(OPT_CP_DETECT);
234 if ((pCtxt->m_iGuessEncodingType >> 16) == 0)
235 pCtxt->m_iGuessEncodingType |= 50001 << 16;
236 pCtxt->m_bIgnoreSmallTimeDiff = GetOptionsMgr()->GetBool(OPT_IGNORE_SMALL_FILETIME);
237 pCtxt->m_bStopAfterFirstDiff = GetOptionsMgr()->GetBool(OPT_CMP_STOP_AFTER_FIRST);
238 pCtxt->m_nQuickCompareLimit = GetOptionsMgr()->GetInt(OPT_CMP_QUICK_LIMIT);
239 pCtxt->m_nBinaryCompareLimit = GetOptionsMgr()->GetInt(OPT_CMP_BINARY_LIMIT);
240 pCtxt->m_bPluginsEnabled = GetOptionsMgr()->GetBool(OPT_PLUGINS_ENABLED);
241 pCtxt->m_bWalkUniques = GetOptionsMgr()->GetBool(OPT_CMP_WALK_UNIQUE_DIRS);
242 pCtxt->m_bIgnoreReparsePoints = GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_REPARSE_POINTS);
243 pCtxt->m_bIgnoreCodepage = GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_CODEPAGE);
244 pCtxt->m_bEnableImageCompare = GetOptionsMgr()->GetBool(OPT_CMP_ENABLE_IMGCMP_IN_DIRCMP);
245 pCtxt->m_dColorDistanceThreshold = GetOptionsMgr()->GetInt(OPT_CMP_IMG_THRESHOLD) / 1000.0;
247 m_imgfileFilter.UseMask(true);
248 m_imgfileFilter.SetMask(GetOptionsMgr()->GetString(OPT_CMP_IMG_FILEPATTERNS));
249 pCtxt->m_pImgfileFilter = &m_imgfileFilter;
251 pCtxt->m_pCompareStats = m_pCompareStats.get();
253 // Make sure filters are up-to-date
254 theApp.m_pGlobalFileFilter->ReloadUpdatedFilters();
255 pCtxt->m_piFilterGlobal = theApp.m_pGlobalFileFilter.get();
257 // All plugin management is done by our plugin manager
258 pCtxt->m_piPluginInfos = GetOptionsMgr()->GetBool(OPT_PLUGINS_ENABLED) ? &m_pluginman : nullptr;
262 * @brief Perform directory comparison again from scratch
264 void CDirDoc::Rescan()
266 if (m_pCtxt == nullptr)
269 CDirFrame *pf = m_pDirView->GetParentFrame();
271 // If we're already doing a rescan, bail out
272 UINT threadState = m_diffThread.GetThreadState();
273 if (threadState == CDiffThread::THREAD_COMPARING)
276 if (!m_bGeneratingReport)
277 m_pCompareStats->Reset();
278 m_pDirView->StartCompare(m_pCompareStats.get());
280 if (!m_bGeneratingReport)
281 m_pDirView->DeleteAllDisplayItems();
282 // Don't clear if only scanning selected items
283 if (!m_bMarkedRescan && !m_bGeneratingReport)
285 m_pCtxt->RemoveAll();
286 m_pCtxt->InitDiffItemList();
289 InitDiffContext(m_pCtxt.get());
291 pf->GetHeaderInterface()->SetPaneCount(m_nDirs);
292 pf->GetHeaderInterface()->SetOnSetFocusCallback([&](int pane) {
293 m_pDirView->SetActivePane(pane);
294 GetOptionsMgr()->SaveOption(OPT_ACTIVE_PANE, pane);
296 for (int nIndex = 0; nIndex < m_nDirs; nIndex++)
298 UpdateHeaderPath(nIndex);
299 // draw the headers as inactive ones
300 pf->GetHeaderInterface()->SetActive(nIndex, false);
302 pf->GetHeaderInterface()->Resize();
303 int nPane = GetOptionsMgr()->GetInt(OPT_ACTIVE_PANE);
304 m_pDirView->SetActivePane((nPane >= 0 && nPane < m_nDirs) ? nPane : 0);
306 // Show current compare method name and active filter name in statusbar
307 pf->SetFilterStatusDisplay(theApp.m_pGlobalFileFilter->GetFilterNameOrMask().c_str());
308 pf->SetCompareMethodStatusDisplay(m_pCtxt->GetCompareMethod());
310 // Folder names to compare are in the compare context
311 m_diffThread.SetContext(m_pCtxt.get());
312 m_diffThread.RemoveListener(this, &CDirDoc::DiffThreadCallback);
313 m_diffThread.AddListener(this, &CDirDoc::DiffThreadCallback);
314 if (m_bGeneratingReport)
316 m_diffThread.SetCollectFunction([&](DiffFuncStruct* myStruct) {
318 if (m_pReport->GetCopyToClipboard())
321 if (m_pReport->GetReportType() == REPORT_TYPE_SIMPLEHTML)
324 if (!m_pReport->GetReportFile().empty())
326 myStruct->context->m_pCompareStats->IncreaseTotalItems(
327 (m_pDirView->GetListCtrl().GetItemCount() - (myStruct->context->m_bRecursive ? 0 : 1)) * m);
329 m_diffThread.SetCompareFunction([&](DiffFuncStruct* myStruct) {
330 m_pReport->SetDiffFuncStruct(myStruct);
331 myStruct->pSemaphore->wait();
333 if (m_pReport->GenerateReport(errStr))
337 if (GetReportFile().empty())
338 LangMessageBox(IDS_REPORT_SUCCESS, MB_OK | MB_ICONINFORMATION);
342 String msg = strutils::format_string1(
343 _("Error creating the report:\n%1"),
345 AfxMessageBox(msg.c_str(), MB_OK | MB_ICONSTOP);
348 SetGeneratingReport(false);
352 else if (m_bMarkedRescan)
354 m_diffThread.SetCollectFunction(nullptr);
355 m_diffThread.SetCompareFunction([](DiffFuncStruct* myStruct) {
356 int nItems = DirScan_UpdateMarkedItems(myStruct, nullptr);
357 myStruct->context->m_pCompareStats->IncreaseTotalItems(nItems);
358 DirScan_CompareRequestedItems(myStruct, nullptr);
363 m_diffThread.SetCollectFunction([](DiffFuncStruct* myStruct) {
364 bool casesensitive = false;
365 int depth = myStruct->context->m_bRecursive ? -1 : 0;
366 PathContext paths = myStruct->context->GetNormalizedPaths();
367 String subdir[3] = {_T(""), _T(""), _T("")}; // blank to start at roots specified in diff context
368 // Build results list (except delaying file comparisons until below)
369 DirScan_GetItems(paths, subdir, myStruct,
370 casesensitive, depth, nullptr, myStruct->context->m_bWalkUniques);
372 m_diffThread.SetCompareFunction([](DiffFuncStruct* myStruct) {
373 DirScan_CompareItems(myStruct, nullptr);
376 m_diffThread.CompareDirectories();
377 m_bMarkedRescan = false;
381 * @brief Empty & reload listview (of files & columns) with comparison results
382 * @todo Better solution for special items ("..")?
384 void CDirDoc::Redisplay()
386 if (m_pDirView == nullptr)
389 // Do not redisplay an empty CDirView
390 // Not only does it not have results, but AddSpecialItems will crash
391 // trying to dereference null context pointer to get to paths
395 m_pDirView->Redisplay();
398 CDirView * CDirDoc::GetMainView() const
400 CDirView *pView = nullptr;
401 if (POSITION pos = GetFirstViewPosition())
403 pView = static_cast<CDirView*>(GetNextView(pos));
404 ASSERT_KINDOF(CDirView, pView);
410 * @brief Update in-memory diffitem status from disk and update view.
411 * @param [in] diffPos POSITION of item in UI list.
412 * @param [in] idx index to reload.
413 * @note Do not call this function from DirView code! This function
414 * calls slow DirView functions to get item position and to update GUI.
415 * Use UpdateStatusFromDisk() function instead.
417 void CDirDoc::ReloadItemStatus(DIFFITEM *diffPos, int idx)
419 // in case just copied (into existence) or modified
420 m_pCtxt->UpdateStatusFromDisk(diffPos, idx);
422 int nIdx = m_pDirView->GetItemIndex(diffPos);
426 m_pDirView->UpdateDiffItemStatus(nIdx);
430 void CDirDoc::InitStatusStrings()
436 * @brief Update any resources necessary after a GUI language change
438 void CDirDoc::UpdateResources()
440 if (m_pDirView != nullptr)
441 m_pDirView->UpdateResources();
449 * @brief Stash away our view pointer.
451 void CDirDoc::SetDirView(CDirView * newView)
453 m_pDirView = newView;
454 // MFC has a view list for us, so lets check against it
455 POSITION pos = GetFirstViewPosition();
456 CDirView * temp = static_cast<CDirView *>(GetNextView(pos));
457 ASSERT(temp == m_pDirView); // verify that our stashed pointer is the same as MFC's
461 * @brief A new MergeDoc has been opened.
463 void CDirDoc::AddMergeDoc(IMergeDoc * pMergeDoc)
465 ASSERT(pMergeDoc != nullptr);
466 m_MergeDocs.AddTail(pMergeDoc);
470 * @brief MergeDoc informs us it is closing.
472 void CDirDoc::MergeDocClosing(IMergeDoc * pMergeDoc)
474 ASSERT(pMergeDoc != nullptr);
475 if (POSITION pos = m_MergeDocs.CPtrList::Find(pMergeDoc))
476 m_MergeDocs.RemoveAt(pos);
480 // If dir compare is empty (no compare results) and we are not closing
481 // because of reuse close also dir compare
482 if (m_pDirView != nullptr)
484 if (m_pCtxt == nullptr)
485 m_pDirView->PostMessage(WM_COMMAND, ID_FILE_CLOSE);
487 else if (m_MergeDocs.GetCount() == 0)
494 * @brief Close MergeDocs opened from DirDoc.
496 * Asks confirmation for docs containing unsaved data and then
498 * @return `true` if success, `false` if user canceled or closing failed
500 bool CDirDoc::CloseMergeDocs()
502 while (!m_MergeDocs.IsEmpty())
503 if (!m_MergeDocs.GetTail()->CloseNow())
509 * @brief Update changed item's compare status
510 * @param [in] paths Paths for files we update
511 * @param [in] nDiffs Total amount of differences
512 * @param [in] nTrivialDiffs Amount of ignored differences
513 * @param [in] bIdentical `true` if files became identical, `false` otherwise.
515 void CDirDoc::UpdateChangedItem(const PathContext &paths,
516 UINT nDiffs, UINT nTrivialDiffs, bool bIdentical)
518 DIFFITEM *pos = FindItemFromPaths(*m_pCtxt, paths);
519 // If we failed files could have been swapped so lets try again
522 PathContext pathsSwapped(paths);
523 std::swap(pathsSwapped[0], pathsSwapped[pathsSwapped.GetSize() - 1]);
524 pos = FindItemFromPaths(*m_pCtxt, pathsSwapped);
525 if (!pos && paths.GetSize() > 2)
527 pathsSwapped = paths;
528 std::swap(pathsSwapped[0], pathsSwapped[1]);
529 pos = FindItemFromPaths(*m_pCtxt, pathsSwapped);
530 if (!pos && paths.GetSize() > 2)
532 pathsSwapped = paths;
533 std::swap(pathsSwapped[1], pathsSwapped[2]);
534 pos = FindItemFromPaths(*m_pCtxt, pathsSwapped);
539 // Update status if paths were found for items.
540 // Fail means we had unique items compared as 'renamed' items
541 // so there really is not status to update.
544 // Figure out new status code
545 UINT diffcode = (bIdentical ? DIFFCODE::SAME : DIFFCODE::DIFF);
547 // Update both views and diff context memory
548 m_pCtxt->SetDiffStatusCode(pos, diffcode, DIFFCODE::COMPAREFLAGS);
550 if (nDiffs != -1 && nTrivialDiffs != -1)
551 m_pCtxt->SetDiffCounts(pos, nDiffs, nTrivialDiffs);
552 for (int i = 0; i < m_pCtxt->GetCompareDirs(); ++i)
553 ReloadItemStatus(pos, i);
558 * @brief Cleans up after directory compare
560 void CDirDoc::CompareReady()
565 * @brief Refresh cached options.
567 * For compare speed, we have to cache some frequently needed options,
568 * instead of getting option value every time from OptionsMgr. This
569 * function must be called every time options are changed to OptionsMgr.
571 void CDirDoc::RefreshOptions()
573 if (m_pCtxt != nullptr)
574 m_pCtxt->m_bRecursive = GetOptionsMgr()->GetBool(OPT_CMP_INCLUDE_SUBDIRS);
575 if (m_pDirView != nullptr)
576 m_pDirView->RefreshOptions();
580 * @brief Write path and filename to headerbar
581 * @note SetText() does not repaint unchanged text
583 void CDirDoc::UpdateHeaderPath(int nIndex)
585 CDirFrame *pf = m_pDirView->GetParentFrame();
586 ASSERT(pf != nullptr);
589 if (!m_strDesc[nIndex].empty())
590 sText = m_strDesc[nIndex];
593 sText = m_pCtxt->GetPath(nIndex);
594 ApplyDisplayRoot(nIndex, sText);
597 pf->GetHeaderInterface()->SetText(nIndex, sText);
601 * @brief virtual override called just before document is saved and closed
603 BOOL CDirDoc::SaveModified()
605 // Do not allow closing if there is a thread running
606 if (m_diffThread.GetThreadState() == CDiffThread::THREAD_COMPARING)
608 int ans = LangMessageBox(IDS_CONFIRM_CLOSE_WINDOW, MB_YESNO | MB_ICONWARNING);
611 m_diffThread.Abort();
612 while (m_diffThread.GetThreadState() == CDiffThread::THREAD_COMPARING)
616 return CDocument::SaveModified();
620 * @brief Send signal to thread to stop current scan
622 * @sa CDirCompStateBar::OnStop()
624 void CDirDoc::AbortCurrentScan()
626 m_diffThread.Abort();
630 * @brief Send signal to thread to pause current scan
632 void CDirDoc::PauseCurrentScan()
634 m_diffThread.Pause();
638 * @brief Send signal to thread to continue current scan
640 void CDirDoc::ContinueCurrentScan()
642 m_diffThread.Continue();
646 * @brief Returns true if there is an active scan that hasn't been aborted.
648 bool CDirDoc::IsCurrentScanAbortable() const
650 return (m_diffThread.GetThreadState() == CDiffThread::THREAD_COMPARING
651 && !m_diffThread.IsAborting());
655 * @brief Set directory description texts shown in headerbar
657 void CDirDoc::SetDescriptions(const String strDesc[])
659 if (strDesc != nullptr)
660 std::copy_n(strDesc, m_nDirs, m_strDesc);
664 * @brief Replace internal root by display root
665 * When we have a archive file open, this function converts physical folder
666 * (that is in the temp folder where archive was extracted) to the virtual
667 * path for showing. The virtual path is path to the archive file, archive
668 * file name and folder inside the archive.
669 * @param [in, out] sText Path to convert.
671 void CDirDoc::ApplyDisplayRoot(int nIndex, String &sText)
673 if (m_pTempPathContext != nullptr)
675 if (sText.find(m_pTempPathContext->m_strRoot[nIndex]) == String::npos)
677 for (int pane = 0; pane < m_nDirs; ++pane)
679 if (sText.find(m_pTempPathContext->m_strRoot[pane]) != String::npos)
686 sText.erase(0, m_pTempPathContext->m_strRoot[nIndex].length());
687 sText.insert(0, m_pTempPathContext->m_strDisplayRoot[nIndex]);
692 * @brief Set document title to given string or items compared.
694 * Formats and sets caption for directory compare window. Caption
695 * has left- and right-side paths separated with '-'.
697 * @param [in] lpszTitle New title for window. If this parameter
698 * is not `nullptr` we use this string, otherwise format caption from
701 void CDirDoc::SetTitle(LPCTSTR lpszTitle)
703 if (m_pDirView == nullptr)
706 if (lpszTitle != nullptr)
707 CDocument::SetTitle(lpszTitle);
708 else if (m_pCtxt == nullptr || m_pCtxt->GetLeftPath().empty() ||
709 m_pCtxt->GetRightPath().empty() ||
710 (m_nDirs > 2 && m_pCtxt->GetMiddlePath().empty()))
712 String title = _("Folder Comparison Results");
713 CDocument::SetTitle(title.c_str());
719 for (int index = 0; index < m_nDirs; index++)
721 String strPath = m_pCtxt->GetPath(index);
722 ApplyDisplayRoot(index, strPath);
723 sDirName[index] = paths::FindFileName(strPath);
725 if (std::count(&sDirName[0], &sDirName[0] + m_nDirs, sDirName[0]) == m_nDirs)
726 sTitle = sDirName[0] + strutils::format(_T(" x %d"), m_nDirs);
728 sTitle = strutils::join(&sDirName[0], &sDirName[0] + m_nDirs, _T(" - "));
729 CDocument::SetTitle(sTitle.c_str());
735 * @brief Checks if current folders are opened from archive file.
736 * @return true if we are inside archive, false otherwise.
738 bool CDirDoc::IsArchiveFolders() const
740 if (m_pTempPathContext != nullptr)
746 void CDirDoc::Swap(int idx1, int idx2)
748 std::swap(m_bRO[idx1], m_bRO[idx2]);
749 std::swap(m_strDesc[idx1], m_strDesc[idx2]);
750 if (m_pTempPathContext != nullptr)
751 m_pTempPathContext->Swap(idx1, idx2);
752 m_pCtxt->Swap(idx1, idx2);
753 m_pCompareStats->Swap(idx1, idx2);
754 for (int nIndex = 0; nIndex < m_nDirs; nIndex++)
755 UpdateHeaderPath(nIndex);
759 bool CDirDoc::MoveableToNextDiff()
761 if (m_pDirView == nullptr)
763 CMessageBoxDialog dlg(nullptr, _("Do you want to move to the next file?").c_str());
764 const int nFormerResult = dlg.GetFormerResult();
765 if (nFormerResult != -1 && nFormerResult == IDNO)
767 return m_pDirView->HasNextDiff();
770 bool CDirDoc::MoveableToPrevDiff()
772 if (m_pDirView == nullptr)
774 CMessageBoxDialog dlg(nullptr, _("Do you want to move to the previous file?").c_str());
775 const int nFormerResult = dlg.GetFormerResult();
776 if (nFormerResult != -1 && nFormerResult == IDNO)
778 return m_pDirView->HasPrevDiff();
781 void CDirDoc::MoveToNextDiff(IMergeDoc *pMergeDoc)
783 if (m_pDirView == nullptr)
785 if (AfxMessageBox(_("Do you want to move to the next file?").c_str(), MB_YESNO | MB_DONT_ASK_AGAIN) == IDYES)
787 pMergeDoc->CloseNow();
788 m_pDirView->OpenNextDiff();
789 GetMainFrame()->OnUpdateFrameTitle(FALSE);
793 void CDirDoc::MoveToPrevDiff(IMergeDoc *pMergeDoc)
795 if (m_pDirView == nullptr)
797 if (AfxMessageBox(_("Do you want to move to the previous file?").c_str(), MB_YESNO | MB_DONT_ASK_AGAIN) == IDYES)
799 pMergeDoc->CloseNow();
800 m_pDirView->OpenPrevDiff();
801 GetMainFrame()->OnUpdateFrameTitle(FALSE);
805 void CDirDoc::MoveToFirstFile(IMergeDoc* pMergeDoc)
807 if (m_pDirView == nullptr)
809 if (AfxMessageBox(_("Do you want to move to the first file?").c_str(), MB_YESNO | MB_DONT_ASK_AGAIN) == IDYES)
811 pMergeDoc->CloseNow();
812 m_pDirView->OpenFirstFile();
813 GetMainFrame()->OnUpdateFrameTitle(FALSE);
817 void CDirDoc::MoveToNextFile(IMergeDoc* pMergeDoc)
819 if (m_pDirView == nullptr)
821 if (AfxMessageBox(_("Do you want to move to the next file?").c_str(), MB_YESNO | MB_DONT_ASK_AGAIN) == IDYES)
823 pMergeDoc->CloseNow();
824 m_pDirView->OpenNextFile();
825 GetMainFrame()->OnUpdateFrameTitle(FALSE);
829 void CDirDoc::MoveToPrevFile(IMergeDoc* pMergeDoc)
831 if (m_pDirView == nullptr)
833 if (AfxMessageBox(_("Do you want to move to the previous file?").c_str(), MB_YESNO | MB_DONT_ASK_AGAIN) == IDYES)
835 pMergeDoc->CloseNow();
836 m_pDirView->OpenPrevFile();
837 GetMainFrame()->OnUpdateFrameTitle(FALSE);
841 void CDirDoc::MoveToLastFile(IMergeDoc* pMergeDoc)
843 if (m_pDirView == nullptr)
845 if (AfxMessageBox(_("Do you want to move to the last file?").c_str(), MB_YESNO | MB_DONT_ASK_AGAIN) == IDYES)
847 pMergeDoc->CloseNow();
848 m_pDirView->OpenLastFile();
849 GetMainFrame()->OnUpdateFrameTitle(FALSE);
853 bool CDirDoc::IsFirstFile()
855 if (m_pDirView == nullptr)
857 return m_pDirView->IsFirstFile();
860 bool CDirDoc::IsLastFile()
862 if (m_pDirView == nullptr)
864 return m_pDirView->IsLastFile();
867 bool CDirDoc::CompareFilesIfFilesAreLarge(int nFiles, const FileLocation ifileloc[])
870 bool bLargeFile = false;
871 for (int i = 0; i < nFiles; ++i)
873 di.diffFileInfo[i].SetFile(paths::FindFileName(ifileloc[i].filepath));
874 if (di.diffFileInfo[i].Update(ifileloc[i].filepath))
875 di.diffcode.setSideFlag(i);
878 di.diffcode.diffcode |= DIFFCODE::THREEWAY;
880 size_t fileSizeThreshold = GetOptionsMgr()->GetInt(OPT_FILE_SIZE_THRESHOLD);
881 for (int i = 0; i < nFiles; ++i)
883 if (di.diffFileInfo[i].size != DirItem::FILE_SIZE_NONE && di.diffFileInfo[i].size > fileSizeThreshold)
890 for (int i = 0; i < nFiles; ++i)
891 paths.SetPath(i, ifileloc[i].filepath.empty() ? _T("NUL") : paths::GetParentPath(ifileloc[i].filepath));
892 CDiffContext ctxt(paths, CMP_QUICK_CONTENT);
893 DirViewColItems ci(nFiles);
894 String msg = LoadResString(IDS_COMPARE_LARGE_FILES);
897 String sidestr[] = { _("Left:"), _("Right:") };
898 for (int i = 0; i < nFiles; ++i)
900 if (ifileloc[i].filepath.empty())
902 msg += strutils::format(_T("%s %s\n\n"), sidestr[i], _("None"));
906 msg += strutils::format(_T("%s %s\n %s: %s\n %s: %s (%s)\n\n"),
907 sidestr[i].c_str(), ifileloc[i].filepath.c_str(),
908 ci.GetColDisplayName(3 + i).c_str(), ci.ColGetTextToDisplay(&ctxt, 3 + i, di).c_str(),
909 ci.GetColDisplayName(8 + i).c_str(), ci.ColGetTextToDisplay(&ctxt, 8 + i, di).c_str(), ci.ColGetTextToDisplay(&ctxt, 10 + i, di).c_str());
915 String sidestr[] = { _("Left:"), _("Middle:"), _("Right:") };
916 for (int i = 0; i < nFiles; ++i)
918 if (ifileloc[i].filepath.empty())
920 msg += strutils::format(_T("%s %s\n\n"), sidestr[i], _("None"));
924 msg += strutils::format(_T("%s %s\n %s: %s\n %s: %s (%s)\n\n"),
925 sidestr[i].c_str(), ifileloc[i].filepath.c_str(),
926 ci.GetColDisplayName(3 + i).c_str(), ci.ColGetTextToDisplay(&ctxt, 3 + i, di).c_str(),
927 ci.GetColDisplayName(10 + i).c_str(), ci.ColGetTextToDisplay(&ctxt, 10 + i, di).c_str(), ci.ColGetTextToDisplay(&ctxt, 13 + i, di).c_str());
931 CMessageBoxDialog dlg(
932 m_pDirView ? m_pDirView->GetParentFrame() : nullptr,
934 MB_YESNOCANCEL | MB_ICONQUESTION | MB_DONT_ASK_AGAIN, 0U,
935 _T("CompareLargeFiles"));
936 INT_PTR ans = dlg.DoModal();
939 else if (ans == IDNO)
942 InitDiffContext(&ctxt);
943 FolderCmp cmp(&ctxt);
944 CWaitCursor waitstatus;
945 di.diffcode.diffcode |= cmp.prepAndCompareFiles(di);
946 AfxMessageBox(ci.ColGetTextToDisplay(&ctxt, 2, di).c_str(), MB_OK | MB_ICONINFORMATION);
947 theApp.SetLastCompareResult(di.diffcode.isResultDiff() ? 1 : 0);