This repository has been archived by the owner on Apr 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AIMPCoreWrapper.cpp
158 lines (134 loc) · 5.04 KB
/
AIMPCoreWrapper.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "stdafx.h"
#include "AIMPCoreWrapper.h"
#include "AIMPServiceConfig.h"
#include "apiMessages.h"
#include "apiMUI.h"
AIMPCoreWrapper::AIMPCoreWrapper(IAIMPCore* core) {
aimpCore = core;
aimpCore->AddRef();
}
AIMPCoreWrapper::~AIMPCoreWrapper() {
aimpCore->Release();
aimpCore = nullptr;
}
HRESULT WINAPI AIMPCoreWrapper::QueryInterface(REFIID iid, void** object) {
return aimpCore->QueryInterface(iid, object);
}
HRESULT WINAPI AIMPCoreWrapper::GetPath(int pathId, IAIMPString** value) {
return aimpCore->GetPath(pathId, value);
}
bool AIMPCoreWrapper::RegisterService(IUnknown* service) {
return SUCCEEDED(aimpCore->RegisterService(service));
}
bool AIMPCoreWrapper::CreateObject(REFIID iid, void** object) {
return SUCCEEDED(aimpCore->CreateObject(iid, object));
}
bool AIMPCoreWrapper::GetService(REFIID iid, void** service) {
return SUCCEEDED(aimpCore->QueryInterface(iid, service));
}
bool AIMPCoreWrapper::IsServiceAvailable(REFIID riid) {
IUnknown* dummyService;
if (SUCCEEDED(aimpCore->QueryInterface(riid, (void**)&dummyService))) {
dummyService->Release();
return true;
}
return false;
}
bool AIMPCoreWrapper::RegisterExtension(REFIID iid, IUnknown* extension) {
return SUCCEEDED(aimpCore->RegisterExtension(iid, extension));
}
AIMPServiceConfig* AIMPCoreWrapper::CreateServiceConfig() {
return new AIMPServiceConfig(this);
}
IAIMPString* AIMPCoreWrapper::GetProfilePath() {
IAIMPString* profilePath;
CheckResult(aimpCore->GetPath(AIMP_CORE_PATH_PROFILE, &profilePath), UNABLE_TO_GET_PROFILE_PATH);
return profilePath;
}
IAIMPString* AIMPCoreWrapper::LangGetName() {
IAIMPServiceMUIPtr muiService;
if (GetService(IID_IAIMPServiceMUI, (void**)&muiService)) {
IAIMPString* langName;
muiService->GetName(&langName);
return langName;
}
return MakeString(L"");
}
IAIMPString* AIMPCoreWrapper::LangGetValue(PWCHAR keyPath) {
IAIMPString* value;
if (SUCCEEDED(LangLoadString(keyPath, &value))) {
return value;
}
return MakeString(L"");
}
IAIMPString* AIMPCoreWrapper::LangGetValue(PWCHAR keyPath, int partIndex) {
IAIMPString* value;
if (SUCCEEDED(LangLoadString(keyPath, partIndex, &value))) {
return value;
}
return MakeString(L"");
}
HRESULT AIMPCoreWrapper::MessageDispatcherSend(DWORD message, int param1, void* param2) {
IAIMPServiceMessageDispatcherPtr messageService;
if (GetService(IID_IAIMPServiceMessageDispatcher, (void**)&messageService)) {
messageService->Send(message, param1, param2);
return S_OK;
}
return E_UNEXPECTED;
}
HRESULT AIMPCoreWrapper::MessageDispatcherGetPropValue(int propertyId, void* buffer) {
return MessageDispatcherSend(propertyId, AIMP_MSG_PROPVALUE_GET, buffer);
}
HRESULT AIMPCoreWrapper::MessageDispatcherSetPropValue(int propertyId, void* value) {
return MessageDispatcherSend(propertyId, AIMP_MSG_PROPVALUE_SET, value);
}
HWND AIMPCoreWrapper::MainWindowGetHandle() {
HWND aimpHwnd = 0;
MessageDispatcherGetPropValue(AIMP_MSG_PROPERTY_HWND, &aimpHwnd);
return aimpHwnd;
}
IAIMPString* AIMPCoreWrapper::MakeString(PWCHAR strSeq) {
return MakeString(strSeq, wcslen(strSeq));
}
IAIMPString* AIMPCoreWrapper::MakeString(PWCHAR strSeq, int strSeqLen) {
IAIMPString* string;
CheckResult(aimpCore->CreateObject(IID_IAIMPString, (void**)&string), UNABLE_TO_CREATE_IAIMPSTRING);
CheckResult(string->SetData(strSeq, strSeqLen), UNABLE_TO_CREATE_IAIMPSTRING);
return string;
}
HRESULT AIMPCoreWrapper::MakeString(PWCHAR strSeq, IAIMPString** out) {
return MakeString(strSeq, wcslen(strSeq), out);
}
HRESULT AIMPCoreWrapper::MakeString(PWCHAR strSeq, int strSeqLen, IAIMPString** out) {
HRESULT result = aimpCore->CreateObject(IID_IAIMPString, (void**)out);
if (SUCCEEDED(result)) {
return (*out)->SetData(strSeq, wcslen(strSeq));
}
return result;
}
bool AIMPCoreWrapper::PropListGetStr(IAIMPPropertyList* propList, int propId, IAIMPString** out) {
return SUCCEEDED(propList->GetValueAsObject(propId, IID_IAIMPString, (void**)out));
}
void AIMPCoreWrapper::CheckResult(HRESULT result, PWCHAR message) {
if (FAILED(result)) {
throw message;
}
}
HRESULT AIMPCoreWrapper::LangLoadString(PWCHAR keyPath, IAIMPString** out) {
IAIMPServiceMUIPtr muiService;
if (GetService(IID_IAIMPServiceMUI, (void**)&muiService)) {
IAIMPStringPtr sKeyPath;
MakeString(keyPath, &sKeyPath);
return muiService->GetValue(sKeyPath, out);
}
return E_NOINTERFACE;
}
HRESULT AIMPCoreWrapper::LangLoadString(PWCHAR keyPath, int partIndex, IAIMPString** out) {
IAIMPServiceMUIPtr muiService;
if (GetService(IID_IAIMPServiceMUI, (void**)&muiService)) {
IAIMPStringPtr sKeyPath;
MakeString(keyPath, &sKeyPath);
return muiService->GetValuePart(sKeyPath, partIndex, out);
}
return E_NOINTERFACE;
}