1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2010-2011,2014-2016 - 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 BOOL
CAppUtils::GetVersionedFile(CString sPath
, CString sVersion
, CString sSavePath
, CSysProgressDlg
* progDlg
, HWND hWnd
/*=nullptr*/)
41 CString sSCMPath
= CRegString(L
"Software\\TortoiseGitMerge\\SCMPath", L
"");
42 if (sSCMPath
.IsEmpty())
44 // no path set, so use TortoiseGit as default
45 sSCMPath
= CPathUtils::GetAppDirectory() + L
"TortoiseGitProc.exe";
46 sSCMPath
+= L
" /command:cat /path:\"%1\" /revision:%2 /savepath:\"%3\" /hwnd:%4";
49 sTemp
.Format(L
"%p", (void*)hWnd
);
50 sSCMPath
.Replace(L
"%1", sPath
);
51 sSCMPath
.Replace(L
"%2", sVersion
);
52 sSCMPath
.Replace(L
"%3", sSavePath
);
53 sSCMPath
.Replace(L
"%4", sTemp
);
54 // start the external SCM program to fetch the specific version of the file
55 PROCESS_INFORMATION process
;
56 if (!CCreateProcessHelper::CreateProcess(nullptr, sSCMPath
.GetBuffer(), &process
))
58 CFormatMessageWrapper errorDetails
;
59 MessageBox(nullptr, errorDetails
, L
"TortoiseGitMerge", MB_OK
| MB_ICONERROR
);
65 ret
= WaitForSingleObject(process
.hProcess
, 100);
66 } while ((ret
== WAIT_TIMEOUT
) && (!progDlg
|| !progDlg
->HasUserCancelled()));
67 CloseHandle(process
.hThread
);
68 CloseHandle(process
.hProcess
);
70 if (progDlg
&& progDlg
->HasUserCancelled())
74 if (!PathFileExists(sSavePath
))
79 bool CAppUtils::CreateUnifiedDiff(const CString
& orig
, const CString
& modified
, const CString
& output
, int contextsize
, bool bShowError
)
83 diffContext
.Format(L
"--unified=%d", contextsize
);
85 cmd
.Format(L
"git.exe diff --no-index %s -- \"%s\" \"%s\"", (LPCTSTR
)diffContext
, (LPCTSTR
)orig
, (LPCTSTR
)modified
);
87 int result
= g_Git
.RunLogFile(cmd
, output
, &err
);
88 if (result
!= 0 && result
!= 1 && bShowError
)
90 MessageBox(nullptr, L
"Failed to create patch.\n" + err
, L
"TortoiseGit", MB_OK
| MB_ICONERROR
);
96 bool CAppUtils::HasClipboardFormat(UINT format
)
98 if (OpenClipboard(nullptr))
103 if (enumFormat
== format
)
108 } while((enumFormat
= EnumClipboardFormats(enumFormat
))!=0);
114 COLORREF
CAppUtils::IntenseColor(long scale
, COLORREF col
)
116 // if the color is already dark (gray scale below 127),
117 // then lighten the color by 'scale', otherwise darken it
118 int Gray
= (((int)GetRValue(col
)) + GetGValue(col
) + GetBValue(col
))/3;
121 long red
= MulDiv(GetRValue(col
),(255-scale
),255);
122 long green
= MulDiv(GetGValue(col
),(255-scale
),255);
123 long blue
= MulDiv(GetBValue(col
),(255-scale
),255);
125 return RGB(red
, green
, blue
);
127 long R
= MulDiv(255-GetRValue(col
),scale
,255)+GetRValue(col
);
128 long G
= MulDiv(255-GetGValue(col
),scale
,255)+GetGValue(col
);
129 long B
= MulDiv(255-GetBValue(col
),scale
,255)+GetBValue(col
);