libgit2: show down animate when clone
[TortoiseGit.git] / src / TortoiseProc / GitProgressDlg.cpp
blobd3eed81b155a29760113fc30203043a4d1d13357
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "messagebox.h"
23 #include "GITProgressDlg.h"
24 #include "LogDlg.h"
25 #include "TGitPath.h"
26 #include "registry.h"
27 #include "GitStatus.h"
28 #include "AppUtils.h"
29 #include "PathUtils.h"
30 #include "StringUtils.h"
31 #include "TempFile.h"
32 #include "UnicodeUtils.h"
33 #include "SoundUtils.h"
34 #include "GitDiff.h"
35 #include "Hooks.h"
36 #include "DropFiles.h"
37 //#include "GitLogHelper.h"
38 #include "RegHistory.h"
39 //#include "ConflictResolveDlg.h"
40 #include "LogFile.h"
41 #include "ShellUpdater.h"
42 #include "IconMenu.h"
43 #include "BugTraqAssociations.h"
44 #include "patch.h"
45 #include "MassiveGitTask.h"
46 #include "git2.h"
47 #include "SmartHandle.h"
49 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));
51 BOOL CGitProgressDlg::m_bAscending = FALSE;
52 int CGitProgressDlg::m_nSortedColumn = -1;
54 #define TRANSFERTIMER 100
55 #define VISIBLETIMER 101
57 enum GITProgressDlgContextMenuCommands
59 // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu
60 ID_COMPARE = 1,
61 ID_EDITCONFLICT,
62 ID_CONFLICTRESOLVE,
63 ID_CONFLICTUSETHEIRS,
64 ID_CONFLICTUSEMINE,
65 ID_LOG,
66 ID_OPEN,
67 ID_OPENWITH,
68 ID_EXPLORE,
69 ID_COPY
72 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)
73 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)
74 : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)
75 , m_bCancelled(FALSE)
76 , m_pThread(NULL)
77 , m_bErrorsOccurred(false)
78 , m_bBare(false)
79 , m_bNoCheckout(false)
80 #if 0
81 , m_Revision(_T("HEAD"))
82 //, m_RevisionEnd(0)
83 , m_bLockWarning(false)
84 , m_bLockExists(false)
85 , m_bThreadRunning(FALSE)
86 , m_nConflicts(0)
87 , m_bMergesAddsDeletesOccurred(FALSE)
89 , m_options(ProgOptNone)
90 , m_dwCloseOnEnd((DWORD)-1)
91 , m_bFinishedItemAdded(false)
92 , m_bLastVisible(false)
93 // , m_depth(svn_depth_unknown)
94 , m_itemCount(-1)
95 , m_itemCountTotal(-1)
96 , m_AlwaysConflicted(false)
97 , m_BugTraqProvider(NULL)
98 , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))
99 , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))
100 #endif
104 CGitProgressDlg::~CGitProgressDlg()
106 for (size_t i = 0; i < m_arData.size(); ++i)
108 delete m_arData[i];
110 if(m_pThread != NULL)
112 delete m_pThread;
116 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)
118 CResizableStandAloneDialog::DoDataExchange(pDX);
119 DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);
120 DDX_Control(pDX, IDC_TITLE_ANIMATE, m_Animate);
123 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)
124 ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)
125 ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)
126 ON_WM_CLOSE()
127 ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)
128 ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)
129 ON_WM_SETCURSOR()
130 ON_WM_CONTEXTMENU()
131 ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)
132 ON_WM_TIMER()
133 ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)
134 ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)
135 ON_WM_SIZE()
136 ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)
137 ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)
138 ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)
139 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
140 ON_WM_CTLCOLOR()
141 END_MESSAGE_MAP()
143 BOOL CGitProgressDlg::Cancel()
145 return m_bCancelled;
148 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM /*lParam*/)
150 #if 0
151 CConflictResolveDlg dlg(this);
152 const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;
153 if (description)
155 dlg.SetConflictDescription(description);
156 if (m_pTaskbarList)
158 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED);
160 if (dlg.DoModal() == IDOK)
162 if (dlg.GetResult() == svn_wc_conflict_choose_postpone)
164 // if the result is conflicted and the dialog returned IDOK,
165 // that means we should not ask again in case of a conflict
166 m_AlwaysConflicted = true;
167 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);
170 m_mergedfile = dlg.GetMergedFile();
171 m_bCancelled = dlg.IsCancelled();
172 if (m_pTaskbarList)
173 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
174 return dlg.GetResult();
177 return svn_wc_conflict_choose_postpone;
178 #endif
179 return 0;
181 #if 0
182 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)
184 // we only bother the user when merging
185 if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))
187 // we're in a worker thread here. That means we must not show a dialog from the thread
188 // but let the UI thread do it.
189 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.
190 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);
191 mergedfile = m_mergedfile;
192 return (svn_wc_conflict_choice_t)dlgResult;
195 return svn_wc_conflict_choose_postpone;
197 #endif
198 void CGitProgressDlg::AddItemToList()
200 int totalcount = m_ProgList.GetItemCount();
202 m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);
203 // make columns width fit
204 if (iFirstResized < 30)
206 // only resize the columns for the first 30 or so entries.
207 // after that, don't resize them anymore because that's an
208 // expensive function call and the columns will be sized
209 // close enough already.
210 ResizeColumns();
211 ++iFirstResized;
214 // Make sure the item is *entirely* visible even if the horizontal
215 // scroll bar is visible.
216 int count = m_ProgList.GetCountPerPage();
217 if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))
219 ++nEnsureVisibleCount;
220 m_bLastVisible = true;
222 else
224 nEnsureVisibleCount = 0;
225 if (IsIconic() == 0)
226 m_bLastVisible = false;
231 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,
232 int /*status*/ ,
233 CString *strErr
235 svn_node_kind_t kind, const CString& mime_type,
236 svn_wc_notify_state_t content_state,
237 svn_wc_notify_state_t prop_state, LONG rev,
238 const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,
239 const CString& changelistname,
240 svn_merge_range_t * range,
241 svn_error_t * err, apr_pool_t * pool
244 bool bNoNotify = false;
245 bool bDoAddData = true;
246 NotificationData * data = new NotificationData();
247 data->path = path;
248 data->action = action;
249 data->sPathColumnText=path.GetGitPathString();
250 data->bAuxItem = false;
252 this->m_Animate.ShowWindow(SW_HIDE);
254 #if 0
255 data->kind = kind;
256 data->mime_type = mime_type;
257 data->content_state = content_state;
258 data->prop_state = prop_state;
259 data->rev = rev;
260 data->lock_state = lock_state;
261 data->changelistname = changelistname;
262 if ((lock)&&(lock->owner))
263 data->owner = CUnicodeUtils::GetUnicode(lock->owner);
264 data->sPathColumnText = path.GetUIPathString();
265 if (!m_basePath.IsEmpty())
266 data->basepath = m_basePath;
267 if (range)
268 data->merge_range = *range;
269 #endif
270 switch (data->action)
272 case git_wc_notify_add:
273 //case svn_wc_notify_update_add:
274 // if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
275 // {
276 // data->color = m_Colors.GetColor(CColors::Conflict);
277 // data->bConflictedActionItem = true;
278 // data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
279 // ++m_nConflicts;
280 // }
281 // else
282 // {
283 // m_bMergesAddsDeletesOccurred = true;
284 data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);
285 data->color = m_Colors.GetColor(CColors::Added);
286 // }
287 break;
288 case git_wc_notify_sendmail_start:
289 data->bAuxItem = true;
290 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);
291 data->color = m_Colors.GetColor(CColors::Modified);
292 break;
294 case git_wc_notify_sendmail_error:
295 data->bAuxItem = true;
296 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);
297 if(strErr)
298 data->sPathColumnText = *strErr;
299 else
300 data->sPathColumnText.Empty();
301 data->color = m_Colors.GetColor(CColors::Modified);
302 break;
304 case git_wc_notify_sendmail_done:
306 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);
307 data->sPathColumnText.Empty();
308 data->color = m_Colors.GetColor(CColors::Modified);
309 break;
311 case git_wc_notify_sendmail_retry:
312 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);
313 data->sPathColumnText.Empty();
314 data->color = m_Colors.GetColor(CColors::Modified);
315 break;
318 case git_wc_notify_resolved:
319 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
320 break;
322 case git_wc_notify_revert:
323 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);
324 break;
326 case git_wc_notify_checkout:
327 data->sActionColumnText.LoadString(IDS_PROGRS_CMD_CHECKOUT);
328 data->color = m_Colors.GetColor(CColors::Added);
329 data->bAuxItem = false;
330 break;
332 #if 0
333 case svn_wc_notify_commit_added:
334 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);
335 data->color = m_Colors.GetColor(CColors::Added);
336 break;
337 case svn_wc_notify_copy:
338 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);
339 break;
340 case svn_wc_notify_commit_modified:
341 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);
342 data->color = m_Colors.GetColor(CColors::Modified);
343 break;
344 case svn_wc_notify_delete:
345 case svn_wc_notify_update_delete:
346 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);
347 m_bMergesAddsDeletesOccurred = true;
348 data->color = m_Colors.GetColor(CColors::Deleted);
349 break;
350 case svn_wc_notify_commit_deleted:
351 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);
352 data->color = m_Colors.GetColor(CColors::Deleted);
353 break;
354 case svn_wc_notify_restore:
355 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);
356 break;
358 case svn_wc_notify_update_replace:
359 case svn_wc_notify_commit_replaced:
360 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);
361 data->color = m_Colors.GetColor(CColors::Deleted);
362 break;
363 case svn_wc_notify_exists:
364 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
366 data->color = m_Colors.GetColor(CColors::Conflict);
367 data->bConflictedActionItem = true;
368 ++m_nConflicts;
369 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
371 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
373 data->color = m_Colors.GetColor(CColors::Merged);
374 m_bMergesAddsDeletesOccurred = true;
375 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
377 else
378 data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);
379 break;
380 case svn_wc_notify_update_update:
381 // if this is an inoperative dir change, don't show the notification.
382 // an inoperative dir change is when a directory gets updated without
383 // any real change in either text or properties.
384 if ((kind == svn_node_dir)
385 && ((prop_state == svn_wc_notify_state_inapplicable)
386 || (prop_state == svn_wc_notify_state_unknown)
387 || (prop_state == svn_wc_notify_state_unchanged)))
389 bNoNotify = true;
390 break;
392 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))
394 data->color = m_Colors.GetColor(CColors::Conflict);
395 data->bConflictedActionItem = true;
396 ++m_nConflicts;
397 data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);
399 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))
401 data->color = m_Colors.GetColor(CColors::Merged);
402 m_bMergesAddsDeletesOccurred = true;
403 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);
405 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) ||
406 ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))
408 data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);
410 else
412 bNoNotify = true;
413 break;
415 if (lock_state == svn_wc_notify_lock_state_unlocked)
417 CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));
418 data->sActionColumnText += _T(", ") + temp;
420 break;
422 case svn_wc_notify_update_external:
423 // For some reason we build a list of externals...
424 m_ExtStack.AddHead(path.GetUIPathString());
425 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);
426 data->bAuxItem = true;
427 break;
429 case svn_wc_notify_update_completed:
431 data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);
432 data->bAuxItem = true;
433 bool bEmpty = !!m_ExtStack.IsEmpty();
434 if (!bEmpty)
435 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);
436 else
437 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);
439 if ((m_nConflicts>0)&&(bEmpty))
441 // We're going to add another aux item - let's shove this current onto the list first
442 // I don't really like this, but it will do for the moment.
443 m_arData.push_back(data);
444 AddItemToList();
446 data = new NotificationData();
447 data->bAuxItem = true;
448 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);
449 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);
450 data->color = m_Colors.GetColor(CColors::Conflict);
451 CSoundUtils::PlayTSVNWarning();
452 // This item will now be added after the switch statement
454 if (!m_basePath.IsEmpty())
455 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;
456 m_RevisionEnd = rev;
457 m_bFinishedItemAdded = true;
459 break;
460 case svn_wc_notify_commit_postfix_txdelta:
461 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);
462 break;
463 case svn_wc_notify_failed_revert:
464 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);
465 break;
466 case svn_wc_notify_status_completed:
467 case svn_wc_notify_status_external:
468 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);
469 break;
470 case svn_wc_notify_skip:
471 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))
473 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);
475 // The color settings dialog describes the red color with
476 // "possible or real conflict / obstructed" which also applies to
477 // skipped targets during a merge. So we just use the same color.
478 data->color = m_Colors.GetColor(CColors::Conflict);
480 else
481 data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);
482 break;
483 case svn_wc_notify_locked:
484 if ((lock)&&(lock->owner))
485 data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));
486 break;
487 case svn_wc_notify_unlocked:
488 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);
489 break;
490 case svn_wc_notify_failed_lock:
491 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);
492 m_arData.push_back(data);
493 AddItemToList();
494 ReportError(SVN::GetErrorString(err));
495 bDoAddData = false;
496 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
497 m_bLockWarning = true;
498 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)
499 m_bLockExists = true;
500 break;
501 case svn_wc_notify_failed_unlock:
502 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);
503 m_arData.push_back(data);
504 AddItemToList();
505 ReportError(SVN::GetErrorString(err));
506 bDoAddData = false;
507 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)
508 m_bLockWarning = true;
509 break;
510 case svn_wc_notify_changelist_set:
511 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);
512 break;
513 case svn_wc_notify_changelist_clear:
514 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);
515 break;
516 case svn_wc_notify_changelist_moved:
517 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);
518 break;
519 case svn_wc_notify_foreign_merge_begin:
520 case svn_wc_notify_merge_begin:
521 if (range == NULL)
522 data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);
523 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))
524 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);
525 else if (data->merge_range.start - 1 == data->merge_range.end)
526 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);
527 else if (data->merge_range.start < data->merge_range.end)
528 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);
529 else
530 data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);
531 data->bAuxItem = true;
532 break;
533 #endif
534 default:
535 break;
536 } // switch (data->action)
538 if (bNoNotify)
539 delete data;
540 else
542 if (bDoAddData)
544 m_arData.push_back(data);
545 AddItemToList();
546 if ((!data->bAuxItem) && (m_itemCount > 0))
548 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
549 progControl->ShowWindow(SW_SHOW);
550 progControl->SetPos(m_itemCountTotal - m_itemCount);
551 progControl->SetRange32(0, m_itemCountTotal);
552 if (m_pTaskbarList)
554 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
555 m_pTaskbarList->SetProgressValue(m_hWnd, m_itemCountTotal-m_itemCount, m_itemCountTotal);
559 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))
561 // ResizeColumns();
562 // bSecondResized = TRUE;
566 return TRUE;
570 CString CGitProgressDlg::BuildInfoString()
572 CString infotext;
573 if(this->m_Command == GitProgress_Resolve)
574 infotext = _T("You need commit your change after resolve conflict");
575 #if 0
577 CString temp;
578 int added = 0;
579 int copied = 0;
580 int deleted = 0;
581 int restored = 0;
582 int reverted = 0;
583 int resolved = 0;
584 int conflicted = 0;
585 int updated = 0;
586 int merged = 0;
587 int modified = 0;
588 int skipped = 0;
589 int replaced = 0;
591 for (size_t i=0; i<m_arData.size(); ++i)
593 const NotificationData * dat = m_arData[i];
594 switch (dat->action)
596 case svn_wc_notify_add:
597 case svn_wc_notify_update_add:
598 case svn_wc_notify_commit_added:
599 if (dat->bConflictedActionItem)
600 ++conflicted;
601 else
602 ++added;
603 break;
604 case svn_wc_notify_copy:
605 ++copied;
606 break;
607 case svn_wc_notify_delete:
608 case svn_wc_notify_update_delete:
609 case svn_wc_notify_commit_deleted:
610 ++deleted;
611 break;
612 case svn_wc_notify_restore:
613 ++restored;
614 break;
615 case svn_wc_notify_revert:
616 ++reverted;
617 break;
618 case svn_wc_notify_resolved:
619 ++resolved;
620 break;
621 case svn_wc_notify_update_update:
622 if (dat->bConflictedActionItem)
623 ++conflicted;
624 else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))
625 ++merged;
626 else
627 ++updated;
628 break;
629 case svn_wc_notify_commit_modified:
630 ++modified;
631 break;
632 case svn_wc_notify_skip:
633 ++skipped;
634 break;
635 case svn_wc_notify_commit_replaced:
636 ++replaced;
637 break;
640 if (conflicted)
642 temp.LoadString(IDS_SVNACTION_CONFLICTED);
643 infotext += temp;
644 temp.Format(_T(":%d "), conflicted);
645 infotext += temp;
647 if (skipped)
649 temp.LoadString(IDS_SVNACTION_SKIP);
650 infotext += temp;
651 infotext.AppendFormat(_T(":%d "), skipped);
653 if (merged)
655 temp.LoadString(IDS_SVNACTION_MERGED);
656 infotext += temp;
657 infotext.AppendFormat(_T(":%d "), merged);
659 if (added)
661 temp.LoadString(IDS_SVNACTION_ADD);
662 infotext += temp;
663 infotext.AppendFormat(_T(":%d "), added);
665 if (deleted)
667 temp.LoadString(IDS_SVNACTION_DELETE);
668 infotext += temp;
669 infotext.AppendFormat(_T(":%d "), deleted);
671 if (modified)
673 temp.LoadString(IDS_SVNACTION_MODIFIED);
674 infotext += temp;
675 infotext.AppendFormat(_T(":%d "), modified);
677 if (copied)
679 temp.LoadString(IDS_SVNACTION_COPY);
680 infotext += temp;
681 infotext.AppendFormat(_T(":%d "), copied);
683 if (replaced)
685 temp.LoadString(IDS_SVNACTION_REPLACED);
686 infotext += temp;
687 infotext.AppendFormat(_T(":%d "), replaced);
689 if (updated)
691 temp.LoadString(IDS_SVNACTION_UPDATE);
692 infotext += temp;
693 infotext.AppendFormat(_T(":%d "), updated);
695 if (restored)
697 temp.LoadString(IDS_SVNACTION_RESTORE);
698 infotext += temp;
699 infotext.AppendFormat(_T(":%d "), restored);
701 if (reverted)
703 temp.LoadString(IDS_SVNACTION_REVERT);
704 infotext += temp;
705 infotext.AppendFormat(_T(":%d "), reverted);
707 if (resolved)
709 temp.LoadString(IDS_SVNACTION_RESOLVE);
710 infotext += temp;
711 infotext.AppendFormat(_T(":%d "), resolved);
713 #endif
714 return infotext;
717 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)
719 m_selectedPaths = selPaths;
722 void CGitProgressDlg::ResizeColumns()
724 m_ProgList.SetRedraw(FALSE);
726 TCHAR textbuf[MAX_PATH];
728 int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
729 for (int col = 0; col <= maxcol; ++col)
731 // find the longest width of all items
732 int count = m_ProgList.GetItemCount();
733 HDITEM hdi = {0};
734 hdi.mask = HDI_TEXT;
735 hdi.pszText = textbuf;
736 hdi.cchTextMax = sizeof(textbuf);
737 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);
738 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin
740 for (int index = 0; index<count; ++index)
742 // get the width of the string and add 12 pixels for the column separator and margins
743 int linewidth = cx;
744 switch (col)
746 case 0:
747 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;
748 break;
749 case 1:
750 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;
751 break;
753 if (cx < linewidth)
754 cx = linewidth;
756 m_ProgList.SetColumnWidth(col, cx);
759 m_ProgList.SetRedraw(TRUE);
762 BOOL CGitProgressDlg::OnInitDialog()
764 __super::OnInitDialog();
766 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
767 // do this, Explorer would be unable to send that message to our window if we
768 // were running elevated. It's OK to make the call all the time, since if we're
769 // not elevated, this is a no-op.
770 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
771 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
772 CAutoLibrary hUser = AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
773 if (hUser)
775 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
776 if (pfnChangeWindowMessageFilterEx)
778 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
781 m_pTaskbarList.Release();
782 if (FAILED(m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList)))
783 m_pTaskbarList = nullptr;
785 m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
787 m_ProgList.DeleteAllItems();
788 int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;
789 while (c>=0)
790 m_ProgList.DeleteColumn(c--);
791 CString temp;
792 temp.LoadString(IDS_PROGRS_ACTION);
793 m_ProgList.InsertColumn(0, temp);
794 temp.LoadString(IDS_PROGRS_PATH);
795 m_ProgList.InsertColumn(1, temp);
797 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
798 if (m_pThread==NULL)
800 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
802 else
804 m_pThread->m_bAutoDelete = FALSE;
805 m_pThread->ResumeThread();
808 UpdateData(FALSE);
810 // Call this early so that the column headings aren't hidden before any
811 // text gets added.
812 ResizeColumns();
814 SetTimer(VISIBLETIMER, 300, NULL);
816 AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);
817 AddAnchor(IDC_TITLE_ANIMATE, TOP_LEFT, BOTTOM_RIGHT);
818 AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);
819 AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);
820 AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
821 AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);
822 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
823 AddAnchor(IDOK, BOTTOM_RIGHT);
824 AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);
825 //SetPromptParentWindow(this->m_hWnd);
827 m_Animate.Open(IDR_DOWNLOAD);
829 if (hWndExplorer)
830 CenterWindow(CWnd::FromHandle(hWndExplorer));
831 EnableSaveRestore(_T("GITProgressDlg"));
833 m_background_brush.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
834 return TRUE;
837 bool CGitProgressDlg::SetBackgroundImage(UINT nID)
839 return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);
842 void CGitProgressDlg::ReportGitError()
844 const git_error *err = giterr_last();
845 if (err == nullptr)
846 ReportError(_T("An error occoured in libgit2, but no message is available."));
847 else
848 ReportError(CUnicodeUtils::GetUnicode(giterr_last()->message));
851 void CGitProgressDlg::ReportError(const CString& sError)
853 CSoundUtils::PlayTGitError();
854 ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));
855 m_bErrorsOccurred = true;
858 void CGitProgressDlg::ReportWarning(const CString& sWarning)
860 CSoundUtils::PlayTGitWarning();
861 ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));
864 void CGitProgressDlg::ReportNotification(const CString& sNotification)
866 CSoundUtils::PlayTGitNotification();
867 ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));
870 void CGitProgressDlg::ReportCmd(const CString& sCmd)
872 ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));
875 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)
877 // instead of showing a dialog box with the error message or notification,
878 // just insert the error text into the list control.
879 // that way the user isn't 'interrupted' by a dialog box popping up!
881 // the message may be split up into different lines
882 // so add a new entry for each line of the message
883 while (!sMessage.IsEmpty())
885 NotificationData * data = new NotificationData();
886 data->bAuxItem = true;
887 data->sActionColumnText = sMsgKind;
888 if (sMessage.Find('\n')>=0)
889 data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));
890 else
891 data->sPathColumnText = sMessage;
892 data->sPathColumnText.Trim(_T("\n\r"));
893 data->color = color;
894 if (sMessage.Find('\n')>=0)
896 sMessage = sMessage.Mid(sMessage.Find('\n'));
897 sMessage.Trim(_T("\n\r"));
899 else
900 sMessage.Empty();
901 m_arData.push_back(data);
902 AddItemToList();
906 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)
908 return ((CGitProgressDlg*)pVoid)->ProgressThread();
911 UINT CGitProgressDlg::ProgressThread()
913 // The SetParams function should have loaded something for us
915 CString temp;
916 CString sWindowTitle;
917 bool localoperation = false;
918 bool bSuccess = false;
919 m_AlwaysConflicted = false;
921 DialogEnableWindow(IDOK, FALSE);
922 DialogEnableWindow(IDCANCEL, TRUE);
923 // SetAndClearProgressInfo(m_hWnd);
924 m_itemCount = m_itemCountTotal;
926 InterlockedExchange(&m_bThreadRunning, TRUE);
927 iFirstResized = 0;
928 bSecondResized = FALSE;
929 m_bFinishedItemAdded = false;
930 CTime startTime = CTime::GetCurrentTime();
932 if (m_pTaskbarList)
933 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
935 switch (m_Command)
937 case GitProgress_Add:
938 bSuccess = CmdAdd(sWindowTitle, localoperation);
939 break;
940 case GitProgress_Copy:
941 bSuccess = CmdCopy(sWindowTitle, localoperation);
942 break;
943 case GitProgress_Export:
944 bSuccess = CmdExport(sWindowTitle, localoperation);
945 break;
946 case GitProgress_Rename:
947 bSuccess = CmdRename(sWindowTitle, localoperation);
948 break;
949 case GitProgress_Resolve:
950 bSuccess = CmdResolve(sWindowTitle, localoperation);
951 break;
952 case GitProgress_Revert:
953 bSuccess = CmdRevert(sWindowTitle, localoperation);
954 break;
955 case GitProgress_Switch:
956 bSuccess = CmdSwitch(sWindowTitle, localoperation);
957 break;
958 case GitProgress_SendMail:
959 bSuccess = CmdSendMail(sWindowTitle, localoperation);
960 break;
961 case GitProgress_Clone:
962 bSuccess = CmdClone(sWindowTitle, localoperation);
963 break;
965 if (!bSuccess)
966 temp.LoadString(IDS_PROGRS_TITLEFAILED);
967 else
968 temp.LoadString(IDS_PROGRS_TITLEFIN);
969 sWindowTitle = sWindowTitle + _T(" ") + temp;
970 SetWindowText(sWindowTitle);
972 KillTimer(TRANSFERTIMER);
973 KillTimer(VISIBLETIMER);
975 if (m_pTaskbarList)
977 if (DidErrorsOccur())
979 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR);
980 m_pTaskbarList->SetProgressValue(m_hWnd, 100, 100);
982 else
983 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
986 DialogEnableWindow(IDCANCEL, FALSE);
987 DialogEnableWindow(IDOK, TRUE);
989 CString info = BuildInfoString();
990 if (!bSuccess)
991 info.LoadString(IDS_PROGRS_INFOFAILED);
992 SetDlgItemText(IDC_INFOTEXT, info);
993 ResizeColumns();
994 CWnd * pWndOk = GetDlgItem(IDOK);
995 if (pWndOk && ::IsWindow(pWndOk->GetSafeHwnd()))
997 SendMessage(DM_SETDEFID, IDOK);
998 GetDlgItem(IDOK)->SetFocus();
1001 CString sFinalInfo;
1002 if (!m_sTotalBytesTransferred.IsEmpty())
1004 CTimeSpan time = CTime::GetCurrentTime() - startTime;
1005 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());
1006 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);
1007 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);
1009 else
1010 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);
1012 GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);
1014 if (!m_bFinishedItemAdded)
1016 // there's no "finished: xxx" line at the end. We add one here to make
1017 // sure the user sees that the command is actually finished.
1018 NotificationData * data = new NotificationData();
1019 data->bAuxItem = true;
1020 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);
1021 m_arData.push_back(data);
1022 AddItemToList();
1025 int count = m_ProgList.GetItemCount();
1026 if ((count > 0)&&(m_bLastVisible))
1027 m_ProgList.EnsureVisible(count-1, FALSE);
1029 CLogFile logfile;
1030 if (logfile.Open())
1032 logfile.AddTimeLine();
1033 for (size_t i = 0; i < m_arData.size(); ++i)
1035 NotificationData * data = m_arData[i];
1036 temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);
1037 logfile.AddLine(temp);
1039 if (!sFinalInfo.IsEmpty())
1040 logfile.AddLine(sFinalInfo);
1041 logfile.Close();
1044 m_bCancelled = TRUE;
1045 InterlockedExchange(&m_bThreadRunning, FALSE);
1046 RefreshCursor();
1048 #if 0
1049 DWORD dwAutoClose = CRegStdDWORD(_T("Software\\TortoiseGit\\AutoClose"), CLOSE_MANUAL);
1050 if (m_options & ProgOptDryRun)
1051 dwAutoClose = 0; // dry run means progress dialog doesn't auto close at all
1052 if (!m_bLastVisible)
1053 dwAutoClose = 0;
1054 if (m_dwCloseOnEnd != (DWORD)-1)
1055 dwAutoClose = m_dwCloseOnEnd; // command line value has priority over setting value
1056 if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))
1057 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1058 if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))
1059 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1060 if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))
1061 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1062 if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))
1063 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);
1064 #endif
1066 //Don't do anything here which might cause messages to be sent to the window
1067 //The window thread is probably now blocked in OnOK if we've done an auto close
1068 return 0;
1071 void CGitProgressDlg::OnBnClickedLogbutton()
1073 switch(this->m_Command)
1075 case GitProgress_Add:
1076 case GitProgress_Resolve:
1078 CString cmd = _T(" /command:commit");
1079 cmd += _T(" /path:\"")+g_Git.m_CurrentDir+_T("\"");
1081 CAppUtils::RunTortoiseGitProc(cmd);
1082 this->EndDialog(IDOK);
1083 break;
1086 #if 0
1087 if (m_targetPathList.GetCount() != 1)
1088 return;
1089 StringRevMap::iterator it = m_UpdateStartRevMap.begin();
1090 svn_revnum_t rev = -1;
1091 if (it != m_UpdateStartRevMap.end())
1093 rev = it->second;
1095 CLogDlg dlg;
1096 dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);
1097 dlg.DoModal();
1098 #endif
1102 void CGitProgressDlg::OnClose()
1104 if (m_bCancelled)
1106 TerminateThread(m_pThread->m_hThread, (DWORD)-1);
1107 InterlockedExchange(&m_bThreadRunning, FALSE);
1109 else
1111 m_bCancelled = TRUE;
1112 return;
1114 DialogEnableWindow(IDCANCEL, TRUE);
1115 __super::OnClose();
1118 void CGitProgressDlg::OnOK()
1120 if ((m_bCancelled)&&(!m_bThreadRunning))
1122 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish
1123 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you
1124 // don't do any more operations on the window which might require message passing
1125 // If you try to send windows messages once we're waiting here, then the thread can't finished
1126 // because the Window's message loop is blocked at this wait
1127 WaitForSingleObject(m_pThread->m_hThread, 10000);
1128 __super::OnOK();
1130 m_bCancelled = TRUE;
1133 void CGitProgressDlg::OnCancel()
1135 if ((m_bCancelled)&&(!m_bThreadRunning))
1136 __super::OnCancel();
1137 m_bCancelled = TRUE;
1140 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1142 NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
1144 if (pDispInfo)
1146 if (pDispInfo->item.mask & LVIF_TEXT)
1148 if (pDispInfo->item.iItem < (int)m_arData.size())
1150 const NotificationData * data = m_arData[pDispInfo->item.iItem];
1151 switch (pDispInfo->item.iSubItem)
1153 case 0:
1154 lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);
1155 break;
1156 case 1:
1157 lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);
1158 if (!data->bAuxItem)
1160 int cWidth = m_ProgList.GetColumnWidth(1);
1161 cWidth = max(12, cWidth-12);
1162 CDC * pDC = m_ProgList.GetDC();
1163 if (pDC != NULL)
1165 CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());
1166 PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);
1167 pDC->SelectObject(pFont);
1168 ReleaseDC(pDC);
1171 break;
1172 default:
1173 m_columnbuf[0] = 0;
1175 pDispInfo->item.pszText = m_columnbuf;
1179 *pResult = 0;
1182 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1184 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
1186 // Take the default processing unless we set this to something else below.
1187 *pResult = CDRF_DODEFAULT;
1189 // First thing - check the draw stage. If it's the control's prepaint
1190 // stage, then tell Windows we want messages for every item.
1192 if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
1194 *pResult = CDRF_NOTIFYITEMDRAW;
1196 else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
1198 // This is the prepaint stage for an item. Here's where we set the
1199 // item's text color. Our return value will tell Windows to draw the
1200 // item itself, but it will use the new color we set here.
1202 // Tell Windows to paint the control itself.
1203 *pResult = CDRF_DODEFAULT;
1205 ASSERT(pLVCD->nmcd.dwItemSpec < m_arData.size());
1206 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())
1208 return;
1210 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];
1211 ASSERT(data != NULL);
1212 if (data == NULL)
1213 return;
1215 // Store the color back in the NMLVCUSTOMDRAW struct.
1216 pLVCD->clrText = data->color;
1220 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR * /*pNMHDR*/, LRESULT * /*pResult*/)
1222 #if 0
1223 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1224 *pResult = 0;
1225 if (pNMLV->iItem < 0)
1226 return;
1227 if (m_options & ProgOptDryRun)
1228 return; //don't do anything in a dry-run.
1230 const NotificationData * data = m_arData[pNMLV->iItem];
1231 if (data == NULL)
1232 return;
1234 if (data->bConflictedActionItem)
1236 // We've double-clicked on a conflicted item - do a three-way merge on it
1237 SVNDiff::StartConflictEditor(data->path);
1239 else if ((data->action == svn_wc_notify_update_update) && ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)) || (data->action == svn_wc_notify_resolved))
1241 // This is a modified file which has been merged on update. Diff it against base
1242 CTGitPath temporaryFile;
1243 SVNDiff diff(this, this->m_hWnd, true);
1244 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));
1245 svn_revnum_t baseRev = 0;
1246 diff.DiffFileAgainstBase(data->path, baseRev);
1248 else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))
1250 bool bOpenWith = false;
1251 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);
1252 if (ret <= HINSTANCE_ERROR)
1253 bOpenWith = true;
1254 if (bOpenWith)
1256 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1257 cmd += data->path.GetWinPathString() + _T(" ");
1258 CAppUtils::LaunchApplication(cmd, NULL, false);
1261 #endif
1264 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)
1266 LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
1267 if (m_bThreadRunning)
1268 return;
1269 if (m_nSortedColumn == phdr->iItem)
1270 m_bAscending = !m_bAscending;
1271 else
1272 m_bAscending = TRUE;
1273 m_nSortedColumn = phdr->iItem;
1274 Sort();
1276 CString temp;
1277 m_ProgList.SetRedraw(FALSE);
1278 m_ProgList.DeleteAllItems();
1279 m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));
1281 m_ProgList.SetRedraw(TRUE);
1283 *pResult = 0;
1286 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)
1288 return pData->bAuxItem;
1291 BOOL CGitProgressDlg::Notify(const git_wc_notify_action_t /*action*/, const git_transfer_progress *stat)
1293 static unsigned int start = 0;
1294 unsigned int dt = GetCurrentTime() - start;
1295 size_t ds;
1296 double speed = 0;
1297 if (dt > 100)
1299 start = GetCurrentTime();
1300 ds = stat->received_bytes - m_TotalBytesTransferred;
1301 speed = ds * 1000.0/dt;
1302 m_TotalBytesTransferred = stat->received_bytes;
1304 else
1306 return TRUE;
1309 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1311 int progress;
1312 if (stat->received_objects < stat->total_objects)
1313 progress = stat->received_objects;
1314 else
1315 progress = stat->indexed_objects;
1317 if ((stat->total_objects > 1000) && (!progControl->IsWindowVisible()))
1319 progControl->ShowWindow(SW_SHOW);
1320 if (m_pTaskbarList)
1321 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1323 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1324 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1326 progControl->SetPos(progress);
1327 progControl->SetRange32(0, stat->total_objects);
1328 if (m_pTaskbarList)
1330 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1331 m_pTaskbarList->SetProgressValue(m_hWnd, progress, stat->total_objects);
1334 CString progText;
1335 if (stat->received_bytes < 1024)
1336 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, (int64_t)stat->received_bytes);
1337 else if (stat->received_bytes < 1200000)
1338 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, (int64_t)stat->received_bytes / 1024);
1339 else
1340 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)stat->received_bytes / 1024000.0));
1342 CString str;
1343 if(speed < 1024)
1344 str.Format(_T("%fB/s"), speed);
1345 else if(speed < 1024 * 1024)
1346 str.Format(_T("%.2fKB/s"), speed / 1024);
1347 else
1348 str.Format(_T("%.2fMB/s"), speed / 1024000.0);
1350 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)str);
1351 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1353 return TRUE;
1356 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM /*lParam*/)
1358 #if 0
1359 SVNProgress * pProgressData = (SVNProgress *)lParam;
1360 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);
1361 if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))
1363 progControl->ShowWindow(SW_SHOW);
1364 if (m_pTaskbarList)
1365 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1367 if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))
1369 progControl->ShowWindow(SW_HIDE);
1370 if (m_pTaskbarList)
1371 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_INDETERMINATE);
1373 if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())
1374 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);
1375 SetTimer(TRANSFERTIMER, 2000, NULL);
1376 if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))
1378 progControl->SetPos((int)pProgressData->progress);
1379 progControl->SetRange32(0, (int)pProgressData->total);
1380 if (m_pTaskbarList)
1382 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
1383 m_pTaskbarList->SetProgressValue(m_hWnd, pProgressData->progress, pProgressData->total);
1386 CString progText;
1387 if (pProgressData->overall_total < 1024)
1388 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);
1389 else if (pProgressData->overall_total < 1200000)
1390 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);
1391 else
1392 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));
1393 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);
1394 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1395 #endif
1396 return 0;
1399 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)
1401 if (nIDEvent == TRANSFERTIMER)
1403 CString progText;
1404 CString progSpeed;
1405 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);
1406 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);
1407 SetDlgItemText(IDC_PROGRESSLABEL, progText);
1408 KillTimer(TRANSFERTIMER);
1410 if (nIDEvent == VISIBLETIMER)
1412 if (nEnsureVisibleCount)
1413 m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);
1414 nEnsureVisibleCount = 0;
1418 void CGitProgressDlg::Sort()
1420 if(m_arData.size() < 2)
1422 return;
1425 // We need to sort the blocks which lie between the auxiliary entries
1426 // This is so that any aux data stays where it was
1427 NotificationDataVect::iterator actionBlockBegin;
1428 NotificationDataVect::iterator actionBlockEnd = m_arData.begin(); // We start searching from here
1430 for(;;)
1432 // Search to the start of the non-aux entry in the next block
1433 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));
1434 if(actionBlockBegin == m_arData.end())
1436 // There are no more actions
1437 break;
1439 // Now search to find the end of the block
1440 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));
1441 // Now sort the block
1442 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);
1446 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)
1448 int result = 0;
1449 switch (m_nSortedColumn)
1451 case 0: //action column
1452 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);
1453 break;
1454 case 1: //path column
1455 // Compare happens after switch()
1456 break;
1457 default:
1458 break;
1461 // Sort by path if everything else is equal
1462 if (result == 0)
1464 result = CTGitPath::Compare(pData1->path, pData2->path);
1467 if (!m_bAscending)
1468 result = -result;
1469 return result < 0;
1472 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
1474 if (!GetDlgItem(IDOK)->IsWindowEnabled())
1476 // only show the wait cursor over the list control
1477 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))
1479 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
1480 SetCursor(hCur);
1481 return TRUE;
1484 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
1485 SetCursor(hCur);
1486 return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);
1489 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)
1491 if (pMsg->message == WM_KEYDOWN)
1493 if (pMsg->wParam == VK_ESCAPE)
1495 // pressing the ESC key should close the dialog. But since we disabled the escape
1496 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
1497 // this won't work.
1498 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
1499 // the impression that the OK button was pressed.
1500 if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())
1501 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))
1503 // since we convert ESC to RETURN, make sure the OK button has the focus.
1504 GetDlgItem(IDOK)->SetFocus();
1505 pMsg->wParam = VK_RETURN;
1508 if (pMsg->wParam == 'A')
1510 if (GetKeyState(VK_CONTROL)&0x8000)
1512 // Ctrl-A -> select all
1513 m_ProgList.SetSelectionMark(0);
1514 for (int i=0; i<m_ProgList.GetItemCount(); ++i)
1516 m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
1520 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))
1522 int selIndex = m_ProgList.GetSelectionMark();
1523 if (selIndex >= 0)
1525 if (GetKeyState(VK_CONTROL)&0x8000)
1527 //Ctrl-C -> copy to clipboard
1528 CString sClipdata;
1529 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1530 if (pos != NULL)
1532 while (pos)
1534 int nItem = m_ProgList.GetNextSelectedItem(pos);
1535 CString sAction = m_ProgList.GetItemText(nItem, 0);
1536 CString sPath = m_ProgList.GetItemText(nItem, 1);
1537 CString sMime = m_ProgList.GetItemText(nItem, 2);
1538 CString sLogCopyText;
1539 sLogCopyText.Format(_T("%s: %s %s\r\n"),
1540 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);
1541 sClipdata += sLogCopyText;
1543 CStringUtils::WriteAsciiStringToClipboard(sClipdata);
1548 } // if (pMsg->message == WM_KEYDOWN)
1549 return __super::PreTranslateMessage(pMsg);
1552 void CGitProgressDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
1554 #if 0
1555 if (m_options & ProgOptDryRun)
1556 return; // don't do anything in a dry-run.
1558 if (pWnd == &m_ProgList)
1560 int selIndex = m_ProgList.GetSelectionMark();
1561 if ((point.x == -1) && (point.y == -1))
1563 // Menu was invoked from the keyboard rather than by right-clicking
1564 CRect rect;
1565 m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);
1566 m_ProgList.ClientToScreen(&rect);
1567 point = rect.CenterPoint();
1570 if ((selIndex >= 0)&&(!m_bThreadRunning))
1572 // entry is selected, thread has finished with updating so show the popup menu
1573 CIconMenu popup;
1574 if (popup.CreatePopupMenu())
1576 bool bAdded = false;
1577 NotificationData * data = m_arData[selIndex];
1578 if ((data)&&(!data->path.IsDirectory()))
1580 if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)
1582 if (m_ProgList.GetSelectedCount() == 1)
1584 popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);
1585 bAdded = true;
1588 if (data->bConflictedActionItem)
1590 if (m_ProgList.GetSelectedCount() == 1)
1592 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);
1593 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);
1594 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);
1596 popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);
1597 popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);
1599 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))
1600 popup.SetDefaultItem(ID_COMPARE, FALSE);
1602 if (m_ProgList.GetSelectedCount() == 1)
1604 if ((data->action == svn_wc_notify_add)||
1605 (data->action == svn_wc_notify_update_add)||
1606 (data->action == svn_wc_notify_commit_added)||
1607 (data->action == svn_wc_notify_commit_modified)||
1608 (data->action == svn_wc_notify_restore)||
1609 (data->action == svn_wc_notify_revert)||
1610 (data->action == svn_wc_notify_resolved)||
1611 (data->action == svn_wc_notify_commit_replaced)||
1612 (data->action == svn_wc_notify_commit_modified)||
1613 (data->action == svn_wc_notify_commit_postfix_txdelta)||
1614 (data->action == svn_wc_notify_update_update))
1616 popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);
1617 if (data->action == svn_wc_notify_update_update)
1618 popup.AppendMenu(MF_SEPARATOR, NULL);
1619 popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);
1620 popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);
1621 bAdded = true;
1624 } // if ((data)&&(!data->path.IsDirectory()))
1625 if (m_ProgList.GetSelectedCount() == 1)
1627 if (data)
1629 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1630 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))
1632 CTGitPath path = CTGitPath(sPath);
1633 if (path.GetDirectory().Exists())
1635 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);
1636 bAdded = true;
1641 if (m_ProgList.GetSelectedCount() > 0)
1643 if (bAdded)
1644 popup.AppendMenu(MF_SEPARATOR, NULL);
1645 popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);
1646 bAdded = true;
1648 if (bAdded)
1650 int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
1651 DialogEnableWindow(IDOK, FALSE);
1652 this->SetPromptApp(&theApp);
1653 theApp.DoWaitCursor(1);
1654 bool bOpenWith = false;
1655 switch (cmd)
1657 case ID_COPY:
1659 CString sLines;
1660 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1661 while (pos)
1663 int nItem = m_ProgList.GetNextSelectedItem(pos);
1664 NotificationData * data = m_arData[nItem];
1665 if (data)
1667 sLines += data->sPathColumnText;
1668 sLines += _T("\r\n");
1671 sLines.TrimRight();
1672 if (!sLines.IsEmpty())
1674 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());
1677 break;
1678 case ID_EXPLORE:
1680 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1682 CTGitPath path = CTGitPath(sPath);
1683 ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);
1685 break;
1686 case ID_COMPARE:
1688 svn_revnum_t rev = -1;
1689 StringRevMap::iterator it = m_UpdateStartRevMap.end();
1690 if (data->basepath.IsEmpty())
1691 it = m_UpdateStartRevMap.begin();
1692 else
1693 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));
1694 if (it != m_UpdateStartRevMap.end())
1695 rev = it->second;
1696 // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS
1697 if (data->content_state == svn_wc_notify_state_merged)
1699 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1700 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);
1701 SVN svn;
1702 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))
1704 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1705 DialogEnableWindow(IDOK, TRUE);
1706 break;
1708 // If necessary, convert the line-endings on the file before diffing
1709 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))
1711 CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);
1712 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))
1714 temporaryFile.Reset();
1715 break;
1717 else
1719 newfile = temporaryFile;
1723 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1724 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1725 CString revname, wcname, basename;
1726 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1727 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1728 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1729 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);
1731 else
1733 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);
1734 SVN svn;
1735 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))
1737 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1738 DialogEnableWindow(IDOK, TRUE);
1739 break;
1741 else
1743 SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);
1744 CString revname, wcname;
1745 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);
1746 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());
1747 CAppUtils::StartExtDiff(
1748 tempfile, data->path, revname, wcname,
1749 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));
1753 break;
1754 case ID_EDITCONFLICT:
1756 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1757 SVNDiff::StartConflictEditor(CTGitPath(sPath));
1759 break;
1760 case ID_CONFLICTUSETHEIRS:
1761 case ID_CONFLICTUSEMINE:
1762 case ID_CONFLICTRESOLVE:
1764 svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;
1765 switch (cmd)
1767 case ID_CONFLICTUSETHEIRS:
1768 result = svn_wc_conflict_choose_theirs_full;
1769 break;
1770 case ID_CONFLICTUSEMINE:
1771 result = svn_wc_conflict_choose_mine_full;
1772 break;
1773 case ID_CONFLICTRESOLVE:
1774 result = svn_wc_conflict_choose_merged;
1775 break;
1777 SVN svn;
1778 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1779 CString sResolvedPaths;
1780 while (pos)
1782 int nItem = m_ProgList.GetNextSelectedItem(pos);
1783 NotificationData * data = m_arData[nItem];
1784 if (data)
1786 if (data->bConflictedActionItem)
1788 if (!svn.Resolve(data->path, result, FALSE))
1790 CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
1791 DialogEnableWindow(IDOK, TRUE);
1792 break;
1794 else
1796 data->color = ::GetSysColor(COLOR_WINDOWTEXT);
1797 data->action = svn_wc_notify_resolved;
1798 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);
1799 data->bConflictedActionItem = false;
1800 m_nConflicts--;
1802 if (m_nConflicts==0)
1804 // When the last conflict is resolved we remove
1805 // the warning which we assume is in the last line.
1806 int nIndex = m_ProgList.GetItemCount()-1;
1807 VERIFY(m_ProgList.DeleteItem(nIndex));
1809 delete m_arData[nIndex];
1810 m_arData.pop_back();
1812 sResolvedPaths += data->path.GetWinPathString() + _T("\n");
1817 m_ProgList.Invalidate();
1818 CString info = BuildInfoString();
1819 SetDlgItemText(IDC_INFOTEXT, info);
1821 if (!sResolvedPaths.IsEmpty())
1823 CString msg;
1824 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);
1825 CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
1828 break;
1829 case ID_LOG:
1831 svn_revnum_t rev = m_RevisionEnd;
1832 if (!data->basepath.IsEmpty())
1834 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));
1835 if (it != m_FinishedRevMap.end())
1836 rev = it->second;
1838 CLogDlg dlg;
1839 // fetch the log from HEAD, not the revision we updated to:
1840 // the path might be inside an external folder which has its own
1841 // revisions.
1842 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1843 dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, -1, TRUE);
1844 dlg.DoModal();
1846 break;
1847 case ID_OPENWITH:
1848 bOpenWith = true;
1849 case ID_OPEN:
1851 int ret = 0;
1852 CString sWinPath = GetPathFromColumnText(data->sPathColumnText);
1853 if (!bOpenWith)
1854 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);
1855 if ((ret <= HINSTANCE_ERROR)||bOpenWith)
1857 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");
1858 cmd += sWinPath + _T(" ");
1859 CAppUtils::LaunchApplication(cmd, NULL, false);
1863 DialogEnableWindow(IDOK, TRUE);
1864 theApp.DoWaitCursor(-1);
1865 } // if (bAdded)
1869 #endif
1872 void CGitProgressDlg::OnEnSetfocusInfotext()
1874 CString sTemp;
1875 GetDlgItemText(IDC_INFOTEXT, sTemp);
1876 if (sTemp.IsEmpty())
1877 GetDlgItem(IDC_INFOTEXT)->HideCaret();
1880 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)
1882 //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
1883 #if 0
1884 int selIndex = m_ProgList.GetSelectionMark();
1885 if (selIndex < 0)
1886 return;
1888 CDropFiles dropFiles; // class for creating DROPFILES struct
1890 int index;
1891 POSITION pos = m_ProgList.GetFirstSelectedItemPosition();
1892 while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )
1894 NotificationData * data = m_arData[index];
1896 if ( data->kind==svn_node_file || data->kind==svn_node_dir )
1898 CString sPath = GetPathFromColumnText(data->sPathColumnText);
1900 dropFiles.AddFile( sPath );
1904 if ( dropFiles.GetCount()>0 )
1906 dropFiles.CreateStructure();
1908 #endif
1909 *pResult = 0;
1912 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)
1914 CResizableStandAloneDialog::OnSize(nType, cx, cy);
1915 if ((nType == SIZE_RESTORED)&&(m_bLastVisible))
1917 if(!m_ProgList.m_hWnd)
1918 return;
1920 int count = m_ProgList.GetItemCount();
1921 if (count > 0)
1922 m_ProgList.EnsureVisible(count-1, false);
1926 //////////////////////////////////////////////////////////////////////////
1927 /// commands
1928 //////////////////////////////////////////////////////////////////////////
1929 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)
1931 localoperation = true;
1932 sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);
1933 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
1934 SetBackgroundImage(IDI_ADD_BKG);
1935 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));
1937 if (CRegDWORD(_T("Software\\TortoiseGit\\UseLibgit2"), TRUE) == TRUE)
1939 git_repository *repo = NULL;
1940 git_index *index;
1942 CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(g_Git.m_CurrentDir).GetGitPathString(), CP_UTF8);
1943 if (git_repository_open(&repo, gitdir.GetBuffer()))
1945 gitdir.ReleaseBuffer();
1946 ReportGitError();
1947 return false;
1949 gitdir.ReleaseBuffer();
1951 git_config * config;
1952 git_config_new(&config);
1954 CStringA projectConfigA = CUnicodeUtils::GetMulti(g_Git.GetGitLocalConfig(), CP_UTF8);
1955 if (git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), 4, FALSE))
1957 projectConfigA.ReleaseBuffer();
1958 ReportGitError();
1959 git_config_free(config);
1960 git_repository_free(repo);
1961 return false;
1963 projectConfigA.ReleaseBuffer();
1964 CString globalConfig = g_Git.GetGitGlobalConfig();
1965 if (PathFileExists(globalConfig))
1967 CStringA globalConfigA = CUnicodeUtils::GetMulti(globalConfig, CP_UTF8);
1968 if (git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), 3, FALSE))
1970 globalConfigA.ReleaseBuffer();
1971 ReportGitError();
1972 git_config_free(config);
1973 git_repository_free(repo);
1974 return false;
1976 globalConfigA.ReleaseBuffer();
1978 CString globalXDGConfig = g_Git.GetGitGlobalXDGConfig();
1979 if (PathFileExists(globalXDGConfig))
1981 CStringA globalXDGConfigA = CUnicodeUtils::GetMulti(globalXDGConfig, CP_UTF8);
1982 if (git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), 2, FALSE))
1984 globalXDGConfigA.ReleaseBuffer();
1985 ReportGitError();
1986 git_config_free(config);
1987 git_repository_free(repo);
1988 return false;
1990 globalXDGConfigA.ReleaseBuffer();
1992 CString systemConfig = g_Git.GetGitSystemConfig();
1993 if (!systemConfig.IsEmpty())
1995 CStringA systemConfigA = CUnicodeUtils::GetMulti(systemConfig, CP_UTF8);
1996 if (git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), 1, FALSE))
1998 systemConfigA.ReleaseBuffer();
1999 ReportGitError();
2000 git_config_free(config);
2001 git_repository_free(repo);
2002 return false;
2004 systemConfigA.ReleaseBuffer();
2007 git_repository_set_config(repo, config);
2009 if (git_repository_index(&index, repo))
2011 ReportGitError();
2012 git_repository_free(repo);
2013 return false;
2015 if (git_index_read(index))
2017 ReportGitError();
2018 git_index_free(index);
2019 git_repository_free(repo);
2020 return false;
2023 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
2025 if (git_index_add_bypath(index, CStringA(CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_UTF8)).GetBuffer()))
2027 ReportGitError();
2028 git_index_free(index);
2029 git_repository_free(repo);
2030 return false;
2032 Notify(m_targetPathList[i],git_wc_notify_add);
2035 if (git_index_write(index))
2037 ReportGitError();
2038 git_index_free(index);
2039 git_repository_free(repo);
2040 return false;
2043 git_index_free(index);
2044 git_repository_free(repo);
2046 else
2048 CMassiveGitTask mgt(L"add -f");
2049 mgt.ExecuteWithNotify(&m_targetPathList, m_bCancelled, git_wc_notify_add, this, &CGitProgressDlg::Notify);
2052 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2054 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2055 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2056 return true;
2059 bool CGitProgressDlg::CmdCopy(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2061 #if 0
2062 ASSERT(m_targetPathList.GetCount() == 1);
2063 sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);
2064 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2065 SetBackgroundImage(IDI_COPY_BKG);
2067 CString sCmdInfo;
2068 sCmdInfo.Format(IDS_PROGRS_CMD_COPY,
2069 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),
2070 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2071 ReportCmd(sCmdInfo);
2073 if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))
2075 ReportSVNError();
2076 return false;
2078 if (m_options & ProgOptSwitchAfterCopy)
2080 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2081 m_targetPathList[0].GetWinPath(),
2082 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());
2083 ReportCmd(sCmdInfo);
2084 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2086 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))
2088 ReportSVNError();
2089 return false;
2093 else
2095 if (SVN::PathIsURL(m_url))
2097 CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));
2098 ReportNotification(sMsg);
2101 #endif
2102 return true;
2105 bool CGitProgressDlg::CmdExport(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2107 #if 0
2108 ASSERT(m_targetPathList.GetCount() == 1);
2109 sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);
2110 sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;
2111 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2112 SetBackgroundImage(IDI_EXPORT_BKG);
2113 CString eol;
2114 if (m_options & ProgOptEolCRLF)
2115 eol = _T("CRLF");
2116 if (m_options & ProgOptEolLF)
2117 eol = _T("LF");
2118 if (m_options & ProgOptEolCR)
2119 eol = _T("CR");
2120 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));
2121 if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))
2123 ReportSVNError();
2124 return false;
2126 #endif
2127 return true;
2130 bool CGitProgressDlg::CmdRename(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2132 #if 0
2133 ASSERT(m_targetPathList.GetCount() == 1);
2134 if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))
2135 localoperation = true;
2136 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);
2137 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2138 SetBackgroundImage(IDI_RENAME_BKG);
2139 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));
2140 if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))
2142 ReportSVNError();
2143 return false;
2145 #endif
2146 return true;
2149 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)
2152 localoperation = true;
2153 ASSERT(m_targetPathList.GetCount() == 1);
2154 sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);
2155 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2156 SetBackgroundImage(IDI_RESOLVE_BKG);
2157 // check if the file may still have conflict markers in it.
2158 //BOOL bMarkers = FALSE;
2160 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
2162 CString cmd,out,tempmergefile;
2163 cmd.Format(_T("git.exe add -f -- \"%s\""),m_targetPathList[i].GetGitPathString());
2164 if (g_Git.Run(cmd, &out, CP_UTF8))
2166 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2167 m_bErrorsOccurred=true;
2168 return false;
2171 CAppUtils::RemoveTempMergeFile((CTGitPath &)m_targetPathList[i]);
2173 Notify(m_targetPathList[i],git_wc_notify_resolved);
2175 #if 0
2176 if ((m_options & ProgOptSkipConflictCheck) == 0)
2180 for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)
2182 if (!m_targetPathList[fileindex].IsDirectory())
2184 CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);
2185 CString strLine = _T("");
2186 while (file.ReadString(strLine))
2188 if (strLine.Find(_T("<<<<<<<"))==0)
2190 bMarkers = TRUE;
2191 break;
2194 file.Close();
2198 catch (CFileException* pE)
2200 TRACE(_T("CFileException in Resolve!\n"));
2201 TCHAR error[10000] = {0};
2202 pE->GetErrorMessage(error, 10000);
2203 ReportError(error);
2204 pE->Delete();
2205 return false;
2208 if (bMarkers)
2210 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)
2212 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2213 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2214 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2217 else
2219 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));
2220 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)
2221 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);
2223 #endif
2224 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
2226 this->GetDlgItem(IDC_LOGBUTTON)->SetWindowText(_T("Commit ..."));
2227 this->GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2229 return true;
2232 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)
2235 localoperation = true;
2236 sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);
2237 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2238 SetBackgroundImage(IDI_REVERT_BKG);
2240 CTGitPathList delList;
2241 for (int i = 0; i < m_selectedPaths.GetCount(); ++i)
2243 CTGitPath path;
2244 int action;
2245 path.SetFromWin(g_Git.m_CurrentDir+_T("\\")+m_selectedPaths[i].GetWinPath());
2246 action = m_selectedPaths[i].m_Action;
2247 /* rename file can't delete because it needs original file*/
2248 if((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
2249 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
2250 delList.AddPath(path);
2252 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
2253 delList.DeleteAllFiles(true);
2255 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
2256 for (int i = 0; i < m_selectedPaths.GetCount(); ++i)
2258 if(g_Git.Revert(_T("HEAD"), (CTGitPath&)m_selectedPaths[i]))
2260 CMessageBox::Show(NULL,_T("Revert Fail"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2261 m_bErrorsOccurred=true;
2262 return false;
2264 Notify(m_selectedPaths[i],git_wc_notify_revert);
2267 CShellUpdater::Instance().AddPathsForUpdate(m_selectedPaths);
2269 return true;
2272 bool CGitProgressDlg::CmdSwitch(CString& /*sWindowTitle*/, bool& /*localoperation*/)
2274 #if 0
2275 ASSERT(m_targetPathList.GetCount() == 1);
2276 SVNStatus st;
2277 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);
2278 SetWindowText(sWindowTitle); // needs to be updated, see TSVN rev. 21375
2279 SetBackgroundImage(IDI_SWITCH_BKG);
2280 LONG rev = 0;
2281 if (st.GetStatus(m_targetPathList[0]) != (-2))
2283 if (st.status->entry != NULL)
2285 rev = st.status->entry->revision;
2289 CString sCmdInfo;
2290 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH,
2291 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),
2292 (LPCTSTR)m_Revision.ToString());
2293 ReportCmd(sCmdInfo);
2295 bool depthIsSticky = true;
2296 if (m_depth == svn_depth_unknown)
2297 depthIsSticky = false;
2298 if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))
2300 ReportSVNError();
2301 return false;
2303 m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;
2304 if ((m_RevisionEnd >= 0)&&(rev >= 0)
2305 &&((LONG)m_RevisionEnd > (LONG)rev))
2307 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);
2309 #endif
2310 return true;
2312 bool CGitProgressDlg::CmdClone(CString& sWindowTitle, bool& /*localoperation*/)
2314 if (!g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE))
2316 // should never run to here
2317 ASSERT(FALSE);
2318 return false;
2320 this->m_TotalBytesTransferred = 0;
2322 sWindowTitle.LoadString(IDS_PROGRS_TITLE_CLONE);
2323 CAppUtils::SetWindowTitle(m_hWnd, m_url.GetGitPathString(), sWindowTitle);
2324 SetBackgroundImage(IDI_SWITCH_BKG);
2325 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROG_CLONE)));
2327 if (m_url.IsEmpty() || m_targetPathList.GetCount() == 0)
2328 return false;
2330 CStringA url = CUnicodeUtils::GetMulti(m_url.GetGitPathString(), CP_UTF8);
2331 CStringA path = CUnicodeUtils::GetMulti(m_targetPathList[0].GetWinPathString(),CP_UTF8);
2333 git_repository *cloned_repo = NULL;
2334 git_remote *origin = NULL;
2335 git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT;
2337 int error = 0;
2339 git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
2341 clone_opts.checkout_opts = checkout_opts;
2343 clone_opts.checkout_opts.checkout_strategy = m_bNoCheckout? GIT_CHECKOUT_NONE : GIT_CHECKOUT_SAFE;
2344 clone_opts.checkout_opts.progress_cb = CheckoutCallback;
2345 clone_opts.checkout_opts.progress_payload = this;
2347 if (!m_RefSpec.IsEmpty())
2348 clone_opts.checkout_branch = CUnicodeUtils::GetMulti(m_RefSpec, CP_UTF8).GetBuffer();
2350 clone_opts.fetch_progress_cb = FetchCallback;
2351 clone_opts.fetch_progress_payload = this;
2353 clone_opts.cred_acquire_cb = CAppUtils::Git2GetUserPassword;
2355 clone_opts.bare = m_bBare;
2357 m_Animate.ShowWindow(SW_SHOW);
2358 m_Animate.Play(0, INT_MAX, INT_MAX);
2359 error = git_clone(&cloned_repo, url, path, &clone_opts);
2360 m_Animate.Stop();
2361 m_Animate.ShowWindow(SW_HIDE);
2363 git_remote_free(origin);
2364 if (error)
2366 ReportGitError();
2367 return false;
2369 else if (cloned_repo)
2370 git_repository_free(cloned_repo);
2371 return true;
2374 void CGitProgressDlg::OnBnClickedNoninteractive()
2376 LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);
2377 m_AlwaysConflicted = (res == BST_CHECKED);
2378 CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);
2379 nonint = m_AlwaysConflicted;
2382 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)
2384 CString sPath = CPathUtils::ParsePathInString(sColumnText);
2385 if (sPath.Find(':')<0)
2387 // the path is not absolute: add the common root of all paths to it
2388 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);
2390 return sPath;
2393 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)
2395 sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);
2396 CAppUtils::SetWindowTitle(m_hWnd, m_targetPathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
2397 //SetBackgroundImage(IDI_ADD_BKG);
2398 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));
2399 bool ret=true;
2400 if(this->m_SendMailFlags&SENDMAIL_COMBINED)
2402 CString error;
2403 CTGitPath path;
2404 Notify(path,git_wc_notify_sendmail_start);
2405 CString err;
2406 int retry=0;
2407 while(retry <3)
2409 if(!!CPatch::SendPatchesCombined(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI),&err))
2411 Notify(path,git_wc_notify_sendmail_error,ret,&err);
2412 ret = false;
2414 else
2416 break;
2419 ++retry;
2420 if (retry < 3)
2421 Notify(path,git_wc_notify_sendmail_retry,ret,&err);
2422 Sleep(2000);
2423 if(m_bCancelled)
2425 CString str(_T("User Canceled"));
2426 Notify(path,git_wc_notify_sendmail_error,ret,&str);
2427 return false;
2430 if (ret)
2431 Notify(path,git_wc_notify_sendmail_done,ret);
2433 else
2435 for (int i = 0; ret && i < m_targetPathList.GetCount(); ++i)
2437 CPatch patch;
2438 Notify(m_targetPathList[i],git_wc_notify_sendmail_start);
2440 int retry=0;
2441 while(retry<3)
2443 if(!!patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,
2444 this->m_SendMailCC,!!(this->m_SendMailFlags&SENDMAIL_ATTACHMENT),!!(this->m_SendMailFlags&SENDMAIL_MAPI)))
2446 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);
2447 ret = false;
2450 else
2452 ret = true;
2453 break;
2455 ++retry;
2456 if (retry < 3)
2457 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);
2458 Sleep(2000);
2459 if(m_bCancelled)
2461 CString str(_T("User Canceled"));
2462 Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&str);
2463 return false;
2466 if (ret)
2467 Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);
2470 return ret;
2473 LRESULT CGitProgressDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
2475 m_pTaskbarList.Release();
2476 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
2477 return 0;
2480 HBRUSH CGitProgressDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
2482 HBRUSH hbr;
2483 if (pWnd->GetDlgCtrlID() == IDC_TITLE_ANIMATE)
2485 pDC->SetBkColor(GetSysColor(COLOR_WINDOW)); // add this
2486 pDC->SetBkMode(TRANSPARENT);
2487 return (HBRUSH)m_background_brush.GetSafeHandle();
2489 else
2490 hbr = CResizableStandAloneDialog::OnCtlColor(pDC, pWnd, nCtlColor);
2492 // TODO: Return a different brush if the default is not desired
2493 return hbr;
2495 LRESULT CGitProgressDlg::OnCtlColorStatic(WPARAM wParam, LPARAM lParam)
2497 HDC hDC = (HDC)wParam;
2498 HWND hwndCtl = (HWND)lParam;
2500 if (::GetDlgCtrlID(hwndCtl) == IDC_TITLE_ANIMATE)
2502 CDC *pDC = CDC::FromHandle(hDC);
2503 pDC->SetBkColor(GetSysColor(COLOR_WINDOW));
2504 pDC->SetBkMode(TRANSPARENT);
2505 return (LRESULT)(HBRUSH)m_background_brush.GetSafeHandle();
2507 return FALSE;