cleanup
[TortoiseGit.git] / src / TortoiseProc / AppUtils.cpp
blob1de5e8f4d8b375d0310546fa277c45c12f4afca6
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2011 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "StdAfx.h"
21 #include "resource.h"
22 #include "TortoiseProc.h"
23 #include "PathUtils.h"
24 #include "AppUtils.h"
25 //#include "GitProperties.h"
26 #include "StringUtils.h"
27 #include "MessageBox.h"
28 #include "Registry.h"
29 #include "TGitPath.h"
30 #include "Git.h"
31 //#include "RepositoryBrowser.h"
32 //#include "BrowseFolder.h"
33 #include "UnicodeUtils.h"
34 #include "ExportDlg.h"
35 #include "ProgressDlg.h"
36 #include "GitAdminDir.h"
37 #include "ProgressDlg.h"
38 #include "BrowseFolder.h"
39 #include "DirFileEnum.h"
40 #include "MessageBox.h"
41 #include "GitStatus.h"
42 #include "CreateBranchTagDlg.h"
43 #include "GitSwitchDlg.h"
44 #include "ResetDlg.h"
45 #include "DeleteConflictDlg.h"
46 #include "ChangedDlg.h"
47 #include "SendMailDlg.h"
48 #include "GITProgressDlg.h"
49 #include "PushDlg.h"
50 #include "CommitDlg.h"
51 #include "MergeDlg.h"
52 #include "hooks.h"
53 #include "..\Settings\Settings.h"
54 #include "InputDlg.h"
55 #include "SVNDCommitDlg.h"
56 #include "requestpulldlg.h"
57 #include "PullFetchDlg.h"
58 #include "RebaseDlg.h"
59 #include "PropKey.h"
60 #include "StashSave.h"
61 #include "FormatMessageWrapper.h"
63 CAppUtils::CAppUtils(void)
67 CAppUtils::~CAppUtils(void)
71 bool CAppUtils::StashSave()
73 CStashSaveDlg dlg;
75 if (dlg.DoModal() == IDOK)
77 CString cmd, out;
78 cmd = _T("git.exe stash save");
80 if (dlg.m_bIncludeUntracked && CAppUtils::GetMsysgitVersion() >= 0x01070700)
81 cmd += _T(" --include-untracked");
83 if (!dlg.m_sMessage.IsEmpty())
85 CString message = dlg.m_sMessage;
86 message.Replace(_T("\""), _T("\"\""));
87 cmd += _T(" \"") + message + _T("\"");
90 if (g_Git.Run(cmd, &out, CP_ACP))
92 CMessageBox::Show(NULL, CString(_T("<ct=0x0000FF>Stash Fail!!!</ct>\n")) + out, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
94 else
96 CMessageBox::Show(NULL, CString(_T("<ct=0xff0000>Stash Success</ct>\n")) + out, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
97 return true;
100 return false;
103 int CAppUtils::StashApply(CString ref, bool showChanges /* true */)
105 CString cmd,out;
106 cmd = _T("git.exe stash apply ");
107 if (ref.Find(_T("refs/")) == 0)
108 ref = ref.Mid(5);
109 if (ref.Find(_T("stash{")) == 0)
110 ref = _T("stash@") + ref.Mid(5);
111 cmd += ref;
113 int ret = g_Git.Run(cmd, &out, CP_ACP);
114 bool hasConflicts = (out.Find(_T("CONFLICT")) >= 0);
115 if (ret && !(ret == 1 && hasConflicts))
117 CMessageBox::Show(NULL,CString(_T("<ct=0x0000FF>Stash Apply Fail!!!</ct>\n"))+out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
119 else
121 CString withConflicts;
122 if (hasConflicts)
123 withConflicts = _T(" with conflicts");
124 if (showChanges)
126 if(CMessageBox::Show(NULL,CString(_T("<ct=0xff0000>Stash Apply Success") + withConflicts + _T("</ct>\nDo you want to show change?"))
127 ,_T("TortoiseGit"),MB_YESNO|MB_ICONINFORMATION) == IDYES)
129 CChangedDlg dlg;
130 dlg.m_pathList.AddPath(CTGitPath());
131 dlg.DoModal();
133 return 0;
135 else
137 CMessageBox::Show(NULL, _T("<ct=0xff0000>Stash Apply Success") + withConflicts + _T("</ct>") ,_T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
138 return 0;
141 return -1;
144 int CAppUtils::StashPop(bool showChanges /* true */)
146 CString cmd,out;
147 cmd=_T("git.exe stash pop ");
149 int ret = g_Git.Run(cmd, &out, CP_ACP);
150 bool hasConflicts = (out.Find(_T("CONFLICT")) >= 0);
151 if (ret && !(ret == 1 && hasConflicts))
153 CMessageBox::Show(NULL,CString(_T("<ct=0x0000FF>Stash POP Fail!!!</ct>\n"))+out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
155 else
157 CString message = _T("<ct=0xff0000>Stash POP Success</ct>");
158 if (hasConflicts)
159 message = _T("<ct=0x000000ff>Stash POP Failed, there are conflicts</ct>");
160 if (showChanges)
162 if(CMessageBox::Show(NULL,CString(message + _T("\nDo you want to show change?"))
163 ,_T("TortoiseGit"),MB_YESNO|MB_ICONINFORMATION) == IDYES)
165 CChangedDlg dlg;
166 dlg.m_pathList.AddPath(CTGitPath());
167 dlg.DoModal();
169 return 0;
171 else
173 CMessageBox::Show(NULL, message ,_T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
174 return 0;
177 return -1;
180 bool CAppUtils::GetMimeType(const CTGitPath& /*file*/, CString& /*mimetype*/)
182 #if 0
183 GitProperties props(file, GitRev::REV_WC, false);
184 for (int i = 0; i < props.GetCount(); ++i)
186 if (props.GetItemName(i).compare(_T("svn:mime-type"))==0)
188 mimetype = props.GetItemValue(i).c_str();
189 return true;
192 #endif
193 return false;
196 BOOL CAppUtils::StartExtMerge(
197 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
198 const CString& basename, const CString& theirname, const CString& yourname, const CString& mergedname, bool bReadOnly)
201 CRegString regCom = CRegString(_T("Software\\TortoiseGit\\Merge"));
202 CString ext = mergedfile.GetFileExtension();
203 CString com = regCom;
204 bool bInternal = false;
206 CString mimetype;
207 if (ext != "")
209 // is there an extension specific merge tool?
210 CRegString mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext.MakeLower());
211 if (CString(mergetool) != "")
213 com = mergetool;
216 if (GetMimeType(yourfile, mimetype) || GetMimeType(theirfile, mimetype) || GetMimeType(basefile, mimetype))
218 // is there a mime type specific merge tool?
219 CRegString mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype);
220 if (CString(mergetool) != "")
222 com = mergetool;
226 if (com.IsEmpty()||(com.Left(1).Compare(_T("#"))==0))
228 // use TortoiseMerge
229 bInternal = true;
230 CRegString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE);
231 com = tortoiseMergePath;
232 if (com.IsEmpty())
234 com = CPathUtils::GetAppDirectory();
235 com += _T("TortoiseMerge.exe");
237 com = _T("\"") + com + _T("\"");
238 com = com + _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
239 com = com + _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
241 // check if the params are set. If not, just add the files to the command line
242 if ((com.Find(_T("%merged"))<0)&&(com.Find(_T("%base"))<0)&&(com.Find(_T("%theirs"))<0)&&(com.Find(_T("%mine"))<0))
244 com += _T(" \"")+basefile.GetWinPathString()+_T("\"");
245 com += _T(" \"")+theirfile.GetWinPathString()+_T("\"");
246 com += _T(" \"")+yourfile.GetWinPathString()+_T("\"");
247 com += _T(" \"")+mergedfile.GetWinPathString()+_T("\"");
249 if (basefile.IsEmpty())
251 com.Replace(_T("/base:%base"), _T(""));
252 com.Replace(_T("%base"), _T(""));
254 else
255 com.Replace(_T("%base"), _T("\"") + basefile.GetWinPathString() + _T("\""));
256 if (theirfile.IsEmpty())
258 com.Replace(_T("/theirs:%theirs"), _T(""));
259 com.Replace(_T("%theirs"), _T(""));
261 else
262 com.Replace(_T("%theirs"), _T("\"") + theirfile.GetWinPathString() + _T("\""));
263 if (yourfile.IsEmpty())
265 com.Replace(_T("/mine:%mine"), _T(""));
266 com.Replace(_T("%mine"), _T(""));
268 else
269 com.Replace(_T("%mine"), _T("\"") + yourfile.GetWinPathString() + _T("\""));
270 if (mergedfile.IsEmpty())
272 com.Replace(_T("/merged:%merged"), _T(""));
273 com.Replace(_T("%merged"), _T(""));
275 else
276 com.Replace(_T("%merged"), _T("\"") + mergedfile.GetWinPathString() + _T("\""));
277 if (basename.IsEmpty())
279 if (basefile.IsEmpty())
281 com.Replace(_T("/basename:%bname"), _T(""));
282 com.Replace(_T("%bname"), _T(""));
284 else
286 com.Replace(_T("%bname"), _T("\"") + basefile.GetUIFileOrDirectoryName() + _T("\""));
289 else
290 com.Replace(_T("%bname"), _T("\"") + basename + _T("\""));
291 if (theirname.IsEmpty())
293 if (theirfile.IsEmpty())
295 com.Replace(_T("/theirsname:%tname"), _T(""));
296 com.Replace(_T("%tname"), _T(""));
298 else
300 com.Replace(_T("%tname"), _T("\"") + theirfile.GetUIFileOrDirectoryName() + _T("\""));
303 else
304 com.Replace(_T("%tname"), _T("\"") + theirname + _T("\""));
305 if (yourname.IsEmpty())
307 if (yourfile.IsEmpty())
309 com.Replace(_T("/minename:%yname"), _T(""));
310 com.Replace(_T("%yname"), _T(""));
312 else
314 com.Replace(_T("%yname"), _T("\"") + yourfile.GetUIFileOrDirectoryName() + _T("\""));
317 else
318 com.Replace(_T("%yname"), _T("\"") + yourname + _T("\""));
319 if (mergedname.IsEmpty())
321 if (mergedfile.IsEmpty())
323 com.Replace(_T("/mergedname:%mname"), _T(""));
324 com.Replace(_T("%mname"), _T(""));
326 else
328 com.Replace(_T("%mname"), _T("\"") + mergedfile.GetUIFileOrDirectoryName() + _T("\""));
331 else
332 com.Replace(_T("%mname"), _T("\"") + mergedname + _T("\""));
334 if ((bReadOnly)&&(bInternal))
335 com += _T(" /readonly");
337 if(!LaunchApplication(com, IDS_ERR_EXTMERGESTART, false))
339 return FALSE;
342 return TRUE;
345 BOOL CAppUtils::StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir, const CString& sOriginalDescription, const CString& sPatchedDescription, BOOL bReversed, BOOL bWait)
347 CString viewer;
348 // use TortoiseMerge
349 viewer = CPathUtils::GetAppDirectory();
350 viewer += _T("TortoiseMerge.exe");
352 viewer = _T("\"") + viewer + _T("\"");
353 viewer = viewer + _T(" /diff:\"") + patchfile.GetWinPathString() + _T("\"");
354 viewer = viewer + _T(" /patchpath:\"") + dir.GetWinPathString() + _T("\"");
355 if (bReversed)
356 viewer += _T(" /reversedpatch");
357 if (!sOriginalDescription.IsEmpty())
358 viewer = viewer + _T(" /patchoriginal:\"") + sOriginalDescription + _T("\"");
359 if (!sPatchedDescription.IsEmpty())
360 viewer = viewer + _T(" /patchpatched:\"") + sPatchedDescription + _T("\"");
361 if(!LaunchApplication(viewer, IDS_ERR_DIFFVIEWSTART, !!bWait))
363 return FALSE;
365 return TRUE;
368 CString CAppUtils::PickDiffTool(const CTGitPath& file1, const CTGitPath& file2)
370 // Is there a mime type specific diff tool?
371 CString mimetype;
372 if (GetMimeType(file1, mimetype) || GetMimeType(file2, mimetype))
374 CString difftool = CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype);
375 if (!difftool.IsEmpty())
376 return difftool;
379 // Is there an extension specific diff tool?
380 CString ext = file2.GetFileExtension().MakeLower();
381 if (!ext.IsEmpty())
383 CString difftool = CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext);
384 if (!difftool.IsEmpty())
385 return difftool;
386 // Maybe we should use TortoiseIDiff?
387 if ((ext == _T(".jpg")) || (ext == _T(".jpeg")) ||
388 (ext == _T(".bmp")) || (ext == _T(".gif")) ||
389 (ext == _T(".png")) || (ext == _T(".ico")) ||
390 (ext == _T(".dib")) || (ext == _T(".emf")))
392 return
393 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
394 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
398 // Finally, pick a generic external diff tool
399 CString difftool = CRegString(_T("Software\\TortoiseGit\\Diff"));
400 return difftool;
403 bool CAppUtils::StartExtDiff(
404 const CString& file1, const CString& file2,
405 const CString& sName1, const CString& sName2,
406 const DiffFlags& flags)
408 CString viewer;
410 CRegDWORD blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE);
411 if (!flags.bBlame || !(DWORD)blamediff)
413 viewer = PickDiffTool(file1, file2);
414 // If registry entry for a diff program is commented out, use TortoiseMerge.
415 bool bCommentedOut = viewer.Left(1) == _T("#");
416 if (flags.bAlternativeTool)
418 // Invert external vs. internal diff tool selection.
419 if (bCommentedOut)
420 viewer.Delete(0); // uncomment
421 else
422 viewer = "";
424 else if (bCommentedOut)
425 viewer = "";
428 bool bInternal = viewer.IsEmpty();
429 if (bInternal)
431 viewer =
432 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
433 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
434 if (flags.bBlame)
435 viewer += _T(" /blame");
437 // check if the params are set. If not, just add the files to the command line
438 if ((viewer.Find(_T("%base"))<0)&&(viewer.Find(_T("%mine"))<0))
440 viewer += _T(" \"")+file1+_T("\"");
441 viewer += _T(" \"")+file2+_T("\"");
443 if (viewer.Find(_T("%base")) >= 0)
445 viewer.Replace(_T("%base"), _T("\"")+file1+_T("\""));
447 if (viewer.Find(_T("%mine")) >= 0)
449 viewer.Replace(_T("%mine"), _T("\"")+file2+_T("\""));
452 if (sName1.IsEmpty())
453 viewer.Replace(_T("%bname"), _T("\"") + file1 + _T("\""));
454 else
455 viewer.Replace(_T("%bname"), _T("\"") + sName1 + _T("\""));
457 if (sName2.IsEmpty())
458 viewer.Replace(_T("%yname"), _T("\"") + file2 + _T("\""));
459 else
460 viewer.Replace(_T("%yname"), _T("\"") + sName2 + _T("\""));
462 if (flags.bReadOnly && bInternal)
463 viewer += _T(" /readonly");
465 return LaunchApplication(viewer, IDS_ERR_EXTDIFFSTART, flags.bWait);
468 BOOL CAppUtils::StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait)
470 CString viewer;
471 CRegString v = CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
472 viewer = v;
473 if (viewer.IsEmpty() || (viewer.Left(1).Compare(_T("#"))==0))
475 // use TortoiseUDiff
476 viewer = CPathUtils::GetAppDirectory();
477 viewer += _T("TortoiseUDiff.exe");
478 // enquote the path to TortoiseUDiff
479 viewer = _T("\"") + viewer + _T("\"");
480 // add the params
481 viewer = viewer + _T(" /patchfile:%1 /title:\"%title\"");
484 if (viewer.Find(_T("%1"))>=0)
486 if (viewer.Find(_T("\"%1\"")) >= 0)
487 viewer.Replace(_T("%1"), patchfile);
488 else
489 viewer.Replace(_T("%1"), _T("\"") + patchfile + _T("\""));
491 else
492 viewer += _T(" \"") + patchfile + _T("\"");
493 if (viewer.Find(_T("%title")) >= 0)
495 viewer.Replace(_T("%title"), title);
498 if(!LaunchApplication(viewer, IDS_ERR_DIFFVIEWSTART, !!bWait))
500 return FALSE;
502 return TRUE;
505 BOOL CAppUtils::StartTextViewer(CString file)
507 CString viewer;
508 CRegString txt = CRegString(_T(".txt\\"), _T(""), FALSE, HKEY_CLASSES_ROOT);
509 viewer = txt;
510 viewer = viewer + _T("\\Shell\\Open\\Command\\");
511 CRegString txtexe = CRegString(viewer, _T(""), FALSE, HKEY_CLASSES_ROOT);
512 viewer = txtexe;
514 DWORD len = ExpandEnvironmentStrings(viewer, NULL, 0);
515 TCHAR * buf = new TCHAR[len+1];
516 ExpandEnvironmentStrings(viewer, buf, len);
517 viewer = buf;
518 delete [] buf;
519 len = ExpandEnvironmentStrings(file, NULL, 0);
520 buf = new TCHAR[len+1];
521 ExpandEnvironmentStrings(file, buf, len);
522 file = buf;
523 delete [] buf;
524 file = _T("\"")+file+_T("\"");
525 if (viewer.IsEmpty())
527 viewer = _T("RUNDLL32 Shell32,OpenAs_RunDLL");
529 if (viewer.Find(_T("\"%1\"")) >= 0)
531 viewer.Replace(_T("\"%1\""), file);
533 else if (viewer.Find(_T("%1")) >= 0)
535 viewer.Replace(_T("%1"), file);
537 else
539 viewer += _T(" ");
540 viewer += file;
543 if(!LaunchApplication(viewer, IDS_ERR_TEXTVIEWSTART, false))
545 return FALSE;
547 return TRUE;
550 BOOL CAppUtils::CheckForEmptyDiff(const CTGitPath& sDiffPath)
552 DWORD length = 0;
553 HANDLE hFile = ::CreateFile(sDiffPath.GetWinPath(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
554 if (hFile == INVALID_HANDLE_VALUE)
555 return TRUE;
556 length = ::GetFileSize(hFile, NULL);
557 ::CloseHandle(hFile);
558 if (length < 4)
559 return TRUE;
560 return FALSE;
564 void CAppUtils::CreateFontForLogs(CFont& fontToCreate)
566 LOGFONT logFont;
567 HDC hScreenDC = ::GetDC(NULL);
568 logFont.lfHeight = -MulDiv((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC, LOGPIXELSY), 72);
569 ::ReleaseDC(NULL, hScreenDC);
570 logFont.lfWidth = 0;
571 logFont.lfEscapement = 0;
572 logFont.lfOrientation = 0;
573 logFont.lfWeight = FW_NORMAL;
574 logFont.lfItalic = 0;
575 logFont.lfUnderline = 0;
576 logFont.lfStrikeOut = 0;
577 logFont.lfCharSet = DEFAULT_CHARSET;
578 logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
579 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
580 logFont.lfQuality = DRAFT_QUALITY;
581 logFont.lfPitchAndFamily = FF_DONTCARE | FIXED_PITCH;
582 _tcscpy_s(logFont.lfFaceName, 32, (LPCTSTR)(CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
583 VERIFY(fontToCreate.CreateFontIndirect(&logFont));
586 bool CAppUtils::LaunchApplication(const CString& sCommandLine, UINT idErrMessageFormat, bool bWaitForStartup)
588 STARTUPINFO startup;
589 PROCESS_INFORMATION process;
590 memset(&startup, 0, sizeof(startup));
591 startup.cb = sizeof(startup);
592 memset(&process, 0, sizeof(process));
594 CString cleanCommandLine(sCommandLine);
596 if (CreateProcess(NULL, const_cast<TCHAR*>((LPCTSTR)cleanCommandLine), NULL, NULL, FALSE, 0, 0, g_Git.m_CurrentDir, &startup, &process)==0)
598 if(idErrMessageFormat != 0)
600 CString temp;
601 temp.Format(idErrMessageFormat, CFormatMessageWrapper());
602 MessageBox(NULL, temp, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
604 return false;
607 if (bWaitForStartup)
609 WaitForInputIdle(process.hProcess, 10000);
612 CloseHandle(process.hThread);
613 CloseHandle(process.hProcess);
614 return true;
616 bool CAppUtils::LaunchPAgent(CString *keyfile,CString * pRemote)
618 CString key,remote;
619 CString cmd,out;
620 if( pRemote == NULL)
622 remote=_T("origin");
624 else
626 remote=*pRemote;
628 if(keyfile == NULL)
630 cmd.Format(_T("remote.%s.puttykeyfile"),remote);
631 key = g_Git.GetConfigValue(cmd);
632 int start=0;
633 key = key.Tokenize(_T("\n"),start);
635 else
636 key=*keyfile;
638 if(key.IsEmpty())
639 return false;
641 CString proc=CPathUtils::GetAppDirectory();
642 proc += _T("pageant.exe \"");
643 proc += key;
644 proc += _T("\"");
646 CString tempfile = GetTempFile();
647 ::DeleteFile(tempfile);
649 proc += _T(" -c \"");
650 proc += CPathUtils::GetAppDirectory();
651 proc += _T("touch.exe\"");
652 proc += _T(" \"");
653 proc += tempfile;
654 proc += _T("\"");
656 bool b = LaunchApplication(proc, IDS_ERR_PAGEANT, true);
657 if(!b)
658 return b;
660 int i=0;
661 while(!::PathFileExists(tempfile))
663 Sleep(100);
664 i++;
665 if(i>10*60*5)
666 break; //timeout 5 minutes
669 if( i== 10*60*5)
671 CMessageBox::Show(NULL, _T("Fail wait for pageant finish load key"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
673 ::DeleteFile(tempfile);
674 return true;
676 bool CAppUtils::LaunchAlternativeEditor(const CString& filename)
678 CString editTool = CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
679 if (editTool.IsEmpty() || (editTool.Left(1).Compare(_T("#"))==0)) {
680 editTool = CPathUtils::GetAppDirectory() + _T("notepad2.exe");
683 CString sCmd;
684 sCmd.Format(_T("\"%s\" \"%s\""), editTool, filename);
686 LaunchApplication(sCmd, NULL, false);
687 return true;
689 bool CAppUtils::LaunchRemoteSetting()
691 CTGitPath path(g_Git.m_CurrentDir);
692 CSettings dlg(IDS_PROC_SETTINGS_TITLE, &path);
693 dlg.SetTreeViewMode(TRUE, TRUE, TRUE);
694 //dlg.SetTreeWidth(220);
695 dlg.m_DefaultPage = _T("gitremote");
697 dlg.DoModal();
698 dlg.HandleRestart();
699 return true;
702 * Launch the external blame viewer
704 bool CAppUtils::LaunchTortoiseBlame(const CString& sBlameFile,CString Rev,const CString& sParams)
706 CString viewer = _T("\"") + CPathUtils::GetAppDirectory();
707 viewer += _T("TortoiseGitBlame.exe");
708 viewer += _T("\" \"") + sBlameFile + _T("\"");
709 //viewer += _T(" \"") + sLogFile + _T("\"");
710 //viewer += _T(" \"") + sOriginalFile + _T("\"");
711 if(!Rev.IsEmpty() && Rev != GIT_REV_ZERO)
712 viewer += CString(_T(" /rev:"))+Rev;
713 viewer += _T(" ")+sParams;
715 return LaunchApplication(viewer, IDS_ERR_TGITBLAME, false);
718 bool CAppUtils::FormatTextInRichEditControl(CWnd * pWnd)
720 CString sText;
721 if (pWnd == NULL)
722 return false;
723 bool bStyled = false;
724 pWnd->GetWindowText(sText);
725 // the rich edit control doesn't count the CR char!
726 // to be exact: CRLF is treated as one char.
727 sText.Remove('\r');
729 // style each line separately
730 int offset = 0;
731 int nNewlinePos;
734 nNewlinePos = sText.Find('\n', offset);
735 CString sLine = sText.Mid(offset);
736 if (nNewlinePos>=0)
737 sLine = sLine.Left(nNewlinePos-offset);
738 int start = 0;
739 int end = 0;
740 while (FindStyleChars(sLine, '*', start, end))
742 CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
743 pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
744 CHARFORMAT2 format;
745 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
746 format.cbSize = sizeof(CHARFORMAT2);
747 format.dwMask = CFM_BOLD;
748 format.dwEffects = CFE_BOLD;
749 pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
750 bStyled = true;
751 start = end;
753 start = 0;
754 end = 0;
755 while (FindStyleChars(sLine, '^', start, end))
757 CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
758 pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
759 CHARFORMAT2 format;
760 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
761 format.cbSize = sizeof(CHARFORMAT2);
762 format.dwMask = CFM_ITALIC;
763 format.dwEffects = CFE_ITALIC;
764 pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
765 bStyled = true;
766 start = end;
768 start = 0;
769 end = 0;
770 while (FindStyleChars(sLine, '_', start, end))
772 CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
773 pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
774 CHARFORMAT2 format;
775 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
776 format.cbSize = sizeof(CHARFORMAT2);
777 format.dwMask = CFM_UNDERLINE;
778 format.dwEffects = CFE_UNDERLINE;
779 pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
780 bStyled = true;
781 start = end;
783 offset = nNewlinePos+1;
784 } while(nNewlinePos>=0);
785 return bStyled;
788 bool CAppUtils::FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end)
790 int i=start;
791 bool bFoundMarker = false;
792 // find a starting marker
793 while (sText[i] != 0)
795 if (sText[i] == stylechar)
797 if (((i+1)<sText.GetLength())&&(IsCharAlphaNumeric(sText[i+1])) &&
798 (((i>0)&&(!IsCharAlphaNumeric(sText[i-1])))||(i==0)))
800 start = i+1;
801 i++;
802 bFoundMarker = true;
803 break;
806 i++;
808 if (!bFoundMarker)
809 return false;
810 // find ending marker
811 bFoundMarker = false;
812 while (sText[i] != 0)
814 if (sText[i] == stylechar)
816 if ((IsCharAlphaNumeric(sText[i-1])) &&
817 ((((i+1)<sText.GetLength())&&(!IsCharAlphaNumeric(sText[i+1])))||(i+1)==sText.GetLength()))
819 end = i;
820 i++;
821 bFoundMarker = true;
822 break;
825 i++;
827 return bFoundMarker;
830 bool CAppUtils::FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner)
832 OPENFILENAME ofn = {0}; // common dialog box structure
833 TCHAR szFile[MAX_PATH] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
834 ofn.lStructSize = sizeof(OPENFILENAME);
835 ofn.hwndOwner = hwndOwner;
836 _tcscpy_s(szFile, MAX_PATH, (LPCTSTR)path);
837 ofn.lpstrFile = szFile;
838 ofn.nMaxFile = _countof(szFile);
839 CString sFilter;
840 TCHAR * pszFilters = NULL;
841 if (filter)
843 sFilter.LoadString(filter);
844 pszFilters = new TCHAR[sFilter.GetLength()+4];
845 _tcscpy_s (pszFilters, sFilter.GetLength()+4, sFilter);
846 // Replace '|' delimiters with '\0's
847 TCHAR *ptr = pszFilters + _tcslen(pszFilters); //set ptr at the NULL
848 while (ptr != pszFilters)
850 if (*ptr == '|')
851 *ptr = '\0';
852 ptr--;
854 ofn.lpstrFilter = pszFilters;
856 ofn.nFilterIndex = 1;
857 ofn.lpstrFileTitle = NULL;
858 ofn.nMaxFileTitle = 0;
859 ofn.lpstrInitialDir = NULL;
860 CString temp;
861 if (title)
863 temp.LoadString(title);
864 CStringUtils::RemoveAccelerators(temp);
866 ofn.lpstrTitle = temp;
867 if (bOpen)
868 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
869 else
870 ofn.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER;
873 // Display the Open dialog box.
874 bool bRet = false;
875 if (bOpen)
877 bRet = !!GetOpenFileName(&ofn);
879 else
881 bRet = !!GetSaveFileName(&ofn);
883 if (bRet)
885 if (pszFilters)
886 delete [] pszFilters;
887 path = CString(ofn.lpstrFile);
888 if (filterindex)
889 *filterindex = ofn.nFilterIndex;
890 return true;
892 if (pszFilters)
893 delete [] pszFilters;
894 return false;
897 bool CAppUtils::SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width /* = 128 */, int height /* = 128 */)
899 ListView_SetTextBkColor(hListCtrl, CLR_NONE);
900 COLORREF bkColor = ListView_GetBkColor(hListCtrl);
901 // create a bitmap from the icon
902 HICON hIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(nID), IMAGE_ICON, width, height, LR_DEFAULTCOLOR);
903 if (!hIcon)
904 return false;
906 RECT rect = {0};
907 rect.right = width;
908 rect.bottom = height;
909 HBITMAP bmp = NULL;
911 HWND desktop = ::GetDesktopWindow();
912 if (desktop)
914 HDC screen_dev = ::GetDC(desktop);
915 if (screen_dev)
917 // Create a compatible DC
918 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
919 if (dst_hdc)
921 // Create a new bitmap of icon size
922 bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
923 if (bmp)
925 // Select it into the compatible DC
926 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
927 // Fill the background of the compatible DC with the given color
928 ::SetBkColor(dst_hdc, bkColor);
929 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
931 // Draw the icon into the compatible DC
932 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
933 ::SelectObject(dst_hdc, old_dst_bmp);
935 ::DeleteDC(dst_hdc);
938 ::ReleaseDC(desktop, screen_dev);
941 // Restore settings
942 DestroyIcon(hIcon);
944 if (bmp == NULL)
945 return false;
947 LVBKIMAGE lv;
948 lv.ulFlags = LVBKIF_TYPE_WATERMARK;
949 lv.hbm = bmp;
950 lv.xOffsetPercent = 100;
951 lv.yOffsetPercent = 100;
952 ListView_SetBkImage(hListCtrl, &lv);
953 return true;
956 CString CAppUtils::GetProjectNameFromURL(CString url)
958 CString name;
959 while (name.IsEmpty() || (name.CompareNoCase(_T("branches"))==0) ||
960 (name.CompareNoCase(_T("tags"))==0) ||
961 (name.CompareNoCase(_T("trunk"))==0))
963 name = url.Mid(url.ReverseFind('/')+1);
964 url = url.Left(url.ReverseFind('/'));
966 if ((name.Compare(_T("svn")) == 0)||(name.Compare(_T("svnroot")) == 0))
968 // a name of svn or svnroot indicates that it's not really the project name. In that
969 // case, we try the first part of the URL
970 // of course, this won't work in all cases (but it works for Google project hosting)
971 url.Replace(_T("http://"), _T(""));
972 url.Replace(_T("https://"), _T(""));
973 url.Replace(_T("svn://"), _T(""));
974 url.Replace(_T("svn+ssh://"), _T(""));
975 url.TrimLeft(_T("/"));
976 name = url.Left(url.Find('.'));
978 return name;
981 bool CAppUtils::StartShowUnifiedDiff(HWND /*hWnd*/, const CTGitPath& url1, const git_revnum_t& rev1,
982 const CTGitPath& /*url2*/, const git_revnum_t& rev2,
983 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
984 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge)
987 CString tempfile=GetTempFile();
988 CString cmd;
989 if(rev1 == GitRev::GetWorkingCopy())
991 cmd.Format(_T("git.exe diff --stat -p %s "),rev2);
993 else
995 CString merge;
996 if(bMerge)
997 merge = _T("-c");
999 cmd.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge, rev1,rev2);
1002 if( !url1.IsEmpty() )
1004 cmd += _T(" -- \"");
1005 cmd += url1.GetGitPathString();
1006 cmd += _T("\" ");
1008 g_Git.RunLogFile(cmd,tempfile);
1009 CAppUtils::StartUnifiedDiffViewer(tempfile,rev1.Left(6)+_T(":")+rev2.Left(6));
1012 #if 0
1013 CString sCmd;
1014 sCmd.Format(_T("%s /command:showcompare /unified"),
1015 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1016 sCmd += _T(" /url1:\"") + url1.GetGitPathString() + _T("\"");
1017 if (rev1.IsValid())
1018 sCmd += _T(" /revision1:") + rev1.ToString();
1019 sCmd += _T(" /url2:\"") + url2.GetGitPathString() + _T("\"");
1020 if (rev2.IsValid())
1021 sCmd += _T(" /revision2:") + rev2.ToString();
1022 if (peg.IsValid())
1023 sCmd += _T(" /pegrevision:") + peg.ToString();
1024 if (headpeg.IsValid())
1025 sCmd += _T(" /headpegrevision:") + headpeg.ToString();
1027 if (bAlternateDiff)
1028 sCmd += _T(" /alternatediff");
1030 if (bIgnoreAncestry)
1031 sCmd += _T(" /ignoreancestry");
1033 if (hWnd)
1035 sCmd += _T(" /hwnd:");
1036 TCHAR buf[30];
1037 _stprintf_s(buf, 30, _T("%d"), hWnd);
1038 sCmd += buf;
1041 return CAppUtils::LaunchApplication(sCmd, NULL, false);
1042 #endif
1043 return TRUE;
1047 bool CAppUtils::Export(CString *BashHash)
1049 bool bRet = false;
1051 // ask from where the export has to be done
1052 CExportDlg dlg;
1053 if(BashHash)
1054 dlg.m_Revision=*BashHash;
1056 if (dlg.DoModal() == IDOK)
1058 CString cmd;
1059 cmd.Format(_T("git.exe archive --output=\"%s\" --format=zip --verbose %s"),
1060 dlg.m_strExportDirectory, g_Git.FixBranchName(dlg.m_VersionName));
1062 CProgressDlg pro;
1063 pro.m_GitCmd=cmd;
1064 pro.DoModal();
1065 return TRUE;
1067 return bRet;
1070 bool CAppUtils::CreateBranchTag(bool IsTag,CString *CommitHash, bool switch_new_brach)
1072 CCreateBranchTagDlg dlg;
1073 dlg.m_bIsTag=IsTag;
1074 dlg.m_bSwitch=switch_new_brach;
1076 if(CommitHash)
1077 dlg.m_Base = *CommitHash;
1079 if(dlg.DoModal()==IDOK)
1081 CString cmd;
1082 CString force;
1083 CString track;
1084 if(dlg.m_bTrack)
1085 track=_T(" --track ");
1087 if(dlg.m_bForce)
1088 force=_T(" -f ");
1090 if(IsTag)
1092 CString sign;
1093 if(dlg.m_bSign)
1094 sign=_T("-s");
1096 cmd.Format(_T("git.exe tag %s %s %s %s %s"),
1097 track,
1098 force,
1099 sign,
1100 dlg.m_BranchTagName,
1101 g_Git.FixBranchName(dlg.m_VersionName)
1104 CString tempfile=::GetTempFile();
1105 if(!dlg.m_Message.Trim().IsEmpty())
1107 CAppUtils::SaveCommitUnicodeFile(tempfile,dlg.m_Message);
1108 cmd += _T(" -F ")+tempfile;
1111 else
1113 cmd.Format(_T("git.exe branch %s %s %s %s"),
1114 track,
1115 force,
1116 dlg.m_BranchTagName,
1117 g_Git.FixBranchName(dlg.m_VersionName)
1120 CString out;
1121 if(g_Git.Run(cmd,&out,CP_UTF8))
1123 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1125 if( !IsTag && dlg.m_bSwitch )
1127 // it is a new branch and the user has requested to switch to it
1128 cmd.Format(_T("git.exe checkout %s"), dlg.m_BranchTagName);
1129 g_Git.Run(cmd,&out,CP_UTF8);
1130 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1133 return TRUE;
1135 return FALSE;
1138 bool CAppUtils::Switch(CString *CommitHash, CString initialRefName, bool autoclose)
1140 CGitSwitchDlg dlg;
1141 if(CommitHash)
1142 dlg.m_Base=*CommitHash;
1143 if(!initialRefName.IsEmpty())
1144 dlg.m_initialRefName = initialRefName;
1146 if (dlg.DoModal() == IDOK)
1148 CString branch;
1149 if (dlg.m_bBranch)
1150 branch = dlg.m_NewBranch;
1152 return PerformSwitch(dlg.m_VersionName, dlg.m_bForce == TRUE , branch, dlg.m_bBranchOverride == TRUE, dlg.m_bTrack == TRUE, autoclose);
1154 return FALSE;
1157 bool CAppUtils::PerformSwitch(CString ref, bool bForce /* false */, CString sNewBranch /* CString() */, bool bBranchOverride /* false */, bool bTrack /* false */, bool autoClose /* false */)
1159 CString cmd;
1160 CString track;
1161 CString force;
1162 CString branch;
1164 if(!sNewBranch.IsEmpty()){
1165 if (bBranchOverride)
1167 branch.Format(_T("-B %s"), sNewBranch);
1169 else
1171 branch.Format(_T("-b %s"), sNewBranch);
1173 if (bTrack)
1174 track = _T("--track");
1176 if (bForce)
1177 force = _T("-f");
1179 cmd.Format(_T("git.exe checkout %s %s %s %s"),
1180 force,
1181 track,
1182 branch,
1183 g_Git.FixBranchName(ref));
1185 CProgressDlg progress;
1186 progress.m_bAutoCloseOnSuccess = autoClose;
1187 progress.m_GitCmd = cmd;
1189 CTGitPath gitPath = g_Git.m_CurrentDir;
1190 if (gitPath.HasSubmodules())
1191 progress.m_PostCmdList.Add(_T("Update Submodules"));
1193 int ret = progress.DoModal();
1194 if (gitPath.HasSubmodules() && ret == IDC_PROGRESS_BUTTON1)
1196 CString sCmd;
1197 sCmd.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR)(CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe")), (LPCTSTR)g_Git.m_CurrentDir);
1199 LaunchApplication(sCmd, NULL, false);
1200 return TRUE;
1202 else if (ret == IDOK)
1203 return TRUE;
1205 return FALSE;
1208 bool CAppUtils::IgnoreFile(CTGitPathList &path,bool IsMask)
1210 CString ignorefile;
1211 ignorefile=g_Git.m_CurrentDir+_T("\\");
1213 if(IsMask)
1215 ignorefile+=path.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1218 else
1220 ignorefile += _T("\\.gitignore");
1223 CStdioFile file;
1224 if(!file.Open(ignorefile,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate))
1226 CMessageBox::Show(NULL,ignorefile+_T(" Open Failure"),_T("TortoiseGit"),MB_OK);
1227 return FALSE;
1230 CString ignorelist;
1231 CString mask;
1234 //file.ReadString(ignorelist);
1235 file.SeekToEnd();
1236 for(int i=0;i<path.GetCount();i++)
1238 if(IsMask)
1240 mask=_T("*")+path[i].GetFileExtension();
1241 if(ignorelist.Find(mask)<0)
1242 ignorelist += _T("\n")+mask;
1244 else
1246 ignorelist += _T("\n/")+path[i].GetGitPathString();
1249 file.WriteString(ignorelist);
1251 file.Close();
1253 }catch(...)
1255 file.Close();
1256 return FALSE;
1259 return TRUE;
1263 bool CAppUtils::GitReset(CString *CommitHash,int type)
1265 CResetDlg dlg;
1266 dlg.m_ResetType=type;
1267 dlg.m_ResetToVersion=*CommitHash;
1268 if (dlg.DoModal() == IDOK)
1270 CString cmd;
1271 CString type;
1272 switch(dlg.m_ResetType)
1274 case 0:
1275 type=_T("--soft");
1276 break;
1277 case 1:
1278 type=_T("--mixed");
1279 break;
1280 case 2:
1281 type=_T("--hard");
1282 break;
1283 default:
1284 type=_T("--mixed");
1285 break;
1287 cmd.Format(_T("git.exe reset %s %s"),type, *CommitHash);
1289 CProgressDlg progress;
1290 progress.m_GitCmd=cmd;
1292 CTGitPath gitPath = g_Git.m_CurrentDir;
1293 if (gitPath.HasSubmodules() && dlg.m_ResetType == 2)
1294 progress.m_PostCmdList.Add(_T("Update Submodules"));
1296 int ret = progress.DoModal();
1297 if (gitPath.HasSubmodules() && dlg.m_ResetType == 2 && ret == IDC_PROGRESS_BUTTON1)
1299 CString sCmd;
1300 sCmd.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)g_Git.m_CurrentDir);
1302 LaunchApplication(sCmd, NULL, false);
1303 return TRUE;
1305 else if (ret == IDOK)
1306 return TRUE;
1309 return FALSE;
1312 void CAppUtils::DescribeFile(bool mode, bool base,CString &descript)
1314 if(mode == FALSE)
1316 descript=_T("Deleted");
1317 return;
1319 if(base)
1321 descript=_T("Modified");
1322 return;
1324 descript=_T("Created");
1325 return;
1328 void CAppUtils::RemoveTempMergeFile(CTGitPath &path)
1330 CString tempmergefile;
1333 tempmergefile = CAppUtils::GetMergeTempFile(_T("LOCAL"),path);
1334 CFile::Remove(tempmergefile);
1335 }catch(...)
1341 tempmergefile = CAppUtils::GetMergeTempFile(_T("REMOTE"),path);
1342 CFile::Remove(tempmergefile);
1343 }catch(...)
1349 tempmergefile = CAppUtils::GetMergeTempFile(_T("BASE"),path);
1350 CFile::Remove(tempmergefile);
1351 }catch(...)
1355 CString CAppUtils::GetMergeTempFile(CString type,CTGitPath &merge)
1357 CString file;
1358 file=g_Git.m_CurrentDir+_T("\\") + merge.GetWinPathString()+_T(".")+type+merge.GetFileExtension();
1360 return file;
1363 bool CAppUtils::ConflictEdit(CTGitPath &path,bool /*bAlternativeTool*/,bool revertTheirMy)
1365 bool bRet = false;
1367 CTGitPath merge=path;
1368 CTGitPath directory = merge.GetDirectory();
1370 // we have the conflicted file (%merged)
1371 // now look for the other required files
1372 //GitStatus stat;
1373 //stat.GetStatus(merge);
1374 //if (stat.status == NULL)
1375 // return false;
1377 BYTE_VECTOR vector;
1379 CString cmd;
1380 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge.GetGitPathString());
1382 if (g_Git.Run(cmd, &vector))
1384 return FALSE;
1387 CTGitPathList list;
1388 list.ParserFromLsFile(vector);
1390 if(list.GetCount() == 0)
1391 return FALSE;
1393 CTGitPath theirs;
1394 CTGitPath mine;
1395 CTGitPath base;
1397 mine.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge));
1398 theirs.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge));
1399 base.SetFromGit(GetMergeTempFile(_T("BASE"),merge));
1401 CString format;
1403 //format=_T("git.exe cat-file blob \":%d:%s\"");
1404 format = _T("git checkout-index --temp --stage=%d -- \"%s\"");
1405 CFile tempfile;
1406 //create a empty file, incase stage is not three
1407 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1408 tempfile.Close();
1409 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1410 tempfile.Close();
1411 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1412 tempfile.Close();
1414 bool b_base=false, b_local=false, b_remote=false;
1416 for(int i=0;i<list.GetCount();i++)
1418 CString cmd;
1419 CString outfile;
1420 cmd.Empty();
1421 outfile.Empty();
1423 if( list[i].m_Stage == 1)
1425 cmd.Format(format, list[i].m_Stage, list[i].GetGitPathString());
1426 b_base = true;
1427 outfile = base.GetWinPathString();
1430 if( list[i].m_Stage == 2 )
1432 cmd.Format(format, list[i].m_Stage, list[i].GetGitPathString());
1433 b_local = true;
1434 outfile = mine.GetWinPathString();
1437 if( list[i].m_Stage == 3 )
1439 cmd.Format(format, list[i].m_Stage, list[i].GetGitPathString());
1440 b_remote = true;
1441 outfile = theirs.GetWinPathString();
1443 CString output, err;
1444 if(!outfile.IsEmpty())
1445 if (!g_Git.Run(cmd, &output, &err, CP_ACP))
1447 CString file;
1448 int start =0 ;
1449 file = output.Tokenize(_T("\t"), start);
1450 ::MoveFileEx(file,outfile,MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED);
1452 else
1454 CMessageBox::Show(NULL, output + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
1458 if(b_local && b_remote )
1460 merge.SetFromWin(g_Git.m_CurrentDir+_T("\\")+merge.GetWinPathString());
1461 if( revertTheirMy )
1462 bRet = !!CAppUtils::StartExtMerge(base,mine, theirs, merge,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1463 else
1464 bRet = !!CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1467 else
1469 CFile::Remove(mine.GetWinPathString());
1470 CFile::Remove(theirs.GetWinPathString());
1471 CFile::Remove(base.GetWinPathString());
1473 CDeleteConflictDlg dlg;
1474 DescribeFile(b_local, b_base,dlg.m_LocalStatus);
1475 DescribeFile(b_remote,b_base,dlg.m_RemoteStatus);
1476 dlg.m_bShowModifiedButton=b_base;
1477 dlg.m_File=merge.GetGitPathString();
1478 if(dlg.DoModal() == IDOK)
1480 CString cmd,out;
1481 if(dlg.m_bIsDelete)
1483 cmd.Format(_T("git.exe rm -- \"%s\""),merge.GetGitPathString());
1485 else
1486 cmd.Format(_T("git.exe add -- \"%s\""),merge.GetGitPathString());
1488 if(g_Git.Run(cmd,&out,CP_ACP))
1490 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1491 return FALSE;
1493 return TRUE;
1495 else
1496 return FALSE;
1499 #if 0
1500 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1501 base, theirs, mine, merge);
1502 #endif
1503 #if 0
1504 if (stat.status->text_status == svn_wc_status_conflicted)
1506 // we have a text conflict, use our merge tool to resolve the conflict
1508 CTSVNPath theirs(directory);
1509 CTSVNPath mine(directory);
1510 CTSVNPath base(directory);
1511 bool bConflictData = false;
1513 if ((stat.status->entry)&&(stat.status->entry->conflict_new))
1515 theirs.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_new));
1516 bConflictData = true;
1518 if ((stat.status->entry)&&(stat.status->entry->conflict_old))
1520 base.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_old));
1521 bConflictData = true;
1523 if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
1525 mine.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_wrk));
1526 bConflictData = true;
1528 else
1530 mine = merge;
1532 if (bConflictData)
1533 bRet = !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1534 base, theirs, mine, merge);
1537 if (stat.status->prop_status == svn_wc_status_conflicted)
1539 // we have a property conflict
1540 CTSVNPath prej(directory);
1541 if ((stat.status->entry)&&(stat.status->entry->prejfile))
1543 prej.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->prejfile));
1544 // there's a problem: the prej file contains a _description_ of the conflict, and
1545 // that description string might be translated. That means we have no way of parsing
1546 // the file to find out the conflicting values.
1547 // The only thing we can do: show a dialog with the conflict description, then
1548 // let the user either accept the existing property or open the property edit dialog
1549 // to manually change the properties and values. And a button to mark the conflict as
1550 // resolved.
1551 CEditPropConflictDlg dlg;
1552 dlg.SetPrejFile(prej);
1553 dlg.SetConflictedItem(merge);
1554 bRet = (dlg.DoModal() != IDCANCEL);
1558 if (stat.status->tree_conflict)
1560 // we have a tree conflict
1561 SVNInfo info;
1562 const SVNInfoData * pInfoData = info.GetFirstFileInfo(merge, SVNRev(), SVNRev());
1563 if (pInfoData)
1565 if (pInfoData->treeconflict_kind == svn_wc_conflict_kind_text)
1567 CTSVNPath theirs(directory);
1568 CTSVNPath mine(directory);
1569 CTSVNPath base(directory);
1570 bool bConflictData = false;
1572 if (pInfoData->treeconflict_theirfile)
1574 theirs.AppendPathString(pInfoData->treeconflict_theirfile);
1575 bConflictData = true;
1577 if (pInfoData->treeconflict_basefile)
1579 base.AppendPathString(pInfoData->treeconflict_basefile);
1580 bConflictData = true;
1582 if (pInfoData->treeconflict_myfile)
1584 mine.AppendPathString(pInfoData->treeconflict_myfile);
1585 bConflictData = true;
1587 else
1589 mine = merge;
1591 if (bConflictData)
1592 bRet = !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1593 base, theirs, mine, merge);
1595 else if (pInfoData->treeconflict_kind == svn_wc_conflict_kind_tree)
1597 CString sConflictAction;
1598 CString sConflictReason;
1599 CString sResolveTheirs;
1600 CString sResolveMine;
1601 CTSVNPath treeConflictPath = CTSVNPath(pInfoData->treeconflict_path);
1602 CString sItemName = treeConflictPath.GetUIFileOrDirectoryName();
1604 if (pInfoData->treeconflict_nodekind == svn_node_file)
1606 switch (pInfoData->treeconflict_operation)
1608 case svn_wc_operation_update:
1609 switch (pInfoData->treeconflict_action)
1611 case svn_wc_conflict_action_edit:
1612 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEEDIT, (LPCTSTR)sItemName);
1613 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1614 break;
1615 case svn_wc_conflict_action_add:
1616 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEADD, (LPCTSTR)sItemName);
1617 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1618 break;
1619 case svn_wc_conflict_action_delete:
1620 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEDELETE, (LPCTSTR)sItemName);
1621 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1622 break;
1624 break;
1625 case svn_wc_operation_switch:
1626 switch (pInfoData->treeconflict_action)
1628 case svn_wc_conflict_action_edit:
1629 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHEDIT, (LPCTSTR)sItemName);
1630 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1631 break;
1632 case svn_wc_conflict_action_add:
1633 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHADD, (LPCTSTR)sItemName);
1634 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1635 break;
1636 case svn_wc_conflict_action_delete:
1637 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHDELETE, (LPCTSTR)sItemName);
1638 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1639 break;
1641 break;
1642 case svn_wc_operation_merge:
1643 switch (pInfoData->treeconflict_action)
1645 case svn_wc_conflict_action_edit:
1646 sConflictAction.Format(IDS_TREECONFLICT_FILEMERGEEDIT, (LPCTSTR)sItemName);
1647 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1648 break;
1649 case svn_wc_conflict_action_add:
1650 sResolveTheirs.Format(IDS_TREECONFLICT_FILEMERGEADD, (LPCTSTR)sItemName);
1651 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1652 break;
1653 case svn_wc_conflict_action_delete:
1654 sConflictAction.Format(IDS_TREECONFLICT_FILEMERGEDELETE, (LPCTSTR)sItemName);
1655 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1656 break;
1658 break;
1661 else if (pInfoData->treeconflict_nodekind == svn_node_dir)
1663 switch (pInfoData->treeconflict_operation)
1665 case svn_wc_operation_update:
1666 switch (pInfoData->treeconflict_action)
1668 case svn_wc_conflict_action_edit:
1669 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEEDIT, (LPCTSTR)sItemName);
1670 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1671 break;
1672 case svn_wc_conflict_action_add:
1673 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEADD, (LPCTSTR)sItemName);
1674 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1675 break;
1676 case svn_wc_conflict_action_delete:
1677 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEDELETE, (LPCTSTR)sItemName);
1678 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1679 break;
1681 break;
1682 case svn_wc_operation_switch:
1683 switch (pInfoData->treeconflict_action)
1685 case svn_wc_conflict_action_edit:
1686 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHEDIT, (LPCTSTR)sItemName);
1687 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1688 break;
1689 case svn_wc_conflict_action_add:
1690 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHADD, (LPCTSTR)sItemName);
1691 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1692 break;
1693 case svn_wc_conflict_action_delete:
1694 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHDELETE, (LPCTSTR)sItemName);
1695 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1696 break;
1698 break;
1699 case svn_wc_operation_merge:
1700 switch (pInfoData->treeconflict_action)
1702 case svn_wc_conflict_action_edit:
1703 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEEDIT, (LPCTSTR)sItemName);
1704 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1705 break;
1706 case svn_wc_conflict_action_add:
1707 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEADD, (LPCTSTR)sItemName);
1708 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1709 break;
1710 case svn_wc_conflict_action_delete:
1711 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEDELETE, (LPCTSTR)sItemName);
1712 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1713 break;
1715 break;
1719 UINT uReasonID = 0;
1720 switch (pInfoData->treeconflict_reason)
1722 case svn_wc_conflict_reason_edited:
1723 uReasonID = IDS_TREECONFLICT_REASON_EDITED;
1724 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1725 break;
1726 case svn_wc_conflict_reason_obstructed:
1727 uReasonID = IDS_TREECONFLICT_REASON_OBSTRUCTED;
1728 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1729 break;
1730 case svn_wc_conflict_reason_deleted:
1731 uReasonID = IDS_TREECONFLICT_REASON_DELETED;
1732 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_REMOVEDIR : IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1733 break;
1734 case svn_wc_conflict_reason_added:
1735 uReasonID = IDS_TREECONFLICT_REASON_ADDED;
1736 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1737 break;
1738 case svn_wc_conflict_reason_missing:
1739 uReasonID = IDS_TREECONFLICT_REASON_MISSING;
1740 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_REMOVEDIR : IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1741 break;
1742 case svn_wc_conflict_reason_unversioned:
1743 uReasonID = IDS_TREECONFLICT_REASON_UNVERSIONED;
1744 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1745 break;
1747 sConflictReason.Format(uReasonID, (LPCTSTR)sConflictAction);
1749 CTreeConflictEditorDlg dlg;
1750 dlg.SetConflictInfoText(sConflictReason);
1751 dlg.SetResolveTexts(sResolveTheirs, sResolveMine);
1752 dlg.SetPath(treeConflictPath);
1753 INT_PTR dlgRet = dlg.DoModal();
1754 bRet = (dlgRet != IDCANCEL);
1758 #endif
1759 return bRet;
1763 * FUNCTION : FormatDateAndTime
1764 * DESCRIPTION : Generates a displayable string from a CTime object in
1765 * system short or long format or as a relative value
1766 * cTime - the time
1767 * option - DATE_SHORTDATE or DATE_LONGDATE
1768 * bIncluedeTime - whether to show time as well as date
1769 * bRelative - if true then relative time is shown if reasonable
1770 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
1771 * rather than locale
1772 * RETURN : CString containing date/time
1774 CString CAppUtils::FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime /*=true*/,
1775 bool bRelative /*=false*/)
1777 CString datetime;
1778 if ( bRelative )
1780 datetime = ToRelativeTimeString( cTime );
1782 else
1784 // should we use the locale settings for formatting the date/time?
1785 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE))
1787 // yes
1788 SYSTEMTIME sysTime;
1789 cTime.GetAsSystemTime( sysTime );
1791 TCHAR buf[100];
1793 GetDateFormat(LOCALE_USER_DEFAULT, option, &sysTime, NULL, buf,
1794 _countof(buf) - 1);
1795 datetime = buf;
1796 if ( bIncludeTime )
1798 datetime += _T(" ");
1799 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, NULL, buf, _countof(buf) - 1);
1800 datetime += buf;
1803 else
1805 // no, so fixed format
1806 if ( bIncludeTime )
1808 datetime = cTime.Format(_T("%Y-%m-%d %H:%M:%S"));
1810 else
1812 datetime = cTime.Format(_T("%Y-%m-%d"));
1816 return datetime;
1820 * Converts a given time to a relative display string (relative to current time)
1821 * Given time must be in local timezone
1823 CString CAppUtils::ToRelativeTimeString(CTime time)
1825 CString answer;
1826 // convert to COleDateTime
1827 SYSTEMTIME sysTime;
1828 time.GetAsSystemTime( sysTime );
1829 COleDateTime oleTime( sysTime );
1830 answer = ToRelativeTimeString(oleTime, COleDateTime::GetCurrentTime());
1831 return answer;
1835 * Generates a display string showing the relative time between the two given times as COleDateTimes
1837 CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo)
1839 CString answer;
1840 COleDateTimeSpan ts = RelativeTo - time;
1841 //years
1842 if(fabs(ts.GetTotalDays()) >= 3*365)
1844 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/365, IDS_YEAR_AGO, IDS_YEARS_AGO );
1846 //Months
1847 if(fabs(ts.GetTotalDays()) >= 60)
1849 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/30, IDS_MONTH_AGO, IDS_MONTHS_AGO );
1850 return answer;
1852 //Weeks
1853 if(fabs(ts.GetTotalDays()) >= 14)
1855 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/7, IDS_WEEK_AGO, IDS_WEEKS_AGO );
1856 return answer;
1858 //Days
1859 if(fabs(ts.GetTotalDays()) >= 2)
1861 answer = ExpandRelativeTime( (int)ts.GetTotalDays(), IDS_DAY_AGO, IDS_DAYS_AGO );
1862 return answer;
1864 //hours
1865 if(fabs(ts.GetTotalHours()) >= 2)
1867 answer = ExpandRelativeTime( (int)ts.GetTotalHours(), IDS_HOUR_AGO, IDS_HOURS_AGO );
1868 return answer;
1870 //minutes
1871 if(fabs(ts.GetTotalMinutes()) >= 2)
1873 answer = ExpandRelativeTime( (int)ts.GetTotalMinutes(), IDS_MINUTE_AGO, IDS_MINUTES_AGO );
1874 return answer;
1876 //seconds
1877 answer = ExpandRelativeTime( (int)ts.GetTotalSeconds(), IDS_SECOND_AGO, IDS_SECONDS_AGO );
1878 return answer;
1882 * Passed a value and two resource string ids
1883 * if count is 1 then FormatString is called with format_1 and the value
1884 * otherwise format_2 is used
1885 * the formatted string is returned
1887 CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n )
1889 CString answer;
1890 if ( count == 1 )
1892 answer.FormatMessage( format_1, count );
1894 else
1896 answer.FormatMessage( format_n, count );
1898 return answer;
1901 bool CAppUtils::IsSSHPutty()
1903 CString sshclient=g_Git.m_Environment.GetEnv(_T("GIT_SSH"));
1904 sshclient=sshclient.MakeLower();
1905 if(sshclient.Find(_T("plink.exe"),0)>=0)
1907 return true;
1909 return false;
1912 CString CAppUtils::GetClipboardLink()
1914 if (!OpenClipboard(NULL))
1915 return CString();
1917 CString sClipboardText;
1918 HGLOBAL hglb = GetClipboardData(CF_TEXT);
1919 if (hglb)
1921 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
1922 sClipboardText = CString(lpstr);
1923 GlobalUnlock(hglb);
1925 hglb = GetClipboardData(CF_UNICODETEXT);
1926 if (hglb)
1928 LPCTSTR lpstr = (LPCTSTR)GlobalLock(hglb);
1929 sClipboardText = lpstr;
1930 GlobalUnlock(hglb);
1932 CloseClipboard();
1934 if(!sClipboardText.IsEmpty())
1936 if(sClipboardText[0] == _T('\"') && sClipboardText[sClipboardText.GetLength()-1] == _T('\"'))
1937 sClipboardText=sClipboardText.Mid(1,sClipboardText.GetLength()-2);
1939 if(sClipboardText.Find( _T("http://")) == 0)
1940 return sClipboardText;
1942 if(sClipboardText.Find( _T("https://")) == 0)
1943 return sClipboardText;
1945 if(sClipboardText.Find( _T("git://")) == 0)
1946 return sClipboardText;
1948 if(sClipboardText.Find( _T("ssh://")) == 0)
1949 return sClipboardText;
1951 if(sClipboardText.GetLength()>=2)
1952 if( sClipboardText[1] == _T(':') )
1953 if( (sClipboardText[0] >= 'A' && sClipboardText[0] <= 'Z')
1954 || (sClipboardText[0] >= 'a' && sClipboardText[0] <= 'z') )
1955 return sClipboardText;
1958 return CString(_T(""));
1961 CString CAppUtils::ChooseRepository(CString *path)
1963 CBrowseFolder browseFolder;
1964 CRegString regLastResopitory = CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1966 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
1967 CString strCloneDirectory;
1968 if(path)
1969 strCloneDirectory=*path;
1970 else
1972 strCloneDirectory = regLastResopitory;
1975 CString title;
1976 title.LoadString(IDS_CHOOSE_REPOSITORY);
1978 browseFolder.SetInfo(title);
1980 if (browseFolder.Show(NULL, strCloneDirectory) == CBrowseFolder::OK)
1982 regLastResopitory = strCloneDirectory;
1983 return strCloneDirectory;
1985 else
1987 return CString();
1991 bool CAppUtils::SendPatchMail(CTGitPathList &list,bool autoclose)
1993 CSendMailDlg dlg;
1995 dlg.m_PathList = list;
1997 if(dlg.DoModal()==IDOK)
1999 if(dlg.m_PathList.GetCount() == 0)
2000 return FALSE;
2002 CGitProgressDlg progDlg;
2004 theApp.m_pMainWnd = &progDlg;
2005 progDlg.SetCommand(CGitProgressDlg::GitProgress_SendMail);
2007 progDlg.SetAutoClose(autoclose);
2009 progDlg.SetPathList(dlg.m_PathList);
2010 //ProjectProperties props;
2011 //props.ReadPropsPathList(dlg.m_pathList);
2012 //progDlg.SetProjectProperties(props);
2013 progDlg.SetItemCount(dlg.m_PathList.GetCount());
2015 DWORD flags =0;
2016 if(dlg.m_bAttachment)
2017 flags |= SENDMAIL_ATTACHMENT;
2018 if(dlg.m_bCombine)
2019 flags |= SENDMAIL_COMBINED;
2020 if(dlg.m_bUseMAPI)
2021 flags |= SENDMAIL_MAPI;
2023 progDlg.SetSendMailOption(dlg.m_To,dlg.m_CC,dlg.m_Subject,flags);
2025 progDlg.DoModal();
2027 return true;
2029 return false;
2032 bool CAppUtils::SendPatchMail(CString &cmd,CString &formatpatchoutput,bool autoclose)
2034 CTGitPathList list;
2035 CString log=formatpatchoutput;
2036 int start=log.Find(cmd);
2037 if(start >=0)
2038 CString one=log.Tokenize(_T("\n"),start);
2039 else
2040 start = 0;
2042 while(start>=0)
2044 CString one=log.Tokenize(_T("\n"),start);
2045 one=one.Trim();
2046 if(one.IsEmpty() || one == _T("Success"))
2047 continue;
2048 one.Replace(_T('/'),_T('\\'));
2049 CTGitPath path;
2050 path.SetFromWin(one);
2051 list.AddPath(path);
2053 if (list.GetCount() > 0)
2055 return SendPatchMail(list, autoclose);
2057 else
2059 CMessageBox::Show(NULL, _T("Not patches generated."), _T("TortoiseGit"), MB_ICONINFORMATION);
2060 return true;
2065 int CAppUtils::GetLogOutputEncode(CGit *pGit)
2067 CString cmd,output;
2068 int start=0;
2070 output = pGit->GetConfigValue(_T("i18n.logOutputEncoding"));
2071 if(output.IsEmpty())
2073 output = pGit->GetConfigValue(_T("i18n.commitencoding"));
2074 if(output.IsEmpty())
2075 return CP_UTF8;
2077 int start=0;
2078 output=output.Tokenize(_T("\n"),start);
2079 return CUnicodeUtils::GetCPCode(output);
2082 else
2084 output=output.Tokenize(_T("\n"),start);
2085 return CUnicodeUtils::GetCPCode(output);
2088 int CAppUtils::GetCommitTemplate(CString &temp)
2090 CString cmd,output;
2092 output= g_Git.GetConfigValue(_T("commit.template"),CP_ACP);
2093 if( output.IsEmpty() )
2094 return -1;
2096 if( output.GetLength()<1)
2097 return -1;
2099 if( output[0] == _T('/'))
2101 if(output.GetLength()>=3)
2102 if(output[2] == _T('/'))
2104 output.GetBuffer()[0] = output[1];
2105 output.GetBuffer()[1] = _T(':');
2109 int start=0;
2110 output=output.Tokenize(_T("\n"),start);
2112 output.Replace(_T('/'),_T('\\'));
2116 CStdioFile file(output,CFile::modeRead|CFile::typeText);
2117 CString str;
2118 while(file.ReadString(str))
2120 temp+=str+_T("\n");
2123 }catch(...)
2125 return -1;
2127 return 0;
2129 int CAppUtils::SaveCommitUnicodeFile(CString &filename, CString &message)
2131 CFile file(filename,CFile::modeReadWrite|CFile::modeCreate );
2132 CString cmd,output;
2133 int cp=CP_UTF8;
2135 output= g_Git.GetConfigValue(_T("i18n.commitencoding"));
2136 if(output.IsEmpty())
2137 cp=CP_UTF8;
2139 int start=0;
2140 output=output.Tokenize(_T("\n"),start);
2141 cp=CUnicodeUtils::GetCPCode(output);
2143 int len=message.GetLength();
2145 char * buf;
2146 buf = new char[len*4 + 4];
2147 SecureZeroMemory(buf, (len*4 + 4));
2149 int lengthIncTerminator = WideCharToMultiByte(cp, 0, message, -1, buf, len*4, NULL, NULL);
2151 file.Write(buf,lengthIncTerminator-1);
2152 file.Close();
2153 delete buf;
2154 return 0;
2157 bool CAppUtils::Fetch(CString remoteName, bool allowRebase, bool autoClose)
2159 CPullFetchDlg dlg;
2160 dlg.m_PreSelectRemote = remoteName;
2161 dlg.m_bAllowRebase = allowRebase;
2162 dlg.m_IsPull=FALSE;
2164 if(dlg.DoModal()==IDOK)
2166 if(dlg.m_bAutoLoad)
2168 CAppUtils::LaunchPAgent(NULL,&dlg.m_RemoteURL);
2171 CString url;
2172 url=dlg.m_RemoteURL;
2173 CString cmd;
2174 CString arg;
2176 int ver = CAppUtils::GetMsysgitVersion();
2178 if(ver >= 0x01070203) //above 1.7.0.2
2179 arg = _T("--progress ");
2181 if (dlg.m_bPrune) {
2182 arg += _T("--prune ");
2185 if (dlg.m_bFetchTags) {
2186 arg += _T("--tags ");
2189 cmd.Format(_T("git.exe fetch -v %s \"%s\" %s"),arg, url,dlg.m_RemoteBranchName);
2190 CProgressDlg progress;
2192 progress.m_bAutoCloseOnSuccess = autoClose;
2194 progress.m_PostCmdList.Add(_T("Show Log"));
2196 if(!dlg.m_bRebase && !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir))
2198 progress.m_PostCmdList.Add(_T("&Rebase"));
2201 progress.m_GitCmd=cmd;
2202 int userResponse=progress.DoModal();
2204 if (userResponse == IDC_PROGRESS_BUTTON1)
2206 CString cmd;
2207 cmd = CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
2208 cmd += _T(" /command:log");
2209 cmd += _T(" /path:\"") + g_Git.m_CurrentDir + _T("\"");
2210 CAppUtils::LaunchApplication(cmd, IDS_ERR_PROC, false);
2211 return TRUE;
2213 else if ((userResponse == IDC_PROGRESS_BUTTON1 + 1) || (progress.m_GitStatus == 0 && dlg.m_bRebase))
2215 while(1)
2217 CRebaseDlg dlg;
2218 dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));
2219 dlg.m_PostButtonTexts.Add(_T("Restart Rebase"));
2220 int response = dlg.DoModal();
2221 if(response == IDOK)
2223 return TRUE;
2225 if(response == IDC_REBASE_POST_BUTTON )
2227 CString cmd, out, err;
2228 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2229 g_Git.m_CurrentDir,
2230 g_Git.FixBranchName(dlg.m_Upstream),
2231 g_Git.FixBranchName(dlg.m_Branch));
2232 if (g_Git.Run(cmd, &out, &err, CP_ACP))
2234 CMessageBox::Show(NULL, out + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
2235 return FALSE;
2238 CAppUtils::SendPatchMail(cmd,out);
2239 return TRUE;
2242 if(response == IDC_REBASE_POST_BUTTON +1 )
2243 continue;
2245 if(response == IDCANCEL)
2246 return FALSE;
2248 return TRUE;
2251 return FALSE;
2254 bool CAppUtils::Push(CString selectLocalBranch, bool autoClose)
2256 CPushDlg dlg;
2257 dlg.m_BranchSourceName = selectLocalBranch;
2258 CString error;
2259 DWORD exitcode = 0xFFFFFFFF;
2260 CTGitPathList list;
2261 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
2262 if (CHooks::Instance().PrePush(list,exitcode, error))
2264 if (exitcode)
2266 CString temp;
2267 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2268 //ReportError(temp);
2269 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2270 return false;
2274 if(dlg.DoModal()==IDOK)
2276 CString cmd;
2277 CString arg;
2279 if(dlg.m_bAutoLoad)
2281 CAppUtils::LaunchPAgent(NULL,&dlg.m_URL);
2284 if(dlg.m_bPack)
2285 arg += _T("--thin ");
2286 if(dlg.m_bTags && !dlg.m_bPushAllBranches)
2287 arg += _T("--tags ");
2288 if(dlg.m_bForce)
2289 arg += _T("--force ");
2291 int ver = CAppUtils::GetMsysgitVersion();
2293 if(ver >= 0x01070203) //above 1.7.0.2
2294 arg += _T("--progress ");
2296 if (dlg.m_bPushAllBranches)
2298 cmd.Format(_T("git.exe push --all %s \"%s\""),
2299 arg,
2300 dlg.m_URL);
2302 else
2304 cmd.Format(_T("git.exe push %s \"%s\" %s"),
2305 arg,
2306 dlg.m_URL,
2307 dlg.m_BranchSourceName);
2308 if (!dlg.m_BranchRemoteName.IsEmpty())
2310 cmd += _T(":") + dlg.m_BranchRemoteName;
2314 CProgressDlg progress;
2315 progress.m_bAutoCloseOnSuccess=autoClose;
2316 progress.m_GitCmd=cmd;
2317 progress.m_PostCmdList.Add(_T("&Request pull"));
2318 progress.m_PostCmdList.Add(_T("Re&Push"));
2319 int ret = progress.DoModal();
2321 if(!progress.m_GitStatus)
2323 if (CHooks::Instance().PostPush(list,exitcode, error))
2325 if (exitcode)
2327 CString temp;
2328 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2329 //ReportError(temp);
2330 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2331 return false;
2334 if(ret == IDC_PROGRESS_BUTTON1)
2336 RequestPull(dlg.m_BranchRemoteName);
2338 else if(ret == IDC_PROGRESS_BUTTON1 + 1)
2340 Push();
2342 return TRUE;
2346 return FALSE;
2349 bool CAppUtils::RequestPull(CString endrevision, CString repositoryUrl)
2351 CRequestPullDlg dlg;
2352 dlg.m_RepositoryURL = repositoryUrl;
2353 dlg.m_EndRevision = endrevision;
2354 if (dlg.DoModal()==IDOK)
2356 CString cmd;
2357 cmd.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg.m_StartRevision, dlg.m_RepositoryURL, dlg.m_EndRevision);
2359 CProgressDlg progress;
2360 progress.m_GitCmd=cmd;
2361 progress.DoModal();
2363 return true;
2366 bool CAppUtils::CreateMultipleDirectory(const CString& szPath)
2368 CString strDir(szPath);
2369 if (strDir.GetAt(strDir.GetLength()-1)!=_T('\\'))
2371 strDir.AppendChar(_T('\\'));
2373 std::vector<CString> vPath;
2374 CString strTemp;
2375 bool bSuccess = false;
2377 for (int i=0;i<strDir.GetLength();++i)
2379 if (strDir.GetAt(i) != _T('\\'))
2381 strTemp.AppendChar(strDir.GetAt(i));
2383 else
2385 vPath.push_back(strTemp);
2386 strTemp.AppendChar(_T('\\'));
2390 std::vector<CString>::const_iterator vIter;
2391 for (vIter = vPath.begin(); vIter != vPath.end(); vIter++)
2393 bSuccess = CreateDirectory(*vIter, NULL) ? true : false;
2396 return bSuccess;
2399 void CAppUtils::RemoveTrailSlash(CString &path)
2401 if(path.IsEmpty())
2402 return ;
2404 while(path[path.GetLength()-1] == _T('\\') || path[path.GetLength()-1] == _T('/' ) )
2406 path=path.Left(path.GetLength()-1);
2407 if(path.IsEmpty())
2408 return;
2412 BOOL CAppUtils::Commit(CString bugid,BOOL bWholeProject,CString &sLogMsg,
2413 CTGitPathList &pathList,
2414 CTGitPathList &selectedList,
2415 bool bSelectFilesForCommit,
2416 bool autoClose)
2418 bool bFailed = true;
2420 while(g_Git.GetUserName().IsEmpty() || g_Git.GetConfigValue(_T("user.email")).IsEmpty())
2422 if(CMessageBox::Show(NULL,_T("User name and email must be set before commit.\r\n Do you want to set these now?\r\n"),
2423 _T("TortoiseGit"),MB_YESNO| MB_ICONERROR) == IDYES)
2425 CTGitPath path(g_Git.m_CurrentDir);
2426 CSettings dlg(IDS_PROC_SETTINGS_TITLE,&path);
2427 dlg.SetTreeViewMode(TRUE, TRUE, TRUE);
2428 dlg.SetTreeWidth(220);
2429 dlg.m_DefaultPage = _T("gitconfig");
2431 dlg.DoModal();
2432 dlg.HandleRestart();
2435 else
2436 return false;
2439 while (bFailed)
2441 bFailed = false;
2442 CCommitDlg dlg;
2443 dlg.m_sBugID = bugid;
2445 dlg.m_bWholeProject = bWholeProject;
2447 dlg.m_sLogMessage = sLogMsg;
2448 dlg.m_pathList = pathList;
2449 dlg.m_checkedPathList = selectedList;
2450 dlg.m_bSelectFilesForCommit = bSelectFilesForCommit;
2451 dlg.m_bAutoClose = autoClose;
2452 if (dlg.DoModal() == IDOK)
2454 if (dlg.m_pathList.GetCount()==0)
2455 return false;
2456 // if the user hasn't changed the list of selected items
2457 // we don't use that list. Because if we would use the list
2458 // of pre-checked items, the dialog would show different
2459 // checked items on the next startup: it would only try
2460 // to check the parent folder (which might not even show)
2461 // instead, we simply use an empty list and let the
2462 // default checking do its job.
2463 if (!dlg.m_pathList.IsEqual(pathList))
2464 selectedList = dlg.m_pathList;
2465 pathList = dlg.m_updatedPathList;
2466 sLogMsg = dlg.m_sLogMessage;
2467 bSelectFilesForCommit = true;
2469 if( dlg.m_bPushAfterCommit )
2471 switch(dlg.m_PostCmd)
2473 case GIT_POST_CMD_DCOMMIT:
2474 CAppUtils::SVNDCommit();
2475 break;
2476 default:
2477 CAppUtils::Push();
2480 // CGitProgressDlg progDlg;
2481 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2482 // if (parser.HasVal(_T("closeonend")))
2483 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2484 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2485 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2486 // progDlg.SetPathList(dlg.m_pathList);
2487 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2488 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2489 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2490 // progDlg.SetItemCount(dlg.m_itemsCount);
2491 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2492 // progDlg.DoModal();
2493 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2494 // err = (DWORD)progDlg.DidErrorsOccur();
2495 // bFailed = progDlg.DidErrorsOccur();
2496 // bRet = progDlg.DidErrorsOccur();
2497 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2498 // if (DWORD(bFailRepeat)==0)
2499 // bFailed = false; // do not repeat if the user chose not to in the settings.
2502 return true;
2506 BOOL CAppUtils::SVNDCommit()
2508 CSVNDCommitDlg dcommitdlg;
2509 CString gitSetting = g_Git.GetConfigValue(_T("svn.rmdir"));
2510 if (gitSetting == _T("")) {
2511 if (dcommitdlg.DoModal() != IDOK)
2513 return false;
2515 else
2517 if (dcommitdlg.m_remember)
2519 if (dcommitdlg.m_rmdir)
2521 gitSetting = _T("true");
2523 else
2525 gitSetting = _T("false");
2527 if(g_Git.SetConfigValue(_T("svn.rmdir"),gitSetting))
2529 CMessageBox::Show(NULL,_T("Fail to set config"),_T("TortoiseGit"),MB_OK);
2535 BOOL IsStash = false;
2536 if(!g_Git.CheckCleanWorkTree())
2538 if(CMessageBox::Show(NULL, IDS_ERROR_NOCLEAN_STASH,IDS_APPNAME,MB_YESNO|MB_ICONINFORMATION)==IDYES)
2540 CString cmd,out;
2541 cmd=_T("git.exe stash");
2542 if(g_Git.Run(cmd,&out,CP_ACP))
2544 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
2545 return false;
2547 IsStash =true;
2550 else
2552 return false;
2556 CProgressDlg progress;
2557 if (dcommitdlg.m_rmdir)
2559 progress.m_GitCmd=_T("git.exe svn dcommit --rmdir");
2561 else
2563 progress.m_GitCmd=_T("git.exe svn dcommit");
2565 if(progress.DoModal()==IDOK && progress.m_GitStatus == 0)
2567 if( IsStash)
2569 if(CMessageBox::Show(NULL,IDS_DCOMMIT_STASH_POP,IDS_APPNAME,MB_YESNO|MB_ICONINFORMATION)==IDYES)
2571 CString cmd,out;
2572 cmd=_T("git.exe stash pop");
2573 if(g_Git.Run(cmd,&out,CP_ACP))
2575 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
2576 return false;
2580 else
2582 return false;
2585 return TRUE;
2587 return FALSE;
2590 BOOL CAppUtils::Merge(CString *commit)
2592 CMergeDlg dlg;
2593 if(commit)
2594 dlg.m_initialRefName = *commit;
2596 if(dlg.DoModal()==IDOK)
2598 CString cmd;
2599 CString noff;
2600 CString squash;
2601 CString nocommit;
2602 CString msg;
2604 if(dlg.m_bNoFF)
2605 noff=_T("--no-ff");
2607 if(dlg.m_bSquash)
2608 squash=_T("--squash");
2610 if(dlg.m_bNoCommit)
2611 nocommit=_T("--no-commit");
2613 if(!dlg.m_strLogMesage.IsEmpty())
2615 msg += _T("-m \"")+dlg.m_strLogMesage+_T("\"");
2617 cmd.Format(_T("git.exe merge %s %s %s %s %s"),
2618 msg,
2619 noff,
2620 squash,
2621 nocommit,
2622 g_Git.FixBranchName(dlg.m_VersionName));
2624 CProgressDlg Prodlg;
2625 Prodlg.m_GitCmd = cmd;
2627 if (dlg.m_bNoCommit)
2628 Prodlg.m_PostCmdList.Add(_T("Commit"));
2630 int ret = Prodlg.DoModal();
2632 if (ret == IDC_PROGRESS_BUTTON1)
2633 return Commit(_T(""), TRUE, CString(), CTGitPathList(), CTGitPathList(), true);
2635 return !Prodlg.m_GitStatus;
2637 return false;
2640 void CAppUtils::EditNote(GitRev *rev)
2642 CInputDlg dlg;
2643 dlg.m_sHintText=_T("Edit Notes");
2644 dlg.m_sInputText = rev->m_Notes;
2645 dlg.m_sTitle=_T("Edit Notes");
2646 //dlg.m_pProjectProperties = &m_ProjectProperties;
2647 dlg.m_bUseLogWidth = true;
2648 if(dlg.DoModal() == IDOK)
2650 CString cmd,output;
2651 cmd=_T("notes add -f -F \"");
2653 CString tempfile=::GetTempFile();
2654 CAppUtils::SaveCommitUnicodeFile(tempfile,dlg.m_sInputText);
2655 cmd += tempfile;
2656 cmd += _T("\" ");
2657 cmd += rev->m_CommitHash.ToString();
2661 if(git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd,CP_ACP).GetBuffer()))
2663 CMessageBox::Show(NULL,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
2666 else
2668 rev->m_Notes = dlg.m_sInputText;
2670 }catch(...)
2672 CMessageBox::Show(NULL,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
2674 CFile::Remove(tempfile);
2679 int CAppUtils::GetMsysgitVersion(CString *versionstr)
2681 CString cmd;
2682 CString progressarg;
2683 CString version;
2685 CRegDWORD regTime = CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2686 CRegDWORD regVersion = CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2688 CString gitpath = CGit::ms_LastMsysGitDir+_T("\\git.exe");
2690 __int64 time=0;
2691 if(!g_Git.GetFileModifyTime(gitpath, &time) && !versionstr)
2693 if((DWORD)time == regTime)
2695 return regVersion;
2699 if(versionstr)
2700 version = *versionstr;
2701 else
2703 CString err;
2704 cmd = _T("git.exe --version");
2705 if(g_Git.Run(cmd, &version, &err, CP_ACP))
2707 CMessageBox::Show(NULL, _T("git have not installed (") + err + _T(")"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
2708 return false;
2712 int start=0;
2713 int ver;
2715 CString str=version.Tokenize(_T("."),start);
2716 int space = str.ReverseFind(_T(' '));
2717 str=str.Mid(space+1,start);
2718 ver = _ttol(str);
2719 ver <<=24;
2721 version = version.Mid(start);
2722 start = 0;
2723 str = version.Tokenize(_T("."),start);
2725 ver |= (_ttol(str)&0xFF)<<16;
2727 str = version.Tokenize(_T("."),start);
2728 ver |= (_ttol(str)&0xFF)<<8;
2730 str = version.Tokenize(_T("."),start);
2731 ver |= (_ttol(str)&0xFF);
2733 regTime = time&0xFFFFFFFF;
2734 regVersion = ver;
2736 return ver;
2739 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd)
2741 typedef HRESULT (WINAPI *SHGPSFW) (HWND hwnd,REFIID riid,void** ppv);
2743 HMODULE hShell = LoadLibrary(_T("Shell32.dll"));
2745 if (hShell) {
2746 SHGPSFW pfnSHGPSFW = (SHGPSFW)::GetProcAddress(hShell, "SHGetPropertyStoreForWindow");
2747 if (pfnSHGPSFW) {
2748 IPropertyStore *pps;
2749 HRESULT hr = pfnSHGPSFW(hWnd, IID_PPV_ARGS(&pps));
2750 if (SUCCEEDED(hr)) {
2751 PROPVARIANT var;
2752 var.vt = VT_BOOL;
2753 var.boolVal = VARIANT_TRUE;
2754 hr = pps->SetValue(PKEY_AppUserModel_PreventPinning, var);
2755 pps->Release();
2758 FreeLibrary(hShell);
2762 void CAppUtils::SetWindowTitle(HWND hWnd, const CString& urlorpath, const CString& dialogname)
2764 ASSERT(dialogname.GetLength() < 70);
2765 ASSERT(urlorpath.GetLength() < MAX_PATH);
2766 WCHAR pathbuf[MAX_PATH] = {0};
2768 PathCompactPathEx(pathbuf, urlorpath, 70 - dialogname.GetLength(), 0);
2770 wcscat_s(pathbuf, L" - ");
2771 wcscat_s(pathbuf, dialogname);
2772 wcscat_s(pathbuf, L" - ");
2773 wcscat_s(pathbuf, CString(MAKEINTRESOURCE(IDS_APPNAME)));
2774 SetWindowText(hWnd, pathbuf);