Add support i18n.logOutputEncoding at log list
[TortoiseGit.git] / src / TortoiseProc / AppUtils.cpp
blobc1c0f54172133cee229ac1e70da6889642ca53d8
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);
1032 if( !url1.IsEmpty() )
1034 cmd+=_T(" \"");
1035 cmd+=url1.GetGitPathString();
1036 cmd+=_T("\" ");
1038 g_Git.RunLogFile(cmd,tempfile);
1039 CAppUtils::StartUnifiedDiffViewer(tempfile,rev1.Left(6)+_T(":")+rev2.Left(6));
1042 #if 0
1043 CString sCmd;
1044 sCmd.Format(_T("%s /command:showcompare /unified"),
1045 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1046 sCmd += _T(" /url1:\"") + url1.GetGitPathString() + _T("\"");
1047 if (rev1.IsValid())
1048 sCmd += _T(" /revision1:") + rev1.ToString();
1049 sCmd += _T(" /url2:\"") + url2.GetGitPathString() + _T("\"");
1050 if (rev2.IsValid())
1051 sCmd += _T(" /revision2:") + rev2.ToString();
1052 if (peg.IsValid())
1053 sCmd += _T(" /pegrevision:") + peg.ToString();
1054 if (headpeg.IsValid())
1055 sCmd += _T(" /headpegrevision:") + headpeg.ToString();
1057 if (bAlternateDiff)
1058 sCmd += _T(" /alternatediff");
1060 if (bIgnoreAncestry)
1061 sCmd += _T(" /ignoreancestry");
1063 if (hWnd)
1065 sCmd += _T(" /hwnd:");
1066 TCHAR buf[30];
1067 _stprintf_s(buf, 30, _T("%d"), hWnd);
1068 sCmd += buf;
1071 return CAppUtils::LaunchApplication(sCmd, NULL, false);
1072 #endif
1073 return TRUE;
1076 bool CAppUtils::StartShowCompare(HWND hWnd, const CTGitPath& url1, const GitRev& rev1,
1077 const CTGitPath& url2, const GitRev& rev2,
1078 const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
1079 bool bAlternateDiff /* = false */, bool bIgnoreAncestry /* = false */, bool blame /* = false */)
1081 #if 0
1082 CString sCmd;
1083 sCmd.Format(_T("%s /command:showcompare"),
1084 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1085 sCmd += _T(" /url1:\"") + url1.GetGitPathString() + _T("\"");
1086 if (rev1.IsValid())
1087 sCmd += _T(" /revision1:") + rev1.ToString();
1088 sCmd += _T(" /url2:\"") + url2.GetGitPathString() + _T("\"");
1089 if (rev2.IsValid())
1090 sCmd += _T(" /revision2:") + rev2.ToString();
1091 if (peg.IsValid())
1092 sCmd += _T(" /pegrevision:") + peg.ToString();
1093 if (headpeg.IsValid())
1094 sCmd += _T(" /headpegrevision:") + headpeg.ToString();
1095 if (bAlternateDiff)
1096 sCmd += _T(" /alternatediff");
1097 if (bIgnoreAncestry)
1098 sCmd += _T(" /ignoreancestry");
1099 if (blame)
1100 sCmd += _T(" /blame");
1102 if (hWnd)
1104 sCmd += _T(" /hwnd:");
1105 TCHAR buf[30];
1106 _stprintf_s(buf, 30, _T("%d"), hWnd);
1107 sCmd += buf;
1110 return CAppUtils::LaunchApplication(sCmd, NULL, false);
1111 #endif
1112 return true;
1115 bool CAppUtils::Export(CString *BashHash)
1117 bool bRet = false;
1119 // ask from where the export has to be done
1120 CExportDlg dlg;
1121 if(BashHash)
1122 dlg.m_Revision=*BashHash;
1124 if (dlg.DoModal() == IDOK)
1126 CString cmd;
1127 cmd.Format(_T("git.exe archive --format=zip --verbose %s"),
1128 dlg.m_VersionName);
1130 //g_Git.RunLogFile(cmd,dlg.m_strExportDirectory);
1131 CProgressDlg pro;
1132 pro.m_GitCmd=cmd;
1133 pro.m_LogFile=dlg.m_strExportDirectory;
1134 pro.DoModal();
1135 return TRUE;
1137 return bRet;
1140 bool CAppUtils::CreateBranchTag(bool IsTag,CString *CommitHash)
1142 CCreateBranchTagDlg dlg;
1143 dlg.m_bIsTag=IsTag;
1144 if(CommitHash)
1145 dlg.m_Base = *CommitHash;
1147 if(dlg.DoModal()==IDOK)
1149 CString cmd;
1150 CString force;
1151 CString track;
1152 if(dlg.m_bTrack)
1153 track=_T(" --track ");
1155 if(dlg.m_bForce)
1156 force=_T(" -f ");
1158 if(IsTag)
1160 cmd.Format(_T("git.exe tag %s %s %s %s"),
1161 track,
1162 force,
1163 dlg.m_BranchTagName,
1164 dlg.m_VersionName
1168 }else
1170 cmd.Format(_T("git.exe branch %s %s %s %s"),
1171 track,
1172 force,
1173 dlg.m_BranchTagName,
1174 dlg.m_VersionName
1177 CString out;
1178 if(g_Git.Run(cmd,&out,CP_UTF8))
1180 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1182 if( !IsTag && dlg.m_bSwitch )
1184 // it is a new branch and the user has requested to switch to it
1185 cmd.Format(_T("git.exe checkout %s"), dlg.m_BranchTagName);
1186 g_Git.Run(cmd,&out,CP_UTF8);
1187 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1190 return TRUE;
1193 return FALSE;
1196 bool CAppUtils::Switch(CString *CommitHash)
1198 CGitSwitchDlg dlg;
1199 if(CommitHash)
1200 dlg.m_Base=*CommitHash;
1202 if (dlg.DoModal() == IDOK)
1204 CString cmd;
1205 CString track;
1206 CString base;
1207 CString force;
1208 CString branch;
1210 if(dlg.m_bBranch)
1211 branch.Format(_T("-b %s"),dlg.m_NewBranch);
1212 if(dlg.m_bForce)
1213 force=_T("-f");
1214 if(dlg.m_bTrack)
1215 track=_T("--track");
1217 cmd.Format(_T("git.exe checkout %s %s %s %s"),
1218 force,
1219 track,
1220 branch,
1221 dlg.m_VersionName);
1223 CProgressDlg progress;
1224 progress.m_GitCmd=cmd;
1225 if(progress.DoModal()==IDOK)
1226 return TRUE;
1229 return FALSE;
1232 bool CAppUtils::IgnoreFile(CTGitPathList &path,bool IsMask)
1234 CString ignorefile;
1235 ignorefile=g_Git.m_CurrentDir+_T("\\");
1237 if(IsMask)
1239 ignorefile+=path.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1241 }else
1243 ignorefile+=_T("\\.gitignore");
1246 CStdioFile file;
1247 if(!file.Open(ignorefile,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate))
1249 CMessageBox::Show(NULL,ignorefile+_T(" Open Failure"),_T("TortoiseGit"),MB_OK);
1250 return FALSE;
1253 CString ignorelist;
1254 CString mask;
1257 //file.ReadString(ignorelist);
1258 file.SeekToEnd();
1259 for(int i=0;i<path.GetCount();i++)
1261 if(IsMask)
1263 mask=_T("*")+path[i].GetFileExtension();
1264 if(ignorelist.Find(mask)<0)
1265 ignorelist+=_T("\n")+mask;
1267 }else
1269 ignorelist+=_T("\n/")+path[i].GetGitPathString();
1272 file.WriteString(ignorelist);
1274 file.Close();
1276 }catch(...)
1278 file.Close();
1279 return FALSE;
1282 return TRUE;
1286 bool CAppUtils::GitReset(CString *CommitHash,int type)
1288 CResetDlg dlg;
1289 dlg.m_ResetType=type;
1290 if (dlg.DoModal() == IDOK)
1292 CString cmd;
1293 CString type;
1294 switch(dlg.m_ResetType)
1296 case 0:
1297 type=_T("--soft");
1298 break;
1299 case 1:
1300 type=_T("--mixed");
1301 break;
1302 case 2:
1303 type=_T("--hard");
1304 break;
1305 default:
1306 type=_T("--mixed");
1307 break;
1309 cmd.Format(_T("git.exe reset %s %s"),type, *CommitHash);
1311 CProgressDlg progress;
1312 progress.m_GitCmd=cmd;
1313 if(progress.DoModal()==IDOK)
1314 return TRUE;
1317 return FALSE;
1320 void CAppUtils::DescribeFile(bool mode, bool base,CString &descript)
1322 if(mode == FALSE)
1324 descript=_T("Deleted");
1325 return;
1327 if(base)
1329 descript=_T("Modified");
1330 return;
1332 descript=_T("Created");
1333 return;
1336 CString CAppUtils::GetMergeTempFile(CString type,CTGitPath &merge)
1338 CString file;
1339 file=g_Git.m_CurrentDir+_T("\\")+merge.GetDirectory().GetWinPathString()+_T("\\")+merge.GetFilename()+_T(".")+type+merge.GetFileExtension();
1341 return file;
1344 bool CAppUtils::ConflictEdit(CTGitPath &path,bool bAlternativeTool)
1346 bool bRet = false;
1348 CTGitPath merge=path;
1349 CTGitPath directory = merge.GetDirectory();
1353 // we have the conflicted file (%merged)
1354 // now look for the other required files
1355 //GitStatus stat;
1356 //stat.GetStatus(merge);
1357 //if (stat.status == NULL)
1358 // return false;
1360 BYTE_VECTOR vector;
1362 CString cmd;
1363 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge.GetGitPathString());
1365 if(g_Git.Run(cmd,&vector))
1367 return FALSE;
1370 CTGitPathList list;
1371 list.ParserFromLsFile(vector);
1373 if(list.GetCount() == 0)
1374 return FALSE;
1376 TCHAR szTempName[512];
1377 GetTempFileName(_T(""),_T(""),0,szTempName);
1378 CString temp(szTempName);
1379 temp=temp.Mid(1,temp.GetLength()-5);
1381 CTGitPath theirs;
1382 CTGitPath mine;
1383 CTGitPath base;
1386 mine.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge));
1387 theirs.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge));
1388 base.SetFromGit(GetMergeTempFile(_T("BASE"),merge));
1390 CString format;
1392 format=_T("git.exe cat-file blob \":%d:%s\"");
1393 CFile tempfile;
1394 //create a empty file, incase stage is not three
1395 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1396 tempfile.Close();
1397 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1398 tempfile.Close();
1399 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1400 tempfile.Close();
1402 bool b_base=false, b_local=false, b_remote=false;
1404 for(int i=0;i<list.GetCount();i++)
1406 CString cmd;
1407 CString outfile;
1408 cmd.Format(format,list[i].m_Stage,list[i].GetGitPathString());
1410 if( list[i].m_Stage == 1)
1412 b_base = true;
1413 outfile=base.GetWinPathString();
1415 if( list[i].m_Stage == 2 )
1417 b_local = true;
1418 outfile=mine.GetWinPathString();
1420 if( list[i].m_Stage == 3 )
1422 b_remote = true;
1423 outfile=theirs.GetWinPathString();
1425 g_Git.RunLogFile(cmd,outfile);
1428 if(b_local && b_remote )
1430 merge.SetFromWin(g_Git.m_CurrentDir+_T("\\")+merge.GetWinPathString());
1431 bRet = !!CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1433 }else
1435 CFile::Remove(mine.GetWinPathString());
1436 CFile::Remove(theirs.GetWinPathString());
1437 CFile::Remove(base.GetWinPathString());
1439 CDeleteConflictDlg dlg;
1440 DescribeFile(b_local, b_base,dlg.m_LocalStatus);
1441 DescribeFile(b_remote,b_base,dlg.m_RemoteStatus);
1442 dlg.m_bShowModifiedButton=b_base;
1443 dlg.m_File=merge.GetGitPathString();
1444 if(dlg.DoModal() == IDOK)
1446 CString cmd,out;
1447 if(dlg.m_bIsDelete)
1449 cmd.Format(_T("git.exe rm \"%s\""),merge.GetGitPathString());
1450 }else
1451 cmd.Format(_T("git.exe add \"%s\""),merge.GetGitPathString());
1453 if(g_Git.Run(cmd,&out,CP_ACP))
1455 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1456 return FALSE;
1458 return TRUE;
1460 else
1461 return FALSE;
1467 #if 0
1469 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1470 base, theirs, mine, merge);
1471 #endif
1472 #if 0
1473 if (stat.status->text_status == svn_wc_status_conflicted)
1475 // we have a text conflict, use our merge tool to resolve the conflict
1477 CTSVNPath theirs(directory);
1478 CTSVNPath mine(directory);
1479 CTSVNPath base(directory);
1480 bool bConflictData = false;
1482 if ((stat.status->entry)&&(stat.status->entry->conflict_new))
1484 theirs.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_new));
1485 bConflictData = true;
1487 if ((stat.status->entry)&&(stat.status->entry->conflict_old))
1489 base.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_old));
1490 bConflictData = true;
1492 if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
1494 mine.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_wrk));
1495 bConflictData = true;
1497 else
1499 mine = merge;
1501 if (bConflictData)
1502 bRet = !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1503 base, theirs, mine, merge);
1506 if (stat.status->prop_status == svn_wc_status_conflicted)
1508 // we have a property conflict
1509 CTSVNPath prej(directory);
1510 if ((stat.status->entry)&&(stat.status->entry->prejfile))
1512 prej.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->prejfile));
1513 // there's a problem: the prej file contains a _description_ of the conflict, and
1514 // that description string might be translated. That means we have no way of parsing
1515 // the file to find out the conflicting values.
1516 // The only thing we can do: show a dialog with the conflict description, then
1517 // let the user either accept the existing property or open the property edit dialog
1518 // to manually change the properties and values. And a button to mark the conflict as
1519 // resolved.
1520 CEditPropConflictDlg dlg;
1521 dlg.SetPrejFile(prej);
1522 dlg.SetConflictedItem(merge);
1523 bRet = (dlg.DoModal() != IDCANCEL);
1527 if (stat.status->tree_conflict)
1529 // we have a tree conflict
1530 SVNInfo info;
1531 const SVNInfoData * pInfoData = info.GetFirstFileInfo(merge, SVNRev(), SVNRev());
1532 if (pInfoData)
1534 if (pInfoData->treeconflict_kind == svn_wc_conflict_kind_text)
1536 CTSVNPath theirs(directory);
1537 CTSVNPath mine(directory);
1538 CTSVNPath base(directory);
1539 bool bConflictData = false;
1541 if (pInfoData->treeconflict_theirfile)
1543 theirs.AppendPathString(pInfoData->treeconflict_theirfile);
1544 bConflictData = true;
1546 if (pInfoData->treeconflict_basefile)
1548 base.AppendPathString(pInfoData->treeconflict_basefile);
1549 bConflictData = true;
1551 if (pInfoData->treeconflict_myfile)
1553 mine.AppendPathString(pInfoData->treeconflict_myfile);
1554 bConflictData = true;
1556 else
1558 mine = merge;
1560 if (bConflictData)
1561 bRet = !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1562 base, theirs, mine, merge);
1564 else if (pInfoData->treeconflict_kind == svn_wc_conflict_kind_tree)
1566 CString sConflictAction;
1567 CString sConflictReason;
1568 CString sResolveTheirs;
1569 CString sResolveMine;
1570 CTSVNPath treeConflictPath = CTSVNPath(pInfoData->treeconflict_path);
1571 CString sItemName = treeConflictPath.GetUIFileOrDirectoryName();
1573 if (pInfoData->treeconflict_nodekind == svn_node_file)
1575 switch (pInfoData->treeconflict_operation)
1577 case svn_wc_operation_update:
1578 switch (pInfoData->treeconflict_action)
1580 case svn_wc_conflict_action_edit:
1581 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEEDIT, (LPCTSTR)sItemName);
1582 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1583 break;
1584 case svn_wc_conflict_action_add:
1585 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEADD, (LPCTSTR)sItemName);
1586 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1587 break;
1588 case svn_wc_conflict_action_delete:
1589 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEDELETE, (LPCTSTR)sItemName);
1590 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1591 break;
1593 break;
1594 case svn_wc_operation_switch:
1595 switch (pInfoData->treeconflict_action)
1597 case svn_wc_conflict_action_edit:
1598 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHEDIT, (LPCTSTR)sItemName);
1599 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1600 break;
1601 case svn_wc_conflict_action_add:
1602 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHADD, (LPCTSTR)sItemName);
1603 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1604 break;
1605 case svn_wc_conflict_action_delete:
1606 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHDELETE, (LPCTSTR)sItemName);
1607 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1608 break;
1610 break;
1611 case svn_wc_operation_merge:
1612 switch (pInfoData->treeconflict_action)
1614 case svn_wc_conflict_action_edit:
1615 sConflictAction.Format(IDS_TREECONFLICT_FILEMERGEEDIT, (LPCTSTR)sItemName);
1616 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1617 break;
1618 case svn_wc_conflict_action_add:
1619 sResolveTheirs.Format(IDS_TREECONFLICT_FILEMERGEADD, (LPCTSTR)sItemName);
1620 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1621 break;
1622 case svn_wc_conflict_action_delete:
1623 sConflictAction.Format(IDS_TREECONFLICT_FILEMERGEDELETE, (LPCTSTR)sItemName);
1624 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1625 break;
1627 break;
1630 else if (pInfoData->treeconflict_nodekind == svn_node_dir)
1632 switch (pInfoData->treeconflict_operation)
1634 case svn_wc_operation_update:
1635 switch (pInfoData->treeconflict_action)
1637 case svn_wc_conflict_action_edit:
1638 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEEDIT, (LPCTSTR)sItemName);
1639 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1640 break;
1641 case svn_wc_conflict_action_add:
1642 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEADD, (LPCTSTR)sItemName);
1643 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1644 break;
1645 case svn_wc_conflict_action_delete:
1646 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEDELETE, (LPCTSTR)sItemName);
1647 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1648 break;
1650 break;
1651 case svn_wc_operation_switch:
1652 switch (pInfoData->treeconflict_action)
1654 case svn_wc_conflict_action_edit:
1655 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHEDIT, (LPCTSTR)sItemName);
1656 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1657 break;
1658 case svn_wc_conflict_action_add:
1659 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHADD, (LPCTSTR)sItemName);
1660 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1661 break;
1662 case svn_wc_conflict_action_delete:
1663 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHDELETE, (LPCTSTR)sItemName);
1664 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1665 break;
1667 break;
1668 case svn_wc_operation_merge:
1669 switch (pInfoData->treeconflict_action)
1671 case svn_wc_conflict_action_edit:
1672 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEEDIT, (LPCTSTR)sItemName);
1673 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1674 break;
1675 case svn_wc_conflict_action_add:
1676 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEADD, (LPCTSTR)sItemName);
1677 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1678 break;
1679 case svn_wc_conflict_action_delete:
1680 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEDELETE, (LPCTSTR)sItemName);
1681 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1682 break;
1684 break;
1688 UINT uReasonID = 0;
1689 switch (pInfoData->treeconflict_reason)
1691 case svn_wc_conflict_reason_edited:
1692 uReasonID = IDS_TREECONFLICT_REASON_EDITED;
1693 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1694 break;
1695 case svn_wc_conflict_reason_obstructed:
1696 uReasonID = IDS_TREECONFLICT_REASON_OBSTRUCTED;
1697 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1698 break;
1699 case svn_wc_conflict_reason_deleted:
1700 uReasonID = IDS_TREECONFLICT_REASON_DELETED;
1701 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_REMOVEDIR : IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1702 break;
1703 case svn_wc_conflict_reason_added:
1704 uReasonID = IDS_TREECONFLICT_REASON_ADDED;
1705 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1706 break;
1707 case svn_wc_conflict_reason_missing:
1708 uReasonID = IDS_TREECONFLICT_REASON_MISSING;
1709 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_REMOVEDIR : IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1710 break;
1711 case svn_wc_conflict_reason_unversioned:
1712 uReasonID = IDS_TREECONFLICT_REASON_UNVERSIONED;
1713 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1714 break;
1716 sConflictReason.Format(uReasonID, (LPCTSTR)sConflictAction);
1718 CTreeConflictEditorDlg dlg;
1719 dlg.SetConflictInfoText(sConflictReason);
1720 dlg.SetResolveTexts(sResolveTheirs, sResolveMine);
1721 dlg.SetPath(treeConflictPath);
1722 INT_PTR dlgRet = dlg.DoModal();
1723 bRet = (dlgRet != IDCANCEL);
1727 #endif
1728 return bRet;
1732 * FUNCTION : FormatDateAndTime
1733 * DESCRIPTION : Generates a displayable string from a CTime object in
1734 * system short or long format or as a relative value
1735 * cTime - the time
1736 * option - DATE_SHORTDATE or DATE_LONGDATE
1737 * bIncluedeTime - whether to show time as well as date
1738 * bRelative - if true then relative time is shown if reasonable
1739 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
1740 * rather than locale
1741 * RETURN : CString containing date/time
1743 CString CAppUtils::FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime /*=true*/,
1744 bool bRelative /*=false*/)
1746 CString datetime;
1747 if ( bRelative )
1749 datetime = ToRelativeTimeString( cTime );
1751 else
1753 // should we use the locale settings for formatting the date/time?
1754 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE))
1756 // yes
1757 SYSTEMTIME sysTime;
1758 cTime.GetAsSystemTime( sysTime );
1760 TCHAR buf[100];
1762 GetDateFormat(LOCALE_USER_DEFAULT, option, &sysTime, NULL, buf,
1763 sizeof(buf)/sizeof(TCHAR)-1);
1764 datetime = buf;
1765 if ( bIncludeTime )
1767 datetime += _T(" ");
1768 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, NULL, buf, sizeof(buf)/sizeof(TCHAR)-1);
1769 datetime += buf;
1772 else
1774 // no, so fixed format
1775 if ( bIncludeTime )
1777 datetime = cTime.Format(_T("%Y-%m-%d %H:%M:%S"));
1779 else
1781 datetime = cTime.Format(_T("%Y-%m-%d"));
1785 return datetime;
1789 * Converts a given time to a relative display string (relative to current time)
1790 * Given time must be in local timezone
1792 CString CAppUtils::ToRelativeTimeString(CTime time)
1794 CString answer;
1795 // convert to COleDateTime
1796 SYSTEMTIME sysTime;
1797 time.GetAsSystemTime( sysTime );
1798 COleDateTime oleTime( sysTime );
1799 answer = ToRelativeTimeString(oleTime, COleDateTime::GetCurrentTime());
1800 return answer;
1804 * Generates a display string showing the relative time between the two given times as COleDateTimes
1806 CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo)
1808 CString answer;
1809 COleDateTimeSpan ts = RelativeTo - time;
1810 //years
1811 if(fabs(ts.GetTotalDays()) >= 3*365)
1813 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/365, IDS_YEAR_AGO, IDS_YEARS_AGO );
1815 //Months
1816 if(fabs(ts.GetTotalDays()) >= 60)
1818 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/30, IDS_MONTH_AGO, IDS_MONTHS_AGO );
1819 return answer;
1821 //Weeks
1822 if(fabs(ts.GetTotalDays()) >= 14)
1824 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/7, IDS_WEEK_AGO, IDS_WEEKS_AGO );
1825 return answer;
1827 //Days
1828 if(fabs(ts.GetTotalDays()) >= 2)
1830 answer = ExpandRelativeTime( (int)ts.GetTotalDays(), IDS_DAY_AGO, IDS_DAYS_AGO );
1831 return answer;
1833 //hours
1834 if(fabs(ts.GetTotalHours()) >= 2)
1836 answer = ExpandRelativeTime( (int)ts.GetTotalHours(), IDS_HOUR_AGO, IDS_HOURS_AGO );
1837 return answer;
1839 //minutes
1840 if(fabs(ts.GetTotalMinutes()) >= 2)
1842 answer = ExpandRelativeTime( (int)ts.GetTotalMinutes(), IDS_MINUTE_AGO, IDS_MINUTES_AGO );
1843 return answer;
1845 //seconds
1846 answer = ExpandRelativeTime( (int)ts.GetTotalSeconds(), IDS_SECOND_AGO, IDS_SECONDS_AGO );
1847 return answer;
1850 /**
1851 * Passed a value and two resource string ids
1852 * if count is 1 then FormatString is called with format_1 and the value
1853 * otherwise format_2 is used
1854 * the formatted string is returned
1856 CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n )
1858 CString answer;
1859 if ( count == 1 )
1861 answer.FormatMessage( format_1, count );
1863 else
1865 answer.FormatMessage( format_n, count );
1867 return answer;
1870 bool CAppUtils::IsSSHPutty()
1872 CString sshclient=CRegString(_T("Software\\TortoiseGit\\SSH"));
1873 sshclient=sshclient.MakeLower();
1874 if(sshclient.Find(_T("plink.exe"),0)>=0)
1876 return true;
1878 return false;
1881 CString CAppUtils::GetClipboardLink()
1883 if (!OpenClipboard(NULL))
1884 return CString();
1886 CString sClipboardText;
1887 HGLOBAL hglb = GetClipboardData(CF_TEXT);
1888 if (hglb)
1890 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
1891 sClipboardText = CString(lpstr);
1892 GlobalUnlock(hglb);
1894 hglb = GetClipboardData(CF_UNICODETEXT);
1895 if (hglb)
1897 LPCTSTR lpstr = (LPCTSTR)GlobalLock(hglb);
1898 sClipboardText = lpstr;
1899 GlobalUnlock(hglb);
1901 CloseClipboard();
1903 if(!sClipboardText.IsEmpty())
1905 if(sClipboardText[0] == _T('\"') && sClipboardText[sClipboardText.GetLength()-1] == _T('\"'))
1906 sClipboardText=sClipboardText.Mid(1,sClipboardText.GetLength()-2);
1908 if(sClipboardText.Find( _T("http://")) == 0)
1909 return sClipboardText;
1911 if(sClipboardText.Find( _T("https://")) == 0)
1912 return sClipboardText;
1914 if(sClipboardText.Find( _T("git://")) == 0)
1915 return sClipboardText;
1917 if(sClipboardText.Find( _T("ssh://")) == 0)
1918 return sClipboardText;
1920 if(sClipboardText.GetLength()>=2)
1921 if( sClipboardText[1] == _T(':') )
1922 if( (sClipboardText[0] >= 'A' && sClipboardText[0] <= 'Z')
1923 || (sClipboardText[0] >= 'a' && sClipboardText[0] <= 'z') )
1924 return sClipboardText;
1927 return CString(_T(""));
1930 CString CAppUtils::ChooseRepository(CString *path)
1932 CBrowseFolder browseFolder;
1933 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
1934 CString strCloneDirectory;
1935 if(path)
1936 strCloneDirectory=*path;
1938 CString title;
1939 title.LoadString(IDS_CHOOSE_REPOSITORY);
1941 browseFolder.SetInfo(title);
1943 if (browseFolder.Show(NULL, strCloneDirectory) == CBrowseFolder::OK)
1945 return strCloneDirectory;
1947 }else
1949 return CString();
1954 bool CAppUtils::SendPatchMail(CTGitPathList &list,bool autoclose)
1956 CSendMailDlg dlg;
1958 dlg.m_PathList = list;
1960 if(dlg.DoModal()==IDOK)
1962 if(dlg.m_PathList.GetCount() == 0)
1963 return FALSE;
1965 CGitProgressDlg progDlg;
1967 theApp.m_pMainWnd = &progDlg;
1968 progDlg.SetCommand(CGitProgressDlg::GitProgress_SendMail);
1970 progDlg.SetAutoClose(autoclose);
1972 progDlg.SetPathList(dlg.m_PathList);
1973 //ProjectProperties props;
1974 //props.ReadPropsPathList(dlg.m_pathList);
1975 //progDlg.SetProjectProperties(props);
1976 progDlg.SetItemCount(dlg.m_PathList.GetCount());
1978 DWORD flags =0;
1979 if(dlg.m_bAttachment)
1980 flags |= SENDMAIL_ATTACHMENT;
1981 if(dlg.m_bCombine)
1982 flags |= SENDMAIL_COMBINED;
1984 progDlg.SetSendMailOption(dlg.m_To,dlg.m_CC,dlg.m_Subject,flags);
1986 progDlg.DoModal();
1988 return true;
1990 return false;
1992 int CAppUtils::GetLogOutputEncode()
1994 CString cmd,output;
1995 int start=0;
1996 cmd=_T("git.exe config i18n.logOutputEncoding");
1997 if(g_Git.Run(cmd,&output,CP_ACP))
1999 cmd=_T("git.exe config i18n.commitencoding");
2000 if(g_Git.Run(cmd,&output,CP_ACP))
2001 return CP_UTF8;
2003 int start=0;
2004 output=output.Tokenize(_T("\n"),start);
2005 return CUnicodeUtils::GetCPCode(output);
2007 }else
2009 output=output.Tokenize(_T("\n"),start);
2010 return CUnicodeUtils::GetCPCode(output);
2013 int CAppUtils::SaveCommitUnicodeFile(CString &filename, CString &message)
2015 CFile file(filename,CFile::modeReadWrite|CFile::modeCreate );
2016 CString cmd,output;
2017 int cp=CP_UTF8;
2019 cmd=_T("git.exe config i18n.commitencoding");
2020 if(g_Git.Run(cmd,&output,CP_ACP))
2021 cp=CP_UTF8;
2023 int start=0;
2024 output=output.Tokenize(_T("\n"),start);
2025 cp=CUnicodeUtils::GetCPCode(output);
2027 int len=message.GetLength();
2029 char * buf;
2030 buf = new char[len*4 + 4];
2031 SecureZeroMemory(buf, (len*4 + 4));
2033 int lengthIncTerminator = WideCharToMultiByte(cp, 0, message, -1, buf, len*4, NULL, NULL);
2035 file.Write(buf,lengthIncTerminator-1);
2036 file.Close();
2037 delete buf;
2038 return 0;