/
ClipCompare.cpp
158 lines (133 loc) · 3 KB
/
ClipCompare.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "stdafx.h"
#include "ClipCompare.h"
#include "Misc.h"
#include "Options.h"
CClipCompare::CClipCompare(void)
{
}
CClipCompare::~CClipCompare(void)
{
}
void CClipCompare::Compare(int leftId, int rightId)
{
CClip leftClip;
if(leftClip.LoadFormats(leftId, true))
{
CClip rightClip;
if(rightClip.LoadFormats(rightId, true))
{
bool saveW = true;
bool saveA = true;
if(leftClip.GetUnicodeTextFormat() == _T("") || rightClip.GetUnicodeTextFormat() == _T(""))
{
saveW = false;
}
if(leftClip.GetCFTextTextFormat() == "" || rightClip.GetCFTextTextFormat() == "")
{
saveA = false;
}
if(saveW || saveA)
{
CString leftFile = SaveToFile(leftId, &leftClip, saveW, saveA);
CString rightFile = SaveToFile(rightId, &rightClip, saveW, saveA);
CString path = GetComparePath();
if(path != _T(""))
{
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.lpFile = path;
CString csParam;
csParam.Format(_T("%s %s"), leftFile, rightFile);
sei.lpParameters = csParam;
sei.nShow = SW_NORMAL;
Log(StrF(_T("Comparing two clips, left Id %d, right Id %d, Path: %s %s"), leftId, rightId, path, csParam));
if (!ShellExecuteEx(&sei))
{
}
}
else
{
Log(StrF(_T("CClipCompare::Compare, No Valid compare apps, not doing compare")));
ShellExecute(NULL, _T("open"), _T("http://winmerge.org/"), NULL,NULL, SW_SHOW);
}
}
else
{
Log(StrF(_T("CClipCompare::Compare, did not find valid text for both passed in clips")));
}
}
else
{
Log(StrF(_T("CClipCompare::Compare, Failed to load RIGHT clip formats Id: %d"), rightId));
}
}
else
{
Log(StrF(_T("CClipCompare::Compare, Failed to load LEFT clip formats Id: %d"), leftId));
}
}
CString CClipCompare::GetComparePath()
{
CString path = CGetSetOptions::GetDiffApp();
if(path != _T(""))
{
return path;
}
path = _T("C:\\Program Files (x86)\\Beyond Compare 3\\BCompare.exe");
if(FileExists(path))
{
return path;
}
path = _T("C:\\Program Files\\Beyond Compare 3\\BCompare.exe");
if(FileExists(path))
{
return path;
}
path = _T("C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe");
if(FileExists(path))
{
return path;
}
path = _T("C:\\Program Files (x86)\\Araxis\\Araxis Merge\\compare.exe");
if(FileExists(path))
{
return path;
}
path = _T("C:\\Program Files\\Araxis\\Araxis Merge\\compare.exe");
if(FileExists(path))
{
return path;
}
return _T("");
}
CString CClipCompare::SaveToFile(int id, CClip *pClip, bool saveW, bool SaveA)
{
CString path;
wchar_t wchPath[MAX_PATH];
if (GetTempPathW(MAX_PATH, wchPath))
{
CString cs;
cs.Format(_T("%sditto_compare_%d.txt"), wchPath, id);
if(FileExists(cs))
{
for(int i = 0; i < 1000; i++)
{
cs.Format(_T("%sditto_compare_%d.txt"), wchPath, id);
if(FileExists(cs))
{
path = cs;
break;
}
}
}
else
{
path = cs;
}
if(path != _T("") &&
pClip != NULL)
{
pClip->WriteTextToFile(path, saveW, SaveA, false);
}
}
return path;
}