setupfactory.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. #include "./setupfactory.h"
  2. #include <api/service/waservicefactorybase.h>
  3. #include <api/service/services.h>
  4. #include "api.h"
  5. #include "gen.h"
  6. #include "main.h"
  7. #define GUID_DEFINE
  8. #include "./setup.h"
  9. #undef GUID_DEFINE
  10. //#include "./spage_lang.h"
  11. //#include "./spage_connect.h"
  12. #include "./spage_skin.h"
  13. #include "./spage_assoc.h"
  14. //#include "./spage_feedback.h"
  15. #include "./sjob_register.h"
  16. #include <shlwapi.h>
  17. class setup_factory : public waServiceFactory
  18. {
  19. public:
  20. setup_factory();
  21. virtual ~setup_factory();
  22. public:
  23. int AddRef();
  24. int Release();
  25. FOURCC GetServiceType();
  26. const char *GetServiceName();
  27. GUID GetGUID();
  28. void *GetInterface(int global_lock);
  29. int SupportNonLockingInterface();
  30. int ReleaseInterface(void *ifc);
  31. const char *GetTestString();
  32. int ServiceNotify(int msg, int param1, int param2);
  33. private:
  34. int ref;
  35. svc_setup *psvcSetup;
  36. protected:
  37. RECVS_DISPATCH;
  38. };
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif // __cplusplus
  42. BOOL Setup_RegisterService(void)
  43. {
  44. setup_factory *psf = new setup_factory();
  45. WASABI_API_SVC->service_register(psf);
  46. return (0 != psf->Release());
  47. }
  48. int Setup_RegisterDefault(void)
  49. {
  50. waServiceFactory *psf = WASABI_API_SVC->service_getServiceByGuid(UID_SVC_SETUP);
  51. if (!psf) return 0;
  52. svc_setup *pSvc = (svc_setup*)psf->getInterface();
  53. if (pSvc)
  54. {
  55. int index = 0;
  56. ifc_setuppage *pp;
  57. ifc_setupjob *pj;
  58. // pp = new setup_page_lang();
  59. // if (pp) { pSvc->InsertPage(pp, &index); pp->Release(); }
  60. pp = new setup_page_skin();
  61. if (pp) { pSvc->InsertPage(pp, &++index); pp->Release(); }
  62. // pp = new setup_page_connect();
  63. // if (pp) { pSvc->InsertPage(pp, &++index); pp->Release(); }
  64. pp = new setup_page_assoc();
  65. if (pp) { pSvc->InsertPage(pp, &++index); pp->Release(); }
  66. // disabled for 5.66
  67. // pp = new setup_page_feedback();
  68. // if (pp) { pSvc->InsertPage(pp, &++index); pp->Release(); }
  69. pj = new setup_job_register();
  70. if (pj) { pSvc->AddJob(pj); pj->Release(); }
  71. pSvc->Release();
  72. return 1;
  73. }
  74. return 0;
  75. }
  76. int Setup_RegisterPlugins(void)
  77. {
  78. wchar_t dirstr[MAX_PATH] = {0};
  79. WIN32_FIND_DATAW d = {0};
  80. PathCombineW(dirstr, PLUGINDIR, L"GEN_*.DLL");
  81. HANDLE h = FindFirstFileW(dirstr,&d);
  82. if (h != INVALID_HANDLE_VALUE)
  83. {
  84. do
  85. {
  86. wchar_t temp[MAX_PATH] = {0};
  87. PathCombineW(temp, PLUGINDIR, d.cFileName);
  88. HINSTANCE hLib = LoadLibraryW(temp);
  89. if (hLib)
  90. {
  91. winampGeneralPurposePluginGetter pr = (winampGeneralPurposePluginGetter) GetProcAddress(hLib,"winampGetGeneralPurposePlugin");
  92. if (pr)
  93. {
  94. Plugin_RegisterSetup fn = (Plugin_RegisterSetup)GetProcAddress(hLib, "RegisterSetup");
  95. if (NULL == fn || FALSE == fn(hLib, WASABI_API_SVC))
  96. {
  97. winampGeneralPurposePlugin *plugin = pr();
  98. if (plugin && (plugin->version == GPPHDR_VER || plugin->version == GPPHDR_VER_U))
  99. {
  100. char desc[128] = {0};
  101. lstrcpynA(desc, plugin->description, sizeof(desc));
  102. if (desc[0] && !memcmp(desc, "nullsoft(", 9))
  103. {
  104. // we'll let this leak for all 3rd party plug-ins as some crash during
  105. // setup when we try to unload the plug-in e.g gen_Wake_up_call.dll
  106. FreeModule(hLib);
  107. }
  108. }
  109. }
  110. }
  111. }
  112. } while (FindNextFileW(h,&d));
  113. FindClose(h);
  114. }
  115. return 1;
  116. }
  117. #ifdef __cplusplus
  118. }
  119. #endif // __cplusplus
  120. setup_factory::setup_factory() : ref(1), psvcSetup(NULL)
  121. {
  122. }
  123. setup_factory::~setup_factory()
  124. {
  125. if (NULL != psvcSetup)
  126. {
  127. psvcSetup->Release();
  128. }
  129. }
  130. int setup_factory::AddRef(void)
  131. {
  132. return ++ref;
  133. }
  134. int setup_factory::Release(void)
  135. {
  136. if (1 == ref)
  137. {
  138. delete(this);
  139. return 0;
  140. }
  141. return --ref;
  142. }
  143. FOURCC setup_factory::GetServiceType()
  144. {
  145. return WaSvc::UNIQUE;
  146. }
  147. const char *setup_factory::GetServiceName()
  148. {
  149. return "Setup Service";
  150. }
  151. GUID setup_factory::GetGUID()
  152. {
  153. return UID_SVC_SETUP;
  154. }
  155. int setup_factory::SupportNonLockingInterface()
  156. {
  157. return 1;
  158. }
  159. const char *setup_factory::GetTestString()
  160. {
  161. return NULL;
  162. }
  163. int setup_factory::ServiceNotify(int msg, int param1, int param2)
  164. {
  165. switch(msg)
  166. {
  167. case SvcNotify::ONREGISTERED:
  168. AddRef();
  169. break;
  170. case SvcNotify::ONDEREGISTERED:
  171. Release();
  172. break;
  173. }
  174. return 1;
  175. }
  176. void *setup_factory::GetInterface(int global_lock)
  177. {
  178. if (NULL == psvcSetup)
  179. {
  180. psvcSetup = WASetup::CreateInstance();
  181. if (NULL == psvcSetup)
  182. return NULL;
  183. }
  184. psvcSetup->AddRef();
  185. return psvcSetup;
  186. }
  187. int setup_factory::ReleaseInterface(void *ifc)
  188. {
  189. if (ifc == psvcSetup && NULL != psvcSetup)
  190. {
  191. if (0 == psvcSetup->Release())
  192. psvcSetup = NULL;
  193. }
  194. return 1;
  195. }
  196. #ifdef CBCLASS
  197. #undef CBCLASS
  198. #endif
  199. #define CBCLASS setup_factory
  200. START_DISPATCH
  201. CB(ADDREF, AddRef)
  202. CB(RELEASE, Release)
  203. CB(WASERVICEFACTORY_GETSERVICETYPE, GetServiceType)
  204. CB(WASERVICEFACTORY_GETSERVICENAME, GetServiceName)
  205. CB(WASERVICEFACTORY_GETGUID, GetGUID)
  206. CB(WASERVICEFACTORY_GETINTERFACE, GetInterface)
  207. CB(WASERVICEFACTORY_SUPPORTNONLOCKINGGETINTERFACE, SupportNonLockingInterface)
  208. CB(WASERVICEFACTORY_RELEASEINTERFACE, ReleaseInterface)
  209. CB(WASERVICEFACTORY_GETTESTSTRING, GetTestString)
  210. CB(WASERVICEFACTORY_SERVICENOTIFY, ServiceNotify)
  211. END_DISPATCH