1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2010-2011,2014 - TortoiseGit
4 // Copyright (C) 2006-2010, 2012-2014 - 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\\TortoiseGitMerge\\SCMPath"), _T(""));
50 if (sSCMPath
.IsEmpty())
52 // no path set, so use TortoiseGit as default
53 sSCMPath
= CPathUtils::GetAppDirectory() + _T("TortoiseGitProc.exe");
54 sSCMPath
+= _T(" /command:cat /path:\"%1\" /revision:%2 /savepath:\"%3\" /hwnd:%4");
57 sTemp
.Format(_T("%p"), (void*)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("TortoiseGitMerge"), MB_OK
| MB_ICONERROR
);
73 ret
= WaitForSingleObject(process
.hProcess
, 100);
74 } while ((ret
== WAIT_TIMEOUT
) && (!progDlg
|| !progDlg
->HasUserCancelled()));
75 CloseHandle(process
.hThread
);
76 CloseHandle(process
.hProcess
);
78 if (progDlg
&& progDlg
->HasUserCancelled())
82 if (!PathFileExists(sSavePath
))
87 bool CAppUtils::CreateUnifiedDiff(const CString
& orig
, const CString
& modified
, const CString
& output
, int contextsize
, bool bShowError
)
91 diffContext
.Format(_T("--unified=%d"), contextsize
);
93 cmd
.Format(_T("git.exe diff --no-index %s -- \"%s\" \"%s\""), diffContext
, orig
, modified
);
95 int result
= g_Git
.RunLogFile(cmd
, output
, &err
);
96 if (result
!= 0 && result
!= 1 && bShowError
)
98 MessageBox(NULL
, _T("Failed to create patch.\n") + err
, _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
104 bool CAppUtils::HasClipboardFormat(UINT format
)
106 if (OpenClipboard(NULL
))
111 if (enumFormat
== format
)
116 } while((enumFormat
= EnumClipboardFormats(enumFormat
))!=0);
122 COLORREF
CAppUtils::IntenseColor(long scale
, COLORREF col
)
124 // if the color is already dark (gray scale below 127),
125 // then lighten the color by 'scale', otherwise darken it
126 int Gray
= (((int)GetRValue(col
)) + GetGValue(col
) + GetBValue(col
))/3;
129 long red
= MulDiv(GetRValue(col
),(255-scale
),255);
130 long green
= MulDiv(GetGValue(col
),(255-scale
),255);
131 long blue
= MulDiv(GetBValue(col
),(255-scale
),255);
133 return RGB(red
, green
, blue
);
135 long R
= MulDiv(255-GetRValue(col
),scale
,255)+GetRValue(col
);
136 long G
= MulDiv(255-GetGValue(col
),scale
,255)+GetGValue(col
);
137 long B
= MulDiv(255-GetBValue(col
),scale
,255)+GetBValue(col
);