Fixed issue #1507: Submodule Diff Dialog should show dirty state only on working...
[TortoiseGit.git] / src / TortoiseMerge / AppUtils.cpp
blob8aa782555a6488f9d5298c573db7a2843ee62947
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.
20 #include "StdAfx.h"
21 #include "Registry.h"
22 #include "AppUtils.h"
23 #include "PathUtils.h"
24 #include "UnicodeUtils.h"
25 #include "SysProgressDlg.h"
27 #pragma warning(push)
28 #include "svn_pools.h"
29 #include "svn_io.h"
30 #include "svn_path.h"
31 #include "svn_diff.h"
32 #include "svn_string.h"
33 #include "svn_utf.h"
34 #pragma warning(pop)
35 #include "git.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");
56 CString sTemp;
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);
68 return FALSE;
70 DWORD ret = 0;
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())
80 return FALSE;
82 if (!PathFileExists(sSavePath))
83 return FALSE;
84 return TRUE;
87 bool CAppUtils::CreateUnifiedDiff(const CString& orig, const CString& modified, const CString& output, bool bShowError)
89 CString cmd;
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);
95 return false;
97 return true;
100 bool CAppUtils::HasClipboardFormat(UINT format)
102 if (OpenClipboard(NULL))
104 UINT enumFormat = 0;
107 if (enumFormat == format)
109 CloseClipboard();
110 return true;
112 } while((enumFormat = EnumClipboardFormats(enumFormat))!=0);
113 CloseClipboard();
115 return false;