Fix wrong error message when fail launch pageant
[TortoiseGit.git] / src / TortoiseProc / AppUtils.cpp
blobfa4627d17422ec988e1ec9204adb90ab238efe70
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - 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 #include "StdAfx.h"
20 #include "resource.h"
21 #include "TortoiseProc.h"
22 #include "PathUtils.h"
23 #include "AppUtils.h"
24 //#include "GitProperties.h"
25 #include "StringUtils.h"
26 #include "MessageBox.h"
27 #include "Registry.h"
28 #include "TGitPath.h"
29 #include "Git.h"
30 //#include "RepositoryBrowser.h"
31 //#include "BrowseFolder.h"
32 #include "UnicodeUtils.h"
33 #include "ExportDlg.h"
34 #include "ProgressDlg.h"
35 #include "GitAdminDir.h"
36 #include "ProgressDlg.h"
37 #include "BrowseFolder.h"
38 #include "DirFileEnum.h"
39 #include "MessageBox.h"
40 #include "GitStatus.h"
41 #include "CreateBranchTagDlg.h"
42 #include "GitSwitchDlg.h"
43 #include "ResetDlg.h"
44 #include "DeleteConflictDlg.h"
45 #include "ChangedDlg.h"
46 #include "SendMailDlg.h"
47 #include "SVNProgressDlg.h"
49 CAppUtils::CAppUtils(void)
53 CAppUtils::~CAppUtils(void)
57 int CAppUtils::StashApply(CString ref)
59 CString cmd,out;
60 cmd=_T("git.exe stash apply ");
61 cmd+=ref;
63 if(g_Git.Run(cmd,&out,CP_ACP))
65 CMessageBox::Show(NULL,CString(_T("<ct=0x0000FF>Stash Apply Fail!!!</ct>\n"))+out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
67 }else
69 if(CMessageBox::Show(NULL,CString(_T("<ct=0xff0000>Stash Apply Success</ct>\nDo you want to show change?"))
70 ,_T("TortoiseGit"),MB_YESNO|MB_ICONINFORMATION) == IDYES)
72 CChangedDlg dlg;
73 dlg.m_pathList.AddPath(CTGitPath());
74 dlg.DoModal();
76 return 0;
78 return -1;
80 bool CAppUtils::GetMimeType(const CTGitPath& file, CString& mimetype)
82 #if 0
83 GitProperties props(file, GitRev::REV_WC, false);
84 for (int i = 0; i < props.GetCount(); ++i)
86 if (props.GetItemName(i).compare(_T("svn:mime-type"))==0)
88 mimetype = props.GetItemValue(i).c_str();
89 return true;
92 #endif
93 return false;
96 BOOL CAppUtils::StartExtMerge(
97 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
98 const CString& basename, const CString& theirname, const CString& yourname, const CString& mergedname, bool bReadOnly)
101 CRegString regCom = CRegString(_T("Software\\TortoiseGit\\Merge"));
102 CString ext = mergedfile.GetFileExtension();
103 CString com = regCom;
104 bool bInternal = false;
106 CString mimetype;
107 if (ext != "")
109 // is there an extension specific merge tool?
110 CRegString mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext.MakeLower());
111 if (CString(mergetool) != "")
113 com = mergetool;
116 if (GetMimeType(yourfile, mimetype) || GetMimeType(theirfile, mimetype) || GetMimeType(basefile, mimetype))
118 // is there a mime type specific merge tool?
119 CRegString mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype);
120 if (CString(mergetool) != "")
122 com = mergetool;
126 if (com.IsEmpty()||(com.Left(1).Compare(_T("#"))==0))
128 // use TortoiseMerge
129 bInternal = true;
130 CRegString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE);
131 com = tortoiseMergePath;
132 if (com.IsEmpty())
134 com = CPathUtils::GetAppDirectory();
135 com += _T("TortoiseMerge.exe");
137 com = _T("\"") + com + _T("\"");
138 com = com + _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
139 com = com + _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
141 // check if the params are set. If not, just add the files to the command line
142 if ((com.Find(_T("%merged"))<0)&&(com.Find(_T("%base"))<0)&&(com.Find(_T("%theirs"))<0)&&(com.Find(_T("%mine"))<0))
144 com += _T(" \"")+basefile.GetWinPathString()+_T("\"");
145 com += _T(" \"")+theirfile.GetWinPathString()+_T("\"");
146 com += _T(" \"")+yourfile.GetWinPathString()+_T("\"");
147 com += _T(" \"")+mergedfile.GetWinPathString()+_T("\"");
149 if (basefile.IsEmpty())
151 com.Replace(_T("/base:%base"), _T(""));
152 com.Replace(_T("%base"), _T(""));
154 else
155 com.Replace(_T("%base"), _T("\"") + basefile.GetWinPathString() + _T("\""));
156 if (theirfile.IsEmpty())
158 com.Replace(_T("/theirs:%theirs"), _T(""));
159 com.Replace(_T("%theirs"), _T(""));
161 else
162 com.Replace(_T("%theirs"), _T("\"") + theirfile.GetWinPathString() + _T("\""));
163 if (yourfile.IsEmpty())
165 com.Replace(_T("/mine:%mine"), _T(""));
166 com.Replace(_T("%mine"), _T(""));
168 else
169 com.Replace(_T("%mine"), _T("\"") + yourfile.GetWinPathString() + _T("\""));
170 if (mergedfile.IsEmpty())
172 com.Replace(_T("/merged:%merged"), _T(""));
173 com.Replace(_T("%merged"), _T(""));
175 else
176 com.Replace(_T("%merged"), _T("\"") + mergedfile.GetWinPathString() + _T("\""));
177 if (basename.IsEmpty())
179 if (basefile.IsEmpty())
181 com.Replace(_T("/basename:%bname"), _T(""));
182 com.Replace(_T("%bname"), _T(""));
184 else
186 com.Replace(_T("%bname"), _T("\"") + basefile.GetUIFileOrDirectoryName() + _T("\""));
189 else
190 com.Replace(_T("%bname"), _T("\"") + basename + _T("\""));
191 if (theirname.IsEmpty())
193 if (theirfile.IsEmpty())
195 com.Replace(_T("/theirsname:%tname"), _T(""));
196 com.Replace(_T("%tname"), _T(""));
198 else
200 com.Replace(_T("%tname"), _T("\"") + theirfile.GetUIFileOrDirectoryName() + _T("\""));
203 else
204 com.Replace(_T("%tname"), _T("\"") + theirname + _T("\""));
205 if (yourname.IsEmpty())
207 if (yourfile.IsEmpty())
209 com.Replace(_T("/minename:%yname"), _T(""));
210 com.Replace(_T("%yname"), _T(""));
212 else
214 com.Replace(_T("%yname"), _T("\"") + yourfile.GetUIFileOrDirectoryName() + _T("\""));
217 else
218 com.Replace(_T("%yname"), _T("\"") + yourname + _T("\""));
219 if (mergedname.IsEmpty())
221 if (mergedfile.IsEmpty())
223 com.Replace(_T("/mergedname:%mname"), _T(""));
224 com.Replace(_T("%mname"), _T(""));
226 else
228 com.Replace(_T("%mname"), _T("\"") + mergedfile.GetUIFileOrDirectoryName() + _T("\""));
231 else
232 com.Replace(_T("%mname"), _T("\"") + mergedname + _T("\""));
234 if ((bReadOnly)&&(bInternal))
235 com += _T(" /readonly");
237 if(!LaunchApplication(com, IDS_ERR_EXTMERGESTART, false))
239 return FALSE;
242 return TRUE;
245 BOOL CAppUtils::StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir, const CString& sOriginalDescription, const CString& sPatchedDescription, BOOL bReversed, BOOL bWait)
247 CString viewer;
248 // use TortoiseMerge
249 viewer = CPathUtils::GetAppDirectory();
250 viewer += _T("TortoiseMerge.exe");
252 viewer = _T("\"") + viewer + _T("\"");
253 viewer = viewer + _T(" /diff:\"") + patchfile.GetWinPathString() + _T("\"");
254 viewer = viewer + _T(" /patchpath:\"") + dir.GetWinPathString() + _T("\"");
255 if (bReversed)
256 viewer += _T(" /reversedpatch");
257 if (!sOriginalDescription.IsEmpty())
258 viewer = viewer + _T(" /patchoriginal:\"") + sOriginalDescription + _T("\"");
259 if (!sPatchedDescription.IsEmpty())
260 viewer = viewer + _T(" /patchpatched:\"") + sPatchedDescription + _T("\"");
261 if(!LaunchApplication(viewer, IDS_ERR_DIFFVIEWSTART, !!bWait))
263 return FALSE;
265 return TRUE;
268 CString CAppUtils::PickDiffTool(const CTGitPath& file1, const CTGitPath& file2)
270 // Is there a mime type specific diff tool?
271 CString mimetype;
272 if (GetMimeType(file1, mimetype) || GetMimeType(file2, mimetype))
274 CString difftool = CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype);
275 if (!difftool.IsEmpty())
276 return difftool;
279 // Is there an extension specific diff tool?
280 CString ext = file2.GetFileExtension().MakeLower();
281 if (!ext.IsEmpty())
283 CString difftool = CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext);
284 if (!difftool.IsEmpty())
285 return difftool;
286 // Maybe we should use TortoiseIDiff?
287 if ((ext == _T(".jpg")) || (ext == _T(".jpeg")) ||
288 (ext == _T(".bmp")) || (ext == _T(".gif")) ||
289 (ext == _T(".png")) || (ext == _T(".ico")) ||
290 (ext == _T(".dib")) || (ext == _T(".emf")))
292 return
293 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
294 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
298 // Finally, pick a generic external diff tool
299 CString difftool = CRegString(_T("Software\\TortoiseGit\\Diff"));
300 return difftool;
303 bool CAppUtils::StartExtDiff(
304 const CString& file1, const CString& file2,
305 const CString& sName1, const CString& sName2,
306 const DiffFlags& flags)
308 CString viewer;
310 CRegDWORD blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE);
311 if (!flags.bBlame || !(DWORD)blamediff)
313 viewer = PickDiffTool(file1, file2);
314 // If registry entry for a diff program is commented out, use TortoiseMerge.
315 bool bCommentedOut = viewer.Left(1) == _T("#");
316 if (flags.bAlternativeTool)
318 // Invert external vs. internal diff tool selection.
319 if (bCommentedOut)
320 viewer.Delete(0); // uncomment
321 else
322 viewer = "";
324 else if (bCommentedOut)
325 viewer = "";
328 bool bInternal = viewer.IsEmpty();
329 if (bInternal)
331 viewer =
332 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
333 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
334 if (flags.bBlame)
335 viewer += _T(" /blame");
337 // check if the params are set. If not, just add the files to the command line
338 if ((viewer.Find(_T("%base"))<0)&&(viewer.Find(_T("%mine"))<0))
340 viewer += _T(" \"")+file1+_T("\"");
341 viewer += _T(" \"")+file2+_T("\"");
343 if (viewer.Find(_T("%base")) >= 0)
345 viewer.Replace(_T("%base"), _T("\"")+file1+_T("\""));
347 if (viewer.Find(_T("%mine")) >= 0)
349 viewer.Replace(_T("%mine"), _T("\"")+file2+_T("\""));
352 if (sName1.IsEmpty())
353 viewer.Replace(_T("%bname"), _T("\"") + file1 + _T("\""));
354 else
355 viewer.Replace(_T("%bname"), _T("\"") + sName1 + _T("\""));
357 if (sName2.IsEmpty())
358 viewer.Replace(_T("%yname"), _T("\"") + file2 + _T("\""));
359 else
360 viewer.Replace(_T("%yname"), _T("\"") + sName2 + _T("\""));
362 if (flags.bReadOnly && bInternal)
363 viewer += _T(" /readonly");
365 return LaunchApplication(viewer, IDS_ERR_EXTDIFFSTART, flags.bWait);
368 BOOL CAppUtils::StartExtDiffProps(const CTGitPath& file1, const CTGitPath& file2, const CString& sName1, const CString& sName2, BOOL bWait, BOOL bReadOnly)
370 CRegString diffpropsexe(_T("Software\\TortoiseGit\\DiffProps"));
371 CString viewer = diffpropsexe;
372 bool bInternal = false;
373 if (viewer.IsEmpty()||(viewer.Left(1).Compare(_T("#"))==0))
375 //no registry entry (or commented out) for a diff program
376 //use TortoiseMerge
377 bInternal = true;
378 viewer = CPathUtils::GetAppDirectory();
379 viewer += _T("TortoiseMerge.exe");
380 viewer = _T("\"") + viewer + _T("\"");
381 viewer = viewer + _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
383 // check if the params are set. If not, just add the files to the command line
384 if ((viewer.Find(_T("%base"))<0)&&(viewer.Find(_T("%mine"))<0))
386 viewer += _T(" \"")+file1.GetWinPathString()+_T("\"");
387 viewer += _T(" \"")+file2.GetWinPathString()+_T("\"");
389 if (viewer.Find(_T("%base")) >= 0)
391 viewer.Replace(_T("%base"), _T("\"")+file1.GetWinPathString()+_T("\""));
393 if (viewer.Find(_T("%mine")) >= 0)
395 viewer.Replace(_T("%mine"), _T("\"")+file2.GetWinPathString()+_T("\""));
398 if (sName1.IsEmpty())
399 viewer.Replace(_T("%bname"), _T("\"") + file1.GetUIFileOrDirectoryName() + _T("\""));
400 else
401 viewer.Replace(_T("%bname"), _T("\"") + sName1 + _T("\""));
403 if (sName2.IsEmpty())
404 viewer.Replace(_T("%yname"), _T("\"") + file2.GetUIFileOrDirectoryName() + _T("\""));
405 else
406 viewer.Replace(_T("%yname"), _T("\"") + sName2 + _T("\""));
408 if ((bReadOnly)&&(bInternal))
409 viewer += _T(" /readonly");
411 if(!LaunchApplication(viewer, IDS_ERR_EXTDIFFSTART, !!bWait))
413 return FALSE;
415 return TRUE;
418 BOOL CAppUtils::StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait)
420 CString viewer;
421 CRegString v = CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
422 viewer = v;
423 if (viewer.IsEmpty() || (viewer.Left(1).Compare(_T("#"))==0))
425 // use TortoiseUDiff
426 viewer = CPathUtils::GetAppDirectory();
427 viewer += _T("TortoiseUDiff.exe");
428 // enquote the path to TortoiseUDiff
429 viewer = _T("\"") + viewer + _T("\"");
430 // add the params
431 viewer = viewer + _T(" /patchfile:%1 /title:\"%title\"");
434 if (viewer.Find(_T("%1"))>=0)
436 if (viewer.Find(_T("\"%1\"")) >= 0)
437 viewer.Replace(_T("%1"), patchfile);
438 else
439 viewer.Replace(_T("%1"), _T("\"") + patchfile + _T("\""));
441 else
442 viewer += _T(" \"") + patchfile + _T("\"");
443 if (viewer.Find(_T("%title")) >= 0)
445 viewer.Replace(_T("%title"), title);
448 if(!LaunchApplication(viewer, IDS_ERR_DIFFVIEWSTART, !!bWait))
450 return FALSE;
452 return TRUE;
455 BOOL CAppUtils::StartTextViewer(CString file)
457 CString viewer;
458 CRegString txt = CRegString(_T(".txt\\"), _T(""), FALSE, HKEY_CLASSES_ROOT);
459 viewer = txt;
460 viewer = viewer + _T("\\Shell\\Open\\Command\\");
461 CRegString txtexe = CRegString(viewer, _T(""), FALSE, HKEY_CLASSES_ROOT);
462 viewer = txtexe;
464 DWORD len = ExpandEnvironmentStrings(viewer, NULL, 0);
465 TCHAR * buf = new TCHAR[len+1];
466 ExpandEnvironmentStrings(viewer, buf, len);
467 viewer = buf;
468 delete [] buf;
469 len = ExpandEnvironmentStrings(file, NULL, 0);
470 buf = new TCHAR[len+1];
471 ExpandEnvironmentStrings(file, buf, len);
472 file = buf;
473 delete [] buf;
474 file = _T("\"")+file+_T("\"");
475 if (viewer.IsEmpty())
477 OPENFILENAME ofn = {0}; // common dialog box structure
478 TCHAR szFile[MAX_PATH] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
479 // Initialize OPENFILENAME
480 ofn.lStructSize = sizeof(OPENFILENAME);
481 ofn.hwndOwner = NULL;
482 ofn.lpstrFile = szFile;
483 ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
484 CString sFilter;
485 sFilter.LoadString(IDS_PROGRAMSFILEFILTER);
486 TCHAR * pszFilters = new TCHAR[sFilter.GetLength()+4];
487 _tcscpy_s (pszFilters, sFilter.GetLength()+4, sFilter);
488 // Replace '|' delimiters with '\0's
489 TCHAR *ptr = pszFilters + _tcslen(pszFilters); //set ptr at the NULL
490 while (ptr != pszFilters)
492 if (*ptr == '|')
493 *ptr = '\0';
494 ptr--;
496 ofn.lpstrFilter = pszFilters;
497 ofn.nFilterIndex = 1;
498 ofn.lpstrFileTitle = NULL;
499 ofn.nMaxFileTitle = 0;
500 ofn.lpstrInitialDir = NULL;
501 CString temp;
502 temp.LoadString(IDS_UTILS_SELECTTEXTVIEWER);
503 CStringUtils::RemoveAccelerators(temp);
504 ofn.lpstrTitle = temp;
505 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
507 // Display the Open dialog box.
509 if (GetOpenFileName(&ofn)==TRUE)
511 delete [] pszFilters;
512 viewer = CString(ofn.lpstrFile);
514 else
516 delete [] pszFilters;
517 return FALSE;
520 if (viewer.Find(_T("\"%1\"")) >= 0)
522 viewer.Replace(_T("\"%1\""), file);
524 else if (viewer.Find(_T("%1")) >= 0)
526 viewer.Replace(_T("%1"), file);
528 else
530 viewer += _T(" ");
531 viewer += file;
534 if(!LaunchApplication(viewer, IDS_ERR_TEXTVIEWSTART, false))
536 return FALSE;
538 return TRUE;
541 BOOL CAppUtils::CheckForEmptyDiff(const CTGitPath& sDiffPath)
543 DWORD length = 0;
544 HANDLE hFile = ::CreateFile(sDiffPath.GetWinPath(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
545 if (hFile == INVALID_HANDLE_VALUE)
546 return TRUE;
547 length = ::GetFileSize(hFile, NULL);
548 ::CloseHandle(hFile);
549 if (length < 4)
550 return TRUE;
551 return FALSE;
555 void CAppUtils::CreateFontForLogs(CFont& fontToCreate)
557 LOGFONT logFont;
558 HDC hScreenDC = ::GetDC(NULL);
559 logFont.lfHeight = -MulDiv((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC, LOGPIXELSY), 72);
560 ::ReleaseDC(NULL, hScreenDC);
561 logFont.lfWidth = 0;
562 logFont.lfEscapement = 0;
563 logFont.lfOrientation = 0;
564 logFont.lfWeight = FW_NORMAL;
565 logFont.lfItalic = 0;
566 logFont.lfUnderline = 0;
567 logFont.lfStrikeOut = 0;
568 logFont.lfCharSet = DEFAULT_CHARSET;
569 logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
570 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
571 logFont.lfQuality = DRAFT_QUALITY;
572 logFont.lfPitchAndFamily = FF_DONTCARE | FIXED_PITCH;
573 _tcscpy_s(logFont.lfFaceName, 32, (LPCTSTR)(CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
574 VERIFY(fontToCreate.CreateFontIndirect(&logFont));
577 bool CAppUtils::LaunchApplication(const CString& sCommandLine, UINT idErrMessageFormat, bool bWaitForStartup)
579 STARTUPINFO startup;
580 PROCESS_INFORMATION process;
581 memset(&startup, 0, sizeof(startup));
582 startup.cb = sizeof(startup);
583 memset(&process, 0, sizeof(process));
585 CString cleanCommandLine(sCommandLine);
587 if (CreateProcess(NULL, const_cast<TCHAR*>((LPCTSTR)cleanCommandLine), NULL, NULL, FALSE, 0, 0, sOrigCWD, &startup, &process)==0)
589 if(idErrMessageFormat != 0)
591 LPVOID lpMsgBuf;
592 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
593 FORMAT_MESSAGE_FROM_SYSTEM |
594 FORMAT_MESSAGE_IGNORE_INSERTS,
595 NULL,
596 GetLastError(),
597 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
598 (LPTSTR) &lpMsgBuf,
600 NULL
602 CString temp;
603 temp.Format(idErrMessageFormat, lpMsgBuf);
604 CMessageBox::Show(NULL, temp, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
605 LocalFree( lpMsgBuf );
607 return false;
610 if (bWaitForStartup)
612 WaitForInputIdle(process.hProcess, 10000);
615 CloseHandle(process.hThread);
616 CloseHandle(process.hProcess);
617 return true;
619 bool CAppUtils::LaunchPAgent(CString *keyfile,CString * pRemote)
621 CString key,remote;
622 CString cmd,out;
623 if( pRemote == NULL)
625 remote=_T("origin");
626 }else
628 remote=*pRemote;
630 if(keyfile == NULL)
632 cmd.Format(_T("git.exe config remote.%s.puttykeyfile"),remote);
633 g_Git.Run(cmd,&key,CP_ACP);
634 int start=0;
635 key = key.Tokenize(_T("\n"),start);
637 else
638 key=*keyfile;
640 if(key.IsEmpty())
641 return false;
643 CString proc=CPathUtils::GetAppDirectory();
644 proc += _T("pageant.exe \"");
645 proc += key;
646 proc += _T("\"");
648 return LaunchApplication(proc, IDS_ERR_PAGEANT, false);
650 bool CAppUtils::LaunchRemoteSetting()
652 CString proc=CPathUtils::GetAppDirectory();
653 proc += _T("TortoiseProc.exe /command:settings");
654 proc += _T(" /path:\"");
655 proc += g_Git.m_CurrentDir;
656 proc += _T("\" /page:remote");
657 return LaunchApplication(proc, IDS_ERR_EXTDIFFSTART, false);
660 * Launch the external blame viewer
662 bool CAppUtils::LaunchTortoiseBlame(const CString& sBlameFile,CString Rev,const CString& sParams)
664 CString viewer = CPathUtils::GetAppDirectory();
665 viewer += _T("TortoiseGitBlame.exe");
666 viewer += _T(" \"") + sBlameFile + _T("\"");
667 //viewer += _T(" \"") + sLogFile + _T("\"");
668 //viewer += _T(" \"") + sOriginalFile + _T("\"");
669 if(!Rev.IsEmpty())
670 viewer += CString(_T(" /rev:"))+Rev;
671 viewer += _T(" ")+sParams;
673 return LaunchApplication(viewer, IDS_ERR_EXTDIFFSTART, false);
676 bool CAppUtils::FormatTextInRichEditControl(CWnd * pWnd)
678 CString sText;
679 if (pWnd == NULL)
680 return false;
681 bool bStyled = false;
682 pWnd->GetWindowText(sText);
683 // the rich edit control doesn't count the CR char!
684 // to be exact: CRLF is treated as one char.
685 sText.Replace(_T("\r"), _T(""));
687 // style each line separately
688 int offset = 0;
689 int nNewlinePos;
692 nNewlinePos = sText.Find('\n', offset);
693 CString sLine = sText.Mid(offset);
694 if (nNewlinePos>=0)
695 sLine = sLine.Left(nNewlinePos-offset);
696 int start = 0;
697 int end = 0;
698 while (FindStyleChars(sLine, '*', start, end))
700 CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
701 pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
702 CHARFORMAT2 format;
703 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
704 format.cbSize = sizeof(CHARFORMAT2);
705 format.dwMask = CFM_BOLD;
706 format.dwEffects = CFE_BOLD;
707 pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
708 bStyled = true;
709 start = end;
711 start = 0;
712 end = 0;
713 while (FindStyleChars(sLine, '^', start, end))
715 CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
716 pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
717 CHARFORMAT2 format;
718 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
719 format.cbSize = sizeof(CHARFORMAT2);
720 format.dwMask = CFM_ITALIC;
721 format.dwEffects = CFE_ITALIC;
722 pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
723 bStyled = true;
724 start = end;
726 start = 0;
727 end = 0;
728 while (FindStyleChars(sLine, '_', start, end))
730 CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
731 pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
732 CHARFORMAT2 format;
733 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
734 format.cbSize = sizeof(CHARFORMAT2);
735 format.dwMask = CFM_UNDERLINE;
736 format.dwEffects = CFE_UNDERLINE;
737 pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
738 bStyled = true;
739 start = end;
741 offset = nNewlinePos+1;
742 } while(nNewlinePos>=0);
743 return bStyled;
746 bool CAppUtils::FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end)
748 int i=start;
749 bool bFoundMarker = false;
750 // find a starting marker
751 while (sText[i] != 0)
753 if (sText[i] == stylechar)
755 if (((i+1)<sText.GetLength())&&(IsCharAlphaNumeric(sText[i+1])) &&
756 (((i>0)&&(!IsCharAlphaNumeric(sText[i-1])))||(i==0)))
758 start = i+1;
759 i++;
760 bFoundMarker = true;
761 break;
764 i++;
766 if (!bFoundMarker)
767 return false;
768 // find ending marker
769 bFoundMarker = false;
770 while (sText[i] != 0)
772 if (sText[i] == stylechar)
774 if ((IsCharAlphaNumeric(sText[i-1])) &&
775 ((((i+1)<sText.GetLength())&&(!IsCharAlphaNumeric(sText[i+1])))||(i+1)==sText.GetLength()))
777 end = i;
778 i++;
779 bFoundMarker = true;
780 break;
783 i++;
785 return bFoundMarker;
788 bool CAppUtils::BrowseRepository(CHistoryCombo& combo, CWnd * pParent, GitRev& rev)
790 #if 0
791 CString strUrl;
792 combo.GetWindowText(strUrl);
793 strUrl.Replace('\\', '/');
794 strUrl.Replace(_T("%"), _T("%25"));
795 strUrl = CUnicodeUtils::GetUnicode(CPathUtils::PathEscape(CUnicodeUtils::GetUTF8(strUrl)));
796 if (strUrl.Left(7) == _T("file://"))
798 CString strFile(strUrl);
799 Git::UrlToPath(strFile);
801 Git svn;
802 if (svn.IsRepository(CTGitPath(strFile)))
804 // browse repository - show repository browser
805 Git::preparePath(strUrl);
806 CRepositoryBrowser browser(strUrl, rev, pParent);
807 if (browser.DoModal() == IDOK)
809 combo.SetCurSel(-1);
810 combo.SetWindowText(browser.GetPath());
811 rev = browser.GetRevision();
812 return true;
815 else
817 // browse local directories
818 CBrowseFolder folderBrowser;
819 folderBrowser.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
820 // remove the 'file:///' so the shell can recognize the local path
821 Git::UrlToPath(strUrl);
822 if (folderBrowser.Show(pParent->GetSafeHwnd(), strUrl) == CBrowseFolder::OK)
824 Git::PathToUrl(strUrl);
826 combo.SetCurSel(-1);
827 combo.SetWindowText(strUrl);
828 return true;
832 else if ((strUrl.Left(7) == _T("http://")
833 ||(strUrl.Left(8) == _T("https://"))
834 ||(strUrl.Left(6) == _T("svn://"))
835 ||(strUrl.Left(4) == _T("svn+"))) && strUrl.GetLength() > 6)
837 // browse repository - show repository browser
838 CRepositoryBrowser browser(strUrl, rev, pParent);
839 if (browser.DoModal() == IDOK)
841 combo.SetCurSel(-1);
842 combo.SetWindowText(browser.GetPath());
843 rev = browser.GetRevision();
844 return true;
847 else
849 // browse local directories
850 CBrowseFolder folderBrowser;
851 folderBrowser.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
852 if (folderBrowser.Show(pParent->GetSafeHwnd(), strUrl) == CBrowseFolder::OK)
854 Git::PathToUrl(strUrl);
856 combo.SetCurSel(-1);
857 combo.SetWindowText(strUrl);
858 return true;
861 #endif
862 return false;
865 bool CAppUtils::FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner)
867 OPENFILENAME ofn = {0}; // common dialog box structure
868 TCHAR szFile[MAX_PATH] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
869 ofn.lStructSize = sizeof(OPENFILENAME);
870 ofn.hwndOwner = hwndOwner;
871 _tcscpy_s(szFile, MAX_PATH, (LPCTSTR)path);
872 ofn.lpstrFile = szFile;
873 ofn.nMaxFile = sizeof(szFile)/sizeof(TCHAR);
874 CString sFilter;
875 TCHAR * pszFilters = NULL;
876 if (filter)
878 sFilter.LoadString(filter);
879 pszFilters = new TCHAR[sFilter.GetLength()+4];
880 _tcscpy_s (pszFilters, sFilter.GetLength()+4, sFilter);
881 // Replace '|' delimiters with '\0's
882 TCHAR *ptr = pszFilters + _tcslen(pszFilters); //set ptr at the NULL
883 while (ptr != pszFilters)
885 if (*ptr == '|')
886 *ptr = '\0';
887 ptr--;
889 ofn.lpstrFilter = pszFilters;
891 ofn.nFilterIndex = 1;
892 ofn.lpstrFileTitle = NULL;
893 ofn.nMaxFileTitle = 0;
894 ofn.lpstrInitialDir = NULL;
895 CString temp;
896 if (title)
898 temp.LoadString(title);
899 CStringUtils::RemoveAccelerators(temp);
901 ofn.lpstrTitle = temp;
902 if (bOpen)
903 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
904 else
905 ofn.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER;
908 // Display the Open dialog box.
909 bool bRet = false;
910 if (bOpen)
912 bRet = !!GetOpenFileName(&ofn);
914 else
916 bRet = !!GetSaveFileName(&ofn);
918 if (bRet)
920 if (pszFilters)
921 delete [] pszFilters;
922 path = CString(ofn.lpstrFile);
923 if (filterindex)
924 *filterindex = ofn.nFilterIndex;
925 return true;
927 if (pszFilters)
928 delete [] pszFilters;
929 return false;
932 bool CAppUtils::SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width /* = 128 */, int height /* = 128 */)
934 ListView_SetTextBkColor(hListCtrl, CLR_NONE);
935 COLORREF bkColor = ListView_GetBkColor(hListCtrl);
936 // create a bitmap from the icon
937 HICON hIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(nID), IMAGE_ICON, width, height, LR_DEFAULTCOLOR);
938 if (!hIcon)
939 return false;
941 RECT rect = {0};
942 rect.right = width;
943 rect.bottom = height;
944 HBITMAP bmp = NULL;
946 HWND desktop = ::GetDesktopWindow();
947 if (desktop)
949 HDC screen_dev = ::GetDC(desktop);
950 if (screen_dev)
952 // Create a compatible DC
953 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
954 if (dst_hdc)
956 // Create a new bitmap of icon size
957 bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
958 if (bmp)
960 // Select it into the compatible DC
961 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
962 // Fill the background of the compatible DC with the given color
963 ::SetBkColor(dst_hdc, bkColor);
964 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
966 // Draw the icon into the compatible DC
967 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
968 ::SelectObject(dst_hdc, old_dst_bmp);
970 ::DeleteDC(dst_hdc);
973 ::ReleaseDC(desktop, screen_dev);
976 // Restore settings
977 DestroyIcon(hIcon);
979 if (bmp == NULL)
980 return false;
982 LVBKIMAGE lv;
983 lv.ulFlags = LVBKIF_TYPE_WATERMARK;
984 lv.hbm = bmp;
985 lv.xOffsetPercent = 100;
986 lv.yOffsetPercent = 100;
987 ListView_SetBkImage(hListCtrl, &lv);
988 return true;
991 CString CAppUtils::GetProjectNameFromURL(CString url)
993 CString name;
994 while (name.IsEmpty() || (name.CompareNoCase(_T("branches"))==0) ||
995 (name.CompareNoCase(_T("tags"))==0) ||
996 (name.CompareNoCase(_T("trunk"))==0))
998 name = url.Mid(url.ReverseFind('/')+1);
999 url = url.Left(url.ReverseFind('/'));
1001 if ((name.Compare(_T("svn")) == 0)||(name.Compare(_T("svnroot")) == 0))
1003 // a name of svn or svnroot indicates that it's not really the project name. In that
1004 // case, we try the first part of the URL
1005 // of course, this won't work in all cases (but it works for Google project hosting)
1006 url.Replace(_T("http://"), _T(""));
1007 url.Replace(_T("https://"), _T(""));
1008 url.Replace(_T("svn://"), _T(""));
1009 url.Replace(_T("svn+ssh://"), _T(""));
1010 url.TrimLeft(_T("/"));
1011 name = url.Left(url.Find('.'));
1013 return name;
1016 bool CAppUtils::StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
1017 const CTGitPath& url2, const git_revnum_t& rev2,
1018 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
1019 bool bAlternateDiff /* = false */, bool bIgnoreAncestry /* = false */, bool /* blame = false */)
1022 CString tempfile=GetTempFile();
1023 CString cmd;
1024 if(rev1 == GitRev::GetWorkingCopy())
1026 cmd.Format(_T("git.exe diff --stat -p %s"),rev2);
1027 }else
1029 cmd.Format(_T("git.exe diff-tree -r -p --stat %s %s"),rev1,rev2);
1031 g_Git.RunLogFile(cmd,tempfile);
1032 CAppUtils::StartUnifiedDiffViewer(tempfile,rev1.Left(6)+_T(":")+rev2.Left(6));
1035 #if 0
1036 CString sCmd;
1037 sCmd.Format(_T("%s /command:showcompare /unified"),
1038 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1039 sCmd += _T(" /url1:\"") + url1.GetGitPathString() + _T("\"");
1040 if (rev1.IsValid())
1041 sCmd += _T(" /revision1:") + rev1.ToString();
1042 sCmd += _T(" /url2:\"") + url2.GetGitPathString() + _T("\"");
1043 if (rev2.IsValid())
1044 sCmd += _T(" /revision2:") + rev2.ToString();
1045 if (peg.IsValid())
1046 sCmd += _T(" /pegrevision:") + peg.ToString();
1047 if (headpeg.IsValid())
1048 sCmd += _T(" /headpegrevision:") + headpeg.ToString();
1050 if (bAlternateDiff)
1051 sCmd += _T(" /alternatediff");
1053 if (bIgnoreAncestry)
1054 sCmd += _T(" /ignoreancestry");
1056 if (hWnd)
1058 sCmd += _T(" /hwnd:");
1059 TCHAR buf[30];
1060 _stprintf_s(buf, 30, _T("%d"), hWnd);
1061 sCmd += buf;
1064 return CAppUtils::LaunchApplication(sCmd, NULL, false);
1065 #endif
1066 return TRUE;
1069 bool CAppUtils::StartShowCompare(HWND hWnd, const CTGitPath& url1, const GitRev& rev1,
1070 const CTGitPath& url2, const GitRev& rev2,
1071 const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
1072 bool bAlternateDiff /* = false */, bool bIgnoreAncestry /* = false */, bool blame /* = false */)
1074 #if 0
1075 CString sCmd;
1076 sCmd.Format(_T("%s /command:showcompare"),
1077 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1078 sCmd += _T(" /url1:\"") + url1.GetGitPathString() + _T("\"");
1079 if (rev1.IsValid())
1080 sCmd += _T(" /revision1:") + rev1.ToString();
1081 sCmd += _T(" /url2:\"") + url2.GetGitPathString() + _T("\"");
1082 if (rev2.IsValid())
1083 sCmd += _T(" /revision2:") + rev2.ToString();
1084 if (peg.IsValid())
1085 sCmd += _T(" /pegrevision:") + peg.ToString();
1086 if (headpeg.IsValid())
1087 sCmd += _T(" /headpegrevision:") + headpeg.ToString();
1088 if (bAlternateDiff)
1089 sCmd += _T(" /alternatediff");
1090 if (bIgnoreAncestry)
1091 sCmd += _T(" /ignoreancestry");
1092 if (blame)
1093 sCmd += _T(" /blame");
1095 if (hWnd)
1097 sCmd += _T(" /hwnd:");
1098 TCHAR buf[30];
1099 _stprintf_s(buf, 30, _T("%d"), hWnd);
1100 sCmd += buf;
1103 return CAppUtils::LaunchApplication(sCmd, NULL, false);
1104 #endif
1105 return true;
1108 bool CAppUtils::Export(CString *BashHash)
1110 bool bRet = false;
1112 // ask from where the export has to be done
1113 CExportDlg dlg;
1114 if(BashHash)
1115 dlg.m_Revision=*BashHash;
1117 if (dlg.DoModal() == IDOK)
1119 CString cmd;
1120 cmd.Format(_T("git.exe archive --format=zip --verbose %s"),
1121 dlg.m_VersionName);
1123 //g_Git.RunLogFile(cmd,dlg.m_strExportDirectory);
1124 CProgressDlg pro;
1125 pro.m_GitCmd=cmd;
1126 pro.m_LogFile=dlg.m_strExportDirectory;
1127 pro.DoModal();
1128 return TRUE;
1130 return bRet;
1133 bool CAppUtils::CreateBranchTag(bool IsTag,CString *CommitHash)
1135 CCreateBranchTagDlg dlg;
1136 dlg.m_bIsTag=IsTag;
1137 if(CommitHash)
1138 dlg.m_Base = *CommitHash;
1140 if(dlg.DoModal()==IDOK)
1142 CString cmd;
1143 CString force;
1144 CString track;
1145 if(dlg.m_bTrack)
1146 track=_T(" --track ");
1148 if(dlg.m_bForce)
1149 force=_T(" -f ");
1151 if(IsTag)
1153 cmd.Format(_T("git.exe tag %s %s %s %s"),
1154 track,
1155 force,
1156 dlg.m_BranchTagName,
1157 dlg.m_VersionName
1161 }else
1163 cmd.Format(_T("git.exe branch %s %s %s %s"),
1164 track,
1165 force,
1166 dlg.m_BranchTagName,
1167 dlg.m_VersionName
1170 CString out;
1171 if(g_Git.Run(cmd,&out,CP_UTF8))
1173 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1175 if( !IsTag && dlg.m_bSwitch )
1177 // it is a new branch and the user has requested to switch to it
1178 cmd.Format(_T("git.exe checkout %s"), dlg.m_BranchTagName);
1179 g_Git.Run(cmd,&out,CP_UTF8);
1180 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1183 return TRUE;
1186 return FALSE;
1189 bool CAppUtils::Switch(CString *CommitHash)
1191 CGitSwitchDlg dlg;
1192 if(CommitHash)
1193 dlg.m_Base=*CommitHash;
1195 if (dlg.DoModal() == IDOK)
1197 CString cmd;
1198 CString track;
1199 CString base;
1200 CString force;
1201 CString branch;
1203 if(dlg.m_bBranch)
1204 branch.Format(_T("-b %s"),dlg.m_NewBranch);
1205 if(dlg.m_bForce)
1206 force=_T("-f");
1207 if(dlg.m_bTrack)
1208 track=_T("--track");
1210 cmd.Format(_T("git.exe checkout %s %s %s %s"),
1211 force,
1212 track,
1213 branch,
1214 dlg.m_VersionName);
1216 CProgressDlg progress;
1217 progress.m_GitCmd=cmd;
1218 if(progress.DoModal()==IDOK)
1219 return TRUE;
1222 return FALSE;
1225 bool CAppUtils::IgnoreFile(CTGitPathList &path,bool IsMask)
1227 CString ignorefile;
1228 ignorefile=g_Git.m_CurrentDir+_T("\\");
1230 if(IsMask)
1232 ignorefile+=path.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1234 }else
1236 ignorefile+=_T("\\.gitignore");
1239 CStdioFile file;
1240 if(!file.Open(ignorefile,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate))
1242 CMessageBox::Show(NULL,ignorefile+_T(" Open Failure"),_T("TortoiseGit"),MB_OK);
1243 return FALSE;
1246 CString ignorelist;
1247 CString mask;
1250 //file.ReadString(ignorelist);
1251 file.SeekToEnd();
1252 for(int i=0;i<path.GetCount();i++)
1254 if(IsMask)
1256 mask=_T("*")+path[i].GetFileExtension();
1257 if(ignorelist.Find(mask)<0)
1258 ignorelist+=_T("\n")+mask;
1260 }else
1262 ignorelist+=_T("\n/")+path[i].GetGitPathString();
1265 file.WriteString(ignorelist);
1267 file.Close();
1269 }catch(...)
1271 file.Close();
1272 return FALSE;
1275 return TRUE;
1279 bool CAppUtils::GitReset(CString *CommitHash,int type)
1281 CResetDlg dlg;
1282 dlg.m_ResetType=type;
1283 if (dlg.DoModal() == IDOK)
1285 CString cmd;
1286 CString type;
1287 switch(dlg.m_ResetType)
1289 case 0:
1290 type=_T("--soft");
1291 break;
1292 case 1:
1293 type=_T("--mixed");
1294 break;
1295 case 2:
1296 type=_T("--hard");
1297 break;
1298 default:
1299 type=_T("--mixed");
1300 break;
1302 cmd.Format(_T("git.exe reset %s %s"),type, *CommitHash);
1304 CProgressDlg progress;
1305 progress.m_GitCmd=cmd;
1306 if(progress.DoModal()==IDOK)
1307 return TRUE;
1310 return FALSE;
1313 void CAppUtils::DescribeFile(bool mode, bool base,CString &descript)
1315 if(mode == FALSE)
1317 descript=_T("Deleted");
1318 return;
1320 if(base)
1322 descript=_T("Modified");
1323 return;
1325 descript=_T("Created");
1326 return;
1329 CString CAppUtils::GetMergeTempFile(CString type,CTGitPath &merge)
1331 CString file;
1332 file=g_Git.m_CurrentDir+_T("\\")+merge.GetDirectory().GetWinPathString()+_T("\\")+merge.GetFilename()+_T(".")+type+merge.GetFileExtension();
1334 return file;
1337 bool CAppUtils::ConflictEdit(CTGitPath &path,bool bAlternativeTool)
1339 bool bRet = false;
1341 CTGitPath merge=path;
1342 CTGitPath directory = merge.GetDirectory();
1346 // we have the conflicted file (%merged)
1347 // now look for the other required files
1348 //GitStatus stat;
1349 //stat.GetStatus(merge);
1350 //if (stat.status == NULL)
1351 // return false;
1353 BYTE_VECTOR vector;
1355 CString cmd;
1356 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge.GetGitPathString());
1358 if(g_Git.Run(cmd,&vector))
1360 return FALSE;
1363 CTGitPathList list;
1364 list.ParserFromLsFile(vector);
1366 if(list.GetCount() == 0)
1367 return FALSE;
1369 TCHAR szTempName[512];
1370 GetTempFileName(_T(""),_T(""),0,szTempName);
1371 CString temp(szTempName);
1372 temp=temp.Mid(1,temp.GetLength()-5);
1374 CTGitPath theirs;
1375 CTGitPath mine;
1376 CTGitPath base;
1379 mine.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge));
1380 theirs.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge));
1381 base.SetFromGit(GetMergeTempFile(_T("BASE"),merge));
1383 CString format;
1385 format=_T("git.exe cat-file blob \":%d:%s\"");
1386 CFile tempfile;
1387 //create a empty file, incase stage is not three
1388 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1389 tempfile.Close();
1390 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1391 tempfile.Close();
1392 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1393 tempfile.Close();
1395 bool b_base=false, b_local=false, b_remote=false;
1397 for(int i=0;i<list.GetCount();i++)
1399 CString cmd;
1400 CString outfile;
1401 cmd.Format(format,list[i].m_Stage,list[i].GetGitPathString());
1403 if( list[i].m_Stage == 1)
1405 b_base = true;
1406 outfile=base.GetWinPathString();
1408 if( list[i].m_Stage == 2 )
1410 b_local = true;
1411 outfile=mine.GetWinPathString();
1413 if( list[i].m_Stage == 3 )
1415 b_remote = true;
1416 outfile=theirs.GetWinPathString();
1418 g_Git.RunLogFile(cmd,outfile);
1421 if(b_local && b_remote )
1423 merge.SetFromWin(g_Git.m_CurrentDir+_T("\\")+merge.GetWinPathString());
1424 bRet = !!CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1426 }else
1428 CFile::Remove(mine.GetWinPathString());
1429 CFile::Remove(theirs.GetWinPathString());
1430 CFile::Remove(base.GetWinPathString());
1432 CDeleteConflictDlg dlg;
1433 DescribeFile(b_local, b_base,dlg.m_LocalStatus);
1434 DescribeFile(b_remote,b_base,dlg.m_RemoteStatus);
1435 dlg.m_bShowModifiedButton=b_base;
1436 dlg.m_File=merge.GetGitPathString();
1437 if(dlg.DoModal() == IDOK)
1439 CString cmd,out;
1440 if(dlg.m_bIsDelete)
1442 cmd.Format(_T("git.exe rm \"%s\""),merge.GetGitPathString());
1443 }else
1444 cmd.Format(_T("git.exe add \"%s\""),merge.GetGitPathString());
1446 if(g_Git.Run(cmd,&out,CP_ACP))
1448 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1449 return FALSE;
1451 return TRUE;
1453 else
1454 return FALSE;
1460 #if 0
1462 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1463 base, theirs, mine, merge);
1464 #endif
1465 #if 0
1466 if (stat.status->text_status == svn_wc_status_conflicted)
1468 // we have a text conflict, use our merge tool to resolve the conflict
1470 CTSVNPath theirs(directory);
1471 CTSVNPath mine(directory);
1472 CTSVNPath base(directory);
1473 bool bConflictData = false;
1475 if ((stat.status->entry)&&(stat.status->entry->conflict_new))
1477 theirs.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_new));
1478 bConflictData = true;
1480 if ((stat.status->entry)&&(stat.status->entry->conflict_old))
1482 base.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_old));
1483 bConflictData = true;
1485 if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
1487 mine.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_wrk));
1488 bConflictData = true;
1490 else
1492 mine = merge;
1494 if (bConflictData)
1495 bRet = !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1496 base, theirs, mine, merge);
1499 if (stat.status->prop_status == svn_wc_status_conflicted)
1501 // we have a property conflict
1502 CTSVNPath prej(directory);
1503 if ((stat.status->entry)&&(stat.status->entry->prejfile))
1505 prej.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->prejfile));
1506 // there's a problem: the prej file contains a _description_ of the conflict, and
1507 // that description string might be translated. That means we have no way of parsing
1508 // the file to find out the conflicting values.
1509 // The only thing we can do: show a dialog with the conflict description, then
1510 // let the user either accept the existing property or open the property edit dialog
1511 // to manually change the properties and values. And a button to mark the conflict as
1512 // resolved.
1513 CEditPropConflictDlg dlg;
1514 dlg.SetPrejFile(prej);
1515 dlg.SetConflictedItem(merge);
1516 bRet = (dlg.DoModal() != IDCANCEL);
1520 if (stat.status->tree_conflict)
1522 // we have a tree conflict
1523 SVNInfo info;
1524 const SVNInfoData * pInfoData = info.GetFirstFileInfo(merge, SVNRev(), SVNRev());
1525 if (pInfoData)
1527 if (pInfoData->treeconflict_kind == svn_wc_conflict_kind_text)
1529 CTSVNPath theirs(directory);
1530 CTSVNPath mine(directory);
1531 CTSVNPath base(directory);
1532 bool bConflictData = false;
1534 if (pInfoData->treeconflict_theirfile)
1536 theirs.AppendPathString(pInfoData->treeconflict_theirfile);
1537 bConflictData = true;
1539 if (pInfoData->treeconflict_basefile)
1541 base.AppendPathString(pInfoData->treeconflict_basefile);
1542 bConflictData = true;
1544 if (pInfoData->treeconflict_myfile)
1546 mine.AppendPathString(pInfoData->treeconflict_myfile);
1547 bConflictData = true;
1549 else
1551 mine = merge;
1553 if (bConflictData)
1554 bRet = !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1555 base, theirs, mine, merge);
1557 else if (pInfoData->treeconflict_kind == svn_wc_conflict_kind_tree)
1559 CString sConflictAction;
1560 CString sConflictReason;
1561 CString sResolveTheirs;
1562 CString sResolveMine;
1563 CTSVNPath treeConflictPath = CTSVNPath(pInfoData->treeconflict_path);
1564 CString sItemName = treeConflictPath.GetUIFileOrDirectoryName();
1566 if (pInfoData->treeconflict_nodekind == svn_node_file)
1568 switch (pInfoData->treeconflict_operation)
1570 case svn_wc_operation_update:
1571 switch (pInfoData->treeconflict_action)
1573 case svn_wc_conflict_action_edit:
1574 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEEDIT, (LPCTSTR)sItemName);
1575 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1576 break;
1577 case svn_wc_conflict_action_add:
1578 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEADD, (LPCTSTR)sItemName);
1579 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1580 break;
1581 case svn_wc_conflict_action_delete:
1582 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEDELETE, (LPCTSTR)sItemName);
1583 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1584 break;
1586 break;
1587 case svn_wc_operation_switch:
1588 switch (pInfoData->treeconflict_action)
1590 case svn_wc_conflict_action_edit:
1591 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHEDIT, (LPCTSTR)sItemName);
1592 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1593 break;
1594 case svn_wc_conflict_action_add:
1595 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHADD, (LPCTSTR)sItemName);
1596 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1597 break;
1598 case svn_wc_conflict_action_delete:
1599 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHDELETE, (LPCTSTR)sItemName);
1600 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1601 break;
1603 break;
1604 case svn_wc_operation_merge:
1605 switch (pInfoData->treeconflict_action)
1607 case svn_wc_conflict_action_edit:
1608 sConflictAction.Format(IDS_TREECONFLICT_FILEMERGEEDIT, (LPCTSTR)sItemName);
1609 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1610 break;
1611 case svn_wc_conflict_action_add:
1612 sResolveTheirs.Format(IDS_TREECONFLICT_FILEMERGEADD, (LPCTSTR)sItemName);
1613 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1614 break;
1615 case svn_wc_conflict_action_delete:
1616 sConflictAction.Format(IDS_TREECONFLICT_FILEMERGEDELETE, (LPCTSTR)sItemName);
1617 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1618 break;
1620 break;
1623 else if (pInfoData->treeconflict_nodekind == svn_node_dir)
1625 switch (pInfoData->treeconflict_operation)
1627 case svn_wc_operation_update:
1628 switch (pInfoData->treeconflict_action)
1630 case svn_wc_conflict_action_edit:
1631 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEEDIT, (LPCTSTR)sItemName);
1632 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1633 break;
1634 case svn_wc_conflict_action_add:
1635 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEADD, (LPCTSTR)sItemName);
1636 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1637 break;
1638 case svn_wc_conflict_action_delete:
1639 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEDELETE, (LPCTSTR)sItemName);
1640 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1641 break;
1643 break;
1644 case svn_wc_operation_switch:
1645 switch (pInfoData->treeconflict_action)
1647 case svn_wc_conflict_action_edit:
1648 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHEDIT, (LPCTSTR)sItemName);
1649 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1650 break;
1651 case svn_wc_conflict_action_add:
1652 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHADD, (LPCTSTR)sItemName);
1653 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1654 break;
1655 case svn_wc_conflict_action_delete:
1656 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHDELETE, (LPCTSTR)sItemName);
1657 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1658 break;
1660 break;
1661 case svn_wc_operation_merge:
1662 switch (pInfoData->treeconflict_action)
1664 case svn_wc_conflict_action_edit:
1665 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEEDIT, (LPCTSTR)sItemName);
1666 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1667 break;
1668 case svn_wc_conflict_action_add:
1669 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEADD, (LPCTSTR)sItemName);
1670 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1671 break;
1672 case svn_wc_conflict_action_delete:
1673 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEDELETE, (LPCTSTR)sItemName);
1674 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1675 break;
1677 break;
1681 UINT uReasonID = 0;
1682 switch (pInfoData->treeconflict_reason)
1684 case svn_wc_conflict_reason_edited:
1685 uReasonID = IDS_TREECONFLICT_REASON_EDITED;
1686 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1687 break;
1688 case svn_wc_conflict_reason_obstructed:
1689 uReasonID = IDS_TREECONFLICT_REASON_OBSTRUCTED;
1690 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1691 break;
1692 case svn_wc_conflict_reason_deleted:
1693 uReasonID = IDS_TREECONFLICT_REASON_DELETED;
1694 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_REMOVEDIR : IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1695 break;
1696 case svn_wc_conflict_reason_added:
1697 uReasonID = IDS_TREECONFLICT_REASON_ADDED;
1698 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1699 break;
1700 case svn_wc_conflict_reason_missing:
1701 uReasonID = IDS_TREECONFLICT_REASON_MISSING;
1702 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_REMOVEDIR : IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1703 break;
1704 case svn_wc_conflict_reason_unversioned:
1705 uReasonID = IDS_TREECONFLICT_REASON_UNVERSIONED;
1706 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1707 break;
1709 sConflictReason.Format(uReasonID, (LPCTSTR)sConflictAction);
1711 CTreeConflictEditorDlg dlg;
1712 dlg.SetConflictInfoText(sConflictReason);
1713 dlg.SetResolveTexts(sResolveTheirs, sResolveMine);
1714 dlg.SetPath(treeConflictPath);
1715 INT_PTR dlgRet = dlg.DoModal();
1716 bRet = (dlgRet != IDCANCEL);
1720 #endif
1721 return bRet;
1725 * FUNCTION : FormatDateAndTime
1726 * DESCRIPTION : Generates a displayable string from a CTime object in
1727 * system short or long format or as a relative value
1728 * cTime - the time
1729 * option - DATE_SHORTDATE or DATE_LONGDATE
1730 * bIncluedeTime - whether to show time as well as date
1731 * bRelative - if true then relative time is shown if reasonable
1732 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
1733 * rather than locale
1734 * RETURN : CString containing date/time
1736 CString CAppUtils::FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime /*=true*/,
1737 bool bRelative /*=false*/)
1739 CString datetime;
1740 if ( bRelative )
1742 datetime = ToRelativeTimeString( cTime );
1744 else
1746 // should we use the locale settings for formatting the date/time?
1747 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE))
1749 // yes
1750 SYSTEMTIME sysTime;
1751 cTime.GetAsSystemTime( sysTime );
1753 TCHAR buf[100];
1755 GetDateFormat(LOCALE_USER_DEFAULT, option, &sysTime, NULL, buf,
1756 sizeof(buf)/sizeof(TCHAR)-1);
1757 datetime = buf;
1758 if ( bIncludeTime )
1760 datetime += _T(" ");
1761 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, NULL, buf, sizeof(buf)/sizeof(TCHAR)-1);
1762 datetime += buf;
1765 else
1767 // no, so fixed format
1768 if ( bIncludeTime )
1770 datetime = cTime.Format(_T("%Y-%m-%d %H:%M:%S"));
1772 else
1774 datetime = cTime.Format(_T("%Y-%m-%d"));
1778 return datetime;
1782 * Converts a given time to a relative display string (relative to current time)
1783 * Given time must be in local timezone
1785 CString CAppUtils::ToRelativeTimeString(CTime time)
1787 CString answer;
1788 // convert to COleDateTime
1789 SYSTEMTIME sysTime;
1790 time.GetAsSystemTime( sysTime );
1791 COleDateTime oleTime( sysTime );
1792 answer = ToRelativeTimeString(oleTime, COleDateTime::GetCurrentTime());
1793 return answer;
1797 * Generates a display string showing the relative time between the two given times as COleDateTimes
1799 CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo)
1801 CString answer;
1802 COleDateTimeSpan ts = RelativeTo - time;
1803 //years
1804 if(fabs(ts.GetTotalDays()) >= 3*365)
1806 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/365, IDS_YEAR_AGO, IDS_YEARS_AGO );
1808 //Months
1809 if(fabs(ts.GetTotalDays()) >= 60)
1811 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/30, IDS_MONTH_AGO, IDS_MONTHS_AGO );
1812 return answer;
1814 //Weeks
1815 if(fabs(ts.GetTotalDays()) >= 14)
1817 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/7, IDS_WEEK_AGO, IDS_WEEKS_AGO );
1818 return answer;
1820 //Days
1821 if(fabs(ts.GetTotalDays()) >= 2)
1823 answer = ExpandRelativeTime( (int)ts.GetTotalDays(), IDS_DAY_AGO, IDS_DAYS_AGO );
1824 return answer;
1826 //hours
1827 if(fabs(ts.GetTotalHours()) >= 2)
1829 answer = ExpandRelativeTime( (int)ts.GetTotalHours(), IDS_HOUR_AGO, IDS_HOURS_AGO );
1830 return answer;
1832 //minutes
1833 if(fabs(ts.GetTotalMinutes()) >= 2)
1835 answer = ExpandRelativeTime( (int)ts.GetTotalMinutes(), IDS_MINUTE_AGO, IDS_MINUTES_AGO );
1836 return answer;
1838 //seconds
1839 answer = ExpandRelativeTime( (int)ts.GetTotalSeconds(), IDS_SECOND_AGO, IDS_SECONDS_AGO );
1840 return answer;
1843 /**
1844 * Passed a value and two resource string ids
1845 * if count is 1 then FormatString is called with format_1 and the value
1846 * otherwise format_2 is used
1847 * the formatted string is returned
1849 CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n )
1851 CString answer;
1852 if ( count == 1 )
1854 answer.FormatMessage( format_1, count );
1856 else
1858 answer.FormatMessage( format_n, count );
1860 return answer;
1863 bool CAppUtils::IsSSHPutty()
1865 CString sshclient=CRegString(_T("Software\\TortoiseGit\\SSH"));
1866 sshclient=sshclient.MakeLower();
1867 if(sshclient.Find(_T("plink.exe"),0)>=0)
1869 return true;
1871 return false;
1874 CString CAppUtils::GetClipboardLink()
1876 if (!OpenClipboard(NULL))
1877 return CString();
1879 CString sClipboardText;
1880 HGLOBAL hglb = GetClipboardData(CF_TEXT);
1881 if (hglb)
1883 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
1884 sClipboardText = CString(lpstr);
1885 GlobalUnlock(hglb);
1887 hglb = GetClipboardData(CF_UNICODETEXT);
1888 if (hglb)
1890 LPCTSTR lpstr = (LPCTSTR)GlobalLock(hglb);
1891 sClipboardText = lpstr;
1892 GlobalUnlock(hglb);
1894 CloseClipboard();
1896 if(!sClipboardText.IsEmpty())
1898 if(sClipboardText[0] == _T('\"') && sClipboardText[sClipboardText.GetLength()-1] == _T('\"'))
1899 sClipboardText=sClipboardText.Mid(1,sClipboardText.GetLength()-2);
1901 if(sClipboardText.Find( _T("http://")) == 0)
1902 return sClipboardText;
1904 if(sClipboardText.Find( _T("https://")) == 0)
1905 return sClipboardText;
1907 if(sClipboardText.Find( _T("git://")) == 0)
1908 return sClipboardText;
1910 if(sClipboardText.Find( _T("ssh://")) == 0)
1911 return sClipboardText;
1913 if(sClipboardText.GetLength()>=2)
1914 if( sClipboardText[1] == _T(':') )
1915 if( (sClipboardText[0] >= 'A' && sClipboardText[0] <= 'Z')
1916 || (sClipboardText[0] >= 'a' && sClipboardText[0] <= 'z') )
1917 return sClipboardText;
1920 return CString(_T(""));
1923 CString CAppUtils::ChooseRepository(CString *path)
1925 CBrowseFolder browseFolder;
1926 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
1927 CString strCloneDirectory;
1928 if(path)
1929 strCloneDirectory=*path;
1931 CString title;
1932 title.LoadString(IDS_CHOOSE_REPOSITORY);
1934 browseFolder.SetInfo(title);
1936 if (browseFolder.Show(NULL, strCloneDirectory) == CBrowseFolder::OK)
1938 return strCloneDirectory;
1940 }else
1942 return CString();
1947 bool CAppUtils::SendPatchMail(CTGitPathList &list,bool autoclose)
1949 CSendMailDlg dlg;
1951 dlg.m_PathList = list;
1953 if(dlg.DoModal()==IDOK)
1955 if(dlg.m_PathList.GetCount() == 0)
1956 return FALSE;
1958 CGitProgressDlg progDlg;
1960 theApp.m_pMainWnd = &progDlg;
1961 progDlg.SetCommand(CGitProgressDlg::GitProgress_SendMail);
1963 progDlg.SetAutoClose(autoclose);
1965 progDlg.SetPathList(dlg.m_PathList);
1966 //ProjectProperties props;
1967 //props.ReadPropsPathList(dlg.m_pathList);
1968 //progDlg.SetProjectProperties(props);
1969 progDlg.SetItemCount(dlg.m_PathList.GetCount());
1971 DWORD flags =0;
1972 if(dlg.m_bAttachment)
1973 flags |= SENDMAIL_ATTACHMENT;
1974 if(dlg.m_bCombine)
1975 flags |= SENDMAIL_COMBINED;
1977 progDlg.SetSendMailOption(dlg.m_To,dlg.m_CC,dlg.m_Subject,flags);
1979 progDlg.DoModal();
1981 return true;
1983 return false;