void CImportPatchDlg::OnBnClickedOk() { m_PathList.Clear(); this->UpdateData(); SaveSplitterPos(); if(IsFinish()) { this->OnOK(); return; } m_ctrlTabCtrl.SetActiveTab(1); EnableInputCtrl(false); InterlockedExchange(&m_bThreadRunning, TRUE); InterlockedExchange(&this->m_bExitThread, FALSE); if ( (m_LoadingThread=AfxBeginThread(ThreadEntry, this)) ==NULL) { InterlockedExchange(&m_bThreadRunning, FALSE); CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR); } }
UINT CImportPatchDlg::PatchThread() { CTGitPath path; path.SetFromWin(g_Git.m_CurrentDir); int i=0; UpdateOkCancelText(); for(i=m_CurrentItem;i<m_cList.GetItemCount();i++) { if (m_pTaskbarList) { m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL); m_pTaskbarList->SetProgressValue(m_hWnd, i, m_cList.GetItemCount()); } m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLYING|m_cList.GetItemData(i)); CRect rect; this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS); this->m_cList.InvalidateRect(rect); if(m_bExitThread) break; if(m_cList.GetCheck(i)) { CString cmd; while(path.HasRebaseApply()) { if (m_pTaskbarList) m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR); int ret = CMessageBox::Show(NULL, _T("<ct=0x0000FF>previous rebase directory rebase-apply still exists but mbox given</ct>\n\n Do you want to"), _T("TortoiseGit"), 1,IDI_ERROR ,_T("&Abort"), _T("&Skip"),_T("&Resolved")); switch(ret) { case 1: cmd = _T("git.exe am --abort"); break; case 2: cmd = _T("git.exe am --skip"); i++; break; case 3: cmd = _T("git.exe am --resolved"); break; default: cmd.Empty(); } if(cmd.IsEmpty()) { m_bExitThread = TRUE; break; } this->AddLogString(cmd); CString output; if(g_Git.Run(cmd, &output, CP_ACP)) { this->AddLogString(output); this->AddLogString(_T("Fail")); } else { this->AddLogString(_T("Done")); } } if(m_bExitThread) break; cmd = _T("git.exe am "); if(this->m_bAddSignedOffBy) cmd += _T("--signoff "); if(this->m_b3Way) cmd += _T("--3way "); if(this->m_bIgnoreSpace) cmd += _T("--ignore-space-change "); if(this->m_bKeepCR) cmd += _T("--keep-cr "); cmd += _T("\""); cmd += m_cList.GetItemText(i,0); cmd += _T("\""); this->AddLogString(cmd); CString output; if(g_Git.Run(cmd,&output,CP_ACP)) { //keep STATUS_APPLYING to let user retry failed patch m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_FAIL|CPatchListCtrl::STATUS_APPLYING); this->AddLogString(output); this->AddLogString(_T("Fail")); if (m_pTaskbarList) m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR); break; } else { m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SUCCESS); this->AddLogString(_T("Success")); } } else { AddLogString(CString(_T("Skip Patch: "))+m_cList.GetItemText(i,0)); m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SKIP); } m_cList.SetItemData(m_CurrentItem, (~CPatchListCtrl::STATUS_APPLYING)&m_cList.GetItemData(i)); m_CurrentItem++; this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS); this->m_cList.InvalidateRect(rect); UpdateOkCancelText(); } //in case am fail, need refresh finial item status CRect rect; this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS); this->m_cList.InvalidateRect(rect); this->m_cList.GetItemRect(m_CurrentItem,&rect,LVIR_BOUNDS); this->m_cList.InvalidateRect(rect); if (m_pTaskbarList) { m_pTaskbarList->SetProgressValue(m_hWnd, m_CurrentItem, m_cList.GetItemCount()); if (m_bExitThread && m_CurrentItem != m_cList.GetItemCount()) m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED); else if (!m_bExitThread && m_CurrentItem == m_cList.GetItemCount()) m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL); } EnableInputCtrl(true); InterlockedExchange(&m_bThreadRunning, FALSE); UpdateOkCancelText(); return 0; }
UINT CImportPatchDlg::PatchThread() { CTGitPath path; path.SetFromWin(g_Git.m_CurrentDir); int i=0; UpdateOkCancelText(); for (i = m_CurrentItem; i < m_cList.GetItemCount(); ++i) { if (m_pTaskbarList) { m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL); m_pTaskbarList->SetProgressValue(m_hWnd, i, m_cList.GetItemCount()); } m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLYING|m_cList.GetItemData(i)); CRect rect; this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS); this->m_cList.InvalidateRect(rect); if(m_bExitThread) break; if(m_cList.GetCheck(i)) { CString cmd; while(path.HasRebaseApply()) { if (m_pTaskbarList) m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR); int ret = CMessageBox::Show(NULL, IDS_PROC_APPLYPATCH_REBASEDIRFOUND, IDS_APPNAME, 1, IDI_ERROR, IDS_ABORTBUTTON, IDS_SKIPBUTTON, IDS_RESOLVEDBUTTON); switch(ret) { case 1: cmd = _T("git.exe am --abort"); break; case 2: cmd = _T("git.exe am --skip"); ++i; break; case 3: cmd = _T("git.exe am --resolved"); break; default: cmd.Empty(); } if(cmd.IsEmpty()) { m_bExitThread = TRUE; break; } this->AddLogString(cmd); CString output; if (g_Git.Run(cmd, &output, CP_UTF8)) { this->AddLogString(output); this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL))); } else { this->AddLogString(CString(MAKEINTRESOURCE(IDS_DONE))); } } if(m_bExitThread) break; cmd = _T("git.exe am "); if(this->m_bAddSignedOffBy) cmd += _T("--signoff "); if(this->m_b3Way) cmd += _T("--3way "); if(this->m_bIgnoreSpace) cmd += _T("--ignore-space-change "); if(this->m_bKeepCR) cmd += _T("--keep-cr "); cmd += _T("\""); cmd += m_cList.GetItemText(i,0); cmd += _T("\""); this->AddLogString(cmd); CString output; if (g_Git.Run(cmd, &output, CP_UTF8)) { //keep STATUS_APPLYING to let user retry failed patch m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_FAIL|CPatchListCtrl::STATUS_APPLYING); this->AddLogString(output); this->AddLogString(CString(MAKEINTRESOURCE(IDS_FAIL))); if (m_pTaskbarList) m_pTaskbarList->SetProgressState(m_hWnd, TBPF_ERROR); break; } else { m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SUCCESS); this->AddLogString(CString(MAKEINTRESOURCE(IDS_SUCCESS))); } } else { CString sMessage; sMessage.Format(IDS_PROC_SKIPPATCH, m_cList.GetItemText(i,0)); AddLogString(sMessage); m_cList.SetItemData(i, CPatchListCtrl::STATUS_APPLY_SKIP); } m_cList.SetItemData(m_CurrentItem, (~CPatchListCtrl::STATUS_APPLYING)&m_cList.GetItemData(i)); ++m_CurrentItem; this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS); this->m_cList.InvalidateRect(rect); UpdateOkCancelText(); } //in case am fail, need refresh finial item status CRect rect; this->m_cList.GetItemRect(i,&rect,LVIR_BOUNDS); this->m_cList.InvalidateRect(rect); this->m_cList.GetItemRect(m_CurrentItem,&rect,LVIR_BOUNDS); this->m_cList.InvalidateRect(rect); if (m_pTaskbarList) { m_pTaskbarList->SetProgressValue(m_hWnd, m_CurrentItem, m_cList.GetItemCount()); if (m_bExitThread && m_CurrentItem != m_cList.GetItemCount()) m_pTaskbarList->SetProgressState(m_hWnd, TBPF_PAUSED); else if (!m_bExitThread && m_CurrentItem == m_cList.GetItemCount()) m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL); } EnableInputCtrl(true); InterlockedExchange(&m_bThreadRunning, FALSE); UpdateOkCancelText(); return 0; }