Use the "open as" System dialog for the user to choose an application to open a file...
[TortoiseGit.git] / src / TortoiseProc / AppUtils.cpp
blob76a94cf7e40df8212e1d8d5d735357e4d71d00b6
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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"
62 CAppUtils::CAppUtils(void)
66 CAppUtils::~CAppUtils(void)
70 bool CAppUtils::StashSave()
72 CStashSaveDlg dlg;
74 if (dlg.DoModal() == IDOK)
76 CString cmd, out;
77 cmd = _T("git.exe stash save");
79 if (dlg.m_bIncludeUntracked && CAppUtils::GetMsysgitVersion() >= 0x01070700)
80 cmd += _T(" --include-untracked");
82 if (!dlg.m_sMessage.IsEmpty())
84 CString message = dlg.m_sMessage;
85 message.Replace(_T("\""), _T("\"\""));
86 cmd += _T(" \"") + message + _T("\"");
89 if (g_Git.Run(cmd, &out, CP_ACP))
91 CMessageBox::Show(NULL, CString(_T("<ct=0x0000FF>Stash Fail!!!</ct>\n")) + out, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
93 else
95 CMessageBox::Show(NULL, CString(_T("<ct=0xff0000>Stash Success</ct>\n")) + out, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
96 return true;
99 return false;
102 int CAppUtils::StashApply(CString ref, bool showChanges /* true */)
104 CString cmd,out;
105 cmd = _T("git.exe stash apply ");
106 if (ref.Find(_T("refs/")) == 0)
107 ref = ref.Mid(5);
108 if (ref.Find(_T("stash{")) == 0)
109 ref = _T("stash@") + ref.Mid(5);
110 cmd += ref;
112 int ret = g_Git.Run(cmd, &out, CP_ACP);
113 bool hasConflicts = (out.Find(_T("CONFLICT")) >= 0);
114 if (ret && !(ret == 1 && hasConflicts))
116 CMessageBox::Show(NULL,CString(_T("<ct=0x0000FF>Stash Apply Fail!!!</ct>\n"))+out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
118 else
120 CString withConflicts;
121 if (hasConflicts)
122 withConflicts = _T(" with conflicts");
123 if (showChanges)
125 if(CMessageBox::Show(NULL,CString(_T("<ct=0xff0000>Stash Apply Success") + withConflicts + _T("</ct>\nDo you want to show change?"))
126 ,_T("TortoiseGit"),MB_YESNO|MB_ICONINFORMATION) == IDYES)
128 CChangedDlg dlg;
129 dlg.m_pathList.AddPath(CTGitPath());
130 dlg.DoModal();
132 return 0;
134 else
136 CMessageBox::Show(NULL, _T("<ct=0xff0000>Stash Apply Success") + withConflicts + _T("</ct>") ,_T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
137 return 0;
140 return -1;
143 int CAppUtils::StashPop(bool showChanges /* true */)
145 CString cmd,out;
146 cmd=_T("git.exe stash pop ");
148 int ret = g_Git.Run(cmd, &out, CP_ACP);
149 bool hasConflicts = (out.Find(_T("CONFLICT")) >= 0);
150 if (ret && !(ret == 1 && hasConflicts))
152 CMessageBox::Show(NULL,CString(_T("<ct=0x0000FF>Stash POP Fail!!!</ct>\n"))+out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
154 else
156 CString message = _T("<ct=0xff0000>Stash POP Success</ct>");
157 if (hasConflicts)
158 message = _T("<ct=0x000000ff>Stash POP Failed, there are conflicts</ct>");
159 if (showChanges)
161 if(CMessageBox::Show(NULL,CString(message + _T("\nDo you want to show change?"))
162 ,_T("TortoiseGit"),MB_YESNO|MB_ICONINFORMATION) == IDYES)
164 CChangedDlg dlg;
165 dlg.m_pathList.AddPath(CTGitPath());
166 dlg.DoModal();
168 return 0;
170 else
172 CMessageBox::Show(NULL, message ,_T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
173 return 0;
176 return -1;
179 bool CAppUtils::GetMimeType(const CTGitPath& /*file*/, CString& /*mimetype*/)
181 #if 0
182 GitProperties props(file, GitRev::REV_WC, false);
183 for (int i = 0; i < props.GetCount(); ++i)
185 if (props.GetItemName(i).compare(_T("svn:mime-type"))==0)
187 mimetype = props.GetItemValue(i).c_str();
188 return true;
191 #endif
192 return false;
195 BOOL CAppUtils::StartExtMerge(
196 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
197 const CString& basename, const CString& theirname, const CString& yourname, const CString& mergedname, bool bReadOnly)
200 CRegString regCom = CRegString(_T("Software\\TortoiseGit\\Merge"));
201 CString ext = mergedfile.GetFileExtension();
202 CString com = regCom;
203 bool bInternal = false;
205 CString mimetype;
206 if (ext != "")
208 // is there an extension specific merge tool?
209 CRegString mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + ext.MakeLower());
210 if (CString(mergetool) != "")
212 com = mergetool;
215 if (GetMimeType(yourfile, mimetype) || GetMimeType(theirfile, mimetype) || GetMimeType(basefile, mimetype))
217 // is there a mime type specific merge tool?
218 CRegString mergetool(_T("Software\\TortoiseGit\\MergeTools\\") + mimetype);
219 if (CString(mergetool) != "")
221 com = mergetool;
225 if (com.IsEmpty()||(com.Left(1).Compare(_T("#"))==0))
227 // use TortoiseMerge
228 bInternal = true;
229 CRegString tortoiseMergePath(_T("Software\\TortoiseGit\\TMergePath"), _T(""), false, HKEY_LOCAL_MACHINE);
230 com = tortoiseMergePath;
231 if (com.IsEmpty())
233 com = CPathUtils::GetAppDirectory();
234 com += _T("TortoiseMerge.exe");
236 com = _T("\"") + com + _T("\"");
237 com = com + _T(" /base:%base /theirs:%theirs /mine:%mine /merged:%merged");
238 com = com + _T(" /basename:%bname /theirsname:%tname /minename:%yname /mergedname:%mname");
240 // check if the params are set. If not, just add the files to the command line
241 if ((com.Find(_T("%merged"))<0)&&(com.Find(_T("%base"))<0)&&(com.Find(_T("%theirs"))<0)&&(com.Find(_T("%mine"))<0))
243 com += _T(" \"")+basefile.GetWinPathString()+_T("\"");
244 com += _T(" \"")+theirfile.GetWinPathString()+_T("\"");
245 com += _T(" \"")+yourfile.GetWinPathString()+_T("\"");
246 com += _T(" \"")+mergedfile.GetWinPathString()+_T("\"");
248 if (basefile.IsEmpty())
250 com.Replace(_T("/base:%base"), _T(""));
251 com.Replace(_T("%base"), _T(""));
253 else
254 com.Replace(_T("%base"), _T("\"") + basefile.GetWinPathString() + _T("\""));
255 if (theirfile.IsEmpty())
257 com.Replace(_T("/theirs:%theirs"), _T(""));
258 com.Replace(_T("%theirs"), _T(""));
260 else
261 com.Replace(_T("%theirs"), _T("\"") + theirfile.GetWinPathString() + _T("\""));
262 if (yourfile.IsEmpty())
264 com.Replace(_T("/mine:%mine"), _T(""));
265 com.Replace(_T("%mine"), _T(""));
267 else
268 com.Replace(_T("%mine"), _T("\"") + yourfile.GetWinPathString() + _T("\""));
269 if (mergedfile.IsEmpty())
271 com.Replace(_T("/merged:%merged"), _T(""));
272 com.Replace(_T("%merged"), _T(""));
274 else
275 com.Replace(_T("%merged"), _T("\"") + mergedfile.GetWinPathString() + _T("\""));
276 if (basename.IsEmpty())
278 if (basefile.IsEmpty())
280 com.Replace(_T("/basename:%bname"), _T(""));
281 com.Replace(_T("%bname"), _T(""));
283 else
285 com.Replace(_T("%bname"), _T("\"") + basefile.GetUIFileOrDirectoryName() + _T("\""));
288 else
289 com.Replace(_T("%bname"), _T("\"") + basename + _T("\""));
290 if (theirname.IsEmpty())
292 if (theirfile.IsEmpty())
294 com.Replace(_T("/theirsname:%tname"), _T(""));
295 com.Replace(_T("%tname"), _T(""));
297 else
299 com.Replace(_T("%tname"), _T("\"") + theirfile.GetUIFileOrDirectoryName() + _T("\""));
302 else
303 com.Replace(_T("%tname"), _T("\"") + theirname + _T("\""));
304 if (yourname.IsEmpty())
306 if (yourfile.IsEmpty())
308 com.Replace(_T("/minename:%yname"), _T(""));
309 com.Replace(_T("%yname"), _T(""));
311 else
313 com.Replace(_T("%yname"), _T("\"") + yourfile.GetUIFileOrDirectoryName() + _T("\""));
316 else
317 com.Replace(_T("%yname"), _T("\"") + yourname + _T("\""));
318 if (mergedname.IsEmpty())
320 if (mergedfile.IsEmpty())
322 com.Replace(_T("/mergedname:%mname"), _T(""));
323 com.Replace(_T("%mname"), _T(""));
325 else
327 com.Replace(_T("%mname"), _T("\"") + mergedfile.GetUIFileOrDirectoryName() + _T("\""));
330 else
331 com.Replace(_T("%mname"), _T("\"") + mergedname + _T("\""));
333 if ((bReadOnly)&&(bInternal))
334 com += _T(" /readonly");
336 if(!LaunchApplication(com, IDS_ERR_EXTMERGESTART, false))
338 return FALSE;
341 return TRUE;
344 BOOL CAppUtils::StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir, const CString& sOriginalDescription, const CString& sPatchedDescription, BOOL bReversed, BOOL bWait)
346 CString viewer;
347 // use TortoiseMerge
348 viewer = CPathUtils::GetAppDirectory();
349 viewer += _T("TortoiseMerge.exe");
351 viewer = _T("\"") + viewer + _T("\"");
352 viewer = viewer + _T(" /diff:\"") + patchfile.GetWinPathString() + _T("\"");
353 viewer = viewer + _T(" /patchpath:\"") + dir.GetWinPathString() + _T("\"");
354 if (bReversed)
355 viewer += _T(" /reversedpatch");
356 if (!sOriginalDescription.IsEmpty())
357 viewer = viewer + _T(" /patchoriginal:\"") + sOriginalDescription + _T("\"");
358 if (!sPatchedDescription.IsEmpty())
359 viewer = viewer + _T(" /patchpatched:\"") + sPatchedDescription + _T("\"");
360 if(!LaunchApplication(viewer, IDS_ERR_DIFFVIEWSTART, !!bWait))
362 return FALSE;
364 return TRUE;
367 CString CAppUtils::PickDiffTool(const CTGitPath& file1, const CTGitPath& file2)
369 // Is there a mime type specific diff tool?
370 CString mimetype;
371 if (GetMimeType(file1, mimetype) || GetMimeType(file2, mimetype))
373 CString difftool = CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + mimetype);
374 if (!difftool.IsEmpty())
375 return difftool;
378 // Is there an extension specific diff tool?
379 CString ext = file2.GetFileExtension().MakeLower();
380 if (!ext.IsEmpty())
382 CString difftool = CRegString(_T("Software\\TortoiseGit\\DiffTools\\") + ext);
383 if (!difftool.IsEmpty())
384 return difftool;
385 // Maybe we should use TortoiseIDiff?
386 if ((ext == _T(".jpg")) || (ext == _T(".jpeg")) ||
387 (ext == _T(".bmp")) || (ext == _T(".gif")) ||
388 (ext == _T(".png")) || (ext == _T(".ico")) ||
389 (ext == _T(".dib")) || (ext == _T(".emf")))
391 return
392 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseIDiff.exe") + _T("\"") +
393 _T(" /left:%base /right:%mine /lefttitle:%bname /righttitle:%yname");
397 // Finally, pick a generic external diff tool
398 CString difftool = CRegString(_T("Software\\TortoiseGit\\Diff"));
399 return difftool;
402 bool CAppUtils::StartExtDiff(
403 const CString& file1, const CString& file2,
404 const CString& sName1, const CString& sName2,
405 const DiffFlags& flags)
407 CString viewer;
409 CRegDWORD blamediff(_T("Software\\TortoiseGit\\DiffBlamesWithTortoiseMerge"), FALSE);
410 if (!flags.bBlame || !(DWORD)blamediff)
412 viewer = PickDiffTool(file1, file2);
413 // If registry entry for a diff program is commented out, use TortoiseMerge.
414 bool bCommentedOut = viewer.Left(1) == _T("#");
415 if (flags.bAlternativeTool)
417 // Invert external vs. internal diff tool selection.
418 if (bCommentedOut)
419 viewer.Delete(0); // uncomment
420 else
421 viewer = "";
423 else if (bCommentedOut)
424 viewer = "";
427 bool bInternal = viewer.IsEmpty();
428 if (bInternal)
430 viewer =
431 _T("\"") + CPathUtils::GetAppDirectory() + _T("TortoiseMerge.exe") + _T("\"") +
432 _T(" /base:%base /mine:%mine /basename:%bname /minename:%yname");
433 if (flags.bBlame)
434 viewer += _T(" /blame");
436 // check if the params are set. If not, just add the files to the command line
437 if ((viewer.Find(_T("%base"))<0)&&(viewer.Find(_T("%mine"))<0))
439 viewer += _T(" \"")+file1+_T("\"");
440 viewer += _T(" \"")+file2+_T("\"");
442 if (viewer.Find(_T("%base")) >= 0)
444 viewer.Replace(_T("%base"), _T("\"")+file1+_T("\""));
446 if (viewer.Find(_T("%mine")) >= 0)
448 viewer.Replace(_T("%mine"), _T("\"")+file2+_T("\""));
451 if (sName1.IsEmpty())
452 viewer.Replace(_T("%bname"), _T("\"") + file1 + _T("\""));
453 else
454 viewer.Replace(_T("%bname"), _T("\"") + sName1 + _T("\""));
456 if (sName2.IsEmpty())
457 viewer.Replace(_T("%yname"), _T("\"") + file2 + _T("\""));
458 else
459 viewer.Replace(_T("%yname"), _T("\"") + sName2 + _T("\""));
461 if (flags.bReadOnly && bInternal)
462 viewer += _T(" /readonly");
464 return LaunchApplication(viewer, IDS_ERR_EXTDIFFSTART, flags.bWait);
467 BOOL CAppUtils::StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait)
469 CString viewer;
470 CRegString v = CRegString(_T("Software\\TortoiseGit\\DiffViewer"));
471 viewer = v;
472 if (viewer.IsEmpty() || (viewer.Left(1).Compare(_T("#"))==0))
474 // use TortoiseUDiff
475 viewer = CPathUtils::GetAppDirectory();
476 viewer += _T("TortoiseUDiff.exe");
477 // enquote the path to TortoiseUDiff
478 viewer = _T("\"") + viewer + _T("\"");
479 // add the params
480 viewer = viewer + _T(" /patchfile:%1 /title:\"%title\"");
483 if (viewer.Find(_T("%1"))>=0)
485 if (viewer.Find(_T("\"%1\"")) >= 0)
486 viewer.Replace(_T("%1"), patchfile);
487 else
488 viewer.Replace(_T("%1"), _T("\"") + patchfile + _T("\""));
490 else
491 viewer += _T(" \"") + patchfile + _T("\"");
492 if (viewer.Find(_T("%title")) >= 0)
494 viewer.Replace(_T("%title"), title);
497 if(!LaunchApplication(viewer, IDS_ERR_DIFFVIEWSTART, !!bWait))
499 return FALSE;
501 return TRUE;
504 BOOL CAppUtils::StartTextViewer(CString file)
506 CString viewer;
507 CRegString txt = CRegString(_T(".txt\\"), _T(""), FALSE, HKEY_CLASSES_ROOT);
508 viewer = txt;
509 viewer = viewer + _T("\\Shell\\Open\\Command\\");
510 CRegString txtexe = CRegString(viewer, _T(""), FALSE, HKEY_CLASSES_ROOT);
511 viewer = txtexe;
513 DWORD len = ExpandEnvironmentStrings(viewer, NULL, 0);
514 TCHAR * buf = new TCHAR[len+1];
515 ExpandEnvironmentStrings(viewer, buf, len);
516 viewer = buf;
517 delete [] buf;
518 len = ExpandEnvironmentStrings(file, NULL, 0);
519 buf = new TCHAR[len+1];
520 ExpandEnvironmentStrings(file, buf, len);
521 file = buf;
522 delete [] buf;
523 file = _T("\"")+file+_T("\"");
524 if (viewer.IsEmpty())
526 viewer = _T("RUNDLL32 Shell32,OpenAs_RunDLL");
528 if (viewer.Find(_T("\"%1\"")) >= 0)
530 viewer.Replace(_T("\"%1\""), file);
532 else if (viewer.Find(_T("%1")) >= 0)
534 viewer.Replace(_T("%1"), file);
536 else
538 viewer += _T(" ");
539 viewer += file;
542 if(!LaunchApplication(viewer, IDS_ERR_TEXTVIEWSTART, false))
544 return FALSE;
546 return TRUE;
549 BOOL CAppUtils::CheckForEmptyDiff(const CTGitPath& sDiffPath)
551 DWORD length = 0;
552 HANDLE hFile = ::CreateFile(sDiffPath.GetWinPath(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
553 if (hFile == INVALID_HANDLE_VALUE)
554 return TRUE;
555 length = ::GetFileSize(hFile, NULL);
556 ::CloseHandle(hFile);
557 if (length < 4)
558 return TRUE;
559 return FALSE;
563 void CAppUtils::CreateFontForLogs(CFont& fontToCreate)
565 LOGFONT logFont;
566 HDC hScreenDC = ::GetDC(NULL);
567 logFont.lfHeight = -MulDiv((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8), GetDeviceCaps(hScreenDC, LOGPIXELSY), 72);
568 ::ReleaseDC(NULL, hScreenDC);
569 logFont.lfWidth = 0;
570 logFont.lfEscapement = 0;
571 logFont.lfOrientation = 0;
572 logFont.lfWeight = FW_NORMAL;
573 logFont.lfItalic = 0;
574 logFont.lfUnderline = 0;
575 logFont.lfStrikeOut = 0;
576 logFont.lfCharSet = DEFAULT_CHARSET;
577 logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
578 logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
579 logFont.lfQuality = DRAFT_QUALITY;
580 logFont.lfPitchAndFamily = FF_DONTCARE | FIXED_PITCH;
581 _tcscpy_s(logFont.lfFaceName, 32, (LPCTSTR)(CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")));
582 VERIFY(fontToCreate.CreateFontIndirect(&logFont));
585 bool CAppUtils::LaunchApplication(const CString& sCommandLine, UINT idErrMessageFormat, bool bWaitForStartup)
587 STARTUPINFO startup;
588 PROCESS_INFORMATION process;
589 memset(&startup, 0, sizeof(startup));
590 startup.cb = sizeof(startup);
591 memset(&process, 0, sizeof(process));
593 CString cleanCommandLine(sCommandLine);
595 if (CreateProcess(NULL, const_cast<TCHAR*>((LPCTSTR)cleanCommandLine), NULL, NULL, FALSE, 0, 0, g_Git.m_CurrentDir, &startup, &process)==0)
597 if(idErrMessageFormat != 0)
599 LPVOID lpMsgBuf;
600 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
601 FORMAT_MESSAGE_FROM_SYSTEM |
602 FORMAT_MESSAGE_IGNORE_INSERTS,
603 NULL,
604 GetLastError(),
605 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
606 (LPTSTR) &lpMsgBuf,
608 NULL
610 CString temp;
611 temp.Format(idErrMessageFormat, lpMsgBuf);
612 CMessageBox::Show(NULL, temp, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
613 LocalFree( lpMsgBuf );
615 return false;
618 if (bWaitForStartup)
620 WaitForInputIdle(process.hProcess, 10000);
623 CloseHandle(process.hThread);
624 CloseHandle(process.hProcess);
625 return true;
627 bool CAppUtils::LaunchPAgent(CString *keyfile,CString * pRemote)
629 CString key,remote;
630 CString cmd,out;
631 if( pRemote == NULL)
633 remote=_T("origin");
635 else
637 remote=*pRemote;
639 if(keyfile == NULL)
641 cmd.Format(_T("remote.%s.puttykeyfile"),remote);
642 key = g_Git.GetConfigValue(cmd);
643 int start=0;
644 key = key.Tokenize(_T("\n"),start);
646 else
647 key=*keyfile;
649 if(key.IsEmpty())
650 return false;
652 CString proc=CPathUtils::GetAppDirectory();
653 proc += _T("pageant.exe \"");
654 proc += key;
655 proc += _T("\"");
657 CString tempfile = GetTempFile();
658 ::DeleteFile(tempfile);
660 proc += _T(" -c \"");
661 proc += CPathUtils::GetAppDirectory();
662 proc += _T("touch.exe\"");
663 proc += _T(" \"");
664 proc += tempfile;
665 proc += _T("\"");
667 bool b = LaunchApplication(proc, IDS_ERR_PAGEANT, true);
668 if(!b)
669 return b;
671 int i=0;
672 while(!::PathFileExists(tempfile))
674 Sleep(100);
675 i++;
676 if(i>10*60*5)
677 break; //timeout 5 minutes
680 if( i== 10*60*5)
682 CMessageBox::Show(NULL, _T("Fail wait for pageant finish load key"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
684 ::DeleteFile(tempfile);
685 return true;
687 bool CAppUtils::LaunchAlternativeEditor(const CString& filename)
689 CString editTool = CRegString(_T("Software\\TortoiseGit\\AlternativeEditor"));
690 if (editTool.IsEmpty() || (editTool.Left(1).Compare(_T("#"))==0)) {
691 editTool = CPathUtils::GetAppDirectory() + _T("notepad2.exe");
694 CString sCmd;
695 sCmd.Format(_T("\"%s\" \"%s\""), editTool, filename);
697 LaunchApplication(sCmd, NULL, false);
698 return true;
700 bool CAppUtils::LaunchRemoteSetting()
702 CTGitPath path(g_Git.m_CurrentDir);
703 CSettings dlg(IDS_PROC_SETTINGS_TITLE, &path);
704 dlg.SetTreeViewMode(TRUE, TRUE, TRUE);
705 //dlg.SetTreeWidth(220);
706 dlg.m_DefaultPage = _T("gitremote");
708 dlg.DoModal();
709 dlg.HandleRestart();
710 return true;
713 * Launch the external blame viewer
715 bool CAppUtils::LaunchTortoiseBlame(const CString& sBlameFile,CString Rev,const CString& sParams)
717 CString viewer = _T("\"") + CPathUtils::GetAppDirectory();
718 viewer += _T("TortoiseGitBlame.exe");
719 viewer += _T("\" \"") + sBlameFile + _T("\"");
720 //viewer += _T(" \"") + sLogFile + _T("\"");
721 //viewer += _T(" \"") + sOriginalFile + _T("\"");
722 if(!Rev.IsEmpty() && Rev != GIT_REV_ZERO)
723 viewer += CString(_T(" /rev:"))+Rev;
724 viewer += _T(" ")+sParams;
726 return LaunchApplication(viewer, IDS_ERR_TGITBLAME, false);
729 bool CAppUtils::FormatTextInRichEditControl(CWnd * pWnd)
731 CString sText;
732 if (pWnd == NULL)
733 return false;
734 bool bStyled = false;
735 pWnd->GetWindowText(sText);
736 // the rich edit control doesn't count the CR char!
737 // to be exact: CRLF is treated as one char.
738 sText.Remove('\r');
740 // style each line separately
741 int offset = 0;
742 int nNewlinePos;
745 nNewlinePos = sText.Find('\n', offset);
746 CString sLine = sText.Mid(offset);
747 if (nNewlinePos>=0)
748 sLine = sLine.Left(nNewlinePos-offset);
749 int start = 0;
750 int end = 0;
751 while (FindStyleChars(sLine, '*', start, end))
753 CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
754 pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
755 CHARFORMAT2 format;
756 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
757 format.cbSize = sizeof(CHARFORMAT2);
758 format.dwMask = CFM_BOLD;
759 format.dwEffects = CFE_BOLD;
760 pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
761 bStyled = true;
762 start = end;
764 start = 0;
765 end = 0;
766 while (FindStyleChars(sLine, '^', start, end))
768 CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
769 pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
770 CHARFORMAT2 format;
771 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
772 format.cbSize = sizeof(CHARFORMAT2);
773 format.dwMask = CFM_ITALIC;
774 format.dwEffects = CFE_ITALIC;
775 pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
776 bStyled = true;
777 start = end;
779 start = 0;
780 end = 0;
781 while (FindStyleChars(sLine, '_', start, end))
783 CHARRANGE range = {(LONG)start+offset, (LONG)end+offset};
784 pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range);
785 CHARFORMAT2 format;
786 SecureZeroMemory(&format, sizeof(CHARFORMAT2));
787 format.cbSize = sizeof(CHARFORMAT2);
788 format.dwMask = CFM_UNDERLINE;
789 format.dwEffects = CFE_UNDERLINE;
790 pWnd->SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
791 bStyled = true;
792 start = end;
794 offset = nNewlinePos+1;
795 } while(nNewlinePos>=0);
796 return bStyled;
799 bool CAppUtils::FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end)
801 int i=start;
802 bool bFoundMarker = false;
803 // find a starting marker
804 while (sText[i] != 0)
806 if (sText[i] == stylechar)
808 if (((i+1)<sText.GetLength())&&(IsCharAlphaNumeric(sText[i+1])) &&
809 (((i>0)&&(!IsCharAlphaNumeric(sText[i-1])))||(i==0)))
811 start = i+1;
812 i++;
813 bFoundMarker = true;
814 break;
817 i++;
819 if (!bFoundMarker)
820 return false;
821 // find ending marker
822 bFoundMarker = false;
823 while (sText[i] != 0)
825 if (sText[i] == stylechar)
827 if ((IsCharAlphaNumeric(sText[i-1])) &&
828 ((((i+1)<sText.GetLength())&&(!IsCharAlphaNumeric(sText[i+1])))||(i+1)==sText.GetLength()))
830 end = i;
831 i++;
832 bFoundMarker = true;
833 break;
836 i++;
838 return bFoundMarker;
841 bool CAppUtils::FileOpenSave(CString& path, int * filterindex, UINT title, UINT filter, bool bOpen, HWND hwndOwner)
843 OPENFILENAME ofn = {0}; // common dialog box structure
844 TCHAR szFile[MAX_PATH] = {0}; // buffer for file name. Explorer can't handle paths longer than MAX_PATH.
845 ofn.lStructSize = sizeof(OPENFILENAME);
846 ofn.hwndOwner = hwndOwner;
847 _tcscpy_s(szFile, MAX_PATH, (LPCTSTR)path);
848 ofn.lpstrFile = szFile;
849 ofn.nMaxFile = _countof(szFile);
850 CString sFilter;
851 TCHAR * pszFilters = NULL;
852 if (filter)
854 sFilter.LoadString(filter);
855 pszFilters = new TCHAR[sFilter.GetLength()+4];
856 _tcscpy_s (pszFilters, sFilter.GetLength()+4, sFilter);
857 // Replace '|' delimiters with '\0's
858 TCHAR *ptr = pszFilters + _tcslen(pszFilters); //set ptr at the NULL
859 while (ptr != pszFilters)
861 if (*ptr == '|')
862 *ptr = '\0';
863 ptr--;
865 ofn.lpstrFilter = pszFilters;
867 ofn.nFilterIndex = 1;
868 ofn.lpstrFileTitle = NULL;
869 ofn.nMaxFileTitle = 0;
870 ofn.lpstrInitialDir = NULL;
871 CString temp;
872 if (title)
874 temp.LoadString(title);
875 CStringUtils::RemoveAccelerators(temp);
877 ofn.lpstrTitle = temp;
878 if (bOpen)
879 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
880 else
881 ofn.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER;
884 // Display the Open dialog box.
885 bool bRet = false;
886 if (bOpen)
888 bRet = !!GetOpenFileName(&ofn);
890 else
892 bRet = !!GetSaveFileName(&ofn);
894 if (bRet)
896 if (pszFilters)
897 delete [] pszFilters;
898 path = CString(ofn.lpstrFile);
899 if (filterindex)
900 *filterindex = ofn.nFilterIndex;
901 return true;
903 if (pszFilters)
904 delete [] pszFilters;
905 return false;
908 bool CAppUtils::SetListCtrlBackgroundImage(HWND hListCtrl, UINT nID, int width /* = 128 */, int height /* = 128 */)
910 ListView_SetTextBkColor(hListCtrl, CLR_NONE);
911 COLORREF bkColor = ListView_GetBkColor(hListCtrl);
912 // create a bitmap from the icon
913 HICON hIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(nID), IMAGE_ICON, width, height, LR_DEFAULTCOLOR);
914 if (!hIcon)
915 return false;
917 RECT rect = {0};
918 rect.right = width;
919 rect.bottom = height;
920 HBITMAP bmp = NULL;
922 HWND desktop = ::GetDesktopWindow();
923 if (desktop)
925 HDC screen_dev = ::GetDC(desktop);
926 if (screen_dev)
928 // Create a compatible DC
929 HDC dst_hdc = ::CreateCompatibleDC(screen_dev);
930 if (dst_hdc)
932 // Create a new bitmap of icon size
933 bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom);
934 if (bmp)
936 // Select it into the compatible DC
937 HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp);
938 // Fill the background of the compatible DC with the given color
939 ::SetBkColor(dst_hdc, bkColor);
940 ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
942 // Draw the icon into the compatible DC
943 ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL);
944 ::SelectObject(dst_hdc, old_dst_bmp);
946 ::DeleteDC(dst_hdc);
949 ::ReleaseDC(desktop, screen_dev);
952 // Restore settings
953 DestroyIcon(hIcon);
955 if (bmp == NULL)
956 return false;
958 LVBKIMAGE lv;
959 lv.ulFlags = LVBKIF_TYPE_WATERMARK;
960 lv.hbm = bmp;
961 lv.xOffsetPercent = 100;
962 lv.yOffsetPercent = 100;
963 ListView_SetBkImage(hListCtrl, &lv);
964 return true;
967 CString CAppUtils::GetProjectNameFromURL(CString url)
969 CString name;
970 while (name.IsEmpty() || (name.CompareNoCase(_T("branches"))==0) ||
971 (name.CompareNoCase(_T("tags"))==0) ||
972 (name.CompareNoCase(_T("trunk"))==0))
974 name = url.Mid(url.ReverseFind('/')+1);
975 url = url.Left(url.ReverseFind('/'));
977 if ((name.Compare(_T("svn")) == 0)||(name.Compare(_T("svnroot")) == 0))
979 // a name of svn or svnroot indicates that it's not really the project name. In that
980 // case, we try the first part of the URL
981 // of course, this won't work in all cases (but it works for Google project hosting)
982 url.Replace(_T("http://"), _T(""));
983 url.Replace(_T("https://"), _T(""));
984 url.Replace(_T("svn://"), _T(""));
985 url.Replace(_T("svn+ssh://"), _T(""));
986 url.TrimLeft(_T("/"));
987 name = url.Left(url.Find('.'));
989 return name;
992 bool CAppUtils::StartShowUnifiedDiff(HWND /*hWnd*/, const CTGitPath& url1, const git_revnum_t& rev1,
993 const CTGitPath& /*url2*/, const git_revnum_t& rev2,
994 //const GitRev& peg /* = GitRev */, const GitRev& headpeg /* = GitRev */,
995 bool /*bAlternateDiff*/ /* = false */, bool /*bIgnoreAncestry*/ /* = false */, bool /* blame = false */, bool bMerge)
998 CString tempfile=GetTempFile();
999 CString cmd;
1000 if(rev1 == GitRev::GetWorkingCopy())
1002 cmd.Format(_T("git.exe diff --stat -p %s "),rev2);
1004 else
1006 CString merge;
1007 if(bMerge)
1008 merge = _T("-c");
1010 cmd.Format(_T("git.exe diff-tree -r -p %s --stat %s %s"),merge, rev1,rev2);
1013 if( !url1.IsEmpty() )
1015 cmd += _T(" -- \"");
1016 cmd += url1.GetGitPathString();
1017 cmd += _T("\" ");
1019 g_Git.RunLogFile(cmd,tempfile);
1020 CAppUtils::StartUnifiedDiffViewer(tempfile,rev1.Left(6)+_T(":")+rev2.Left(6));
1023 #if 0
1024 CString sCmd;
1025 sCmd.Format(_T("%s /command:showcompare /unified"),
1026 (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")));
1027 sCmd += _T(" /url1:\"") + url1.GetGitPathString() + _T("\"");
1028 if (rev1.IsValid())
1029 sCmd += _T(" /revision1:") + rev1.ToString();
1030 sCmd += _T(" /url2:\"") + url2.GetGitPathString() + _T("\"");
1031 if (rev2.IsValid())
1032 sCmd += _T(" /revision2:") + rev2.ToString();
1033 if (peg.IsValid())
1034 sCmd += _T(" /pegrevision:") + peg.ToString();
1035 if (headpeg.IsValid())
1036 sCmd += _T(" /headpegrevision:") + headpeg.ToString();
1038 if (bAlternateDiff)
1039 sCmd += _T(" /alternatediff");
1041 if (bIgnoreAncestry)
1042 sCmd += _T(" /ignoreancestry");
1044 if (hWnd)
1046 sCmd += _T(" /hwnd:");
1047 TCHAR buf[30];
1048 _stprintf_s(buf, 30, _T("%d"), hWnd);
1049 sCmd += buf;
1052 return CAppUtils::LaunchApplication(sCmd, NULL, false);
1053 #endif
1054 return TRUE;
1058 bool CAppUtils::Export(CString *BashHash)
1060 bool bRet = false;
1062 // ask from where the export has to be done
1063 CExportDlg dlg;
1064 if(BashHash)
1065 dlg.m_Revision=*BashHash;
1067 if (dlg.DoModal() == IDOK)
1069 CString cmd;
1070 cmd.Format(_T("git.exe archive --format=zip --verbose %s"),
1071 g_Git.FixBranchName(dlg.m_VersionName));
1073 //g_Git.RunLogFile(cmd,dlg.m_strExportDirectory);
1074 CProgressDlg pro;
1075 pro.m_GitCmd=cmd;
1076 pro.m_LogFile=dlg.m_strExportDirectory;
1077 pro.DoModal();
1078 return TRUE;
1080 return bRet;
1083 bool CAppUtils::CreateBranchTag(bool IsTag,CString *CommitHash, bool switch_new_brach)
1085 CCreateBranchTagDlg dlg;
1086 dlg.m_bIsTag=IsTag;
1087 dlg.m_bSwitch=switch_new_brach;
1089 if(CommitHash)
1090 dlg.m_Base = *CommitHash;
1092 if(dlg.DoModal()==IDOK)
1094 CString cmd;
1095 CString force;
1096 CString track;
1097 if(dlg.m_bTrack)
1098 track=_T(" --track ");
1100 if(dlg.m_bForce)
1101 force=_T(" -f ");
1103 if(IsTag)
1105 CString sign;
1106 if(dlg.m_bSign)
1107 sign=_T("-s");
1109 cmd.Format(_T("git.exe tag %s %s %s %s %s"),
1110 track,
1111 force,
1112 sign,
1113 dlg.m_BranchTagName,
1114 g_Git.FixBranchName(dlg.m_VersionName)
1117 CString tempfile=::GetTempFile();
1118 if(!dlg.m_Message.Trim().IsEmpty())
1120 CAppUtils::SaveCommitUnicodeFile(tempfile,dlg.m_Message);
1121 cmd += _T(" -F ")+tempfile;
1124 else
1126 cmd.Format(_T("git.exe branch %s %s %s %s"),
1127 track,
1128 force,
1129 dlg.m_BranchTagName,
1130 g_Git.FixBranchName(dlg.m_VersionName)
1133 CString out;
1134 if(g_Git.Run(cmd,&out,CP_UTF8))
1136 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1138 if( !IsTag && dlg.m_bSwitch )
1140 // it is a new branch and the user has requested to switch to it
1141 cmd.Format(_T("git.exe checkout %s"), dlg.m_BranchTagName);
1142 g_Git.Run(cmd,&out,CP_UTF8);
1143 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1146 return TRUE;
1148 return FALSE;
1151 bool CAppUtils::Switch(CString *CommitHash, CString initialRefName, bool autoclose)
1153 CGitSwitchDlg dlg;
1154 if(CommitHash)
1155 dlg.m_Base=*CommitHash;
1156 if(!initialRefName.IsEmpty())
1157 dlg.m_initialRefName = initialRefName;
1159 if (dlg.DoModal() == IDOK)
1161 CString branch;
1162 if (dlg.m_bBranch)
1163 branch = dlg.m_NewBranch;
1165 return PerformSwitch(dlg.m_VersionName, dlg.m_bForce == TRUE , branch, dlg.m_bBranchOverride == TRUE, dlg.m_bTrack == TRUE, autoclose);
1167 return FALSE;
1170 bool CAppUtils::PerformSwitch(CString ref, bool bForce /* false */, CString sNewBranch /* CString() */, bool bBranchOverride /* false */, bool bTrack /* false */, bool autoClose /* false */)
1172 CString cmd;
1173 CString track;
1174 CString force;
1175 CString branch;
1177 if(!sNewBranch.IsEmpty()){
1178 if (bBranchOverride)
1180 branch.Format(_T("-B %s"), sNewBranch);
1182 else
1184 branch.Format(_T("-b %s"), sNewBranch);
1186 if (bTrack)
1187 track = _T("--track");
1189 if (bForce)
1190 force = _T("-f");
1192 cmd.Format(_T("git.exe checkout %s %s %s %s"),
1193 force,
1194 track,
1195 branch,
1196 g_Git.FixBranchName(ref));
1198 CProgressDlg progress;
1199 progress.m_bAutoCloseOnSuccess = autoClose;
1200 progress.m_GitCmd = cmd;
1202 CTGitPath gitPath = g_Git.m_CurrentDir;
1203 if (gitPath.HasSubmodules())
1204 progress.m_PostCmdList.Add(_T("Update Submodules"));
1206 int ret = progress.DoModal();
1207 if (gitPath.HasSubmodules() && ret == IDC_PROGRESS_BUTTON1)
1209 CString sCmd;
1210 sCmd.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR)(CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe")), (LPCTSTR)g_Git.m_CurrentDir);
1212 LaunchApplication(sCmd, NULL, false);
1213 return TRUE;
1215 else if (ret == IDOK)
1216 return TRUE;
1218 return FALSE;
1221 bool CAppUtils::IgnoreFile(CTGitPathList &path,bool IsMask)
1223 CString ignorefile;
1224 ignorefile=g_Git.m_CurrentDir+_T("\\");
1226 if(IsMask)
1228 ignorefile+=path.GetCommonRoot().GetDirectory().GetWinPathString()+_T("\\.gitignore");
1231 else
1233 ignorefile += _T("\\.gitignore");
1236 CStdioFile file;
1237 if(!file.Open(ignorefile,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate))
1239 CMessageBox::Show(NULL,ignorefile+_T(" Open Failure"),_T("TortoiseGit"),MB_OK);
1240 return FALSE;
1243 CString ignorelist;
1244 CString mask;
1247 //file.ReadString(ignorelist);
1248 file.SeekToEnd();
1249 for(int i=0;i<path.GetCount();i++)
1251 if(IsMask)
1253 mask=_T("*")+path[i].GetFileExtension();
1254 if(ignorelist.Find(mask)<0)
1255 ignorelist += _T("\n")+mask;
1257 else
1259 ignorelist += _T("\n/")+path[i].GetGitPathString();
1262 file.WriteString(ignorelist);
1264 file.Close();
1266 }catch(...)
1268 file.Close();
1269 return FALSE;
1272 return TRUE;
1276 bool CAppUtils::GitReset(CString *CommitHash,int type)
1278 CResetDlg dlg;
1279 dlg.m_ResetType=type;
1280 dlg.m_ResetToVersion=*CommitHash;
1281 if (dlg.DoModal() == IDOK)
1283 CString cmd;
1284 CString type;
1285 switch(dlg.m_ResetType)
1287 case 0:
1288 type=_T("--soft");
1289 break;
1290 case 1:
1291 type=_T("--mixed");
1292 break;
1293 case 2:
1294 type=_T("--hard");
1295 break;
1296 default:
1297 type=_T("--mixed");
1298 break;
1300 cmd.Format(_T("git.exe reset %s %s"),type, *CommitHash);
1302 CProgressDlg progress;
1303 progress.m_GitCmd=cmd;
1305 CTGitPath gitPath = g_Git.m_CurrentDir;
1306 if (gitPath.HasSubmodules() && dlg.m_ResetType == 2)
1307 progress.m_PostCmdList.Add(_T("Update Submodules"));
1309 int ret = progress.DoModal();
1310 if (gitPath.HasSubmodules() && dlg.m_ResetType == 2 && ret == IDC_PROGRESS_BUTTON1)
1312 CString sCmd;
1313 sCmd.Format(_T("\"%s\" /command:subupdate /bkpath:\"%s\""), (LPCTSTR)(CPathUtils::GetAppDirectory()+_T("TortoiseProc.exe")), (LPCTSTR)g_Git.m_CurrentDir);
1315 LaunchApplication(sCmd, NULL, false);
1316 return TRUE;
1318 else if (ret == IDOK)
1319 return TRUE;
1322 return FALSE;
1325 void CAppUtils::DescribeFile(bool mode, bool base,CString &descript)
1327 if(mode == FALSE)
1329 descript=_T("Deleted");
1330 return;
1332 if(base)
1334 descript=_T("Modified");
1335 return;
1337 descript=_T("Created");
1338 return;
1341 void CAppUtils::RemoveTempMergeFile(CTGitPath &path)
1343 CString tempmergefile;
1346 tempmergefile = CAppUtils::GetMergeTempFile(_T("LOCAL"),path);
1347 CFile::Remove(tempmergefile);
1348 }catch(...)
1354 tempmergefile = CAppUtils::GetMergeTempFile(_T("REMOTE"),path);
1355 CFile::Remove(tempmergefile);
1356 }catch(...)
1362 tempmergefile = CAppUtils::GetMergeTempFile(_T("BASE"),path);
1363 CFile::Remove(tempmergefile);
1364 }catch(...)
1368 CString CAppUtils::GetMergeTempFile(CString type,CTGitPath &merge)
1370 CString file;
1371 file=g_Git.m_CurrentDir+_T("\\") + merge.GetWinPathString()+_T(".")+type+merge.GetFileExtension();
1373 return file;
1376 bool CAppUtils::ConflictEdit(CTGitPath &path,bool /*bAlternativeTool*/,bool revertTheirMy)
1378 bool bRet = false;
1380 CTGitPath merge=path;
1381 CTGitPath directory = merge.GetDirectory();
1383 // we have the conflicted file (%merged)
1384 // now look for the other required files
1385 //GitStatus stat;
1386 //stat.GetStatus(merge);
1387 //if (stat.status == NULL)
1388 // return false;
1390 BYTE_VECTOR vector;
1392 CString cmd;
1393 cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),merge.GetGitPathString());
1395 if (g_Git.Run(cmd, &vector))
1397 return FALSE;
1400 CTGitPathList list;
1401 list.ParserFromLsFile(vector);
1403 if(list.GetCount() == 0)
1404 return FALSE;
1406 CTGitPath theirs;
1407 CTGitPath mine;
1408 CTGitPath base;
1410 mine.SetFromGit(GetMergeTempFile(_T("LOCAL"),merge));
1411 theirs.SetFromGit(GetMergeTempFile(_T("REMOTE"),merge));
1412 base.SetFromGit(GetMergeTempFile(_T("BASE"),merge));
1414 CString format;
1416 //format=_T("git.exe cat-file blob \":%d:%s\"");
1417 format = _T("git checkout-index --temp --stage=%d -- \"%s\"");
1418 CFile tempfile;
1419 //create a empty file, incase stage is not three
1420 tempfile.Open(mine.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1421 tempfile.Close();
1422 tempfile.Open(theirs.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1423 tempfile.Close();
1424 tempfile.Open(base.GetWinPathString(),CFile::modeCreate|CFile::modeReadWrite);
1425 tempfile.Close();
1427 bool b_base=false, b_local=false, b_remote=false;
1429 for(int i=0;i<list.GetCount();i++)
1431 CString cmd;
1432 CString outfile;
1433 cmd.Empty();
1434 outfile.Empty();
1436 if( list[i].m_Stage == 1)
1438 cmd.Format(format, list[i].m_Stage, list[i].GetGitPathString());
1439 b_base = true;
1440 outfile = base.GetWinPathString();
1443 if( list[i].m_Stage == 2 )
1445 cmd.Format(format, list[i].m_Stage, list[i].GetGitPathString());
1446 b_local = true;
1447 outfile = mine.GetWinPathString();
1450 if( list[i].m_Stage == 3 )
1452 cmd.Format(format, list[i].m_Stage, list[i].GetGitPathString());
1453 b_remote = true;
1454 outfile = theirs.GetWinPathString();
1456 CString output, err;
1457 if(!outfile.IsEmpty())
1458 if (!g_Git.Run(cmd, &output, &err, CP_ACP))
1460 CString file;
1461 int start =0 ;
1462 file = output.Tokenize(_T("\t"), start);
1463 ::MoveFileEx(file,outfile,MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED);
1465 else
1467 CMessageBox::Show(NULL, output + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
1471 if(b_local && b_remote )
1473 merge.SetFromWin(g_Git.m_CurrentDir+_T("\\")+merge.GetWinPathString());
1474 if( revertTheirMy )
1475 bRet = !!CAppUtils::StartExtMerge(base,mine, theirs, merge,_T("BASE"),_T("LOCAL"),_T("REMOTE"));
1476 else
1477 bRet = !!CAppUtils::StartExtMerge(base, theirs, mine, merge,_T("BASE"),_T("REMOTE"),_T("LOCAL"));
1480 else
1482 CFile::Remove(mine.GetWinPathString());
1483 CFile::Remove(theirs.GetWinPathString());
1484 CFile::Remove(base.GetWinPathString());
1486 CDeleteConflictDlg dlg;
1487 DescribeFile(b_local, b_base,dlg.m_LocalStatus);
1488 DescribeFile(b_remote,b_base,dlg.m_RemoteStatus);
1489 dlg.m_bShowModifiedButton=b_base;
1490 dlg.m_File=merge.GetGitPathString();
1491 if(dlg.DoModal() == IDOK)
1493 CString cmd,out;
1494 if(dlg.m_bIsDelete)
1496 cmd.Format(_T("git.exe rm -- \"%s\""),merge.GetGitPathString());
1498 else
1499 cmd.Format(_T("git.exe add -- \"%s\""),merge.GetGitPathString());
1501 if(g_Git.Run(cmd,&out,CP_ACP))
1503 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
1504 return FALSE;
1506 return TRUE;
1508 else
1509 return FALSE;
1512 #if 0
1513 CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1514 base, theirs, mine, merge);
1515 #endif
1516 #if 0
1517 if (stat.status->text_status == svn_wc_status_conflicted)
1519 // we have a text conflict, use our merge tool to resolve the conflict
1521 CTSVNPath theirs(directory);
1522 CTSVNPath mine(directory);
1523 CTSVNPath base(directory);
1524 bool bConflictData = false;
1526 if ((stat.status->entry)&&(stat.status->entry->conflict_new))
1528 theirs.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_new));
1529 bConflictData = true;
1531 if ((stat.status->entry)&&(stat.status->entry->conflict_old))
1533 base.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_old));
1534 bConflictData = true;
1536 if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))
1538 mine.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->conflict_wrk));
1539 bConflictData = true;
1541 else
1543 mine = merge;
1545 if (bConflictData)
1546 bRet = !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1547 base, theirs, mine, merge);
1550 if (stat.status->prop_status == svn_wc_status_conflicted)
1552 // we have a property conflict
1553 CTSVNPath prej(directory);
1554 if ((stat.status->entry)&&(stat.status->entry->prejfile))
1556 prej.AppendPathString(CUnicodeUtils::GetUnicode(stat.status->entry->prejfile));
1557 // there's a problem: the prej file contains a _description_ of the conflict, and
1558 // that description string might be translated. That means we have no way of parsing
1559 // the file to find out the conflicting values.
1560 // The only thing we can do: show a dialog with the conflict description, then
1561 // let the user either accept the existing property or open the property edit dialog
1562 // to manually change the properties and values. And a button to mark the conflict as
1563 // resolved.
1564 CEditPropConflictDlg dlg;
1565 dlg.SetPrejFile(prej);
1566 dlg.SetConflictedItem(merge);
1567 bRet = (dlg.DoModal() != IDCANCEL);
1571 if (stat.status->tree_conflict)
1573 // we have a tree conflict
1574 SVNInfo info;
1575 const SVNInfoData * pInfoData = info.GetFirstFileInfo(merge, SVNRev(), SVNRev());
1576 if (pInfoData)
1578 if (pInfoData->treeconflict_kind == svn_wc_conflict_kind_text)
1580 CTSVNPath theirs(directory);
1581 CTSVNPath mine(directory);
1582 CTSVNPath base(directory);
1583 bool bConflictData = false;
1585 if (pInfoData->treeconflict_theirfile)
1587 theirs.AppendPathString(pInfoData->treeconflict_theirfile);
1588 bConflictData = true;
1590 if (pInfoData->treeconflict_basefile)
1592 base.AppendPathString(pInfoData->treeconflict_basefile);
1593 bConflictData = true;
1595 if (pInfoData->treeconflict_myfile)
1597 mine.AppendPathString(pInfoData->treeconflict_myfile);
1598 bConflictData = true;
1600 else
1602 mine = merge;
1604 if (bConflictData)
1605 bRet = !!CAppUtils::StartExtMerge(CAppUtils::MergeFlags().AlternativeTool(bAlternativeTool),
1606 base, theirs, mine, merge);
1608 else if (pInfoData->treeconflict_kind == svn_wc_conflict_kind_tree)
1610 CString sConflictAction;
1611 CString sConflictReason;
1612 CString sResolveTheirs;
1613 CString sResolveMine;
1614 CTSVNPath treeConflictPath = CTSVNPath(pInfoData->treeconflict_path);
1615 CString sItemName = treeConflictPath.GetUIFileOrDirectoryName();
1617 if (pInfoData->treeconflict_nodekind == svn_node_file)
1619 switch (pInfoData->treeconflict_operation)
1621 case svn_wc_operation_update:
1622 switch (pInfoData->treeconflict_action)
1624 case svn_wc_conflict_action_edit:
1625 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEEDIT, (LPCTSTR)sItemName);
1626 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1627 break;
1628 case svn_wc_conflict_action_add:
1629 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEADD, (LPCTSTR)sItemName);
1630 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1631 break;
1632 case svn_wc_conflict_action_delete:
1633 sConflictAction.Format(IDS_TREECONFLICT_FILEUPDATEDELETE, (LPCTSTR)sItemName);
1634 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1635 break;
1637 break;
1638 case svn_wc_operation_switch:
1639 switch (pInfoData->treeconflict_action)
1641 case svn_wc_conflict_action_edit:
1642 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHEDIT, (LPCTSTR)sItemName);
1643 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1644 break;
1645 case svn_wc_conflict_action_add:
1646 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHADD, (LPCTSTR)sItemName);
1647 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1648 break;
1649 case svn_wc_conflict_action_delete:
1650 sConflictAction.Format(IDS_TREECONFLICT_FILESWITCHDELETE, (LPCTSTR)sItemName);
1651 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1652 break;
1654 break;
1655 case svn_wc_operation_merge:
1656 switch (pInfoData->treeconflict_action)
1658 case svn_wc_conflict_action_edit:
1659 sConflictAction.Format(IDS_TREECONFLICT_FILEMERGEEDIT, (LPCTSTR)sItemName);
1660 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1661 break;
1662 case svn_wc_conflict_action_add:
1663 sResolveTheirs.Format(IDS_TREECONFLICT_FILEMERGEADD, (LPCTSTR)sItemName);
1664 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYFILE);
1665 break;
1666 case svn_wc_conflict_action_delete:
1667 sConflictAction.Format(IDS_TREECONFLICT_FILEMERGEDELETE, (LPCTSTR)sItemName);
1668 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1669 break;
1671 break;
1674 else if (pInfoData->treeconflict_nodekind == svn_node_dir)
1676 switch (pInfoData->treeconflict_operation)
1678 case svn_wc_operation_update:
1679 switch (pInfoData->treeconflict_action)
1681 case svn_wc_conflict_action_edit:
1682 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEEDIT, (LPCTSTR)sItemName);
1683 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1684 break;
1685 case svn_wc_conflict_action_add:
1686 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEADD, (LPCTSTR)sItemName);
1687 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1688 break;
1689 case svn_wc_conflict_action_delete:
1690 sConflictAction.Format(IDS_TREECONFLICT_DIRUPDATEDELETE, (LPCTSTR)sItemName);
1691 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1692 break;
1694 break;
1695 case svn_wc_operation_switch:
1696 switch (pInfoData->treeconflict_action)
1698 case svn_wc_conflict_action_edit:
1699 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHEDIT, (LPCTSTR)sItemName);
1700 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1701 break;
1702 case svn_wc_conflict_action_add:
1703 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHADD, (LPCTSTR)sItemName);
1704 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1705 break;
1706 case svn_wc_conflict_action_delete:
1707 sConflictAction.Format(IDS_TREECONFLICT_DIRSWITCHDELETE, (LPCTSTR)sItemName);
1708 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1709 break;
1711 break;
1712 case svn_wc_operation_merge:
1713 switch (pInfoData->treeconflict_action)
1715 case svn_wc_conflict_action_edit:
1716 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEEDIT, (LPCTSTR)sItemName);
1717 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1718 break;
1719 case svn_wc_conflict_action_add:
1720 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEADD, (LPCTSTR)sItemName);
1721 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_KEEPREPOSITORYDIR);
1722 break;
1723 case svn_wc_conflict_action_delete:
1724 sConflictAction.Format(IDS_TREECONFLICT_DIRMERGEDELETE, (LPCTSTR)sItemName);
1725 sResolveTheirs.LoadString(IDS_TREECONFLICT_RESOLVE_REMOVEDIR);
1726 break;
1728 break;
1732 UINT uReasonID = 0;
1733 switch (pInfoData->treeconflict_reason)
1735 case svn_wc_conflict_reason_edited:
1736 uReasonID = IDS_TREECONFLICT_REASON_EDITED;
1737 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1738 break;
1739 case svn_wc_conflict_reason_obstructed:
1740 uReasonID = IDS_TREECONFLICT_REASON_OBSTRUCTED;
1741 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1742 break;
1743 case svn_wc_conflict_reason_deleted:
1744 uReasonID = IDS_TREECONFLICT_REASON_DELETED;
1745 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_REMOVEDIR : IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1746 break;
1747 case svn_wc_conflict_reason_added:
1748 uReasonID = IDS_TREECONFLICT_REASON_ADDED;
1749 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1750 break;
1751 case svn_wc_conflict_reason_missing:
1752 uReasonID = IDS_TREECONFLICT_REASON_MISSING;
1753 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_REMOVEDIR : IDS_TREECONFLICT_RESOLVE_REMOVEFILE);
1754 break;
1755 case svn_wc_conflict_reason_unversioned:
1756 uReasonID = IDS_TREECONFLICT_REASON_UNVERSIONED;
1757 sResolveMine.LoadString(pInfoData->treeconflict_nodekind == svn_node_dir ? IDS_TREECONFLICT_RESOLVE_KEEPLOCALDIR : IDS_TREECONFLICT_RESOLVE_KEEPLOCALFILE);
1758 break;
1760 sConflictReason.Format(uReasonID, (LPCTSTR)sConflictAction);
1762 CTreeConflictEditorDlg dlg;
1763 dlg.SetConflictInfoText(sConflictReason);
1764 dlg.SetResolveTexts(sResolveTheirs, sResolveMine);
1765 dlg.SetPath(treeConflictPath);
1766 INT_PTR dlgRet = dlg.DoModal();
1767 bRet = (dlgRet != IDCANCEL);
1771 #endif
1772 return bRet;
1776 * FUNCTION : FormatDateAndTime
1777 * DESCRIPTION : Generates a displayable string from a CTime object in
1778 * system short or long format or as a relative value
1779 * cTime - the time
1780 * option - DATE_SHORTDATE or DATE_LONGDATE
1781 * bIncluedeTime - whether to show time as well as date
1782 * bRelative - if true then relative time is shown if reasonable
1783 * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format
1784 * rather than locale
1785 * RETURN : CString containing date/time
1787 CString CAppUtils::FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime /*=true*/,
1788 bool bRelative /*=false*/)
1790 CString datetime;
1791 if ( bRelative )
1793 datetime = ToRelativeTimeString( cTime );
1795 else
1797 // should we use the locale settings for formatting the date/time?
1798 if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE))
1800 // yes
1801 SYSTEMTIME sysTime;
1802 cTime.GetAsSystemTime( sysTime );
1804 TCHAR buf[100];
1806 GetDateFormat(LOCALE_USER_DEFAULT, option, &sysTime, NULL, buf,
1807 _countof(buf) - 1);
1808 datetime = buf;
1809 if ( bIncludeTime )
1811 datetime += _T(" ");
1812 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, NULL, buf, _countof(buf) - 1);
1813 datetime += buf;
1816 else
1818 // no, so fixed format
1819 if ( bIncludeTime )
1821 datetime = cTime.Format(_T("%Y-%m-%d %H:%M:%S"));
1823 else
1825 datetime = cTime.Format(_T("%Y-%m-%d"));
1829 return datetime;
1833 * Converts a given time to a relative display string (relative to current time)
1834 * Given time must be in local timezone
1836 CString CAppUtils::ToRelativeTimeString(CTime time)
1838 CString answer;
1839 // convert to COleDateTime
1840 SYSTEMTIME sysTime;
1841 time.GetAsSystemTime( sysTime );
1842 COleDateTime oleTime( sysTime );
1843 answer = ToRelativeTimeString(oleTime, COleDateTime::GetCurrentTime());
1844 return answer;
1848 * Generates a display string showing the relative time between the two given times as COleDateTimes
1850 CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo)
1852 CString answer;
1853 COleDateTimeSpan ts = RelativeTo - time;
1854 //years
1855 if(fabs(ts.GetTotalDays()) >= 3*365)
1857 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/365, IDS_YEAR_AGO, IDS_YEARS_AGO );
1859 //Months
1860 if(fabs(ts.GetTotalDays()) >= 60)
1862 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/30, IDS_MONTH_AGO, IDS_MONTHS_AGO );
1863 return answer;
1865 //Weeks
1866 if(fabs(ts.GetTotalDays()) >= 14)
1868 answer = ExpandRelativeTime( (int)ts.GetTotalDays()/7, IDS_WEEK_AGO, IDS_WEEKS_AGO );
1869 return answer;
1871 //Days
1872 if(fabs(ts.GetTotalDays()) >= 2)
1874 answer = ExpandRelativeTime( (int)ts.GetTotalDays(), IDS_DAY_AGO, IDS_DAYS_AGO );
1875 return answer;
1877 //hours
1878 if(fabs(ts.GetTotalHours()) >= 2)
1880 answer = ExpandRelativeTime( (int)ts.GetTotalHours(), IDS_HOUR_AGO, IDS_HOURS_AGO );
1881 return answer;
1883 //minutes
1884 if(fabs(ts.GetTotalMinutes()) >= 2)
1886 answer = ExpandRelativeTime( (int)ts.GetTotalMinutes(), IDS_MINUTE_AGO, IDS_MINUTES_AGO );
1887 return answer;
1889 //seconds
1890 answer = ExpandRelativeTime( (int)ts.GetTotalSeconds(), IDS_SECOND_AGO, IDS_SECONDS_AGO );
1891 return answer;
1895 * Passed a value and two resource string ids
1896 * if count is 1 then FormatString is called with format_1 and the value
1897 * otherwise format_2 is used
1898 * the formatted string is returned
1900 CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n )
1902 CString answer;
1903 if ( count == 1 )
1905 answer.FormatMessage( format_1, count );
1907 else
1909 answer.FormatMessage( format_n, count );
1911 return answer;
1914 bool CAppUtils::IsSSHPutty()
1916 CString sshclient=g_Git.m_Environment.GetEnv(_T("GIT_SSH"));
1917 sshclient=sshclient.MakeLower();
1918 if(sshclient.Find(_T("plink.exe"),0)>=0)
1920 return true;
1922 return false;
1925 CString CAppUtils::GetClipboardLink()
1927 if (!OpenClipboard(NULL))
1928 return CString();
1930 CString sClipboardText;
1931 HGLOBAL hglb = GetClipboardData(CF_TEXT);
1932 if (hglb)
1934 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
1935 sClipboardText = CString(lpstr);
1936 GlobalUnlock(hglb);
1938 hglb = GetClipboardData(CF_UNICODETEXT);
1939 if (hglb)
1941 LPCTSTR lpstr = (LPCTSTR)GlobalLock(hglb);
1942 sClipboardText = lpstr;
1943 GlobalUnlock(hglb);
1945 CloseClipboard();
1947 if(!sClipboardText.IsEmpty())
1949 if(sClipboardText[0] == _T('\"') && sClipboardText[sClipboardText.GetLength()-1] == _T('\"'))
1950 sClipboardText=sClipboardText.Mid(1,sClipboardText.GetLength()-2);
1952 if(sClipboardText.Find( _T("http://")) == 0)
1953 return sClipboardText;
1955 if(sClipboardText.Find( _T("https://")) == 0)
1956 return sClipboardText;
1958 if(sClipboardText.Find( _T("git://")) == 0)
1959 return sClipboardText;
1961 if(sClipboardText.Find( _T("ssh://")) == 0)
1962 return sClipboardText;
1964 if(sClipboardText.GetLength()>=2)
1965 if( sClipboardText[1] == _T(':') )
1966 if( (sClipboardText[0] >= 'A' && sClipboardText[0] <= 'Z')
1967 || (sClipboardText[0] >= 'a' && sClipboardText[0] <= 'z') )
1968 return sClipboardText;
1971 return CString(_T(""));
1974 CString CAppUtils::ChooseRepository(CString *path)
1976 CBrowseFolder browseFolder;
1977 CRegString regLastResopitory = CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\LastRepo"),_T(""));
1979 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
1980 CString strCloneDirectory;
1981 if(path)
1982 strCloneDirectory=*path;
1983 else
1985 strCloneDirectory = regLastResopitory;
1988 CString title;
1989 title.LoadString(IDS_CHOOSE_REPOSITORY);
1991 browseFolder.SetInfo(title);
1993 if (browseFolder.Show(NULL, strCloneDirectory) == CBrowseFolder::OK)
1995 regLastResopitory = strCloneDirectory;
1996 return strCloneDirectory;
1998 else
2000 return CString();
2004 bool CAppUtils::SendPatchMail(CTGitPathList &list,bool autoclose)
2006 CSendMailDlg dlg;
2008 dlg.m_PathList = list;
2010 if(dlg.DoModal()==IDOK)
2012 if(dlg.m_PathList.GetCount() == 0)
2013 return FALSE;
2015 CGitProgressDlg progDlg;
2017 theApp.m_pMainWnd = &progDlg;
2018 progDlg.SetCommand(CGitProgressDlg::GitProgress_SendMail);
2020 progDlg.SetAutoClose(autoclose);
2022 progDlg.SetPathList(dlg.m_PathList);
2023 //ProjectProperties props;
2024 //props.ReadPropsPathList(dlg.m_pathList);
2025 //progDlg.SetProjectProperties(props);
2026 progDlg.SetItemCount(dlg.m_PathList.GetCount());
2028 DWORD flags =0;
2029 if(dlg.m_bAttachment)
2030 flags |= SENDMAIL_ATTACHMENT;
2031 if(dlg.m_bCombine)
2032 flags |= SENDMAIL_COMBINED;
2033 if(dlg.m_bUseMAPI)
2034 flags |= SENDMAIL_MAPI;
2036 progDlg.SetSendMailOption(dlg.m_To,dlg.m_CC,dlg.m_Subject,flags);
2038 progDlg.DoModal();
2040 return true;
2042 return false;
2045 bool CAppUtils::SendPatchMail(CString &cmd,CString &formatpatchoutput,bool autoclose)
2047 CTGitPathList list;
2048 CString log=formatpatchoutput;
2049 int start=log.Find(cmd);
2050 if(start >=0)
2051 CString one=log.Tokenize(_T("\n"),start);
2052 else
2053 start = 0;
2055 while(start>=0)
2057 CString one=log.Tokenize(_T("\n"),start);
2058 one=one.Trim();
2059 if(one.IsEmpty() || one == _T("Success"))
2060 continue;
2061 one.Replace(_T('/'),_T('\\'));
2062 CTGitPath path;
2063 path.SetFromWin(one);
2064 list.AddPath(path);
2066 if (list.GetCount() > 0)
2068 return SendPatchMail(list, autoclose);
2070 else
2072 CMessageBox::Show(NULL, _T("Not patches generated."), _T("TortoiseGit"), MB_ICONINFORMATION);
2073 return true;
2078 int CAppUtils::GetLogOutputEncode(CGit *pGit)
2080 CString cmd,output;
2081 int start=0;
2083 output = pGit->GetConfigValue(_T("i18n.logOutputEncoding"));
2084 if(output.IsEmpty())
2086 output = pGit->GetConfigValue(_T("i18n.commitencoding"));
2087 if(output.IsEmpty())
2088 return CP_UTF8;
2090 int start=0;
2091 output=output.Tokenize(_T("\n"),start);
2092 return CUnicodeUtils::GetCPCode(output);
2095 else
2097 output=output.Tokenize(_T("\n"),start);
2098 return CUnicodeUtils::GetCPCode(output);
2101 int CAppUtils::GetCommitTemplate(CString &temp)
2103 CString cmd,output;
2105 output= g_Git.GetConfigValue(_T("commit.template"),CP_ACP);
2106 if( output.IsEmpty() )
2107 return -1;
2109 if( output.GetLength()<1)
2110 return -1;
2112 if( output[0] == _T('/'))
2114 if(output.GetLength()>=3)
2115 if(output[2] == _T('/'))
2117 output.GetBuffer()[0] = output[1];
2118 output.GetBuffer()[1] = _T(':');
2122 int start=0;
2123 output=output.Tokenize(_T("\n"),start);
2125 output.Replace(_T('/'),_T('\\'));
2129 CStdioFile file(output,CFile::modeRead|CFile::typeText);
2130 CString str;
2131 while(file.ReadString(str))
2133 temp+=str+_T("\n");
2136 }catch(...)
2138 return -1;
2140 return 0;
2142 int CAppUtils::SaveCommitUnicodeFile(CString &filename, CString &message)
2144 CFile file(filename,CFile::modeReadWrite|CFile::modeCreate );
2145 CString cmd,output;
2146 int cp=CP_UTF8;
2148 output= g_Git.GetConfigValue(_T("i18n.commitencoding"));
2149 if(output.IsEmpty())
2150 cp=CP_UTF8;
2152 int start=0;
2153 output=output.Tokenize(_T("\n"),start);
2154 cp=CUnicodeUtils::GetCPCode(output);
2156 int len=message.GetLength();
2158 char * buf;
2159 buf = new char[len*4 + 4];
2160 SecureZeroMemory(buf, (len*4 + 4));
2162 int lengthIncTerminator = WideCharToMultiByte(cp, 0, message, -1, buf, len*4, NULL, NULL);
2164 file.Write(buf,lengthIncTerminator-1);
2165 file.Close();
2166 delete buf;
2167 return 0;
2170 bool CAppUtils::Fetch(CString remoteName, bool allowRebase, bool autoClose)
2172 CPullFetchDlg dlg;
2173 dlg.m_PreSelectRemote = remoteName;
2174 dlg.m_bAllowRebase = allowRebase;
2175 dlg.m_IsPull=FALSE;
2177 if(dlg.DoModal()==IDOK)
2179 if(dlg.m_bAutoLoad)
2181 CAppUtils::LaunchPAgent(NULL,&dlg.m_RemoteURL);
2184 CString url;
2185 url=dlg.m_RemoteURL;
2186 CString cmd;
2187 CString arg;
2189 int ver = CAppUtils::GetMsysgitVersion();
2191 if(ver >= 0x01070203) //above 1.7.0.2
2192 arg = _T("--progress ");
2194 if (dlg.m_bPrune) {
2195 arg += _T("--prune ");
2198 if (dlg.m_bFetchTags) {
2199 arg += _T("--tags ");
2202 cmd.Format(_T("git.exe fetch -v %s \"%s\" %s"),arg, url,dlg.m_RemoteBranchName);
2203 CProgressDlg progress;
2205 progress.m_bAutoCloseOnSuccess = autoClose;
2207 progress.m_PostCmdList.Add(_T("Show Log"));
2209 if(!dlg.m_bRebase && !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir))
2211 progress.m_PostCmdList.Add(_T("&Rebase"));
2214 progress.m_GitCmd=cmd;
2215 int userResponse=progress.DoModal();
2217 if (userResponse == IDC_PROGRESS_BUTTON1)
2219 CString cmd;
2220 cmd = CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
2221 cmd += _T(" /command:log");
2222 cmd += _T(" /path:\"") + g_Git.m_CurrentDir + _T("\"");
2223 CAppUtils::LaunchApplication(cmd, IDS_ERR_PROC, false);
2224 return TRUE;
2226 else if ((userResponse == IDC_PROGRESS_BUTTON1 + 1) || (progress.m_GitStatus == 0 && dlg.m_bRebase))
2228 while(1)
2230 CRebaseDlg dlg;
2231 dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));
2232 dlg.m_PostButtonTexts.Add(_T("Restart Rebase"));
2233 int response = dlg.DoModal();
2234 if(response == IDOK)
2236 return TRUE;
2238 if(response == IDC_REBASE_POST_BUTTON )
2240 CString cmd, out, err;
2241 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
2242 g_Git.m_CurrentDir,
2243 g_Git.FixBranchName(dlg.m_Upstream),
2244 g_Git.FixBranchName(dlg.m_Branch));
2245 if (g_Git.Run(cmd, &out, &err, CP_ACP))
2247 CMessageBox::Show(NULL, out + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
2248 return FALSE;
2251 CAppUtils::SendPatchMail(cmd,out);
2252 return TRUE;
2255 if(response == IDC_REBASE_POST_BUTTON +1 )
2256 continue;
2258 if(response == IDCANCEL)
2259 return FALSE;
2261 return TRUE;
2264 return FALSE;
2267 bool CAppUtils::Push(CString selectLocalBranch, bool autoClose)
2269 CPushDlg dlg;
2270 dlg.m_BranchSourceName = selectLocalBranch;
2271 CString error;
2272 DWORD exitcode = 0xFFFFFFFF;
2273 CTGitPathList list;
2274 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
2275 if (CHooks::Instance().PrePush(list,exitcode, error))
2277 if (exitcode)
2279 CString temp;
2280 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2281 //ReportError(temp);
2282 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2283 return false;
2287 if(dlg.DoModal()==IDOK)
2289 CString cmd;
2290 CString arg;
2292 if(dlg.m_bAutoLoad)
2294 CAppUtils::LaunchPAgent(NULL,&dlg.m_URL);
2297 if(dlg.m_bPack)
2298 arg += _T("--thin ");
2299 if(dlg.m_bTags && !dlg.m_bPushAllBranches)
2300 arg += _T("--tags ");
2301 if(dlg.m_bForce)
2302 arg += _T("--force ");
2304 int ver = CAppUtils::GetMsysgitVersion();
2306 if(ver >= 0x01070203) //above 1.7.0.2
2307 arg += _T("--progress ");
2309 if (dlg.m_bPushAllBranches)
2311 cmd.Format(_T("git.exe push --all %s \"%s\""),
2312 arg,
2313 dlg.m_URL);
2315 else
2317 cmd.Format(_T("git.exe push %s \"%s\" %s"),
2318 arg,
2319 dlg.m_URL,
2320 dlg.m_BranchSourceName);
2321 if (!dlg.m_BranchRemoteName.IsEmpty())
2323 cmd += _T(":") + dlg.m_BranchRemoteName;
2327 CProgressDlg progress;
2328 progress.m_bAutoCloseOnSuccess=autoClose;
2329 progress.m_GitCmd=cmd;
2330 progress.m_PostCmdList.Add(_T("&Request pull"));
2331 progress.m_PostCmdList.Add(_T("Re&Push"));
2332 int ret = progress.DoModal();
2334 if(!progress.m_GitStatus)
2336 if (CHooks::Instance().PostPush(list,exitcode, error))
2338 if (exitcode)
2340 CString temp;
2341 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
2342 //ReportError(temp);
2343 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
2344 return false;
2347 if(ret == IDC_PROGRESS_BUTTON1)
2349 RequestPull(dlg.m_BranchRemoteName);
2351 else if(ret == IDC_PROGRESS_BUTTON1 + 1)
2353 Push();
2355 return TRUE;
2359 return FALSE;
2362 bool CAppUtils::RequestPull(CString endrevision, CString repositoryUrl)
2364 CRequestPullDlg dlg;
2365 dlg.m_RepositoryURL = repositoryUrl;
2366 dlg.m_EndRevision = endrevision;
2367 if (dlg.DoModal()==IDOK)
2369 CString cmd;
2370 cmd.Format(_T("git.exe request-pull %s \"%s\" %s"), dlg.m_StartRevision, dlg.m_RepositoryURL, dlg.m_EndRevision);
2372 CProgressDlg progress;
2373 progress.m_GitCmd=cmd;
2374 progress.DoModal();
2376 return true;
2379 bool CAppUtils::CreateMultipleDirectory(const CString& szPath)
2381 CString strDir(szPath);
2382 if (strDir.GetAt(strDir.GetLength()-1)!=_T('\\'))
2384 strDir.AppendChar(_T('\\'));
2386 std::vector<CString> vPath;
2387 CString strTemp;
2388 bool bSuccess = false;
2390 for (int i=0;i<strDir.GetLength();++i)
2392 if (strDir.GetAt(i) != _T('\\'))
2394 strTemp.AppendChar(strDir.GetAt(i));
2396 else
2398 vPath.push_back(strTemp);
2399 strTemp.AppendChar(_T('\\'));
2403 std::vector<CString>::const_iterator vIter;
2404 for (vIter = vPath.begin(); vIter != vPath.end(); vIter++)
2406 bSuccess = CreateDirectory(*vIter, NULL) ? true : false;
2409 return bSuccess;
2412 void CAppUtils::RemoveTrailSlash(CString &path)
2414 if(path.IsEmpty())
2415 return ;
2417 while(path[path.GetLength()-1] == _T('\\') || path[path.GetLength()-1] == _T('/' ) )
2419 path=path.Left(path.GetLength()-1);
2420 if(path.IsEmpty())
2421 return;
2425 BOOL CAppUtils::Commit(CString bugid,BOOL bWholeProject,CString &sLogMsg,
2426 CTGitPathList &pathList,
2427 CTGitPathList &selectedList,
2428 bool bSelectFilesForCommit,
2429 bool autoClose)
2431 bool bFailed = true;
2433 while(g_Git.GetUserName().IsEmpty() || g_Git.GetConfigValue(_T("user.email")).IsEmpty())
2435 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"),
2436 _T("TortoiseGit"),MB_YESNO| MB_ICONERROR) == IDYES)
2438 CTGitPath path(g_Git.m_CurrentDir);
2439 CSettings dlg(IDS_PROC_SETTINGS_TITLE,&path);
2440 dlg.SetTreeViewMode(TRUE, TRUE, TRUE);
2441 dlg.SetTreeWidth(220);
2442 dlg.m_DefaultPage = _T("gitconfig");
2444 dlg.DoModal();
2445 dlg.HandleRestart();
2448 else
2449 return false;
2452 while (bFailed)
2454 bFailed = false;
2455 CCommitDlg dlg;
2456 dlg.m_sBugID = bugid;
2458 dlg.m_bWholeProject = bWholeProject;
2460 dlg.m_sLogMessage = sLogMsg;
2461 dlg.m_pathList = pathList;
2462 dlg.m_checkedPathList = selectedList;
2463 dlg.m_bSelectFilesForCommit = bSelectFilesForCommit;
2464 dlg.m_bAutoClose = autoClose;
2465 if (dlg.DoModal() == IDOK)
2467 if (dlg.m_pathList.GetCount()==0)
2468 return false;
2469 // if the user hasn't changed the list of selected items
2470 // we don't use that list. Because if we would use the list
2471 // of pre-checked items, the dialog would show different
2472 // checked items on the next startup: it would only try
2473 // to check the parent folder (which might not even show)
2474 // instead, we simply use an empty list and let the
2475 // default checking do its job.
2476 if (!dlg.m_pathList.IsEqual(pathList))
2477 selectedList = dlg.m_pathList;
2478 pathList = dlg.m_updatedPathList;
2479 sLogMsg = dlg.m_sLogMessage;
2480 bSelectFilesForCommit = true;
2482 if( dlg.m_bPushAfterCommit )
2484 switch(dlg.m_PostCmd)
2486 case GIT_POST_CMD_DCOMMIT:
2487 CAppUtils::SVNDCommit();
2488 break;
2489 default:
2490 CAppUtils::Push();
2493 // CGitProgressDlg progDlg;
2494 // progDlg.SetChangeList(dlg.m_sChangeList, !!dlg.m_bKeepChangeList);
2495 // if (parser.HasVal(_T("closeonend")))
2496 // progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
2497 // progDlg.SetCommand(CGitProgressDlg::GitProgress_Commit);
2498 // progDlg.SetOptions(dlg.m_bKeepLocks ? ProgOptKeeplocks : ProgOptNone);
2499 // progDlg.SetPathList(dlg.m_pathList);
2500 // progDlg.SetCommitMessage(dlg.m_sLogMessage);
2501 // progDlg.SetDepth(dlg.m_bRecursive ? Git_depth_infinity : svn_depth_empty);
2502 // progDlg.SetSelectedList(dlg.m_selectedPathList);
2503 // progDlg.SetItemCount(dlg.m_itemsCount);
2504 // progDlg.SetBugTraqProvider(dlg.m_BugTraqProvider);
2505 // progDlg.DoModal();
2506 // CRegDWORD err = CRegDWORD(_T("Software\\TortoiseGit\\ErrorOccurred"), FALSE);
2507 // err = (DWORD)progDlg.DidErrorsOccur();
2508 // bFailed = progDlg.DidErrorsOccur();
2509 // bRet = progDlg.DidErrorsOccur();
2510 // CRegDWORD bFailRepeat = CRegDWORD(_T("Software\\TortoiseGit\\CommitReopen"), FALSE);
2511 // if (DWORD(bFailRepeat)==0)
2512 // bFailed = false; // do not repeat if the user chose not to in the settings.
2515 return true;
2519 BOOL CAppUtils::SVNDCommit()
2521 CSVNDCommitDlg dcommitdlg;
2522 CString gitSetting = g_Git.GetConfigValue(_T("svn.rmdir"));
2523 if (gitSetting == _T("")) {
2524 if (dcommitdlg.DoModal() != IDOK)
2526 return false;
2528 else
2530 if (dcommitdlg.m_remember)
2532 if (dcommitdlg.m_rmdir)
2534 gitSetting = _T("true");
2536 else
2538 gitSetting = _T("false");
2540 if(g_Git.SetConfigValue(_T("svn.rmdir"),gitSetting))
2542 CMessageBox::Show(NULL,_T("Fail to set config"),_T("TortoiseGit"),MB_OK);
2548 BOOL IsStash = false;
2549 if(!g_Git.CheckCleanWorkTree())
2551 if(CMessageBox::Show(NULL, IDS_ERROR_NOCLEAN_STASH,IDS_APPNAME,MB_YESNO|MB_ICONINFORMATION)==IDYES)
2553 CString cmd,out;
2554 cmd=_T("git.exe stash");
2555 if(g_Git.Run(cmd,&out,CP_ACP))
2557 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
2558 return false;
2560 IsStash =true;
2563 else
2565 return false;
2569 CProgressDlg progress;
2570 if (dcommitdlg.m_rmdir)
2572 progress.m_GitCmd=_T("git.exe svn dcommit --rmdir");
2574 else
2576 progress.m_GitCmd=_T("git.exe svn dcommit");
2578 if(progress.DoModal()==IDOK && progress.m_GitStatus == 0)
2580 if( IsStash)
2582 if(CMessageBox::Show(NULL,IDS_DCOMMIT_STASH_POP,IDS_APPNAME,MB_YESNO|MB_ICONINFORMATION)==IDYES)
2584 CString cmd,out;
2585 cmd=_T("git.exe stash pop");
2586 if(g_Git.Run(cmd,&out,CP_ACP))
2588 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK);
2589 return false;
2593 else
2595 return false;
2598 return TRUE;
2600 return FALSE;
2603 BOOL CAppUtils::Merge(CString *commit)
2605 CMergeDlg dlg;
2606 if(commit)
2607 dlg.m_initialRefName = *commit;
2609 if(dlg.DoModal()==IDOK)
2611 CString cmd;
2612 CString noff;
2613 CString squash;
2614 CString nocommit;
2615 CString msg;
2617 if(dlg.m_bNoFF)
2618 noff=_T("--no-ff");
2620 if(dlg.m_bSquash)
2621 squash=_T("--squash");
2623 if(dlg.m_bNoCommit)
2624 nocommit=_T("--no-commit");
2626 if(!dlg.m_strLogMesage.IsEmpty())
2628 msg += _T("-m \"")+dlg.m_strLogMesage+_T("\"");
2630 cmd.Format(_T("git.exe merge %s %s %s %s %s"),
2631 msg,
2632 noff,
2633 squash,
2634 nocommit,
2635 g_Git.FixBranchName(dlg.m_VersionName));
2637 CProgressDlg Prodlg;
2638 Prodlg.m_GitCmd = cmd;
2640 if (dlg.m_bNoCommit)
2641 Prodlg.m_PostCmdList.Add(_T("Commit"));
2643 int ret = Prodlg.DoModal();
2645 if (ret == IDC_PROGRESS_BUTTON1)
2646 return Commit(_T(""), TRUE, CString(), CTGitPathList(), CTGitPathList(), true);
2648 return !Prodlg.m_GitStatus;
2650 return false;
2653 void CAppUtils::EditNote(GitRev *rev)
2655 CInputDlg dlg;
2656 dlg.m_sHintText=_T("Edit Notes");
2657 dlg.m_sInputText = rev->m_Notes;
2658 dlg.m_sTitle=_T("Edit Notes");
2659 //dlg.m_pProjectProperties = &m_ProjectProperties;
2660 dlg.m_bUseLogWidth = true;
2661 if(dlg.DoModal() == IDOK)
2663 CString cmd,output;
2664 cmd=_T("notes add -f -F \"");
2666 CString tempfile=::GetTempFile();
2667 CAppUtils::SaveCommitUnicodeFile(tempfile,dlg.m_sInputText);
2668 cmd += tempfile;
2669 cmd += _T("\" ");
2670 cmd += rev->m_CommitHash.ToString();
2674 if(git_run_cmd("notes", CUnicodeUtils::GetMulti(cmd,CP_ACP).GetBuffer()))
2676 CMessageBox::Show(NULL,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
2679 else
2681 rev->m_Notes = dlg.m_sInputText;
2683 }catch(...)
2685 CMessageBox::Show(NULL,_T("Edit Note Fail"), _T("TortoiseGit"),MB_OK|MB_ICONERROR);
2687 CFile::Remove(tempfile);
2692 int CAppUtils::GetMsysgitVersion(CString *versionstr)
2694 CString cmd;
2695 CString progressarg;
2696 CString version;
2698 CRegDWORD regTime = CRegDWORD(_T("Software\\TortoiseGit\\git_file_time"));
2699 CRegDWORD regVersion = CRegDWORD(_T("Software\\TortoiseGit\\git_cached_version"));
2701 CString gitpath = CGit::ms_LastMsysGitDir+_T("\\git.exe");
2703 __int64 time=0;
2704 if(!g_Git.GetFileModifyTime(gitpath, &time) && !versionstr)
2706 if((DWORD)time == regTime)
2708 return regVersion;
2712 if(versionstr)
2713 version = *versionstr;
2714 else
2716 CString err;
2717 cmd = _T("git.exe --version");
2718 if(g_Git.Run(cmd, &version, &err, CP_ACP))
2720 CMessageBox::Show(NULL, _T("git have not installed (") + err + _T(")"), _T("TortoiseGit"), MB_OK|MB_ICONERROR);
2721 return false;
2725 int start=0;
2726 int ver;
2728 CString str=version.Tokenize(_T("."),start);
2729 int space = str.ReverseFind(_T(' '));
2730 str=str.Mid(space+1,start);
2731 ver = _ttol(str);
2732 ver <<=24;
2734 version = version.Mid(start);
2735 start = 0;
2736 str = version.Tokenize(_T("."),start);
2738 ver |= (_ttol(str)&0xFF)<<16;
2740 str = version.Tokenize(_T("."),start);
2741 ver |= (_ttol(str)&0xFF)<<8;
2743 str = version.Tokenize(_T("."),start);
2744 ver |= (_ttol(str)&0xFF);
2746 regTime = time&0xFFFFFFFF;
2747 regVersion = ver;
2749 return ver;
2752 void CAppUtils::MarkWindowAsUnpinnable(HWND hWnd)
2754 typedef HRESULT (WINAPI *SHGPSFW) (HWND hwnd,REFIID riid,void** ppv);
2756 HMODULE hShell = LoadLibrary(_T("Shell32.dll"));
2758 if (hShell) {
2759 SHGPSFW pfnSHGPSFW = (SHGPSFW)::GetProcAddress(hShell, "SHGetPropertyStoreForWindow");
2760 if (pfnSHGPSFW) {
2761 IPropertyStore *pps;
2762 HRESULT hr = pfnSHGPSFW(hWnd, IID_PPV_ARGS(&pps));
2763 if (SUCCEEDED(hr)) {
2764 PROPVARIANT var;
2765 var.vt = VT_BOOL;
2766 var.boolVal = VARIANT_TRUE;
2767 hr = pps->SetValue(PKEY_AppUserModel_PreventPinning, var);
2768 pps->Release();
2771 FreeLibrary(hShell);
2775 void CAppUtils::SetWindowTitle(HWND hWnd, const CString& urlorpath, const CString& dialogname)
2777 ASSERT(dialogname.GetLength() < 70);
2778 ASSERT(urlorpath.GetLength() < MAX_PATH);
2779 WCHAR pathbuf[MAX_PATH] = {0};
2781 PathCompactPathEx(pathbuf, urlorpath, 70 - dialogname.GetLength(), 0);
2783 wcscat_s(pathbuf, L" - ");
2784 wcscat_s(pathbuf, dialogname);
2785 wcscat_s(pathbuf, L" - ");
2786 wcscat_s(pathbuf, CString(MAKEINTRESOURCE(IDS_APPNAME)));
2787 SetWindowText(hWnd, pathbuf);