1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // ProgressDlg.cpp : implementation file
23 #include "TortoiseProc.h"
24 #include "ProgressDlg.h"
27 #include "UnicodeUtils.h"
29 #include "LoglistCommonResource.h"
32 #include "SmartHandle.h"
33 #include "../TGitCache/CacheInterface.h"
34 #include "LoglistUtils.h"
35 #include "SoundUtils.h"
37 #include "MessageBox.h"
39 #include "CmdLineParser.h"
41 // CProgressDlg dialog
43 IMPLEMENT_DYNAMIC(CProgressDlg
, CResizableStandAloneDialog
)
45 CProgressDlg::CProgressDlg(CWnd
* pParent
/*=NULL*/)
46 : CResizableStandAloneDialog(CProgressDlg::IDD
, pParent
)
47 , m_bShowCommand(true)
50 , m_startTick(GetTickCount())
56 m_GitStatus
= (DWORD
)-1;
57 int autoClose
= CRegDWORD(_T("Software\\TortoiseGit\\AutoCloseGitProgress"), 0);
58 CCmdLineParser
parser(AfxGetApp()->m_lpCmdLine
);
59 if (parser
.HasKey(_T("closeonend")))
60 autoClose
= parser
.GetLongVal(_T("closeonend"));
64 m_AutoClose
= AUTOCLOSE_IF_NO_OPTIONS
;
67 m_AutoClose
= AUTOCLOSE_IF_NO_ERRORS
;
70 m_AutoClose
= AUTOCLOSE_NO
;
75 CProgressDlg::~CProgressDlg()
83 void CProgressDlg::DoDataExchange(CDataExchange
* pDX
)
85 CDialog::DoDataExchange(pDX
);
86 DDX_Control(pDX
, IDC_CURRENT
, this->m_CurrentWork
);
87 DDX_Control(pDX
, IDC_TITLE_ANIMATE
, this->m_Animate
);
88 DDX_Control(pDX
, IDC_RUN_PROGRESS
, this->m_Progress
);
89 DDX_Control(pDX
, IDC_LOG
, this->m_Log
);
90 DDX_Control(pDX
, IDC_PROGRESS_BUTTON1
, this->m_ctrlPostCmd
);
93 BEGIN_MESSAGE_MAP(CProgressDlg
, CResizableStandAloneDialog
)
95 ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI
, OnProgressUpdateUI
)
96 ON_BN_CLICKED(IDOK
, &CProgressDlg::OnBnClickedOk
)
97 ON_BN_CLICKED(IDC_PROGRESS_BUTTON1
,&CProgressDlg::OnBnClickedButton1
)
98 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED
, OnTaskbarBtnCreated
)
101 BOOL
CProgressDlg::OnInitDialog()
103 CResizableStandAloneDialog::OnInitDialog();
105 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
106 // do this, Explorer would be unable to send that message to our window if we
107 // were running elevated. It's OK to make the call all the time, since if we're
108 // not elevated, this is a no-op.
109 CHANGEFILTERSTRUCT cfs
= { sizeof(CHANGEFILTERSTRUCT
) };
110 typedef BOOL STDAPICALLTYPE
ChangeWindowMessageFilterExDFN(HWND hWnd
, UINT message
, DWORD action
, PCHANGEFILTERSTRUCT pChangeFilterStruct
);
111 CAutoLibrary hUser
= AtlLoadSystemLibraryUsingFullPath(_T("user32.dll"));
114 ChangeWindowMessageFilterExDFN
*pfnChangeWindowMessageFilterEx
= (ChangeWindowMessageFilterExDFN
*)GetProcAddress(hUser
, "ChangeWindowMessageFilterEx");
115 if (pfnChangeWindowMessageFilterEx
)
117 pfnChangeWindowMessageFilterEx(m_hWnd
, WM_TASKBARBTNCREATED
, MSGFLT_ALLOW
, &cfs
);
120 m_pTaskbarList
.Release();
121 if (FAILED(m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
)))
122 m_pTaskbarList
= nullptr;
124 AddAnchor(IDC_TITLE_ANIMATE
, TOP_LEFT
, TOP_RIGHT
);
125 AddAnchor(IDC_RUN_PROGRESS
, TOP_LEFT
,TOP_RIGHT
);
126 AddAnchor(IDC_LOG
, TOP_LEFT
,BOTTOM_RIGHT
);
128 AddAnchor(IDOK
,BOTTOM_RIGHT
);
129 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
130 AddAnchor(IDC_PROGRESS_BUTTON1
,BOTTOM_LEFT
);
131 AddAnchor(IDC_CURRENT
,TOP_LEFT
);
133 this->GetDlgItem(IDC_PROGRESS_BUTTON1
)->ShowWindow(SW_HIDE
);
134 m_Animate
.Open(IDR_DOWNLOAD
);
137 CAppUtils::CreateFontForLogs(m_logFont
);
138 //GetDlgItem(IDC_CMD_LOG)->SetFont(&m_logFont);
139 m_Log
.SetFont(&m_logFont
);
142 if ( !m_PreText
.IsEmpty() )
144 InitialText
= m_PreText
+ _T("\r\n");
147 if (m_bShowCommand
&& (!m_GitCmd
.IsEmpty() ))
149 InitialText
+= m_GitCmd
+_T("\r\n\r\n");
152 m_Log
.SetWindowTextW(InitialText
);
153 m_CurrentWork
.SetWindowTextW(_T(""));
155 EnableSaveRestore(_T("ProgressDlg"));
157 m_pThread
= AfxBeginThread(ProgressThreadEntry
, this, THREAD_PRIORITY_NORMAL
,0,CREATE_SUSPENDED
);
160 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
161 DialogEnableWindow(IDCANCEL
, TRUE
);
165 m_pThread
->m_bAutoDelete
= FALSE
;
166 m_pThread
->ResumeThread();
169 CString sWindowTitle
;
170 GetWindowText(sWindowTitle
);
171 CAppUtils::SetWindowTitle(m_hWnd
, m_Git
->m_CurrentDir
, sWindowTitle
);
173 // Make sure this dialog is shown in foreground (see issue #1536)
174 SetForegroundWindow();
179 static void EnsurePostMessage(CWnd
*pWnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
182 if (!pWnd
->PostMessage(Msg
, wParam
, lParam
))
184 if (GetLastError() == ERROR_NOT_ENOUGH_QUOTA
)
190 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": Message %d-%d could not be sent (error %d; %s)\n"), wParam
, lParam
, GetLastError(), (CString
)CFormatMessageWrapper());
194 UINT
CProgressDlg::ProgressThreadEntry(LPVOID pVoid
)
196 return ((CProgressDlg
*)pVoid
)->ProgressThread();
199 //static function, Share with SyncDialog
200 UINT
CProgressDlg::RunCmdList(CWnd
*pWnd
, STRING_VECTOR
&cmdlist
, STRING_VECTOR
&dirlist
, bool bShowCommand
, CString
*pfilename
, bool *bAbort
, CGitByteArray
*pdata
, CGit
*git
)
204 std::vector
<std::unique_ptr
<CBlockCacheForPath
>> cacheBlockList
;
205 std::vector
<std::unique_ptr
<CGit
>> gitList
;
207 cacheBlockList
.push_back(std::unique_ptr
<CBlockCacheForPath
>(new CBlockCacheForPath(git
->m_CurrentDir
)));
210 for (auto dir
: dirlist
)
212 CGit
*pGit
= new CGit
;
213 pGit
->m_CurrentDir
= dir
;
214 gitList
.push_back(std::unique_ptr
<CGit
>(pGit
));
215 cacheBlockList
.push_back(std::unique_ptr
<CBlockCacheForPath
>(new CBlockCacheForPath(dir
)));
219 EnsurePostMessage(pWnd
, MSG_PROGRESSDLG_UPDATE_UI
, MSG_PROGRESSDLG_START
, 0);
224 for (size_t i
= 0; i
< cmdlist
.size(); ++i
)
226 if(cmdlist
[i
].IsEmpty())
232 if (gitList
.empty() || gitList
.size() == 1 && gitList
[0]->m_CurrentDir
== git
->m_CurrentDir
)
233 str
= CUnicodeUtils::GetMulti(cmdlist
[i
].Trim() + _T("\r\n\r\n"), CP_UTF8
);
235 str
= CUnicodeUtils::GetMulti((i
> 0 ? _T("\r\n") : _T("")) + gitList
[i
]->m_CurrentDir
+ _T("\r\n") + cmdlist
[i
].Trim() + _T("\r\n\r\n"), CP_UTF8
);
236 for (int j
= 0; j
< str
.GetLength(); ++j
)
240 pdata
->m_critSec
.Lock();
241 pdata
->push_back(str
[j
]);
242 pdata
->m_critSec
.Unlock();
245 pWnd
->PostMessage(MSG_PROGRESSDLG_UPDATE_UI
,MSG_PROGRESSDLG_RUN
,str
[j
]);
248 pWnd
->PostMessage(MSG_PROGRESSDLG_UPDATE_UI
,MSG_PROGRESSDLG_RUN
,0);
251 PROCESS_INFORMATION pi
;
252 CAutoGeneralHandle hRead
;
253 int runAsyncRet
= -1;
255 runAsyncRet
= git
->RunAsync(cmdlist
[i
].Trim(), &pi
, hRead
.GetPointer(), nullptr, pfilename
);
257 runAsyncRet
= gitList
[i
]->RunAsync(cmdlist
[i
].Trim(), &pi
, hRead
.GetPointer(), nullptr, pfilename
);
260 EnsurePostMessage(pWnd
, MSG_PROGRESSDLG_UPDATE_UI
, MSG_PROGRESSDLG_FAILED
, -1 * runAsyncRet
);
264 CAutoGeneralHandle
piProcess(pi
.hProcess
);
265 CAutoGeneralHandle
piThread(pi
.hThread
);
267 char lastByte
= '\0';
270 while(ReadFile(hRead
,&byte
,1,&readnumber
,NULL
))
277 pdata
->m_critSec
.Lock();
278 if (byte
== '\n' && lastByte
!= '\r')
279 pdata
->push_back('\r');
280 pdata
->push_back( byte
);
282 pdata
->m_critSec
.Unlock();
284 if(byte
== '\r' || byte
== '\n')
285 pWnd
->PostMessage(MSG_PROGRESSDLG_UPDATE_UI
,MSG_PROGRESSDLG_RUN
,0);
288 pWnd
->PostMessage(MSG_PROGRESSDLG_UPDATE_UI
,MSG_PROGRESSDLG_RUN
,byte
);
292 pdata
->m_critSec
.Lock();
293 bool post
= !pdata
->empty();
294 pdata
->m_critSec
.Unlock();
296 EnsurePostMessage(pWnd
, MSG_PROGRESSDLG_UPDATE_UI
, MSG_PROGRESSDLG_RUN
, 0);
299 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": waiting for process to finish (%s), aborted: %d\n"), cmdlist
[i
], *bAbort
);
301 WaitForSingleObject(pi
.hProcess
, INFINITE
);
304 if(!GetExitCodeProcess(pi
.hProcess
,&status
) || *bAbort
)
306 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": process %s finished, status code could not be fetched, (error %d; %s), aborted: %d\n"), cmdlist
[i
], GetLastError(), (CString
)CFormatMessageWrapper(), *bAbort
);
308 EnsurePostMessage(pWnd
, MSG_PROGRESSDLG_UPDATE_UI
, MSG_PROGRESSDLG_FAILED
, status
);
309 return TGIT_GIT_ERROR_GET_EXIT_CODE
;
311 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": process %s finished with code %d\n"), cmdlist
[i
], status
);
315 EnsurePostMessage(pWnd
, MSG_PROGRESSDLG_UPDATE_UI
, MSG_PROGRESSDLG_END
, ret
);
320 UINT
CProgressDlg::ProgressThread()
323 m_GitCmdList
.push_back(m_GitCmd
);
327 if(m_LogFile
.IsEmpty())
330 pfilename
=&m_LogFile
;
332 m_startTick
= GetTickCount();
333 m_GitStatus
= RunCmdList(this, m_GitCmdList
, m_GitDirList
, m_bShowCommand
, pfilename
, &m_bAbort
, &this->m_Databuf
, m_Git
);
337 LRESULT
CProgressDlg::OnProgressUpdateUI(WPARAM wParam
,LPARAM lParam
)
339 if(wParam
== MSG_PROGRESSDLG_START
)
342 m_Animate
.Play(0, INT_MAX
, INT_MAX
);
343 DialogEnableWindow(IDCANCEL
, TRUE
);
346 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
347 m_pTaskbarList
->SetProgressValue(m_hWnd
, 0, 100);
350 if(wParam
== MSG_PROGRESSDLG_END
|| wParam
== MSG_PROGRESSDLG_FAILED
)
352 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": got message: %d\n"), wParam
);
353 DWORD tickSpent
= GetTickCount() - m_startTick
;
354 CString strEndTime
= CLoglistUtils::FormatDateAndTime(CTime::GetCurrentTime(), DATE_SHORTDATE
, true, false);
358 m_Databuf
.m_critSec
.Lock();
359 m_Databuf
.push_back(0);
360 m_Log
.SetWindowText(Convert2UnionCode((char*)&m_Databuf
[0]));
361 m_Databuf
.m_critSec
.Unlock();
362 m_Log
.LineScroll(m_Log
.GetLineCount() - m_Log
.GetFirstVisibleLine() - 4);
365 m_Databuf
.m_critSec
.Lock();
366 this->m_Databuf
.clear();
367 m_Databuf
.m_critSec
.Unlock();
371 m_Progress
.SetPos(100);
372 this->DialogEnableWindow(IDOK
,TRUE
);
374 m_GitStatus
= (DWORD
)lParam
;
376 // detect crashes of perl when performing git svn actions
377 if (m_GitStatus
== 0 && m_GitCmd
.Find(_T(" svn ")) > 1)
380 m_Log
.GetWindowText(log
);
381 if (log
.GetLength() > 18 && log
.Mid(log
.GetLength() - 18) == _T("perl.exe.stackdump"))
382 m_GitStatus
= (DWORD
)-1;
385 if(this->m_GitStatus
)
389 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_ERROR
);
390 m_pTaskbarList
->SetProgressValue(m_hWnd
, 100, 100);
393 log
.Format(IDS_PROC_PROGRESS_GITUNCLEANEXIT
, m_GitStatus
);
395 if (CRegDWORD(_T("Software\\TortoiseGit\\ShowGitexeTimings"), TRUE
))
396 err
.Format(_T("\r\n\r\n%s (%lu ms @ %s)\r\n"), log
, tickSpent
, strEndTime
);
398 err
.Format(_T("\r\n\r\n%s\r\n"), log
);
399 InsertColorText(this->m_Log
, err
, RGB(255,0,0));
400 CSoundUtils::PlayTGitError();
404 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NOPROGRESS
);
406 temp
.LoadString(IDS_SUCCESS
);
408 if (CRegDWORD(_T("Software\\TortoiseGit\\ShowGitexeTimings"), TRUE
))
409 log
.Format(_T("\r\n%s (%lu ms @ %s)\r\n"), temp
, tickSpent
, strEndTime
);
411 log
.Format(_T("\r\n%s\r\n"), temp
);
412 InsertColorText(this->m_Log
, log
, RGB(0,0,255));
413 this->DialogEnableWindow(IDCANCEL
,FALSE
);
416 if (wParam
== MSG_PROGRESSDLG_END
)
418 if (m_PostCmdCallback
) // new handling method using callback
420 m_PostCmdCallback(m_GitStatus
, m_PostCmdList
);
422 if (!m_PostCmdList
.empty())
424 for (auto it
= m_PostCmdList
.cbegin(); it
!= m_PostCmdList
.cend(); ++it
)
425 m_ctrlPostCmd
.AddEntry((*it
).icon
, (*it
).label
);
426 GetDlgItem(IDC_PROGRESS_BUTTON1
)->ShowWindow(SW_SHOW
);
431 if(wParam
== MSG_PROGRESSDLG_END
&& m_GitStatus
== 0)
433 if (m_AutoClose
== AUTOCLOSE_IF_NO_OPTIONS
&& m_PostCmdList
.empty() || m_AutoClose
== AUTOCLOSE_IF_NO_ERRORS
)
434 PostMessage(WM_COMMAND
, 1, (LPARAM
)GetDlgItem(IDOK
)->m_hWnd
);
442 m_Databuf
.m_critSec
.Lock();
443 for (size_t i
= this->m_BufStart
; i
< this->m_Databuf
.size(); ++i
)
445 char c
= this->m_Databuf
[m_BufStart
];
447 m_Databuf
.m_critSec
.Unlock();
450 m_Databuf
.m_critSec
.Lock();
455 m_Databuf
.erase(m_Databuf
.begin(), m_Databuf
.begin()+m_BufStart
);
458 m_Databuf
.m_critSec
.Unlock();
462 ParserCmdOutput((char)lParam
);
467 //static function, Share with SyncDialog
468 int CProgressDlg::FindPercentage(CString
&log
)
470 int s1
=log
.Find(_T('%'));
475 for(int i
=s1
-1;i
>=0;i
--)
477 if(log
[i
]>=_T('0') && log
[i
]<=_T('9'))
482 return _ttol(log
.Mid(s2
,s1
-s2
));
485 void CProgressDlg::ParserCmdOutput(char ch
)
487 ParserCmdOutput(this->m_Log
,this->m_Progress
,this->m_hWnd
,this->m_pTaskbarList
,this->m_LogTextA
,ch
,&this->m_CurrentWork
);
489 void CProgressDlg::ClearESC(CString
&str
)
491 // see http://ascii-table.com/ansi-escape-sequences.php and http://tldp.org/HOWTO/Bash-Prompt-HOWTO/c327.html
492 str
.Replace(_T("\033[K"), _T("")); // erase until end of line; no need to care for this, because we always clear the whole line
497 int escapePosition
= str
.Find(_T('\033'));
498 if (escapePosition
>= 0 && str
.GetLength() >= escapePosition
+ 3)
500 if (str
.Mid(escapePosition
, 2) == _T("\033["))
502 int colorEnd
= str
.Find(_T('m'), escapePosition
+ 2);
506 for (int i
= escapePosition
+ 2; i
< colorEnd
; ++i
)
508 if (str
[i
] != _T(';') && (str
[i
] < _T('0') && str
[i
] > _T('9')))
516 if (escapePosition
> 0)
517 str
= str
.Left(escapePosition
) + str
.Mid(colorEnd
+ 1);
519 str
= str
.Mid(colorEnd
);
528 void CProgressDlg::ParserCmdOutput(CRichEditCtrl
&log
,CProgressCtrl
&progressctrl
,HWND m_hWnd
,CComPtr
<ITaskbarList3
> m_pTaskbarList
,CStringA
&oneline
, char ch
, CWnd
*CurrentWork
)
530 //TRACE(_T("%c"),ch);
531 if( ch
== ('\r') || ch
== ('\n'))
535 // TRACE(_T("End Char %s \r\n"),ch==_T('\r')?_T("lf"):_T(""));
536 // TRACE(_T("End Char %s \r\n"),ch==_T('\n')?_T("cr"):_T(""));
538 int lines
= log
.GetLineCount();
539 g_Git
.StringAppend(&str
, (BYTE
*)oneline
.GetBuffer(), CP_UTF8
);
541 // TRACE(_T("%s"), str);
547 int start
=log
.LineIndex(lines
-1);
548 log
.SetSel(start
, log
.GetTextLength());
553 int length
= log
.GetWindowTextLength();
554 log
.SetSel(length
, length
);
556 log
.ReplaceSel(_T("\r\n") + str
);
561 if (lines
> 500) //limited log length
563 int end
=log
.LineIndex(1);
565 log
.ReplaceSel(_T(""));
567 log
.LineScroll(log
.GetLineCount() - log
.GetFirstVisibleLine() - 4);
569 int s1
=oneline
.ReverseFind(_T(':'));
570 int s2
=oneline
.Find(_T('%'));
571 if (s1
> 0 && s2
> 0)
574 CurrentWork
->SetWindowTextW(str
.Left(s1
));
576 int pos
=FindPercentage(str
);
577 TRACE(_T("Pos %d\r\n"),pos
);
580 progressctrl
.SetPos(pos
);
583 m_pTaskbarList
->SetProgressState(m_hWnd
, TBPF_NORMAL
);
584 m_pTaskbarList
->SetProgressValue(m_hWnd
, pos
, 100);
597 void CProgressDlg::RemoveLastLine(CString
&str
)
600 start
=str
.ReverseFind(_T('\n'));
605 // CProgressDlg message handlers
607 void CProgressDlg::WriteLog() const
609 CLogFile
logfile(g_Git
.m_CurrentDir
);
612 logfile
.AddTimeLine();
613 CString text
= GetLogText();
614 LPTSTR psz_string
= text
.GetBuffer();
617 if (*psz_string
== '\r')
622 size_t i_len
= wcscspn(psz_string
, L
"\n");
623 logfile
.AddLine(CString(psz_string
, (int)i_len
));
625 if (*psz_string
== '\n')
631 canceled
.LoadString(IDS_SVN_USERCANCELLED
);
632 logfile
.AddLine(canceled
);
638 void CProgressDlg::OnBnClickedOk()
640 if (m_pThread
) // added here because Close-button is "called" from thread by PostMessage
641 ::WaitForSingleObject(m_pThread
->m_hThread
, 5000);
642 m_Log
.GetWindowText(this->m_LogText
);
647 void CProgressDlg::OnBnClickedButton1()
651 m_PostCmdList
.at(m_ctrlPostCmd
.GetCurrentEntry()).action();
655 void CProgressDlg::OnClose()
657 DialogEnableWindow(IDCANCEL
, TRUE
);
661 void CProgressDlg::OnCancel()
663 CTraceToOutputDebugString::Instance()(_T(__FUNCTION__
) _T(": User canceled\n"));
668 CResizableStandAloneDialog::OnCancel();
672 if( m_Git
->m_CurrentGitPi
.hProcess
)
674 DWORD dwConfirmKillProcess
= CRegDWORD(_T("Software\\TortoiseGit\\ConfirmKillProcess"));
675 if (dwConfirmKillProcess
&& CMessageBox::Show(m_hWnd
, IDS_PROC_CONFIRMKILLPROCESS
, IDS_APPNAME
, MB_YESNO
| MB_ICONQUESTION
) != IDYES
)
677 if(::GenerateConsoleCtrlEvent(CTRL_C_EVENT
,0))
679 ::WaitForSingleObject(m_Git
->m_CurrentGitPi
.hProcess
,10000);
682 KillProcessTree(m_Git
->m_CurrentGitPi
.dwProcessId
);
685 ::WaitForSingleObject(m_Git
->m_CurrentGitPi
.hProcess
,10000);
687 ::WaitForSingleObject(m_pThread
->m_hThread
, 5000);
689 CResizableStandAloneDialog::OnCancel();
692 void CProgressDlg::KillProcessTree(DWORD dwProcessId
, unsigned int depth
)
694 // recursively kills a process tree
695 // This is not optimized, but works and isn't called very often ;)
697 if (!dwProcessId
|| depth
> 20)
701 memset(&pe
, 0, sizeof(PROCESSENTRY32
));
702 pe
.dwSize
= sizeof(PROCESSENTRY32
);
704 CAutoGeneralHandle hSnap
= ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS
, 0);
706 if (::Process32First(hSnap
, &pe
))
710 if (pe
.th32ParentProcessID
== dwProcessId
)
711 KillProcessTree(pe
.th32ProcessID
, depth
+ 1);
712 } while (::Process32Next(hSnap
, &pe
));
714 CAutoGeneralHandle hProc
= ::OpenProcess(PROCESS_TERMINATE
, FALSE
, dwProcessId
);
716 ::TerminateProcess(hProc
, 1);
720 void CProgressDlg::InsertColorText(CRichEditCtrl
&edit
,CString text
,COLORREF rgb
)
723 edit
.GetDefaultCharFormat(cf
);
725 cf
.dwMask
|=CFM_COLOR
;
727 cf
.dwEffects
|=CFE_BOLD
;
728 cf
.dwEffects
&= ~CFE_AUTOCOLOR
;
729 edit
.SetSel(edit
.GetTextLength()-1,edit
.GetTextLength());
730 edit
.ReplaceSel(text
);
731 edit
.SetSel(edit
.LineIndex(edit
.GetLineCount()-2),edit
.GetTextLength());
732 edit
.SetSelectionCharFormat(cf
);
733 edit
.SetSel(edit
.GetTextLength(),edit
.GetTextLength());
734 edit
.SetDefaultCharFormat(old
);
735 edit
.LineScroll(edit
.GetLineCount() - edit
.GetFirstVisibleLine() - 4);
738 CString
CCommitProgressDlg::Convert2UnionCode(char *buff
, int size
)
742 size
= (int)strlen(buff
);
744 for (int i
= 0; i
< size
; ++i
)
748 if( start
>0 && buff
[i
] =='\n' )
756 g_Git
.StringAppend(&str
, (BYTE
*)buff
, g_Git
.m_LogEncode
, start
);
757 g_Git
.StringAppend(&str
, (BYTE
*)buff
+ start
, CP_UTF8
, size
- start
);
764 LRESULT
CProgressDlg::OnTaskbarBtnCreated(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
766 m_pTaskbarList
.Release();
767 m_pTaskbarList
.CoCreateInstance(CLSID_TaskbarList
);
768 SetUUIDOverlayIcon(m_hWnd
);
772 BOOL
CProgressDlg::PreTranslateMessage(MSG
* pMsg
)
774 if (pMsg
->message
== WM_KEYDOWN
)
776 if (pMsg
->wParam
== VK_ESCAPE
)
778 // pressing the ESC key should close the dialog. But since we disabled the escape
779 // key (so the user doesn't get the idea that he could simply undo an e.g. update)
781 // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets
782 // the impression that the OK button was pressed.
783 if ((!GetDlgItem(IDCANCEL
)->IsWindowEnabled())
784 &&(GetDlgItem(IDOK
)->IsWindowEnabled())&&(GetDlgItem(IDOK
)->IsWindowVisible()))
786 // since we convert ESC to RETURN, make sure the OK button has the focus.
787 GetDlgItem(IDOK
)->SetFocus();
788 pMsg
->wParam
= VK_RETURN
;
792 else if (pMsg
->message
== WM_CONTEXTMENU
|| pMsg
->message
== WM_RBUTTONDOWN
)
794 CWnd
* pWnd
= (CWnd
*) GetDlgItem(IDC_LOG
);
795 if (pWnd
== GetFocus())
798 if (popup
.CreatePopupMenu())
800 popup
.AppendMenuIcon(WM_COPY
, IDS_SCIEDIT_COPY
, IDI_COPYCLIP
);
801 if (m_Log
.GetSelText().IsEmpty())
802 popup
.EnableMenuItem(WM_COPY
, MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
803 popup
.AppendMenu(MF_SEPARATOR
);
804 popup
.AppendMenuIcon(EM_SETSEL
, IDS_SCIEDIT_SELECTALL
);
805 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
, pMsg
->pt
.x
, pMsg
->pt
.y
, this);
808 case 0: // no command selected
812 ::SendMessage(GetDlgItem(IDC_LOG
)->GetSafeHwnd(), cmd
, 0, -1);
819 return __super::PreTranslateMessage(pMsg
);