DittoAddins.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include "stdafx.h"
  2. #include ".\dittoaddins.h"
  3. #include "InternetUpdate.h"
  4. #include "CP_Main.h"
  5. CDittoAddins::CDittoAddins(void)
  6. {
  7. }
  8. CDittoAddins::~CDittoAddins(void)
  9. {
  10. UnloadAll();
  11. }
  12. bool CDittoAddins::UnloadAll()
  13. {
  14. Log(StrF(_T("Ditto Addin - Unloading all addins Count: %d"), m_Addins.size()));
  15. INT_PTR count = m_Addins.size();
  16. for(int i = 0; i < count; i++)
  17. {
  18. CDittoAddin *pAddin = m_Addins[i];
  19. if(pAddin)
  20. {
  21. delete pAddin;
  22. pAddin = NULL;
  23. }
  24. }
  25. m_Addins.clear();
  26. return true;
  27. }
  28. bool CDittoAddins::LoadAll()
  29. {
  30. CDittoInfo DittoInfo;
  31. LoadDittoInfo(DittoInfo);
  32. CString csDir = CGetSetOptions::GetPath(PATH_ADDINS);
  33. CFileFind find;
  34. BOOL bCont = find.FindFile(csDir + _T("*.dll"));
  35. while(bCont)
  36. {
  37. bCont = find.FindNextFile();
  38. Log(StrF(_T("Ditto Addin - Trying to load addin file %s"), find.GetFilePath()));
  39. CDittoAddin *pAddin = new CDittoAddin;
  40. if(pAddin->DoLoad(find.GetFilePath(), DittoInfo))
  41. {
  42. Log(StrF(_T("Ditto Addin - Success, loaded addin: %s"), find.GetFilePath()));
  43. m_Addins.push_back(pAddin);
  44. }
  45. else
  46. {
  47. Log(StrF(_T("Ditto Addin - Failed loading Adding Error: %s"), pAddin->LastError()));
  48. delete pAddin;
  49. pAddin = NULL;
  50. }
  51. }
  52. return m_Addins.size() > 0;
  53. }
  54. bool CDittoAddins::AddPrePasteAddinsToMenu(CMenu *pMenu)
  55. {
  56. bool bRet = false;
  57. m_FunctionMap.RemoveAll();
  58. int nMenuId = 3000;
  59. HMENU AllAddinsMenu = ::CreateMenu();
  60. INT_PTR count = m_Addins.size();
  61. for(int i = 0; i < count; i++)
  62. {
  63. CDittoAddin *pAddin = m_Addins[i];
  64. if(pAddin)
  65. {
  66. INT_PTR subCount = pAddin->m_PrePasteFunctions.size();
  67. if(subCount > 1)
  68. {
  69. HMENU AddinMenu = ::CreateMenu();
  70. for(int x = 0; x < subCount; x++)
  71. {
  72. ::AppendMenu(AddinMenu, MF_ENABLED, nMenuId, pAddin->m_PrePasteFunctions[x].m_csDisplayName);
  73. CFunctionLookup lookup;
  74. lookup.m_csFunctionName = pAddin->m_PrePasteFunctions[x].m_csFunction;
  75. lookup.m_pAddin = pAddin;
  76. m_FunctionMap.SetAt(nMenuId, lookup);
  77. nMenuId++;
  78. }
  79. ::AppendMenu(AllAddinsMenu, MF_ENABLED|MF_POPUP, (UINT)AddinMenu, pAddin->DisplayName());
  80. bRet = true;
  81. }
  82. else if(subCount == 1)
  83. {
  84. //If there is only 1 function for this add in then just show one menu with addin name - function
  85. CFunctionLookup lookup;
  86. lookup.m_csFunctionName = pAddin->m_PrePasteFunctions[0].m_csFunction;
  87. lookup.m_pAddin = pAddin;
  88. m_FunctionMap.SetAt(nMenuId, lookup);
  89. CString menuName;
  90. menuName.Format(_T("%s - %s"), pAddin->DisplayName(), pAddin->m_PrePasteFunctions[0].m_csDisplayName);
  91. ::AppendMenu(AllAddinsMenu, MF_ENABLED, nMenuId, menuName);
  92. bRet = true;
  93. nMenuId++;
  94. }
  95. }
  96. }
  97. if(bRet)
  98. {
  99. pMenu->InsertMenu(3, MF_BYPOSITION|MF_ENABLED|MF_STRING|MF_POPUP, (UINT)AllAddinsMenu, theApp.m_Language.GetString("Add_Ins", "Add-Ins"));
  100. }
  101. return bRet;
  102. }
  103. bool CDittoAddins::CallPrePasteFunction(int Id, IClip *pClip)
  104. {
  105. bool bRet = false;
  106. CFunctionLookup func;
  107. if(m_FunctionMap.Lookup(Id, func))
  108. {
  109. CDittoInfo DittoInfo;
  110. LoadDittoInfo(DittoInfo);
  111. bRet = func.m_pAddin->PrePasteFunction(DittoInfo, func.m_csFunctionName, pClip);
  112. }
  113. return bRet;
  114. }
  115. void CDittoAddins::LoadDittoInfo(CDittoInfo &DittoInfo)
  116. {
  117. DittoInfo.m_csDatabasePath = CGetSetOptions::GetDBPath();
  118. DittoInfo.m_csLanguageCode = theApp.m_Language.GetLangCode();
  119. CInternetUpdate update;
  120. DittoInfo.m_nVersion = update.GetRunningVersion();
  121. DittoInfo.m_csSqliteVersion = sqlite3_libversion();
  122. DittoInfo.m_hWndDitto = theApp.QPastehWnd();
  123. }
  124. void CDittoAddins::AboutScreenText(CStringArray &arr)
  125. {
  126. INT_PTR count = m_Addins.size();
  127. for(int i = 0; i < count; i++)
  128. {
  129. CDittoAddin *pAddin = m_Addins[i];
  130. if(pAddin)
  131. {
  132. CString csLine;
  133. csLine.Format(_T("%s Ver: %d, Ver2: %d"), pAddin->DisplayName(), pAddin->Version(), pAddin->PrivateVersion());
  134. arr.Add(csLine);
  135. INT_PTR subCount = pAddin->m_PrePasteFunctions.size();
  136. for(int x = 0; x < subCount; x++)
  137. {
  138. CString csLine2;
  139. csLine2.Format(_T(" %s (%s)"), pAddin->m_PrePasteFunctions[x].m_csDisplayName, pAddin->m_PrePasteFunctions[x].m_csDetailDescription);
  140. arr.Add(csLine2);
  141. }
  142. arr.Add("");
  143. }
  144. }
  145. }