ClipCompare.cpp 4.4 KB

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