handler.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "main.h"
  2. #include "handler.h"
  3. #include "../Agave/URIHandler/svc_urihandler.h"
  4. #include <api/service/waservicefactory.h>
  5. #include "api.h"
  6. int HandleFilename(const wchar_t *filename)
  7. {
  8. size_t i=0;
  9. waServiceFactory *sf = 0;
  10. int handled_count=0;
  11. while (NULL != (sf=WASABI_API_SVC->service_enumService(svc_urihandler::getServiceType(), i++)))
  12. {
  13. svc_urihandler *handler = (svc_urihandler *)sf->getInterface();
  14. if (handler)
  15. {
  16. int ret = handler->ProcessFilename(filename);
  17. sf->releaseInterface(handler);
  18. if (ret == svc_urihandler::HANDLED)
  19. handled_count++;
  20. else if (ret == svc_urihandler::HANDLED_EXCLUSIVE)
  21. return svc_urihandler::HANDLED;
  22. }
  23. }
  24. return handled_count?svc_urihandler::HANDLED:svc_urihandler::NOT_HANDLED;
  25. }
  26. int WinampURIHandler::ProcessFilename(const wchar_t *filename)
  27. {
  28. //MessageBoxW(NULL, filename, L"oi", MB_OK);
  29. return NOT_HANDLED;
  30. }
  31. int WinampURIHandler::IsMine(const wchar_t *filename)
  32. {
  33. if (CompareStringW(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE, filename, (int)wcsnlen(filename, 9), L"winamp://", 9) == CSTR_EQUAL)
  34. return HANDLED;
  35. else
  36. return NOT_HANDLED;
  37. }
  38. int WinampURIHandler::EnumProtocols(size_t n, wchar_t *protocol, size_t protocolCch, wchar_t *description, size_t descriptionCch)
  39. {
  40. switch(n)
  41. {
  42. case 0:
  43. StringCchCopyW(protocol, protocolCch, L"winamp");
  44. StringCchCopyW(description, descriptionCch, L"Winamp Command Handler");
  45. return 0;
  46. default:
  47. return 1;
  48. }
  49. }
  50. int WinampURIHandler::RegisterProtocol(const wchar_t *protocol, const wchar_t *winampexe)
  51. {
  52. return 1;
  53. IFileTypeRegistrar *registrar=0;
  54. if (GetRegistrar(&registrar, true) == 0 && registrar)
  55. {
  56. wchar_t str[MAX_PATH+32] = {0};
  57. StringCchPrintfW(str,MAX_PATH+32,L"\"%s\" /HANDLE \"%%1\"",winampexe);
  58. wchar_t icon[MAX_PATH+32] = {0};
  59. StringCchPrintfW(icon,MAX_PATH+32,L"\"%s\",%d",winampexe, config_whichicon);
  60. registrar->RegisterProtocol(L"winamp", str, icon);
  61. registrar->Release();
  62. return 0;
  63. }
  64. return 1;
  65. }
  66. int WinampURIHandler::UnregisterProtocol(const wchar_t *protocol)
  67. {
  68. // TODO:
  69. return 1;
  70. }
  71. #define CBCLASS WinampURIHandler
  72. START_DISPATCH;
  73. CB(PROCESSFILENAME, ProcessFilename);
  74. CB(ISMINE, IsMine);
  75. CB(ENUMPROTOCOLS, EnumProtocols);
  76. CB(REGISTERPROTOCOL, RegisterProtocol);
  77. CB(UNREGISTERPROTOCOL, UnregisterProtocol);
  78. END_DISPATCH;
  79. #undef CBCLASS