ClipCompare.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 path = GetComparePath();
  34. if(path != _T(""))
  35. {
  36. SHELLEXECUTEINFO sei = { sizeof(sei) };
  37. sei.lpFile = path;
  38. CString csParam;
  39. csParam.Format(_T("\"%s\" \"%s\""), leftFile, rightFile);
  40. sei.lpParameters = csParam;
  41. sei.nShow = SW_NORMAL;
  42. Log(StrF(_T("Comparing two clips, left Id %d, right Id %d, Path: %s %s"), leftId, rightId, path, csParam));
  43. if (!ShellExecuteEx(&sei))
  44. {
  45. }
  46. }
  47. else
  48. {
  49. Log(StrF(_T("CClipCompare::Compare, No Valid compare apps, not doing compare")));
  50. ShellExecute(NULL, _T("open"), _T("http://winmerge.org/"), NULL,NULL, SW_SHOW);
  51. }
  52. }
  53. else
  54. {
  55. Log(StrF(_T("CClipCompare::Compare, did not find valid text for both passed in clips")));
  56. }
  57. }
  58. else
  59. {
  60. Log(StrF(_T("CClipCompare::Compare, Failed to load RIGHT clip formats Id: %d"), rightId));
  61. }
  62. }
  63. else
  64. {
  65. Log(StrF(_T("CClipCompare::Compare, Failed to load LEFT clip formats Id: %d"), leftId));
  66. }
  67. }
  68. CString CClipCompare::GetComparePath()
  69. {
  70. CString path = CGetSetOptions::GetDiffApp();
  71. if(path != _T(""))
  72. {
  73. return path;
  74. }
  75. path = _T("C:\\Program Files (x86)\\Beyond Compare 3\\BCompare.exe");
  76. if(FileExists(path))
  77. {
  78. return path;
  79. }
  80. path = _T("C:\\Program Files\\Beyond Compare 3\\BCompare.exe");
  81. if(FileExists(path))
  82. {
  83. return path;
  84. }
  85. path = _T("C:\\Program Files (x86)\\Beyond Compare 4\\BCompare.exe");
  86. if (FileExists(path))
  87. {
  88. return path;
  89. }
  90. path = _T("C:\\Program Files\\Beyond Compare 4\\BCompare.exe");
  91. if (FileExists(path))
  92. {
  93. return path;
  94. }
  95. path = _T("C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe");
  96. if(FileExists(path))
  97. {
  98. return path;
  99. }
  100. path = _T("C:\\Program Files\\WinMerge\\WinMergeU.exe");
  101. if (FileExists(path))
  102. {
  103. return path;
  104. }
  105. path = _T("C:\\Program Files (x86)\\Araxis\\Araxis Merge\\compare.exe");
  106. if(FileExists(path))
  107. {
  108. return path;
  109. }
  110. path = _T("C:\\Program Files\\Araxis\\Araxis Merge\\compare.exe");
  111. if(FileExists(path))
  112. {
  113. return path;
  114. }
  115. path = _T("C:\\Program Files (x86)\\Perforce\\p4merge.exe");
  116. if (FileExists(path))
  117. {
  118. return path;
  119. }
  120. path = _T("C:\\Program Files\\Perforce\\p4merge.exe");
  121. if (FileExists(path))
  122. {
  123. return path;
  124. }
  125. return _T("");
  126. }
  127. CString CClipCompare::SaveToFile(int id, CClip *pClip, bool saveW, bool SaveA)
  128. {
  129. CString path;
  130. CString pathCompare = CGetSetOptions::GetPath(PATH_CLIP_DIFF);
  131. CString cs;
  132. cs.Format(_T("%sditto_compare_%d.txt"), pathCompare, id);
  133. if(FileExists(cs))
  134. {
  135. for(int i = 0; i < 1000; i++)
  136. {
  137. cs.Format(_T("%sditto_compare_%d.txt"), pathCompare, id);
  138. if(FileExists(cs))
  139. {
  140. path = cs;
  141. break;
  142. }
  143. }
  144. }
  145. else
  146. {
  147. path = cs;
  148. }
  149. if(path != _T("") &&
  150. pClip != NULL)
  151. {
  152. pClip->WriteTextToFile(path, saveW, SaveA, false);
  153. }
  154. return path;
  155. }