1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2010-2011 - TortoiseGit
4 // Copyright (C) 2006-2010 - 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.
23 #include "PathUtils.h"
24 #include "UnicodeUtils.h"
25 #include "SysProgressDlg.h"
28 #include "svn_pools.h"
32 #include "svn_string.h"
36 #include "CreateProcessHelper.h"
37 #include "FormatMessageWrapper.h"
39 CAppUtils::CAppUtils(void)
43 CAppUtils::~CAppUtils(void)
47 BOOL
CAppUtils::GetVersionedFile(CString sPath
, CString sVersion
, CString sSavePath
, CSysProgressDlg
* progDlg
, HWND hWnd
/*=NULL*/)
49 CString sSCMPath
= CRegString(_T("Software\\TortoiseMerge\\SCMPath"), _T(""));
50 if (sSCMPath
.IsEmpty())
52 // no path set, so use TortoiseSVN as default
53 sSCMPath
= CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
54 sSCMPath
+= _T(" /command:cat /path:\"%1\" /revision:%2 /savepath:\"%3\" /hwnd:%4");
57 sTemp
.Format(_T("%d"), hWnd
);
58 sSCMPath
.Replace(_T("%1"), sPath
);
59 sSCMPath
.Replace(_T("%2"), sVersion
);
60 sSCMPath
.Replace(_T("%3"), sSavePath
);
61 sSCMPath
.Replace(_T("%4"), sTemp
);
62 // start the external SCM program to fetch the specific version of the file
63 PROCESS_INFORMATION process
;
64 if (!CCreateProcessHelper::CreateProcess(NULL
, (LPTSTR
)(LPCTSTR
)sSCMPath
, &process
))
66 CFormatMessageWrapper errorDetails
;
67 MessageBox(NULL
, errorDetails
, _T("TortoiseMerge"), MB_OK
| MB_ICONERROR
);
73 ret
= WaitForSingleObject(process
.hProcess
, 100);
74 } while ((ret
== WAIT_TIMEOUT
) && (!progDlg
->HasUserCancelled()));
75 CloseHandle(process
.hThread
);
76 CloseHandle(process
.hProcess
);
78 if (progDlg
->HasUserCancelled())
82 if (!PathFileExists(sSavePath
))
87 bool CAppUtils::CreateUnifiedDiff(const CString
& orig
, const CString
& modified
, const CString
& output
, bool bShowError
)
90 cmd
.Format(_T("git.exe diff --no-index \"%s\" \"%s\""),orig
, modified
);
92 if(g_Git
.RunLogFile(cmd
,(CString
&)output
) && bShowError
)
94 MessageBox(NULL
, _T("Fail Create Patch"), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
100 bool CAppUtils::HasClipboardFormat(UINT format
)
102 if (OpenClipboard(NULL
))
107 if (enumFormat
== format
)
112 } while((enumFormat
= EnumClipboardFormats(enumFormat
))!=0);