1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006-2009 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "PathUtils.h"
23 #include "UnicodeUtils.h"
24 #include "SysProgressDlg.h"
26 #include "svn_pools.h"
30 #include "svn_string.h"
33 #include "MessageBox.h"
35 CAppUtils::CAppUtils(void)
39 CAppUtils::~CAppUtils(void)
43 BOOL
CAppUtils::GetVersionedFile(CString sPath
, CString sVersion
, CString sSavePath
, CSysProgressDlg
* progDlg
, HWND hWnd
/*=NULL*/)
45 CString sSCMPath
= CRegString(_T("Software\\TortoiseMerge\\SCMPath"), _T(""));
46 if (sSCMPath
.IsEmpty())
48 // no path set, so use TortoiseSVN as default
49 sSCMPath
= CPathUtils::GetAppDirectory() + _T("TortoiseProc.exe");
50 sSCMPath
+= _T(" /command:cat /path:\"%1\" /revision:%2 /savepath:\"%3\" /hwnd:%4");
53 sTemp
.Format(_T("%d"), hWnd
);
54 sSCMPath
.Replace(_T("%1"), sPath
);
55 sSCMPath
.Replace(_T("%2"), sVersion
);
56 sSCMPath
.Replace(_T("%3"), sSavePath
);
57 sSCMPath
.Replace(_T("%4"), sTemp
);
58 // start the external SCM program to fetch the specific version of the file
60 PROCESS_INFORMATION process
;
61 memset(&startup
, 0, sizeof(startup
));
62 startup
.cb
= sizeof(startup
);
63 memset(&process
, 0, sizeof(process
));
64 if (CreateProcess(NULL
, (LPTSTR
)(LPCTSTR
)sSCMPath
, NULL
, NULL
, FALSE
, 0, 0, 0, &startup
, &process
)==0)
67 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
68 FORMAT_MESSAGE_FROM_SYSTEM
|
69 FORMAT_MESSAGE_IGNORE_INSERTS
,
72 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
77 MessageBox(NULL
, (LPCTSTR
)lpMsgBuf
, _T("TortoiseMerge"), MB_OK
| MB_ICONERROR
);
78 LocalFree( lpMsgBuf
);
83 ret
= WaitForSingleObject(process
.hProcess
, 100);
84 } while ((ret
== WAIT_TIMEOUT
) && (!progDlg
->HasUserCancelled()));
85 CloseHandle(process
.hThread
);
86 CloseHandle(process
.hProcess
);
88 if (progDlg
->HasUserCancelled())
92 if (!PathFileExists(sSavePath
))
97 bool CAppUtils::CreateUnifiedDiff(const CString
& orig
, const CString
& modified
, const CString
& output
, bool bShowError
)
100 cmd
.Format(_T("git.exe diff --no-index \"%s\" \"%s\""),orig
, modified
);
102 if(g_Git
.RunLogFile(cmd
,(CString
&)output
) && bShowError
)
104 CMessageBox::Show(NULL
, _T("Fail Create Patch"), _T("TortoiseGit"), MB_OK
|MB_ICONERROR
);
110 CString
CAppUtils::GetErrorString(svn_error_t
* Err
)
118 svn_error_t
* ErrPtr
= Err
;
120 msg
= CUnicodeUtils::GetUnicode(ErrPtr
->message
);
123 /* Is this a Subversion-specific error code? */
124 if ((ErrPtr
->apr_err
> APR_OS_START_USEERR
)
125 && (ErrPtr
->apr_err
<= APR_OS_START_CANONERR
))
126 msg
= svn_strerror (ErrPtr
->apr_err
, errbuf
, sizeof (errbuf
));
127 /* Otherwise, this must be an APR error code. */
130 svn_error_t
*temp_err
= NULL
;
131 const char * err_string
= NULL
;
132 temp_err
= svn_utf_cstring_to_utf8(&err_string
, apr_strerror (ErrPtr
->apr_err
, errbuf
, sizeof (errbuf
)-1), ErrPtr
->pool
);
135 svn_error_clear (temp_err
);
136 msg
= _T("Can't recode error string from APR");
140 msg
= CUnicodeUtils::GetUnicode(err_string
);
144 while (ErrPtr
->child
)
146 ErrPtr
= ErrPtr
->child
;
149 temp
= CUnicodeUtils::GetUnicode(ErrPtr
->message
);
152 /* Is this a Subversion-specific error code? */
153 if ((ErrPtr
->apr_err
> APR_OS_START_USEERR
)
154 && (ErrPtr
->apr_err
<= APR_OS_START_CANONERR
))
155 temp
= svn_strerror (ErrPtr
->apr_err
, errbuf
, sizeof (errbuf
));
156 /* Otherwise, this must be an APR error code. */
159 svn_error_t
*temp_err
= NULL
;
160 const char * err_string
= NULL
;
161 temp_err
= svn_utf_cstring_to_utf8(&err_string
, apr_strerror (ErrPtr
->apr_err
, errbuf
, sizeof (errbuf
)-1), ErrPtr
->pool
);
164 svn_error_clear (temp_err
);
165 temp
= _T("Can't recode error string from APR");
169 temp
= CUnicodeUtils::GetUnicode(err_string
);
180 bool CAppUtils::HasClipboardFormat(UINT format
)
182 if (OpenClipboard(NULL
))
187 if (enumFormat
== format
)
192 } while((enumFormat
= EnumClipboardFormats(enumFormat
))!=0);