aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Portable/pmp_wifi/Pair.cpp
blob: 6eac0e0dadfaae96918148e07caa3b2ec14c2f58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "Pair.h"
#include "api.h"
#include "../../..\Components\wac_network\wac_network_http_receiver_api.h"
#include "main.h"
#include "WifiDevice.h"
#include <strsafe.h>

PairDownloader::PairDownloader(WifiDevice *device) : device(device)
{
	device->AddRef();
}

PairDownloader::~PairDownloader()
{
}

void PairDownloader::OnInit(DownloadToken token)
{
	api_httpreceiver *jnet = WAC_API_DOWNLOADMANAGER->GetReceiver(token);
	if (jnet)
	{
		jnet->AddHeaderValue("X-Winamp-ID", winamp_id_str);
		jnet->AddHeaderValue("X-Winamp-Name", winamp_name);
	}
}

void PairDownloader::OnData(DownloadToken token, void *data, size_t datalen)
{
}

void PairDownloader::OnCancel(DownloadToken token)
{
	device->OnConnectionFailed();
	device->Release();
	Release();
}

void PairDownloader::OnError(DownloadToken token, int error)
{
	api_httpreceiver *jnet = WAC_API_DOWNLOADMANAGER->GetReceiver(token);
	if (jnet)
	{
		jnet->getreplycode();
	}
	device->OnConnectionFailed();
	device->Release();
	Release();
}

void PairDownloader::OnFinish(DownloadToken token)
{
	api_httpreceiver *jnet = WAC_API_DOWNLOADMANAGER->GetReceiver(token);
	if (jnet)
	{
		if (jnet->getreplycode() == 202)
		{
			device->OnPaired();
			device->Release();
			Release();
			return;
		}
	}
	device->OnConnectionFailed();
	device->Release();
	Release();
}

bool IsPaired(uint64_t id)
{
	wchar_t pair_name[64] = {0};
	StringCbPrintfW(pair_name, sizeof(pair_name), L"%016I64x", id);
	if (GetPrivateProfileInt(L"pairs", pair_name, 0, inifile) == 0)
		return false;

	return true;
}

void SetPaired(uint64_t id, bool status)
{
	wchar_t pair_name[64] = {0};
	StringCbPrintfW(pair_name, sizeof(pair_name), L"%016I64x", id);
	if (status)
		WritePrivateProfileString(L"pairs", pair_name, L"1", inifile);
	else
		WritePrivateProfileString(L"pairs", pair_name, L"0", inifile);
	
}