1
0

Loader.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "main.h"
  2. #include "api.h"
  3. #include "../winamp/wa_ipc.h"
  4. #include "DownloadStatus.h"
  5. using namespace Nullsoft::Utility;
  6. static WNDPROC wa_oldWndProc=0;
  7. /* protocol must be all lower case */
  8. bool ProtocolMatch(const char *file, const char *protocol)
  9. {
  10. size_t protSize = strlen(protocol);
  11. for (size_t i=0;i!=protSize;i++)
  12. {
  13. if (!file[i]
  14. || tolower(file[i]) != protocol[i])
  15. return false;
  16. }
  17. return true;
  18. }
  19. LRESULT CALLBACK LoaderProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  20. {
  21. #if 0 // not ready to take links yet... too buggy/weird at this point ...
  22. if (uMsg == WM_COPYDATA)
  23. {
  24. COPYDATASTRUCT *copyData = (COPYDATASTRUCT *)lParam;
  25. if (copyData->dwData == IPC_ENQUEUEFILE)
  26. {
  27. const char *file = (const char *)copyData->lpData;
  28. if (ProtocolMatch(file, "feed://"))
  29. {
  30. Channel newFeed;
  31. newFeed.url = AutoWide((const char *)copyData->lpData);
  32. if (DownloadFeedInformation(newFeed)==DOWNLOADRSS_SUCCESS)
  33. {
  34. AutoLock lock(channels);
  35. channels.push_back(newFeed);
  36. }
  37. return 0;
  38. }
  39. else
  40. if (ProtocolMatch(file, "http://"))
  41. {
  42. // nothing for now, we want to do a head request tho
  43. JNL_HTTPGet head;
  44. head.connect(file, 0, "HEAD");
  45. int ret;
  46. do
  47. {
  48. ret = head.run();
  49. Sleep(50);
  50. } while (ret != -1 && ret != 1);
  51. if (ret!=-1)
  52. {
  53. char *contentType = head.getheader("Content-Type");
  54. // if (contentType)
  55. //MessageBoxA(NULL, contentType, contentType, MB_OK);
  56. if (strstr(contentType, "application/rss+xml") == contentType)
  57. {
  58. MessageBox(NULL, L"woo!", L"woo!", MB_OK);
  59. return 0;
  60. }
  61. if (strstr(contentType, "application/xml") == contentType)
  62. {
  63. MessageBox(NULL, L"regular xml", L"application/xml", MB_OK);
  64. return 0;
  65. }
  66. if (strstr(contentType, "text/xml") == contentType)
  67. {
  68. MessageBox(NULL, L"regular xml", L"text/xml", MB_OK);
  69. return 0;
  70. }
  71. }
  72. }
  73. }
  74. }
  75. #endif
  76. if (wa_oldWndProc)
  77. return CallWindowProc(wa_oldWndProc, hwnd, uMsg, wParam, lParam);
  78. else
  79. return 0;
  80. }
  81. void BuildLoader(HWND winampWindow)
  82. {
  83. if (IsWindowUnicode(winampWindow))
  84. wa_oldWndProc=(WNDPROC) SetWindowLongPtrW(winampWindow,GWLP_WNDPROC,(LONG_PTR)LoaderProc);
  85. else
  86. wa_oldWndProc=(WNDPROC) SetWindowLongPtrA(winampWindow,GWLP_WNDPROC,(LONG_PTR)LoaderProc);
  87. }
  88. void DestroyLoader(HWND winampWindow)
  89. {
  90. //if (wa_oldWndProc)
  91. // SetWindowLong(winampWindow,GWL_WNDPROC,(LONG)wa_oldWndProc);
  92. //wa_oldWndProc=0;
  93. }