Pair.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "Pair.h"
  2. #include "api.h"
  3. #include "../../..\Components\wac_network\wac_network_http_receiver_api.h"
  4. #include "main.h"
  5. #include "WifiDevice.h"
  6. #include <strsafe.h>
  7. PairDownloader::PairDownloader(WifiDevice *device) : device(device)
  8. {
  9. device->AddRef();
  10. }
  11. PairDownloader::~PairDownloader()
  12. {
  13. }
  14. void PairDownloader::OnInit(DownloadToken token)
  15. {
  16. api_httpreceiver *jnet = WAC_API_DOWNLOADMANAGER->GetReceiver(token);
  17. if (jnet)
  18. {
  19. jnet->AddHeaderValue("X-Winamp-ID", winamp_id_str);
  20. jnet->AddHeaderValue("X-Winamp-Name", winamp_name);
  21. }
  22. }
  23. void PairDownloader::OnData(DownloadToken token, void *data, size_t datalen)
  24. {
  25. }
  26. void PairDownloader::OnCancel(DownloadToken token)
  27. {
  28. device->OnConnectionFailed();
  29. device->Release();
  30. Release();
  31. }
  32. void PairDownloader::OnError(DownloadToken token, int error)
  33. {
  34. api_httpreceiver *jnet = WAC_API_DOWNLOADMANAGER->GetReceiver(token);
  35. if (jnet)
  36. {
  37. jnet->getreplycode();
  38. }
  39. device->OnConnectionFailed();
  40. device->Release();
  41. Release();
  42. }
  43. void PairDownloader::OnFinish(DownloadToken token)
  44. {
  45. api_httpreceiver *jnet = WAC_API_DOWNLOADMANAGER->GetReceiver(token);
  46. if (jnet)
  47. {
  48. if (jnet->getreplycode() == 202)
  49. {
  50. device->OnPaired();
  51. device->Release();
  52. Release();
  53. return;
  54. }
  55. }
  56. device->OnConnectionFailed();
  57. device->Release();
  58. Release();
  59. }
  60. bool IsPaired(uint64_t id)
  61. {
  62. wchar_t pair_name[64] = {0};
  63. StringCbPrintfW(pair_name, sizeof(pair_name), L"%016I64x", id);
  64. if (GetPrivateProfileInt(L"pairs", pair_name, 0, inifile) == 0)
  65. return false;
  66. return true;
  67. }
  68. void SetPaired(uint64_t id, bool status)
  69. {
  70. wchar_t pair_name[64] = {0};
  71. StringCbPrintfW(pair_name, sizeof(pair_name), L"%016I64x", id);
  72. if (status)
  73. WritePrivateProfileString(L"pairs", pair_name, L"1", inifile);
  74. else
  75. WritePrivateProfileString(L"pairs", pair_name, L"0", inifile);
  76. }